dune-grid  2.3.1
boundaryprojection.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_BOUNDARYPROJECTION_HH
4 #define DUNE_BOUNDARYPROJECTION_HH
5 
6 //- system includes
7 #include <cmath>
8 
9 //- Dune includes
10 #include <dune/common/fvector.hh>
11 #include <dune/common/shared_ptr.hh>
12 
13 #include <dune/geometry/multilineargeometry.hh>
14 
16 
17 namespace Dune
18 {
19 
22  template <int dimworld>
24  {
26  typedef FieldVector< double, dimworld> CoordinateType;
29 
31  virtual CoordinateType operator() (const CoordinateType& global) const = 0;
32  };
33 
34  template < int dimworld >
36  : public DuneBoundaryProjection< dimworld >
37  {
38  protected:
40  const BaseType& proj_;
41  public:
44 
45  // constructor taking other projection
47  : proj_( proje )
48  {}
49 
52 
55  {
56  return proj_( global );
57  }
58  };
59 
60  // BoundarySegmentWrapper
61  // ----------------------
62 
64  template< int dim, int dimworld >
66  : public DuneBoundaryProjection< dimworld >
67  {
69 
70  typedef MultiLinearGeometry<typename Base::CoordinateType::value_type,dim-1,dimworld> FaceMapping;
71 
72  public:
75 
85  const std::vector< CoordinateType > &vertices,
86  const shared_ptr< BoundarySegment > &boundarySegment )
87  : faceMapping_( FaceMapping( type, vertices ) ),
88  boundarySegment_( boundarySegment )
89  {}
90 
91  CoordinateType operator() ( const CoordinateType &global ) const
92  {
93  return boundarySegment() ( faceMapping_.local( global ) );
94  }
95 
97  {
98  return *boundarySegment_;
99  }
100 
101  private:
102  FaceMapping faceMapping_;
103  const shared_ptr< BoundarySegment > boundarySegment_;
104  };
105 
106 
107 
109  //
110  // Example of boundary projection projection to a circle
111  //
113  template <int dimworld>
115  {
117  typedef FieldVector< double, dimworld> CoordinateType;
118 
120  CircleBoundaryProjection(const double radius = std::sqrt( (double)dimworld ))
121  : radius_( radius ) {}
122 
125 
127  virtual CoordinateType operator() (const CoordinateType& global) const
128  {
129  CoordinateType prj( global );
130  // get adjustment factor
131  const double factor = radius_ / global.two_norm();
132  // adjust
133  prj *= factor;
134  return prj;
135  }
136 
137  protected:
139  const double radius_;
140  };
141 
142 } // end namespace
143 
144 #endif // #ifndef DUNE_BOUNDARYPROJECTION_HH