dune-grid
2.2.0
|
00001 #ifndef DUNE_BOUNDARYPROJECTION_HH 00002 #define DUNE_BOUNDARYPROJECTION_HH 00003 00004 //- system includes 00005 #include <cmath> 00006 00007 //- Dune includes 00008 #include <dune/common/fvector.hh> 00009 #include <dune/common/shared_ptr.hh> 00010 00011 #include <dune/geometry/genericgeometry/mappingprovider.hh> 00012 #include <dune/geometry/genericgeometry/geometrytraits.hh> 00013 00014 #include <dune/grid/common/boundarysegment.hh> 00015 00016 namespace Dune 00017 { 00018 00021 template <int dimworld> 00022 struct DuneBoundaryProjection 00023 { 00025 typedef FieldVector< double, dimworld> CoordinateType; 00027 virtual ~DuneBoundaryProjection() {} 00028 00030 virtual CoordinateType operator() (const CoordinateType& global) const = 0; 00031 }; 00032 00033 template < int dimworld > 00034 class BoundaryProjectionWrapper 00035 : public DuneBoundaryProjection< dimworld > 00036 { 00037 protected: 00038 typedef DuneBoundaryProjection< dimworld > BaseType; 00039 const BaseType& proj_; 00040 public: 00042 typedef typename BaseType :: CoordinateType CoordinateType; 00043 00044 // constructor taking other projection 00045 BoundaryProjectionWrapper( const BaseType& proje ) 00046 : proj_( proje ) 00047 {} 00048 00050 ~BoundaryProjectionWrapper () {} 00051 00053 CoordinateType operator() (const CoordinateType& global) const 00054 { 00055 return proj_( global ); 00056 } 00057 }; 00058 00059 // BoundarySegmentWrapper 00060 // ---------------------- 00061 00062 template< int dim, int dimworld > 00063 class BoundarySegmentWrapper 00064 : public DuneBoundaryProjection< dimworld > 00065 { 00066 typedef BoundarySegmentWrapper< dim, dimworld > This; 00067 typedef DuneBoundaryProjection< dimworld > Base; 00068 00069 typedef GenericGeometry::DefaultGeometryTraits< double, dim-1, dimworld > GeometryTraits; 00070 typedef GenericGeometry::HybridMapping< dim-1, GeometryTraits > FaceMapping; 00071 typedef GenericGeometry::MappingProvider< FaceMapping, 0 > FaceMappingProvider; 00072 00073 public: 00074 typedef typename Base::CoordinateType CoordinateType; 00075 typedef Dune::BoundarySegment< dim, dimworld > BoundarySegment; 00076 00085 BoundarySegmentWrapper ( const GeometryType &type, 00086 const std::vector< CoordinateType > &vertices, 00087 const shared_ptr< BoundarySegment > &boundarySegment ) 00088 : faceMapping_( FaceMappingProvider::create( type.id(), vertices ) ), 00089 boundarySegment_( boundarySegment ) 00090 {} 00091 00092 CoordinateType operator() ( const CoordinateType &global ) const 00093 { 00094 return boundarySegment()( faceMapping_->local( global ) ); 00095 } 00096 00097 const BoundarySegment &boundarySegment () const 00098 { 00099 return *boundarySegment_; 00100 } 00101 00102 private: 00103 shared_ptr< FaceMapping > faceMapping_; 00104 const shared_ptr< BoundarySegment > boundarySegment_; 00105 }; 00106 00107 00108 00110 // 00111 // Example of boundary projection projection to a circle 00112 // 00114 template <int dimworld> 00115 struct CircleBoundaryProjection : public DuneBoundaryProjection< dimworld > 00116 { 00118 typedef FieldVector< double, dimworld> CoordinateType; 00119 00121 CircleBoundaryProjection(const double radius = std::sqrt( (double) dimworld )) 00122 : radius_( radius ) {} 00123 00125 virtual ~CircleBoundaryProjection() {} 00126 00128 virtual CoordinateType operator() (const CoordinateType& global) const 00129 { 00130 CoordinateType prj( global ); 00131 // get adjustment factor 00132 const double factor = radius_ / global.two_norm(); 00133 // adjust 00134 prj *= factor; 00135 return prj; 00136 } 00137 00138 protected: 00140 const double radius_; 00141 }; 00142 00143 } // end namespace 00144 00145 #endif // #ifndef DUNE_BOUNDARYPROJECTION_HH