dune-grid  2.2.1
faceutility.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALU3DGRIDFACEUTILITY_HH
2 #define DUNE_ALU3DGRIDFACEUTILITY_HH
3 
4 #include <dune/common/misc.hh>
5 #include <dune/geometry/referenceelements.hh>
6 
7 #include "mappings.hh"
8 #include "alu3dinclude.hh"
9 #include "topology.hh"
10 
11 namespace Dune
12 {
13 
14  // convert FieldVectors to alu3dtypes
15  // only used for calculating the normals because the method of the
16  // mapping classes want double (&)[3] and we have FieldVectors which store an
17  // double [3] this is why we can cast here
18  // plz say notin' Adrian
19  template< int dim >
20  inline alu3d_ctype (&fieldVector2alu3d_ctype ( FieldVector< alu3d_ctype, dim > &val ))[ dim ]
21  {
22  return ((alu3d_ctype (&)[dim]) (*( &(val[0])) ));
23  }
24 
25  // convert const FieldVectors to const alu3dtypes
26  template< int dim >
27  inline const alu3d_ctype (&fieldVector2alu3d_ctype ( const FieldVector< alu3d_ctype, dim > &val ))[ dim ]
28  {
29  return ((const alu3d_ctype (&)[dim]) (*( &(val[0])) ) );
30  }
31 
32 
33  // * Note: reconsider lazy evaluation of coordinates
34 
35  //- class ALU3dGridFaceInfo
36  /* \brief Stores face and adjoining elements of the underlying ALU3dGrid
37  The class has the same notion of inner and outer element as the
38  intersection iterator.
39  */
40  template< ALU3dGridElementType type, class Comm >
42  {
44  //- private typedefs
45  typedef typename ImplTraits::HasFaceType HasFaceType;
46  public:
48  //- typedefs
49  typedef typename ImplTraits::GEOFaceType GEOFaceType;
50  typedef typename ImplTraits::GEOElementType GEOElementType;
51  typedef typename ImplTraits::GEOPeriodicType GEOPeriodicType;
52  typedef typename ImplTraits::IMPLElementType IMPLElementType;
53  typedef typename ImplTraits::GhostPairType GhostPairType;
54  typedef typename ImplTraits::BNDFaceType BNDFaceType;
55 
56  public:
59  void updateFaceInfo(const GEOFaceType& face, int innerLevel, int innerTwist);
60 
61  //- constructors and destructors
71 
72  protected:
74  bool isElementLike() const;
75 
77  bool innerBoundary() const;
78 
79  public:
80  //- queries
83  bool outerBoundary() const;
84 
86  bool boundary() const;
87 
89  bool neighbor() const ;
90 
93  bool ghostBoundary () const;
94 
96  const GEOFaceType& face() const;
98  const GEOElementType& innerEntity() const;
101  const GEOElementType& outerEntity() const;
104  const BNDFaceType& innerFace() const;
107  const BNDFaceType& boundaryFace() const;
108 
110  int innerTwist() const;
112  int outerTwist() const;
113 
115  int duneTwist(const int faceIdx, const int aluTwist) const;
116 
118  int innerALUFaceIndex() const;
120  int outerALUFaceIndex() const;
121 
122  int outsideLevel() const;
123 
125  int segmentIndex() const;
126 
128  int boundaryId() const;
129 
132 
134  bool parallel() const {
135  return ! Conversion< Comm, No_Comm > :: sameType ;
136  }
137 
138  private:
140  ConformanceState getConformanceState(const int innerLevel) const;
141 
142  //- forbidden methods
143  const ALU3dGridFaceInfo &
144  operator=(const ALU3dGridFaceInfo &orig);
145 
146  private:
147 
148  //- member data
149  const GEOFaceType* face_;
150  const HasFaceType* innerElement_;
151  const HasFaceType* outerElement_;
152 
153  int innerFaceNumber_;
154  int outerFaceNumber_;
155 
156  int innerTwist_;
157  int outerTwist_;
158 
159  int segmentIndex_;
160  int bndId_;
161 
162  enum boundary_t { noBoundary = 0, // no boundary, outside is normal element
163  periodicBoundary = 1, // periodic boundary
164  innerGhostBoundary = 2, // process boundary, inside is ghost, outside is normal element
165  domainBoundary = 3, // boundary with domain, no outside
166  outerGhostBoundary = 4};// process boundary, outside is ghost
167 
168  boundary_t bndType_;
169 
170  ConformanceState conformanceState_;
171  };
172 
173 
174  // ALU3dGridSurfaceMappingFactory
175  // ------------------------------
176 
177  template< ALU3dGridElementType type, class Comm >
179 
180  template< class Comm >
182  {
183  // this is the original ALUGrid LinearSurfaceMapping,
184  // see mapp_tetra_3d.* in ALUGrid code
185  typedef ALU3DSPACE LinearSurfaceMapping SurfaceMappingType;
187 
188  static const int numVerticesPerFace = EntityCount< tetra >::numVerticesPerFace;
189 
190  typedef FieldMatrix< alu3d_ctype, numVerticesPerFace, 3 > CoordinateType;
191 
192  // old method, copies values for tetra twice
193  SurfaceMappingType *buildSurfaceMapping ( const CoordinateType &coords ) const;
194  // get face but doesn't copy values twice
195  SurfaceMappingType *buildSurfaceMapping ( const GEOFaceType &face ) const;
196  };
197 
198  template< class Comm >
200  {
203 
204  static const int numVerticesPerFace = EntityCount< hexa >::numVerticesPerFace;
205 
206  typedef FieldMatrix< alu3d_ctype, numVerticesPerFace, 3 > CoordinateType;
207 
208  // old method, copies values for tetra twice
209  SurfaceMappingType *buildSurfaceMapping ( const CoordinateType &coords ) const;
210  // get face but doesn't copy values twice
211  SurfaceMappingType *buildSurfaceMapping ( const GEOFaceType &face ) const;
212  };
213 
214 
215 
216  // ALU3dGridGeometricFaceInfoBase
217  // ------------------------------
218 
221  template< ALU3dGridElementType type, class Comm >
223  : public ALU3dGridSurfaceMappingFactory< type, Comm >
224  {
226 
227  public:
231 
232  // type of container for reference elements
233  typedef GenericReferenceElements< alu3d_ctype, 3 > ReferenceElementContainerType;
234  // type of container for reference faces
235  typedef GenericReferenceElements< alu3d_ctype, 2 > ReferenceFaceContainerType;
236 
237  // type of reference element
238  typedef GenericReferenceElement<alu3d_ctype, 3> ReferenceElementType;
239  // type of reference face
240  typedef GenericReferenceElement<alu3d_ctype, 2> ReferenceFaceType;
241 
243  enum { dimworld = 3 }; // ALU is a pure 3d grid
246 
247  //- public typedefs
248  typedef FieldVector<alu3d_ctype, 3> NormalType;
249  typedef FieldMatrix<alu3d_ctype,
252 
254 
255  public:
257 
258  //- constructors and destructors
261 
263  void resetFaceGeom();
264 
265  //- functions
266  const CoordinateType& intersectionSelfLocal() const;
268 
269  private:
270  //- forbidden methods
272 
273  private:
274  //- private methods
275  void generateLocalGeometries() const;
276 
277  int globalVertexIndex(const int duneFaceIndex,
278  const int faceTwist,
279  const int duneFaceVertexIndex) const;
280 
281  void referenceElementCoordinatesRefined(SideIdentifier side,
282  CoordinateType& result) const;
283  void referenceElementCoordinatesUnrefined(SideIdentifier side,
284  CoordinateType& result) const;
285 
286  protected:
287  //- private data
289 
292 
293  mutable bool generatedGlobal_;
294  mutable bool generatedLocal_;
295 
297  {
298  return (type == tetra) ?
301  }
302 
303  inline static const ReferenceFaceType& getReferenceFace()
304  {
305  return (type == tetra) ?
308  }
309  };
310 
313  template< class Comm >
315  : public ALU3dGridGeometricFaceInfoBase< tetra, Comm >
316  {
318 
319  public:
320  //- public typedefs
321  typedef FieldVector<alu3d_ctype, 3> NormalType;
322  typedef typename Base::FaceTopo FaceTopo;
324 
326 
327  //- constructors and destructors
330 
331  NormalType & outerNormal(const FieldVector<alu3d_ctype, 2>& local) const;
332 
334  void resetFaceGeom();
335 
337  template <class GeometryImp>
338  void buildGlobalGeom(GeometryImp& geo) const;
339 
340  private:
341  //- forbidden methods
343 
344  protected:
345  using Base::connector_;
346 
347  private:
348  //- private data
349  mutable NormalType outerNormal_;
350 
351  // false if surface mapping needs a update
352  mutable bool normalUp2Date_;
353  };
354 
357  template< class Comm >
359  : public ALU3dGridGeometricFaceInfoBase< hexa, Comm >
360  {
362 
363  public:
364  //- public typedefs
365  typedef FieldVector<alu3d_ctype, 3> NormalType;
366  typedef typename Base::FaceTopo FaceTopo;
369 
371 
372  //- constructors and destructors
375 
376  NormalType & outerNormal(const FieldVector<alu3d_ctype, 2>& local) const;
377 
379  void resetFaceGeom();
380 
382  template <class GeometryImp>
383  void buildGlobalGeom(GeometryImp& geo) const;
384 
385  private:
386  //- forbidden methods
388 
389  protected:
390  using Base::connector_;
391 
392  private:
393  //- private data
394  mutable NormalType outerNormal_;
395 
396  // surface mapping for calculating the outer normal
397  mutable SurfaceMappingType mappingGlobal_;
398 
399  // false if surface mapping needs a update
400  mutable bool mappingGlobalUp2Date_;
401  };
402 
403 } // end namespace Dune
404 
405 #include "faceutility_imp.cc"
406 
407 #endif