• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/export/development/ViennaMath/viennamath/manipulation/apply_coordinate_system.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_MANIPULATION_APPLY_COORDINATE_SYSTEM_HPP
00002 #define VIENNAMATH_MANIPULATION_APPLY_COORDINATE_SYSTEM_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2012, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008                              -----------------
00009                ViennaMath - Symbolic and Numerical Math in C++
00010                              -----------------
00011 
00012    Author:     Karl Rupp                          rupp@iue.tuwien.ac.at
00013 
00014    License:    MIT (X11), see file LICENSE in the ViennaMath base directory
00015 ======================================================================= */
00016 
00017 
00018 
00019 
00020 #include "viennamath/forwards.h"
00021 #include "viennamath/manipulation/detail/unary_operations.hpp"
00022 #include "viennamath/manipulation/substitute.hpp"
00023 #include "viennamath/manipulation/diff.hpp"
00024 #include "viennamath/runtime/equation.hpp"
00025 #include "viennamath/runtime/function_symbol.hpp"
00026 
00031 namespace viennamath
00032 {
00033   
00038   template <typename InterfaceType>
00039   rt_expr<InterfaceType> apply_coordinate_system(cartesian<1>, rt_expr<InterfaceType> const & ex)
00040   {
00041     rt_function_symbol<InterfaceType> u(0, unknown_tag<>());
00042     rt_function_symbol<InterfaceType> v(0, test_tag<>());
00043     rt_variable<InterfaceType> x(0);
00044     
00045     //replace grad:
00046     rt_expr<InterfaceType> new_ex = ex;
00047     rt_expr<InterfaceType> new_ex1(substitute(grad(u), diff(u, x), new_ex) );
00048     rt_expr<InterfaceType> new_ex2(substitute(grad(v), diff(v, x), new_ex1) );
00049     
00050     //replace div:
00051     rt_expr<InterfaceType> new_ex3(substitute(div(u), diff(u, x), new_ex2) );
00052     rt_expr<InterfaceType> new_ex4(substitute(div(v), diff(v, x), new_ex3) );
00053     
00054     return new_ex4;
00055   }
00056 
00057 
00062   template <typename InterfaceType>
00063   rt_expr<InterfaceType> apply_coordinate_system(cartesian<1>, rt_unary_expr<InterfaceType> const & ex)
00064   {
00065     rt_expr<InterfaceType> temp(ex);
00066     return apply_coordinate_system(cartesian<1>(), temp);
00067   }
00068 
00073   template <typename InterfaceType>
00074   rt_expr<InterfaceType> apply_coordinate_system(cartesian<1>, rt_binary_expr<InterfaceType> const & ex)
00075   {
00076     rt_expr<InterfaceType> temp(ex);
00077     return apply_coordinate_system(cartesian<1>(), temp);
00078   }
00079   
00080   
00081   /********* 2d *********/
00082 
00087   template <typename InterfaceType>
00088   rt_expr<InterfaceType> apply_coordinate_system(cartesian<2>, rt_expr<InterfaceType> const & ex)
00089   {
00090     rt_function_symbol<InterfaceType> u(0, unknown_tag<>());
00091     rt_function_symbol<InterfaceType> v(0, test_tag<>());
00092     rt_variable<InterfaceType> x(0);
00093     rt_variable<InterfaceType> y(1);
00094     
00095     rt_vector_expr<InterfaceType> grad_u(2);
00096     grad_u[0] = diff(u, x);
00097     grad_u[1] = diff(u, y);
00098 
00099     rt_vector_expr<InterfaceType> grad_v(2);
00100     grad_v[0] = diff(v, x);
00101     grad_v[1] = diff(v, y);
00102     
00103     //replace grad:
00104     rt_expr<InterfaceType> new_ex1(substitute(grad(u), grad_u, ex) );
00105     rt_expr<InterfaceType> new_ex2(substitute(grad(v), grad_v, new_ex1) );
00106     
00107     //replace div:
00108     rt_expr<InterfaceType> new_ex3(substitute(div(u), diff(u, x) + diff(u, y), new_ex2) );
00109     rt_expr<InterfaceType> new_ex4(substitute(div(v), diff(v, x) + diff(v, y), new_ex3) );
00110     
00111     return new_ex4;
00112   }
00113   
00118   template <typename InterfaceType>
00119   rt_expr<InterfaceType> apply_coordinate_system(cartesian<2>, rt_unary_expr<InterfaceType> const & ex)
00120   {
00121     rt_expr<InterfaceType> temp(ex);
00122     return apply_coordinate_system(cartesian<2>(), temp);
00123   }
00124 
00129   template <typename InterfaceType>
00130   rt_expr<InterfaceType> apply_coordinate_system(cartesian<2>, rt_binary_expr<InterfaceType> const & ex)
00131   {
00132     rt_expr<InterfaceType> temp(ex);
00133     return apply_coordinate_system(cartesian<2>(), temp);
00134   }
00135 
00136 
00137   /******** 3d ***********/
00138 
00143   template <typename InterfaceType>
00144   rt_expr<InterfaceType> apply_coordinate_system(cartesian<3>, rt_expr<InterfaceType> const & ex)
00145   {
00146     rt_function_symbol<InterfaceType> u(0, unknown_tag<>());
00147     rt_function_symbol<InterfaceType> v(0, test_tag<>());
00148     rt_variable<InterfaceType> x(0);
00149     rt_variable<InterfaceType> y(1);
00150     rt_variable<InterfaceType> z(2);
00151     
00152     rt_vector_expr<InterfaceType> grad_u(3);
00153     grad_u[0] = diff(u, x);
00154     grad_u[1] = diff(u, y);
00155     grad_u[2] = diff(u, z);
00156 
00157     rt_vector_expr<InterfaceType> grad_v(3);
00158     grad_v[0] = diff(v, x);
00159     grad_v[1] = diff(v, y);
00160     grad_v[2] = diff(v, z);
00161     
00162     //replace grad:
00163     rt_expr<InterfaceType> new_ex1(substitute(grad(u), grad_u, ex) );
00164     rt_expr<InterfaceType> new_ex2(substitute(grad(v), grad_v, new_ex1) );
00165     
00166     //replace div:
00167     rt_expr<InterfaceType> new_ex3(substitute(div(u), diff(u, x) + diff(u, y) + diff(u, z), new_ex2) );
00168     rt_expr<InterfaceType> new_ex4(substitute(div(v), diff(v, x) + diff(v, y) + diff(v, z), new_ex3) );
00169     
00170     return new_ex4;
00171   }
00172   
00177   template <typename InterfaceType>
00178   rt_expr<InterfaceType> apply_coordinate_system(cartesian<3>, rt_unary_expr<InterfaceType> const & ex)
00179   {
00180     rt_expr<InterfaceType> temp(ex);
00181     return apply_coordinate_system(cartesian<3>(), temp);
00182   }
00183 
00188   template <typename InterfaceType>
00189   rt_expr<InterfaceType> apply_coordinate_system(cartesian<3>, rt_binary_expr<InterfaceType> const & ex)
00190   {
00191     rt_expr<InterfaceType> temp(ex);
00192     return apply_coordinate_system(cartesian<3>(), temp);
00193   }
00194   
00195   
00196   //TODO: more and better compile time derivation
00197   
00198   
00199   
00200   
00201 
00202 
00203   //tries to automatically derive the weak formulation from the strong formulation
00205   template <typename InterfaceType, id_type dim>
00206   rt_equation<InterfaceType> apply_coordinate_system(cartesian<dim>,
00207                                                      rt_equation<InterfaceType> const & equ)
00208   {
00209     return rt_equation<InterfaceType>( apply_coordinate_system(cartesian<dim>(), equ.lhs()),
00210                                        apply_coordinate_system(cartesian<dim>(), equ.rhs())
00211                                      );
00212   }
00213 
00214 }
00215 
00216 #endif

Generated on Wed Feb 29 2012 21:50:43 for ViennaMath by  doxygen 1.7.1