MathTL
|
00001 // -*- c++ -*- 00002 00003 // +--------------------------------------------------------------------+ 00004 // | This file is part of MathTL - the Mathematical Template Library | 00005 // | | 00006 // | Copyright (c) 2002-2009 | 00007 // | Thorsten Raasch, Manuel Werner | 00008 // +--------------------------------------------------------------------+ 00009 00010 #ifndef _MATHTL_CHART_H 00011 #define _MATHTL_CHART_H 00012 00013 #include <iostream> 00014 #include <string> 00015 #include <algebra/matrix.h> 00016 #include <algebra/vector.h> 00017 #include <geometry/point.h> 00018 #include <utils/fixed_array1d.h> 00019 00020 using std::string; 00021 00022 namespace MathTL 00023 { 00029 template <unsigned int DIM_d, unsigned int DIM_m = DIM_d> 00030 class Chart 00031 { 00032 public: 00034 virtual ~Chart() {} 00035 00039 virtual void map_point(const Point<DIM_d>& x, Point<DIM_m>& y) const = 0; 00040 00045 virtual double map_point(const double, const int) const = 0; 00046 00050 virtual void map_point_inv(const Point<DIM_m>& x, Point<DIM_d>& y) const = 0; 00051 00056 virtual double map_point_inv(const double, const int) const = 0; 00057 00062 virtual const double Gram_factor(const Point<DIM_d>& x) const = 0; 00063 00068 virtual const double Gram_D_factor(const unsigned int i, 00069 const Point<DIM_d>& x) const = 0; 00070 00074 virtual const double Dkappa_inv(const unsigned int i, 00075 const unsigned int j, 00076 const Point<DIM_d>& x) const = 0; 00077 00082 virtual const double a_i(const int i) const = 0; 00083 00088 virtual const bool in_patch(const Point<DIM_m>& x) const = 0; 00089 00093 virtual const string to_string() const = 0; 00094 }; 00095 00097 template <unsigned int DIM_d, unsigned int DIM_m> 00098 std::ostream& operator << (std::ostream& s, const Chart<DIM_d,DIM_m>&); 00099 00100 // 00101 // Some examples: 00102 00106 template <unsigned int DIM> 00107 class AffineLinearMapping 00108 : public Chart<DIM,DIM> 00109 { 00110 public: 00112 AffineLinearMapping(); 00113 00115 AffineLinearMapping(const Matrix<double>& A, const Point<DIM>& b); 00116 00117 virtual ~AffineLinearMapping() {} 00118 00119 void map_point(const Point<DIM>&, Point<DIM>&) const; 00120 double map_point(const double, const int) const; 00121 00122 void map_point_inv(const Point<DIM>&, Point<DIM>&) const; 00123 double map_point_inv(const double, const int) const; 00124 00125 const double Gram_factor(const Point<DIM>&) const; 00126 const double Gram_D_factor(const unsigned int i, const Point<DIM>& x) const; 00127 const double Dkappa_inv(const unsigned int i, const unsigned int j, 00128 const Point<DIM>& x) const; 00129 const bool in_patch(const Point<DIM>& x) const; 00130 00131 const double a_i(const int i) const { return A_(i,i); }; 00132 00133 00134 const string to_string() const; 00135 00139 static const string className; 00140 00142 const Matrix<double>& A() const { return A_; } 00143 00145 const Point<DIM>& b() const { return b_; } 00146 00147 protected: 00148 Matrix<double> A_, A_inv; 00149 double det_A; 00150 double square_root_of_abs_det_A; 00151 Point<DIM> b_; 00152 }; 00153 00156 template <unsigned int DIM> 00157 class SimpleAffineLinearMapping 00158 : public Chart<DIM,DIM> 00159 { 00160 public: 00161 virtual ~SimpleAffineLinearMapping() {}; 00162 00163 00165 SimpleAffineLinearMapping(); 00166 00168 SimpleAffineLinearMapping(const FixedArray1D<double,DIM>& A, const Point<DIM>& b); 00169 00170 void map_point(const Point<DIM>&, Point<DIM>&) const; 00171 double map_point(const double, const int) const {return 0.;};// dummy; 00172 00173 void map_point_inv(const Point<DIM>&, Point<DIM>&) const; 00174 double map_point_inv(const double, const int) const {return 0.;};// dummy 00175 00176 const double Gram_factor(const Point<DIM>&) const; 00177 const double Gram_D_factor(const unsigned int i, const Point<DIM>& x) const; 00178 const double Dkappa_inv(const unsigned int i, const unsigned int j, 00179 const Point<DIM>& x) const; 00180 const bool in_patch(const Point<DIM>& x) const; 00181 00182 const double a_i(const int i) const { return A_[i]; }; 00183 00184 const string to_string() const; 00185 00189 static const string className; 00190 00192 const FixedArray1D<double,DIM>& A() const { return A_; } 00193 00195 const Point<DIM>& b() const { return b_; } 00196 00197 protected: 00198 FixedArray1D<double,DIM> A_, A_inv; 00199 double det_A; 00200 double square_root_of_abs_det_A; 00201 Point<DIM> b_; 00202 00203 00204 }; 00205 00216 class LinearBezierMapping : public Chart<2,2> 00217 { 00218 00219 public: 00223 LinearBezierMapping (); 00224 00228 LinearBezierMapping (const LinearBezierMapping&); 00229 00233 LinearBezierMapping (const Point<2> &, const Point<2> &, 00234 const Point<2> &, const Point<2> &); 00235 00239 ~LinearBezierMapping () {}; 00240 00244 LinearBezierMapping& operator = (const LinearBezierMapping& x); 00245 00253 void setup (); 00254 00258 const Point<2>& get_b_00() const; 00259 const Point<2>& get_b_01() const; 00260 const Point<2>& get_b_10() const; 00261 const Point<2>& get_b_11() const; 00262 00263 void map_point(const Point<2>&, Point<2>&) const; 00264 double map_point(const double, const int) const {return 0.;};// dummy; 00265 00266 void map_point_inv(const Point<2>&, Point<2>&) const; 00267 double map_point_inv(const double, const int) const {return 0.;};// dummy; 00268 00269 const double Gram_factor(const Point<2>& x) const; 00270 const double Gram_D_factor(const unsigned int i, const Point<2>& x) const; 00271 const double Dkappa_inv(const unsigned int i, const unsigned int j, 00272 const Point<2>& x) const; 00273 const bool in_patch(const Point<2>& x) const; 00274 00275 const double a_i(const int i) const { return 0.; }; 00276 00277 const string to_string() const; 00278 00282 static const string className; 00283 00284 //vertices of the quadrangle to parametrize 00285 Point<2> b_00; 00286 Point<2> b_01; 00287 Point<2> b_10; 00288 Point<2> b_11; 00289 00290 private: 00291 //the following two routines are helpers that are only of interest 00292 //in this special 2D BezierMapping case! 00293 //only for the special case of LinearBezierMapping 00294 const double det_DKappa(const Point<2>& p) const; 00295 00296 //partial derivative with respect to i-th component 00297 //of j-th component of Kappa 00298 const double partial_i_Kappa_j(const unsigned int i, 00299 const unsigned int j, 00300 const Point<2>& x) const; 00301 00302 //vertices of generic qudrangle, needed for inverting this mapping, 00303 //initialized in constructor 00304 Point<2> b_gen_00; 00305 Point<2> b_gen_10; 00306 Point<2> b_gen_01; 00307 Point<2> b_gen_11; 00308 00309 Vector<double> d_ds_d_dt_kappa_r; 00310 Vector<double> d_dt_d_ds_kappa_r; 00311 00312 Vector<double> min_b00_plus_b10; 00313 Vector<double> min_b00_plus_b01; 00314 00315 //some quantities, worth storing to prevent dispensable recomutation 00316 double cos_rot_angle; 00317 double sin_rot_angle; 00318 double rot_angle; 00319 double shearing_param; 00320 double scaleX; 00321 double scaleY; 00322 00323 //signum of det( D (mapPoint(x,y) ) ) 00324 //identical for all (x,y)! 00325 bool sgn_det_D; 00326 00327 00328 }; 00329 } 00330 00331 #include "geometry/chart.cpp" 00332 00333 #endif