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