dune-grid  2.2.1
boundaryprojection.hh
Go to the documentation of this file.
1 #ifndef DUNE_BOUNDARYPROJECTION_HH
2 #define DUNE_BOUNDARYPROJECTION_HH
3 
4 //- system includes
5 #include <cmath>
6 
7 //- Dune includes
8 #include <dune/common/fvector.hh>
9 #include <dune/common/shared_ptr.hh>
10 
11 #include <dune/geometry/genericgeometry/mappingprovider.hh>
12 #include <dune/geometry/genericgeometry/geometrytraits.hh>
13 
15 
16 namespace Dune
17 {
18 
21  template <int dimworld>
23  {
25  typedef FieldVector< double, dimworld> CoordinateType;
28 
30  virtual CoordinateType operator() (const CoordinateType& global) const = 0;
31  };
32 
33  template < int dimworld >
35  : public DuneBoundaryProjection< dimworld >
36  {
37  protected:
39  const BaseType& proj_;
40  public:
43 
44  // constructor taking other projection
46  : proj_( proje )
47  {}
48 
51 
54  {
55  return proj_( global );
56  }
57  };
58 
59  // BoundarySegmentWrapper
60  // ----------------------
61 
62  template< int dim, int dimworld >
64  : public DuneBoundaryProjection< dimworld >
65  {
68 
69  typedef GenericGeometry::DefaultGeometryTraits< double, dim-1, dimworld > GeometryTraits;
70  typedef GenericGeometry::HybridMapping< dim-1, GeometryTraits > FaceMapping;
71  typedef GenericGeometry::MappingProvider< FaceMapping, 0 > FaceMappingProvider;
72 
73  public:
76 
86  const std::vector< CoordinateType > &vertices,
87  const shared_ptr< BoundarySegment > &boundarySegment )
88  : faceMapping_( FaceMappingProvider::create( type.id(), vertices ) ),
89  boundarySegment_( boundarySegment )
90  {}
91 
92  CoordinateType operator() ( const CoordinateType &global ) const
93  {
94  return boundarySegment()( faceMapping_->local( global ) );
95  }
96 
98  {
99  return *boundarySegment_;
100  }
101 
102  private:
103  shared_ptr< FaceMapping > faceMapping_;
104  const shared_ptr< BoundarySegment > boundarySegment_;
105  };
106 
107 
108 
110  //
111  // Example of boundary projection projection to a circle
112  //
114  template <int dimworld>
116  {
118  typedef FieldVector< double, dimworld> CoordinateType;
119 
121  CircleBoundaryProjection(const double radius = std::sqrt( (double) dimworld ))
122  : radius_( radius ) {}
123 
126 
128  virtual CoordinateType operator() (const CoordinateType& global) const
129  {
130  CoordinateType prj( global );
131  // get adjustment factor
132  const double factor = radius_ / global.two_norm();
133  // adjust
134  prj *= factor;
135  return prj;
136  }
137 
138  protected:
140  const double radius_;
141  };
142 
143 } // end namespace
144 
145 #endif // #ifndef DUNE_BOUNDARYPROJECTION_HH