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