DUNE-FEM (unstable)

checkgeomaffinity.hh
1 #ifndef DUNE_FEM_CHECKGEOMETRYAFFINITY_HH
2 #define DUNE_FEM_CHECKGEOMETRYAFFINITY_HH
3 
4 #include <dune/common/fvector.hh>
5 #include <dune/grid/common/gridenums.hh>
6 
7 #include <dune/fem/space/common/allgeomtypes.hh>
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
20  template <class QuadratureType>
22  {
23  // return true if geometry is affine
24  template< class EntityType, class ElementGeometryType >
25  static bool checkGeometry( const EntityType& entity,
26  const ElementGeometryType& geo,
27  const int quadOrd )
28  {
29  // if method tells that geometry is not affine
30  // then check it carefully
31  if( ! geo.affine() )
32  {
33  // get quadrature of desired order
34  QuadratureType volQuad( entity, quadOrd );
35  const int nop = volQuad.nop();
36 
37  // check all integration elements against the first
38  const double oldIntel = geo.integrationElement( volQuad.point(0) );
39  for(int l=1; l<nop; ++l)
40  {
41  const double intel = geo.integrationElement( volQuad.point(l) );
42  if( std::abs( oldIntel - intel ) > 1e-12 )
43  return false;
44  }
45  }
46  return true ;
47  }
48 
49  // return true if geometry is affine
50  template< class EntityType >
51  static bool checkGeometry( const EntityType& entity, const int quadOrd )
52  {
53  return checkGeometry( entity, entity.geometry(), quadOrd );
54  }
55 
57  template <class IteratorType>
58  static inline bool checkAffinity(const IteratorType& begin,
59  const IteratorType& endit,
60  const int quadOrd)
61  {
62  for(IteratorType it = begin; it != endit; ++it)
63  {
64  if( ! checkGeometry( *it, quadOrd ) ) return false ;
65  }
66  return true;
67  }
68 
70  template <class GridPartType, class Vector >
71  static inline void checkElementAffinity(const GridPartType& gridPart,
72  const int quadOrd,
73  Vector& affineGeomtryVec )
74  {
75  typedef typename GridPartType :: template Codim< 0 > :: IteratorType IteratorType;
76  typedef typename GridPartType :: template Codim< 0 > :: EntityType EntityType;
77  const IteratorType endit = gridPart.template end<0> ();
78  affineGeomtryVec.resize( gridPart.indexSet().size( 0 ) );
79  for(IteratorType it = gridPart.template begin<0>(); it != endit; ++it)
80  {
81  const EntityType& entity = *it ;
82  const int index = gridPart.indexSet().index( entity );
83  affineGeomtryVec[ index ] = checkGeometry( entity, quadOrd );
84  }
85 
86  //for( size_t i=0; i<affineGeomtryVec.size(); ++ i)
87  // std::cout << "geo is " << affineGeomtryVec[ i ] << std::endl;
88  }
89  };
90 
92  template <class GridPartType>
94  {
95  typedef typename GridPartType :: GridType GridType ;
96  protected:
98  template <class IndexSetType>
99  static inline bool doCheck(const GridType& grid, const IndexSetType& indexSet)
100  {
101  typedef typename GridType :: template Codim<0> :: LevelIterator MacroIteratorType;
102  typedef typename GridType :: template Codim<0> :: Entity EntityType;
103  typedef typename GridType :: template Codim<0> :: Geometry Geometry;
104 
105  typedef typename GridType :: LevelGridView MacroGridView ;
106 
107  // get macro grid view
108  MacroGridView macroView = grid.levelGridView( 0 );
109 
110  const MacroIteratorType endit = macroView.template end<0> ();
111  MacroIteratorType it = macroView.template begin<0> ();
112 
113  // empty grids are considerd as cartesian
114  if( it == endit ) return true;
115 
116  typedef AllGeomTypes< IndexSetType, GridType> GeometryInformationType;
117  GeometryInformationType geoInfo( indexSet );
118 
119  // if we have more than one geometry Type return false
120  if( geoInfo.geomTypes(0).size() > 1 ) return false;
121 
122  // if this type is not cube return false
123  if( ! geoInfo.geomTypes(0)[0].isCube() ) return false;
124 
125  typedef typename GridType :: ctype ctype;
126  enum { dimension = GridType :: dimension };
127  enum { dimworld = GridType :: dimensionworld };
128 
129  // grid width
131  FieldVector<ctype, dimension-1> mid(0.5);
132 
133  const int map[3] = {1, 2, 4};
134  {
135  const Geometry geo = it->geometry();
136  if ( ! geo.type().isCube() ) return false;
137 
138  // calculate grid with
139  for(int i=0; i<dimension; ++i)
140  {
141  h[i] = (geo.corner( 0 ) - geo.corner( map[i] )).two_norm();
142  }
143  }
144 
145  // loop over all macro elements
146  for(MacroIteratorType it = macroView.template begin<0> ();
147  it != endit; ++it)
148  {
149  const EntityType& en = *it;
150  const Geometry geo = en.geometry();
151 
152  const FieldVector<ctype, dimworld> enBary =
153  geo.global( geoInfo.localCenter( geo.type() ));
154 
155  typedef typename MacroGridView :: IntersectionIterator IntersectionIteratorType;
156 
157  // if geometry is not cube, it's not a cartesian grid
158  if ( ! geo.type().isCube() ) return false;
159 
160  for(int i=0; i<dimension; ++i)
161  {
162  const ctype w = (geo.corner(0) - geo.corner( map[i] )).two_norm();
163  if( std::abs( h[i] - w ) > 1e-15 ) return false;
164  }
165 
166  IntersectionIteratorType endnit = macroView.iend( en );
167  for(IntersectionIteratorType nit = macroView.ibegin( en );
168  nit != endnit; ++nit)
169  {
170  const typename IntersectionIteratorType::Intersection& inter=*nit;
171  if( ! checkIntersection(inter) ) return false;
172 
173  if( inter.neighbor() )
174  {
175  EntityType nb = inter.outside();
176  Geometry nbGeo = nb.geometry();
177 
178  FieldVector<ctype, dimworld> diff = nbGeo.global( geoInfo.localCenter( nbGeo.type() ));
179  diff -= enBary;
180  assert( diff.two_norm() > 1e-15 );
181  diff /= diff.two_norm();
182 
183  // scalar product should be 1 or -1
184  if( std::abs(std::abs((diff * inter.unitOuterNormal(mid))) - 1.0) > 1e-12 ) return false;
185  }
186  }
187  }
188  return true;
189  }
190 
191  template <class ctype, int dim>
192  class ReferenceNormals
193  {
194  const FieldVector<ctype,dim-1> mid_;
195  enum { numberOfNormals = 2 * dim };
196  FieldVector<ctype,dim> refNormal_[numberOfNormals];
197  public:
198  ReferenceNormals () : mid_(0.5)
199  {
200  for(int i=0; i<numberOfNormals; ++i)
201  {
202  // get i-th reference normal
203  FieldVector<ctype,dim>& refNormal = refNormal_[i];
204  // reset normal
205  refNormal = 0;
206  // set one component
207  int comp = ((int) i/2);
208  refNormal[comp] = ((i % 2) == 0) ? -1 : 1;
209  }
210  }
211 
212  const FieldVector<ctype,dim>& referenceNormal(const int i) const
213  {
214  assert( i >= 0 && i< numberOfNormals );
215  return refNormal_[i];
216  }
217 
218  const FieldVector<ctype,dim-1>& faceMidPoint() const
219  {
220  return mid_;
221  }
222  };
223 
224  public:
225  // check that element is provided following the DUNE reference cube
226  template <class IntersectionType>
227  static bool checkIntersection(const IntersectionType& nit)
228  {
229  if ( ! nit.type().isCube() ) return false;
230 
231  typedef typename IntersectionType :: Entity EntityType;
232  typedef typename EntityType :: Geometry :: ctype ctype;
233  enum { dimworld = EntityType :: Geometry :: coorddimension };
234 
235  // get reference normals
236  static const ReferenceNormals<ctype,dimworld> normals;
237 
238  // get current normal
239  FieldVector<ctype,dimworld> unitNormal = nit.unitOuterNormal(normals.faceMidPoint());
240  unitNormal -= normals.referenceNormal( nit.indexInInside() );
241 
242  // if normals are not equal grid is not cartesian
243  if( unitNormal.infinity_norm() > 1e-10 ) return false;
244 
245  return true;
246  }
247 
249  static inline bool check(const GridPartType& gridPart)
250  {
251  bool cartesian = doCheck( gridPart.grid() , gridPart.indexSet() );
252  int val = (cartesian) ? 1 : 0;
253  // take global minimum
254  val = gridPart.comm().min( val );
255  return (val == 1) ? true : false;
256  }
257  };
258 
260 
261  } // namespace Fem
262 
263 } // namespace Dune
264 
265 #endif // #ifndef DUNE_FEM_CHECKGEOMETRYAFFINITY_HH
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:641
Wrapper class for entities.
Definition: entity.hh:66
default implementation uses method geomTypes of given index set. Used in DiscreteFunctionSpaces.
Definition: allgeomtypes.hh:99
vector space out of a tensor product of fields.
Definition: fvector.hh:95
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:324
Wrapper class for geometries.
Definition: geometry.hh:71
GeometryType type() const
Return the type of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: geometry.hh:194
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the map .
Definition: geometry.hh:228
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: geometry.hh:219
Implements a vector constructed from a given type representing a field and a compile-time given size.
concept Intersection
Model of an intersection.
Definition: intersection.hh:23
concept Entity
Model of a grid entity.
Definition: entity.hh:107
concept IntersectionIterator
Model of an intersection iterator.
Definition: intersectioniterator.hh:21
concept Geometry
Model of a geometry object.
Definition: geometry.hh:29
Dune namespace.
Definition: alignedallocator.hh:13
Helper class to check whether grid is structured or not.
Definition: checkgeomaffinity.hh:94
static bool doCheck(const GridType &grid, const IndexSetType &indexSet)
check whether this is a cartesian grid or not
Definition: checkgeomaffinity.hh:99
static bool check(const GridPartType &gridPart)
check whether all the is grid is a cartesian grid
Definition: checkgeomaffinity.hh:249
Helper class to check affinity of the grid's geometries.
Definition: checkgeomaffinity.hh:22
static void checkElementAffinity(const GridPartType &gridPart, const int quadOrd, Vector &affineGeomtryVec)
check whether all geometry mappings are affine
Definition: checkgeomaffinity.hh:71
static bool checkAffinity(const IteratorType &begin, const IteratorType &endit, const int quadOrd)
check whether all geometry mappings are affine
Definition: checkgeomaffinity.hh:58
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 14, 22:30, 2024)