dune-grid
2.1.1
|
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/grid/common/boundarysegment.hh> 00012 #include <dune/grid/genericgeometry/mappingprovider.hh> 00013 #include <dune/grid/genericgeometry/geometrytraits.hh> 00014 00015 namespace Dune 00016 { 00017 00020 template <int dimworld> 00021 struct DuneBoundaryProjection 00022 { 00024 typedef FieldVector< double, dimworld> CoordinateType; 00026 virtual ~DuneBoundaryProjection() {} 00027 00029 virtual CoordinateType operator() (const CoordinateType& global) const = 0; 00030 }; 00031 00032 template < int dimworld > 00033 class BoundaryProjectionWrapper 00034 : public DuneBoundaryProjection< dimworld > 00035 { 00036 protected: 00037 typedef DuneBoundaryProjection< dimworld > BaseType; 00038 const BaseType& proj_; 00039 public: 00041 typedef typename BaseType :: CoordinateType CoordinateType; 00042 00043 // constructor taking other projection 00044 BoundaryProjectionWrapper( const BaseType& proje ) 00045 : proj_( proje ) 00046 {} 00047 00049 ~BoundaryProjectionWrapper () {} 00050 00052 CoordinateType operator() (const CoordinateType& global) const 00053 { 00054 return proj_( global ); 00055 } 00056 }; 00057 00058 // BoundarySegmentWrapper 00059 // ---------------------- 00060 00061 template< int dim, int dimworld > 00062 class BoundarySegmentWrapper 00063 : public DuneBoundaryProjection< dimworld > 00064 { 00065 typedef BoundarySegmentWrapper< dim, dimworld > This; 00066 typedef DuneBoundaryProjection< dimworld > Base; 00067 00068 typedef GenericGeometry::DefaultGeometryTraits< double, dim-1, dimworld > GeometryTraits; 00069 typedef GenericGeometry::HybridMapping< dim-1, GeometryTraits > FaceMapping; 00070 typedef GenericGeometry::MappingProvider< FaceMapping, 0 > FaceMappingProvider; 00071 00072 public: 00073 typedef typename Base::CoordinateType CoordinateType; 00074 typedef Dune::BoundarySegment< dim, dimworld > BoundarySegment; 00075 00084 BoundarySegmentWrapper ( const GeometryType &type, 00085 const std::vector< CoordinateType > &vertices, 00086 const shared_ptr< BoundarySegment > boundarySegment ) 00087 : faceMapping_( FaceMappingProvider::create( type.id(), vertices ) ), 00088 boundarySegment_( boundarySegment ) 00089 {} 00090 00091 CoordinateType operator() ( const CoordinateType &global ) const 00092 { 00093 return boundarySegment()( faceMapping_->local( global ) ); 00094 } 00095 00096 const BoundarySegment &boundarySegment () const 00097 { 00098 return *boundarySegment_; 00099 } 00100 00101 private: 00102 shared_ptr< FaceMapping > faceMapping_; 00103 const shared_ptr< BoundarySegment > boundarySegment_; 00104 }; 00105 00106 00107 00109 // 00110 // Example of boundary projection projection to a circle 00111 // 00113 template <int dimworld> 00114 struct CircleBoundaryProjection : public DuneBoundaryProjection< dimworld > 00115 { 00117 typedef FieldVector< double, dimworld> CoordinateType; 00118 00120 CircleBoundaryProjection(const double radius = std::sqrt( (double) dimworld )) 00121 : radius_( radius ) {} 00122 00124 virtual ~CircleBoundaryProjection() {} 00125 00127 virtual CoordinateType operator() (const CoordinateType& global) const 00128 { 00129 CoordinateType prj( global ); 00130 // get adjustment factor 00131 const double factor = radius_ / global.two_norm(); 00132 // adjust 00133 prj *= factor; 00134 return prj; 00135 } 00136 00137 protected: 00139 const double radius_; 00140 }; 00141 00142 } // end namespace 00143 00144 #endif // #ifndef DUNE_BOUNDARYPROJECTION_HH