dune-grid  2.2.1
albertagrid/projection.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALBERTA_NODEPROJECTION_HH
2 #define DUNE_ALBERTA_NODEPROJECTION_HH
3 
4 #include <dune/common/shared_ptr.hh>
5 
7 
10 
11 #if HAVE_ALBERTA
12 
13 namespace Dune
14 {
15 
16  namespace Alberta
17  {
18 
19  // Internal Forward Declarations
20  // -----------------------------
21 
22  template< class Proj, class Impl >
24 
25 
26 
27  // DuneBoundaryProjection
28  // ----------------------
29 
30  template< int dim >
32  {
34 
35  public:
36  static const int dimension = dim;
37 
39  typedef FieldVector< Real, dimWorld > GlobalCoordinate;
40 
42  typedef Dune::shared_ptr< const Projection > ProjectionPtr;
43 
45  : projection_( projection )
46  {}
47 
48  // note: GlobalVector is an array type; global is the return value
49  void operator() ( const ElementInfo &elementInfo, const LocalVector local,
50  GlobalVector global ) const
51  {
53  for( int i = 0; i < dimWorld; ++i )
54  x[ i ] = global[ i ];
55  GlobalCoordinate y = projection()( x );
56  for( int i = 0; i < dimWorld; ++i )
57  global[ i ] = y[ i ];
58  }
59 
60  const Projection &projection () const
61  {
62  return *projection_;
63  }
64 
65  private:
66  ProjectionPtr projection_;
67  };
68 
69 
70 
71  // ProjectionFactoryInterface
72  // --------------------------
73 
74  template< class Proj, class Impl >
76  {
78 
79  friend class ProjectionFactory< Proj, Impl >;
80 
81  public:
82  typedef Proj Projection;
83 
84  static const int dimension = Projection::dimension;
85 
87 
88  private:
90  {}
91 
92  ProjectionFactoryInterface ( const This &other );
93  This &operator= ( const This &other );
94 
95  public:
96  bool hasProjection ( const ElementInfo &elementInfo, const int face ) const
97  {
98  return asImpl().hasProjection( elementInfo, face );
99  }
100 
101  bool hasProjection ( const ElementInfo &elementInfo ) const
102  {
103  return asImpl().hasProjection( elementInfo );
104  }
105 
106  Projection projection ( const ElementInfo &elementInfo, const int face ) const
107  {
108  return asImpl().projection( elementInfo, face );
109  };
110 
111  Projection projection ( const ElementInfo &elementInfo ) const
112  {
113  return asImpl().projection( elementInfo );
114  };
115 
116  protected:
117  const Impl &asImpl () const
118  {
119  return static_cast< const Impl & >( *this );
120  }
121  };
122 
123 
124 
125  // ProjectionFactory
126  // -----------------
127 
128  template< class Proj, class Impl >
129  class ProjectionFactory
130  : public ProjectionFactoryInterface< Proj, Impl >
131  {
132  typedef ProjectionFactory< Proj, Impl > This;
133  typedef ProjectionFactoryInterface< Proj, Impl > Base;
134 
135  public:
136  typedef typename Base::Projection Projection;
137  typedef typename Base::ElementInfo ElementInfo;
138 
139  protected:
141  {}
142 
143  private:
144  bool hasProjection ( const ElementInfo &elementInfo, const int face ) const;
145  bool hasProjection ( const ElementInfo &elementInfo ) const;
146 
147  Projection projection ( const ElementInfo &elementInfo, const int face ) const;
148  Projection projection ( const ElementInfo &elementInfo ) const;
149  };
150 
151 
152 
153  // DuneGlobalBoundaryProjectionFactory
154  // -----------------------------------
155 
156  template< int dim >
158  : public ProjectionFactory< DuneBoundaryProjection< dim >, DuneGlobalBoundaryProjectionFactory< dim > >
159  {
162 
163  public:
164  typedef typename Base::Projection Projection;
165  typedef typename Base::ElementInfo ElementInfo;
166 
167  typedef typename Projection::ProjectionPtr DuneProjectionPtr;
168 
170  : projection_( projection )
171  {}
172 
173  bool hasProjection ( const ElementInfo &elementInfo, const int face ) const
174  {
175  return true;
176  }
177 
178  bool hasProjection ( const ElementInfo &elementInfo ) const
179  {
180  return true;
181  }
182 
183  Projection projection ( const ElementInfo &elementInfo, const int face ) const
184  {
185  return projection_;
186  };
187 
188  Projection projection ( const ElementInfo &elementInfo ) const
189  {
190  return projection_;
191  };
192 
193  private:
194  const Projection projection_;
195  };
196 
197 
198 
199  // BasicNodeProjection
200  // -------------------
201 
203  : public ALBERTA NODE_PROJECTION
204  {
205  explicit BasicNodeProjection ( unsigned int boundaryIndex )
206  : boundaryIndex_( boundaryIndex )
207  {
208  func = 0;
209  }
210 
212  {}
213 
214  unsigned int boundaryIndex () const
215  {
216  return boundaryIndex_;
217  }
218 
219  private:
220  unsigned int boundaryIndex_;
221  };
222 
223 
224 
225  // NodeProjection
226  // --------------
227 
228  template< int dim, class Projection >
230  : public BasicNodeProjection
231  {
233  typedef BasicNodeProjection Base;
234 
235  public:
236  static const int dimension = dim;
237 
239 
240  private:
241  Projection projection_;
242 
243  public:
244  NodeProjection ( unsigned int boundaryIndex, const Projection &projection )
245  : Base( boundaryIndex ),
246  projection_( projection )
247  {
248  func = apply;
249  }
250 
251  private:
252  // note: global is the return type (it is an array type and hence no
253  // reference is needed)
254  static void apply ( GlobalVector global, const EL_INFO *info, const LocalVector local )
255  {
256  const ElementInfo elementInfo = ElementInfo::createFake( *info );
257 
258  assert( (info->fill_flag & FillFlags< dimension >::projection) != 0 );
259  const This *nodeProjection = static_cast< const This * >( info->active_projection );
260 
261  assert( nodeProjection != NULL );
262  nodeProjection->projection_( elementInfo, local, global );
263  }
264  };
265 
266  }
267 
268 }
269 
270 #endif // #if HAVE_ALBERTA
271 
272 #endif // #ifndef DUNE_ALBERTA_NODEPROJECTION_HH