- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_ALU2DGRIDGEOMETRY_HH 00002 #define DUNE_ALU2DGRIDGEOMETRY_HH 00003 00004 // Dune includes 00005 #include <dune/common/misc.hh> 00006 #include <dune/grid/common/grid.hh> 00007 #include <dune/grid/genericgeometry/topologytypes.hh> 00008 00009 #include <dune/grid/alugrid/2d/alu2dinclude.hh> 00010 #include <dune/grid/alugrid/3d/mappings.hh> 00011 00012 namespace Dune 00013 { 00014 00015 // Forward declarations 00016 template<int cd, int dim, class GridImp> 00017 class ALU2dGridEntity; 00018 template<int cd, class GridImp > 00019 class ALU2dGridEntityPointer; 00020 template<int mydim, int cdim, class GridImp> 00021 class ALU2dGridGeometry; 00022 template< int dim, int dimworld, ALU2DSPACE ElementType eltype > 00023 class ALU2dGrid; 00024 00025 00026 template< int mydim, int cdim, ALU2DSPACE ElementType eltype > 00027 class MyALU2dGridGeometryImpl; 00028 00029 // geometry implementation for vertices 00030 template< int cdim, ALU2DSPACE ElementType eltype > 00031 class MyALU2dGridGeometryImpl< 0, cdim, eltype > 00032 { 00033 typedef LinearMapping< cdim, 0 > MappingType; 00034 00035 typedef typename MappingType::ctype ctype; 00036 00037 typedef typename MappingType::map_t map_t; 00038 typedef typename MappingType::world_t world_t; 00039 00040 typedef typename MappingType::matrix_t matrix_t; 00041 typedef typename MappingType::inv_t inv_t; 00042 00043 MappingType mapping_; 00044 00045 public: 00046 bool affine() const 00047 { 00048 return mapping_.affine(); 00049 } 00050 00051 int corners () const 00052 { 00053 return 1; 00054 } 00055 00056 GeometryType type () const 00057 { 00058 return GeometryType( 00059 (eltype == ALU2DSPACE triangle ? 00060 GenericGeometry :: SimplexTopology< 0 > :: type :: id : 00061 GenericGeometry :: CubeTopology < 0 > :: type :: id), 00062 0 ); 00063 } 00064 00065 void map2world ( const map_t &m, world_t &w ) const 00066 { 00067 return mapping_.map2world( m, w ); 00068 } 00069 00070 void world2map ( const world_t &w, map_t &m ) const 00071 { 00072 return mapping_.world2map( w, m ); 00073 } 00074 00075 const matrix_t &jacobianTransposed ( const map_t &m ) const 00076 { 00077 return mapping_.jacobianTransposed( m ); 00078 } 00079 00080 const inv_t &jacobianInverseTransposed ( const map_t &m ) const 00081 { 00082 return mapping_.jacobianInverseTransposed( m ); 00083 } 00084 00085 ctype det ( const map_t &m ) const 00086 { 00087 return mapping_.det( m ); 00088 } 00089 00090 // update geometry coordinates 00091 template< class Vector > 00092 void update ( const Vector &p0 ) 00093 { 00094 mapping_.buildMapping( p0 ); 00095 } 00096 }; 00097 00098 // geometry implementation for lines 00099 template< int cdim, ALU2DSPACE ElementType eltype > 00100 class MyALU2dGridGeometryImpl< 1, cdim, eltype > 00101 { 00102 static const int ncorners = 2; 00103 00104 typedef LinearMapping< cdim, 1 > MappingType; 00105 00106 typedef typename MappingType::ctype ctype; 00107 00108 typedef typename MappingType::map_t map_t; 00109 typedef typename MappingType::world_t world_t; 00110 00111 typedef typename MappingType::matrix_t matrix_t; 00112 typedef typename MappingType::inv_t inv_t; 00113 00114 MappingType mapping_; 00115 00116 public: 00117 bool affine() const 00118 { 00119 return mapping_.affine(); 00120 } 00121 00122 int corners () const 00123 { 00124 return ncorners; 00125 } 00126 00127 GeometryType type () const 00128 { 00129 return GeometryType( 00130 (eltype == ALU2DSPACE triangle ? 00131 GenericGeometry :: SimplexTopology< 1 > :: type :: id : 00132 GenericGeometry :: CubeTopology < 1 > :: type :: id), 00133 1 ); 00134 } 00135 00136 void map2world ( const map_t &m, world_t &w ) const 00137 { 00138 return mapping_.map2world( m, w ); 00139 } 00140 00141 void world2map ( const world_t &w, map_t &m ) const 00142 { 00143 return mapping_.world2map( w, m ); 00144 } 00145 00146 const matrix_t &jacobianTransposed ( const map_t &m ) const 00147 { 00148 return mapping_.jacobianTransposed( m ); 00149 } 00150 00151 const inv_t &jacobianInverseTransposed ( const map_t &m ) const 00152 { 00153 return mapping_.jacobianInverseTransposed( m ); 00154 } 00155 00156 ctype det ( const map_t &m ) const 00157 { 00158 return mapping_.det( m ); 00159 } 00160 00161 // update geometry in father coordinates 00162 template< class Geo, class LocalGeo > 00163 void updateLocal ( const Geo &geo, const LocalGeo &localGeo ) 00164 { 00165 assert( localGeo.corners() == ncorners ); 00166 // compute the local coordinates in father refelem 00167 FieldMatrix< alu2d_ctype, ncorners, cdim > coord; 00168 for( int i = 0; i < ncorners; ++i ) 00169 { 00170 // calculate coordinate 00171 coord[ i ] = geo.local( localGeo.corner( i ) ); 00172 // to avoid rounding errors 00173 for( int j = 0; j < cdim; ++j ) 00174 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]); 00175 } 00176 mapping_.buildMapping( coord[ 0 ], coord[ 1 ] ); 00177 } 00178 00179 // update geometry coordinates 00180 template< class Vector > 00181 void update ( const Vector &p0, const Vector &p1 ) 00182 { 00183 mapping_.buildMapping( p0, p1 ); 00184 } 00185 }; 00186 00187 // geometry implementation for triangles 00188 template< int cdim > 00189 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE triangle > 00190 { 00191 static const int ncorners = 3; 00192 00193 typedef LinearMapping< cdim, 2 > MappingType; 00194 00195 typedef typename MappingType::ctype ctype; 00196 00197 typedef typename MappingType::map_t map_t; 00198 typedef typename MappingType::world_t world_t; 00199 00200 typedef typename MappingType::matrix_t matrix_t; 00201 typedef typename MappingType::inv_t inv_t; 00202 00203 MappingType mapping_; 00204 00205 public: 00206 bool affine () const 00207 { 00208 return mapping_.affine(); 00209 } 00210 00211 int corners () const 00212 { 00213 return ncorners; 00214 } 00215 00216 GeometryType type () const 00217 { 00218 return GeometryType( GenericGeometry :: SimplexTopology< 2 > :: type :: id , 2 ); 00219 } 00220 00221 void map2world ( const map_t &m, world_t &w ) const 00222 { 00223 return mapping_.map2world( m, w ); 00224 } 00225 00226 void world2map ( const world_t &w, map_t &m ) const 00227 { 00228 return mapping_.world2map( w, m ); 00229 } 00230 00231 const matrix_t &jacobianTransposed ( const map_t &m ) const 00232 { 00233 return mapping_.jacobianTransposed( m ); 00234 } 00235 00236 const inv_t &jacobianInverseTransposed ( const map_t &m ) const 00237 { 00238 return mapping_.jacobianInverseTransposed( m ); 00239 } 00240 00241 ctype det ( const map_t &m ) const 00242 { 00243 return mapping_.det( m ); 00244 } 00245 00246 // update geometry in father coordinates 00247 template< class Geo, class LocalGeo > 00248 void updateLocal ( const Geo &geo, const LocalGeo &localGeo ) 00249 { 00250 assert( localGeo.corners() == ncorners ); 00251 // compute the local coordinates in father refelem 00252 FieldMatrix< alu2d_ctype, ncorners, cdim > coord; 00253 for( int i = 0; i < ncorners; ++i ) 00254 { 00255 // calculate coordinate 00256 coord[ i ] = geo.local( localGeo.corner( i ) ); 00257 // to avoid rounding errors 00258 for( int j = 0; j < cdim; ++j ) 00259 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]); 00260 } 00261 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] ); 00262 } 00263 00264 template< class HElement > 00265 void update ( const HElement &item ) 00266 { 00267 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(), 00268 item.getVertex( 2 )->coord() ); 00269 } 00270 }; 00271 00272 // geometry implementation for quadrilaterals 00273 template< int cdim > 00274 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE quadrilateral > 00275 { 00276 static const int ncorners = 4; 00277 00278 typedef BilinearMapping< cdim > MappingType; 00279 00280 typedef typename MappingType::ctype ctype; 00281 00282 typedef typename MappingType::map_t map_t; 00283 typedef typename MappingType::world_t world_t; 00284 00285 typedef typename MappingType::matrix_t matrix_t; 00286 typedef typename MappingType::inv_t inv_t; 00287 00288 MappingType mapping_; 00289 00290 public: 00291 bool affine () const 00292 { 00293 return mapping_.affine(); 00294 } 00295 00296 int corners () const 00297 { 00298 return ncorners; 00299 } 00300 00301 GeometryType type () const 00302 { 00303 return GeometryType( GeometryType::cube, 2 ); 00304 } 00305 00306 void map2world ( const map_t &m, world_t &w ) const 00307 { 00308 return mapping_.map2world( m, w ); 00309 } 00310 00311 void world2map ( const world_t &w, map_t &m ) const 00312 { 00313 return mapping_.world2map( w, m ); 00314 } 00315 00316 const matrix_t &jacobianTransposed ( const map_t &m ) const 00317 { 00318 return mapping_.jacobianTransposed( m ); 00319 } 00320 00321 const inv_t &jacobianInverseTransposed ( const map_t &m ) const 00322 { 00323 return mapping_.jacobianInverseTransposed( m ); 00324 } 00325 00326 ctype det ( const map_t &m ) const 00327 { 00328 return mapping_.det( m ); 00329 } 00330 00331 // update geometry in father coordinates 00332 template< class Geo, class LocalGeo > 00333 void updateLocal ( const Geo &geo, const LocalGeo &localGeo ) 00334 { 00335 assert( localGeo.corners() == ncorners ); 00336 // compute the local coordinates in father refelem 00337 FieldMatrix< alu2d_ctype, ncorners, cdim > coord; 00338 for( int i = 0; i < ncorners; ++i ) 00339 { 00340 // calculate coordinate 00341 coord[ i ] = geo.local( localGeo.corner( i ) ); 00342 // to avoid rounding errors 00343 for( int j = 0; j < cdim; ++j ) 00344 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]); 00345 } 00346 mapping_.buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] ); 00347 } 00348 00349 template< class HElement > 00350 void update ( const HElement &item ) 00351 { 00352 mapping_.buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(), 00353 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() ); 00354 } 00355 }; 00356 00357 // geometry implementation for triangles 00358 template< int cdim > 00359 class MyALU2dGridGeometryImpl< 2, cdim, ALU2DSPACE mixed > 00360 { 00361 typedef Dune::LinearMapping< cdim, 2 > LinearMapping; 00362 typedef Dune::BilinearMapping< cdim > BilinearMapping; 00363 00364 typedef typename LinearMapping::ctype ctype; 00365 00366 typedef typename LinearMapping::map_t map_t; 00367 typedef typename LinearMapping::world_t world_t; 00368 00369 typedef typename LinearMapping::matrix_t matrix_t; 00370 typedef typename LinearMapping::inv_t inv_t; 00371 00372 static const int lms = sizeof( LinearMapping ); 00373 static const int bms = sizeof( BilinearMapping ); 00374 00375 int corners_; 00376 char mapping_[ lms > bms ? lms : bms ]; 00377 00378 public: 00379 MyALU2dGridGeometryImpl () : corners_( 0 ) {} 00380 00381 MyALU2dGridGeometryImpl ( const MyALU2dGridGeometryImpl &other ) 00382 : corners_( other.corners() ) 00383 { 00384 if( corners_ == 3 ) 00385 new( &mapping_ ) LinearMapping( other.linearMapping() ); 00386 if( corners_ == 4 ) 00387 new( &mapping_ ) BilinearMapping( other.bilinearMapping() ); 00388 } 00389 00390 bool affine () const 00391 { 00392 return (corners() == 3 ? linearMapping().affine() : bilinearMapping().affine()); 00393 } 00394 00395 int corners () const 00396 { 00397 return corners_; 00398 } 00399 00400 GeometryType type () const 00401 { 00402 return GeometryType( (corners_ == 3 ? 00403 GenericGeometry :: SimplexTopology< 2 > :: type :: id : 00404 GenericGeometry :: CubeTopology < 2 > :: type :: id), 2); 00405 } 00406 00407 void map2world ( const map_t &m, world_t &w ) const 00408 { 00409 if( corners() == 3 ) 00410 linearMapping().map2world( m, w ); 00411 else 00412 bilinearMapping().map2world( m, w ); 00413 } 00414 00415 void world2map ( const world_t &w, map_t &m ) const 00416 { 00417 if( corners() == 3 ) 00418 linearMapping().world2map( w, m ); 00419 else 00420 bilinearMapping().world2map( w, m ); 00421 } 00422 00423 const matrix_t &jacobianTransposed ( const map_t &m ) const 00424 { 00425 return (corners() == 3 ? linearMapping().jacobianTransposed( m ) : bilinearMapping().jacobianTransposed( m )); 00426 } 00427 00428 const inv_t &jacobianInverseTransposed ( const map_t &m ) const 00429 { 00430 return (corners() == 3 ? linearMapping().jacobianInverseTransposed( m ) : bilinearMapping().jacobianInverseTransposed( m )); 00431 } 00432 00433 ctype det ( const map_t &m ) const 00434 { 00435 return (corners() == 3 ? linearMapping().det( m ) : bilinearMapping().det( m )); 00436 } 00437 00438 // update geometry in father coordinates 00439 template< class Geo, class LocalGeo > 00440 void updateLocal ( const Geo &geo, const LocalGeo &localGeo ) 00441 { 00442 const int corners = localGeo.corners(); 00443 00444 // compute the local coordinates in father refelem 00445 FieldMatrix< alu2d_ctype, 4, cdim > coord; 00446 for( int i = 0; i < corners; ++i ) 00447 { 00448 // calculate coordinate 00449 coord[ i ] = geo.local( localGeo.corner( i ) ); 00450 // to avoid rounding errors 00451 for( int j = 0; j < cdim; ++j ) 00452 coord[ i ][ j ] = (coord[ i ][ j ] < 1e-14 ? 0 : coord[ i ][ j ]); 00453 } 00454 00455 updateMapping( corners ); 00456 if( corners == 3 ) 00457 linearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ] ); 00458 else 00459 bilinearMapping().buildMapping( coord[ 0 ], coord[ 1 ], coord[ 2 ], coord[ 3 ] ); 00460 } 00461 00462 template< class HElement > 00463 void update ( const HElement &item ) 00464 { 00465 const int corners = item.numvertices(); 00466 updateMapping( corners ); 00467 if( corners == 3 ) 00468 linearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(), 00469 item.getVertex( 2 )->coord() ); 00470 else 00471 bilinearMapping().buildMapping( item.getVertex( 0 )->coord(), item.getVertex( 1 )->coord(), 00472 item.getVertex( 3 )->coord(), item.getVertex( 2 )->coord() ); 00473 } 00474 00475 private: 00476 MyALU2dGridGeometryImpl &operator= ( const MyALU2dGridGeometryImpl &other ); 00477 00478 const LinearMapping &linearMapping () const { return static_cast< const LinearMapping * >( &mapping_ ); } 00479 LinearMapping &linearMapping () { return static_cast< LinearMapping * >( &mapping_ ); } 00480 00481 const BilinearMapping &bilinearMapping () const { return static_cast< const BilinearMapping * >( &mapping_ ); } 00482 BilinearMapping &bilinearMapping () { return static_cast< BilinearMapping * >( &mapping_ ); } 00483 00484 void updateMapping ( const int corners ) 00485 { 00486 assert( (corners == 3) || (corners == 4) ); 00487 if( corners != corners_ ) 00488 { 00489 destroyMapping(); 00490 corners = corners_; 00491 if( corners == 3 ) 00492 new( &mapping_ ) LinearMapping; 00493 else 00494 new( &mapping_ ) BilinearMapping; 00495 } 00496 } 00497 00498 void destroyMapping () 00499 { 00500 if( corners() == 3 ) 00501 linearMapping().~LinearMapping(); 00502 else if( corners() == 4 ) 00503 bilinearMapping().~BilinearMapping(); 00504 } 00505 }; 00506 00507 00508 //********************************************************************** 00509 // 00510 // --ALU2dGridGeometry 00511 // --Geometry 00512 //********************************************************************** 00525 00526 00527 template< int mydim, int cdim, class GridImp > 00528 class ALU2dGridGeometry 00529 : public GeometryDefaultImplementation< mydim, cdim, GridImp, ALU2dGridGeometry > 00530 { 00531 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00532 00534 typedef typename GridImp::template Codim<0>::Geometry Geometry; 00536 typedef ALU2dGridGeometry<mydim,cdim,GridImp> GeometryImp; 00538 enum { dimbary=mydim+1}; 00539 00540 typedef typename ALU2dImplTraits< GridImp::dimensionworld, eltype >::HElementType HElementType ; 00541 typedef typename ALU2dImplInterface< 0, GridImp::dimensionworld, eltype >::Type VertexType; 00542 00543 // type of specialized geometry implementation 00544 typedef MyALU2dGridGeometryImpl< mydim, cdim, eltype > GeometryImplType; 00545 00546 public: 00547 typedef FieldVector< alu2d_ctype, cdim > GlobalCoordinate; 00548 typedef FieldVector< alu2d_ctype, mydim > LocalCoordinate; 00549 00550 public: 00553 ALU2dGridGeometry(); 00554 00557 const GeometryType type () const { return geoImpl_.type(); } 00558 00560 int corners () const { return geoImpl_.corners(); } 00561 00563 const GlobalCoordinate &operator[] ( int i ) const; 00564 00566 GlobalCoordinate corner ( int i ) const; 00567 00570 GlobalCoordinate global ( const LocalCoordinate& local ) const; 00571 00574 LocalCoordinate local (const GlobalCoordinate& global) const; 00575 00577 alu2d_ctype integrationElement (const LocalCoordinate& local) const; 00578 00580 alu2d_ctype volume () const; 00581 00583 bool affine() const { return geoImpl_.affine(); } 00584 00586 const FieldMatrix<alu2d_ctype,cdim,mydim>& jacobianInverseTransposed (const LocalCoordinate& local) const; 00587 00589 const FieldMatrix<alu2d_ctype,mydim,cdim>& jacobianTransposed (const LocalCoordinate& local) const; 00590 00591 //*********************************************************************** 00593 //*********************************************************************** 00595 // method for elements 00596 bool buildGeom(const HElementType & item); 00597 // method for edges 00598 bool buildGeom(const HElementType & item, const int aluFace); 00599 // method for vertices 00600 bool buildGeom(const VertexType & item, const int ); 00601 00604 template <class GeometryType, class LocalGeomType > 00605 bool buildLocalGeom(const GeometryType & geo , const LocalGeomType & lg); 00606 00608 bool buildLocalGeometry(const int faceNumber, const int twist,const int coorns); 00609 00611 GlobalCoordinate& getCoordVec (int i); 00612 00614 void print (std::ostream& ss) const; 00615 00617 inline bool buildGeomInFather(const Geometry &fatherGeom , 00618 const Geometry & myGeom ); 00619 00620 // returns true if geometry is up-2-date 00621 inline bool up2Date() const { return up2Date_; } 00622 00623 // set up2Date flag to false 00624 inline void unsetUp2Date() const { up2Date_ = false; } 00625 00626 protected: 00627 // return reference coordinates of the alu triangle 00628 static std::pair< FieldMatrix< alu2d_ctype, 4, 2 >, FieldVector< alu2d_ctype, 4 > > 00629 calculateReferenceCoords ( const int corners ); 00630 00631 // implementation of coord and mapping 00632 mutable GeometryImplType geoImpl_; 00633 00634 // determinant 00635 mutable alu2d_ctype det_; 00636 00638 mutable bool up2Date_; 00639 }; 00640 00641 } // end namespace Dune 00642 00643 #include "geometry_imp.cc" 00644 00645 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].