dune-grid
2.1.1
|
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=8 sw=2 sts=2: 00003 00004 #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH 00005 #define DUNE_GENERICGEOMETRY_GEOMETRY_HH 00006 00007 #include <dune/common/typetraits.hh> 00008 #include <dune/common/nullptr.hh> 00009 00010 #include <dune/grid/common/geometry.hh> 00011 #include <dune/grid/common/genericreferenceelements.hh> 00012 00013 #include <dune/grid/genericgeometry/mappingprovider.hh> 00014 #include <dune/grid/genericgeometry/geometrytraits.hh> 00015 00016 namespace Dune 00017 { 00018 00019 namespace GenericGeometry 00020 { 00021 00174 // BasicGeometry 00175 // ------------- 00176 00250 template< int mydim, class Traits > 00251 class BasicGeometry 00252 { 00253 typedef typename Traits :: CoordTraits CoordTraits; 00254 00255 static const int dimGrid = Traits :: dimGrid; 00256 00258 template< int, class > friend class BasicGeometry; 00259 00260 public: 00261 00263 static const int mydimension = mydim; 00264 00266 static const int coorddimension = Traits :: dimWorld; 00267 00269 typedef typename CoordTraits :: ctype ctype; 00270 00272 typedef FieldVector< ctype, mydimension > LocalCoordinate; 00273 00275 typedef FieldVector< ctype, coorddimension > GlobalCoordinate; 00276 00277 private: 00278 dune_static_assert( (0 <= mydimension) && (mydimension <= dimGrid), 00279 "Invalid geometry dimension." ); 00280 00281 static const int codimension = dimGrid - mydimension; 00282 00283 template< bool > 00284 struct Hybrid 00285 { 00286 typedef HybridMapping< dimGrid, Traits > Mapping; 00287 }; 00288 00289 template< bool > 00290 struct NonHybrid 00291 { 00292 typedef typename GenericGeometry::Topology< Traits::topologyId, dimGrid >::type Topology; 00293 typedef GenericGeometry::CachedMapping< Topology, Traits > Mapping; 00294 }; 00295 00296 typedef typename SelectType< Traits::hybrid, Hybrid< true >, NonHybrid< false > >::Type::Mapping 00297 ElementMapping; 00298 typedef GenericGeometry::MappingProvider< ElementMapping, codimension > MappingProvider; 00299 00300 protected: 00301 typedef typename MappingProvider::Mapping Mapping; 00302 00303 public: 00309 typedef typename Mapping::JacobianTransposed JacobianTransposed; 00315 typedef typename Mapping::JacobianInverseTransposed JacobianInverseTransposed; 00316 00317 public: 00320 BasicGeometry () 00321 : mapping_(nullptr) 00322 {} 00323 00329 template< class CoordVector > 00330 DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords ) 00331 { 00332 mapping_ = MappingProvider::construct( topologyId, coords, mappingStorage_ ); 00333 } 00334 00344 template< class CoordVector > 00345 DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine ) 00346 { 00347 mapping_ = MappingProvider::construct( topologyId, coords, affine, mappingStorage_ ); 00348 } 00349 00351 template< class CoordVector > 00352 BasicGeometry ( const GeometryType &type, const CoordVector &coords ) 00353 { 00354 mapping_ = MappingProvider::construct( type.id(), coords, mappingStorage_ ); 00355 } 00356 00370 template< int fatherdim > 00371 BasicGeometry ( const BasicGeometry< fatherdim, Traits > &father, int i ) 00372 { 00373 const unsigned int codim = fatherdim - mydim; 00374 mapping_ = father.mapping_->template trace< codim >( i, mappingStorage_ ); 00375 } 00376 00378 BasicGeometry ( const BasicGeometry &other ) 00379 { 00380 mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr; 00381 } 00382 00384 ~BasicGeometry () 00385 { 00386 if (mapping_) 00387 mapping_->~Mapping(); 00388 } 00389 00391 BasicGeometry &operator= ( const BasicGeometry &other ) 00392 { 00393 if (mapping_) 00394 mapping_->~Mapping(); 00395 mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr; 00396 return *this; 00397 } 00398 00402 bool operator! () const 00403 { 00404 return (mapping_ == 0); 00405 } 00406 00408 GeometryType type () const 00409 { 00410 return GeometryType( mapping_->topologyId(), mydimension ); 00411 } 00412 00414 int corners () const 00415 { 00416 return mapping_->numCorners(); 00417 } 00418 00420 const GlobalCoordinate &operator[] ( int i ) const 00421 { 00422 return mapping_->corner( i ); 00423 } 00424 00426 GlobalCoordinate corner ( const int i ) const 00427 { 00428 return mapping_->corner( i ); 00429 } 00430 00432 GlobalCoordinate global ( const LocalCoordinate &local ) const 00433 { 00434 return mapping_->global( local ); 00435 } 00436 00438 LocalCoordinate local ( const GlobalCoordinate &global ) const 00439 { 00440 return mapping_->local( global ); 00441 } 00442 00444 GlobalCoordinate center () const 00445 { 00446 return mapping_->center(); 00447 } 00448 00450 bool affine () const 00451 { 00452 return mapping_->affine(); 00453 } 00454 00456 ctype integrationElement ( const LocalCoordinate &local ) const 00457 { 00458 return mapping_->integrationElement( local ); 00459 } 00460 00462 ctype volume () const 00463 { 00464 return mapping_->volume(); 00465 } 00466 00471 const JacobianTransposed &jacobianTransposed ( const LocalCoordinate &local ) const 00472 { 00473 return mapping_->jacobianTransposed( local ); 00474 } 00475 00478 const JacobianInverseTransposed &jacobianInverseTransposed ( const LocalCoordinate &local ) const 00479 { 00480 return mapping_->jacobianInverseTransposed( local ); 00481 } 00482 00493 GlobalCoordinate normal ( int face, const LocalCoordinate &local ) const DUNE_DEPRECATED 00494 { 00495 const GenericReferenceElement< ctype, mydimension > &refElement 00496 = GenericReferenceElements< ctype, mydimension>::general( type() ); 00497 assert( face < refElement.size( 1 ) ); 00498 00499 const JacobianInverseTransposed &jit = jacobianInverseTransposed( local ); 00500 const LocalCoordinate &refNormal = refElement.volumeOuterNormal( face ); 00501 00502 GlobalCoordinate normal; 00503 jit.mv( refNormal, normal ); 00504 normal *= integrationElement( local ); 00505 return normal; 00506 } 00507 00508 private: 00509 00511 Mapping* mapping_; 00512 00518 char mappingStorage_[ MappingProvider::maxMappingSize ]; 00519 }; 00520 00521 00522 00523 // Geometry 00524 // -------- 00525 00538 template< int mydim, int cdim, class Grid > 00539 class Geometry 00540 : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > > 00541 { 00542 typedef BasicGeometry< mydim, GlobalGeometryTraits< Grid > > Base; 00543 00544 protected: 00545 typedef typename Base::Mapping Mapping; 00546 00547 public: 00548 00549 Geometry () 00550 {} 00551 00552 template< class CoordVector > 00553 DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords ) 00554 : Base( topologyId, coords ) 00555 {} 00556 00557 template< class CoordVector > 00558 DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine ) 00559 : Base( topologyId, coords, affine ) 00560 {} 00561 00563 template< class Geo > 00564 explicit Geometry ( const Geo &geo ) 00565 : Base( geo.type(), geo, geo.affine() ) 00566 {} 00567 00569 template< class CoordVector > 00570 Geometry ( const GeometryType &type, const CoordVector &coords ) 00571 : Base( type, coords ) 00572 {} 00573 00575 template< int fatherdim > 00576 Geometry ( const Geometry< fatherdim, cdim, Grid > &father, int i ) 00577 : Base( father, i ) 00578 {} 00579 }; 00580 00581 00582 00583 // LocalGeometry 00584 // ------------- 00585 00598 template< int mydim, int cdim, class Grid > 00599 class LocalGeometry 00600 : public BasicGeometry< mydim, LocalGeometryTraits< Grid > > 00601 { 00602 typedef BasicGeometry< mydim, LocalGeometryTraits< Grid > > Base; 00603 00604 protected: 00605 typedef typename Base::Mapping Mapping; 00606 00607 public: 00608 template< class CoordVector > 00609 DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords ) 00610 : Base( topologyId, coords ) 00611 {} 00612 00613 template< class CoordVector > 00614 DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine ) 00615 : Base( topologyId, coords, affine ) 00616 {} 00617 00619 template< class Geo > 00620 explicit LocalGeometry ( const Geo &geo ) 00621 : Base( geo.type(), geo, geo.affine() ) 00622 {} 00623 00625 template< class CoordVector > 00626 LocalGeometry ( const GeometryType &type, const CoordVector &coords ) 00627 : Base( type, coords ) 00628 {} 00629 00631 template< int fatherdim > 00632 LocalGeometry ( const Geometry< fatherdim, cdim, Grid > &father, int i ) 00633 : Base( father, i ) 00634 {} 00635 }; 00636 00637 } 00638 00639 } 00640 00641 #endif // #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH