dune-fem  2.4.1-rc
twistutility.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_TWISTUTILITY_HH
2 #define DUNE_FEM_TWISTUTILITY_HH
3 
4 #include <cassert>
5 
6 #include <dune/common/version.hh>
7 #include <dune/geometry/type.hh>
8 #include <dune/geometry/genericgeometry/topologytypes.hh>
9 
10 #include <dune/grid/utility/hostgridaccess.hh>
11 
12 // this also includes the forward declarations
15 
16 namespace Dune
17 {
18 
19  namespace Fem
20  {
21 
25  template< class Grid >
27  {
28  typedef Grid GridType;
29 
31  template< class Intersection >
32  static int twistInSelf ( const GridType &, const Intersection & )
33  {
34  return 0;
35  }
36 
38  template< class Intersection >
39  static int twistInNeighbor ( const GridType &, const Intersection & )
40  {
41  return 0;
42  }
43 
45  template< class Intersection >
46  static GeometryType elementGeometry ( const Intersection &intersection, const bool inside )
47  {
48  typedef Dune::Capabilities::hasSingleGeometryType< GridType > hasSingleGeometryType;
49  if( hasSingleGeometryType::v )
50  return GeometryType( hasSingleGeometryType::topologyId, GridType::dimension );
51  else
52  return inside ? make_entity( intersection.inside() ).type() : make_entity( intersection.outside() ).type();
53  }
54  };
55 
56 
57 
82  template< class Grid >
83  struct TwistUtility;
84  //{
85  // static_assert( false, "TwistUtility not specialized, please specialize TwistUtility!");
86  //};
87 
88  // Specialization for YaspGrid
89  // ------------------------------
90 
91  template< int dimw, class CoordCont >
92  struct TwistUtility< YaspGrid< dimw, CoordCont > >
93  : public TwistFreeTwistUtility< YaspGrid< dimw, CoordCont > >
94  {
95  };
96 
97 
98  // Specialization for SGrid
99  // ------------------------------
100 
101  template< int dim, int dimworld, class ctype >
102  struct TwistUtility< SGrid<dim, dimworld, ctype> >
103  : public TwistFreeTwistUtility< SGrid<dim, dimworld, ctype> >
104  {
105  };
106 
107 
108  // Specialization for OneDGrid
109  // ------------------------------
110 
111  template <>
112  struct TwistUtility< OneDGrid >
113  : public TwistFreeTwistUtility< OneDGrid >
114  {
115  };
116 
117 
118  // Specialization for AlbertaGrid
119  // ------------------------------
120 
121 #if HAVE_ALBERTA
122 
124  template< int dim, int dimW >
125  struct TwistUtility< AlbertaGrid< dim, dimW > >
126  {
128  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
129  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
130  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
131  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
132 
133  static const int dimension = GridType::dimension;
134 
135  public:
137  static int twistInSelf ( const GridType &grid, const LeafIntersection &it )
138  {
139  return grid.getTwistInInside( it );
140  }
141 
143  static int twistInNeighbor ( const GridType &grid, const LeafIntersection &it )
144  {
145  return grid.getTwistInOutside( it );
146  }
147 
150  template <class Intersection>
151  static inline GeometryType
152  elementGeometry(const Intersection& intersection,
153  const bool inside)
154  {
155  return GeometryType( GenericGeometry::SimplexTopology< dimension >::type::id,
156  dimension );
157  }
158  };
159 #endif
160 
161 
162 
163  // Specialization for ALUGrid
164  // --------------------------
165 
166 #if HAVE_ALUGRID
167 
169  template< int dim, int dimw >
170  struct TwistUtility< ALUSimplexGrid< dim, dimw > >
171  {
172  typedef ALUSimplexGrid< dim, dimw > GridType;
173 
174  typedef typename GridType::Traits::LeafIntersectionIterator
175  LeafIntersectionIterator;
176  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
177 
178  typedef typename GridType::Traits::LevelIntersectionIterator
179  LevelIntersectionIterator;
180  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
181 
182  static const int dimension = GridType::dimension;
183 
184  public:
186  template <class Intersection>
187  static inline int twistInSelf(const GridType & grid,
188  const Intersection& intersection)
189  {
190  return grid.getRealIntersection( intersection ).twistInInside();
191  }
192 
194  template <class Intersection>
195  static inline int twistInNeighbor(const GridType & grid,
196  const Intersection& intersection)
197  {
198  return grid.getRealIntersection( intersection ).twistInOutside();
199  }
200 
203  template <class Intersection>
204  static inline GeometryType
205  elementGeometry(const Intersection& intersection,
206  const bool inside)
207  {
208  return GeometryType( GenericGeometry::SimplexTopology< dim >::type::id,
209  dim );
210  }
211  private:
212  TwistUtility(const TwistUtility&);
213  TwistUtility& operator=(const TwistUtility&);
214  };
215 
218  template< int dim, int dimw >
219  struct TwistUtility< ALUCubeGrid< dim, dimw > >
220  {
221  typedef ALUCubeGrid< dim, dimw > GridType;
222  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
223  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
224  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
225  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
226 
227  public:
229  template <class Intersection>
230  static inline int twistInSelf(const GridType & grid,
231  const Intersection& intersection)
232  {
233  return grid.getRealIntersection( intersection ).twistInInside();
234  }
235 
237  template <class Intersection>
238  static inline int twistInNeighbor(const GridType & grid,
239  const Intersection& intersection)
240  {
241  return grid.getRealIntersection( intersection ).twistInOutside();
242  }
243 
246  template <class Intersection>
247  static inline GeometryType
248  elementGeometry(const Intersection& intersection,
249  const bool inside)
250  {
251  return GeometryType( GenericGeometry::CubeTopology< dim >::type::id,
252  dim );
253  }
254 
255  private:
256  TwistUtility(const TwistUtility&);
257  TwistUtility& operator=(const TwistUtility&);
258  };
259 
262  template< int dim, int dimw >
263  struct TwistUtility< ALUConformGrid< dim, dimw > >
264  {
265  typedef ALUConformGrid< dim, dimw > GridType;
266  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
267  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
268  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
269  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
270 
271  public:
273  static inline int twistInSelf(const GridType & grid, const LeafIntersection& intersection)
274  {
275  return grid.getRealIntersection( intersection ).twistInInside();
276  }
277 
279  static inline int twistInNeighbor(const GridType &grid, const LeafIntersection& intersection )
280  {
281  return grid.getRealIntersection( intersection ).twistInOutside();
282  }
283 
286  template <class Intersection>
287  static inline GeometryType
288  elementGeometry(const Intersection& intersection,
289  const bool inside)
290  {
291  return GeometryType( GenericGeometry::SimplexTopology< dim >::type::id,
292  dim );
293  }
294 
295  private:
296  TwistUtility(const TwistUtility&);
297  TwistUtility& operator=(const TwistUtility&);
298  };
299 #endif // #if HAVE_ALUGRID
300 
301 #if HAVE_ALUGRID || HAVE_DUNE_ALUGRID
302 
304  template< int dim, int dimw, ALUGridElementType elType, ALUGridRefinementType refineType, class Comm >
305  struct TwistUtility< ALUGrid< dim, dimw, elType, refineType, Comm > >
306  {
307  typedef ALUGrid< dim, dimw, elType, refineType, Comm > GridType;
308  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
309  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
310  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
311  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
312 
313  public:
315  static inline int twistInSelf(const GridType & grid, const LeafIntersection& intersection)
316  {
317  return (dim == 2) ? std::abs(grid.getRealIntersection( intersection ).twistInInside()) : grid.getRealIntersection( intersection ).twistInInside();
318  }
319 
321  static inline int twistInNeighbor(const GridType &grid, const LeafIntersection& intersection )
322  {
323  return (dim == 2) ? std::abs(grid.getRealIntersection( intersection ).twistInOutside()) : grid.getRealIntersection( intersection ).twistInOutside();
324  }
325 
328  template <class Intersection>
329  static inline GeometryType
330  elementGeometry(const Intersection& intersection,
331  const bool inside)
332  {
333  return GeometryType( Dune::Capabilities::hasSingleGeometryType< GridType > :: topologyId,
334  dim );
335  }
336 
337  private:
338  TwistUtility(const TwistUtility&);
339  TwistUtility& operator=(const TwistUtility&);
340  };
341 #endif // #if HAVE_ALUGRID || HAVE_DUNE_ALUGRID
342 
343 
344  // Specialization for UGGrid
345  // -------------------------
346 
347 #if HAVE_UG
348  template< int dim >
349  struct TwistUtility< UGGrid< dim > >
350  {
351  typedef UGGrid< dim > GridType;
352 
353  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
354  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
355  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
356  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
357 
358  static int twistInSelf ( const GridType &grid, const LeafIntersection &it );
359  static int twistInSelf ( const GridType &grid, const LevelIntersection &it );
360 
361  static int twistInNeighbor ( const GridType &grid, const LeafIntersection &it );
362  static int twistInNeighbor ( const GridType &grid, const LevelIntersection &it );
363 
364  template< class Intersection >
365  static GeometryType
366  elementGeometry ( const Intersection &intersection, const bool inside )
367  {
368  return (inside ? intersection.inside().type() : intersection.outside().type());
369  }
370  };
371 #endif // #ifdef ENABLE_UG
372 
373 
374 
375  // Specialization for GeometryGrid
376  // -------------------------------
377 
378  template< class HostGrid, class CoordFunction, class Allocator >
379  struct TwistUtility< GeometryGrid< HostGrid, CoordFunction, Allocator > >
380  {
381  typedef GeometryGrid< HostGrid, CoordFunction, Allocator > GridType;
382  typedef typename GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator;
383  typedef typename LeafIntersectionIterator::Intersection LeafIntersection;
384  typedef typename GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator;
385  typedef typename LevelIntersectionIterator::Intersection LevelIntersection;
386 
387  private:
390 
391  public:
393  template< class Intersection >
394  static int twistInSelf ( const GridType &grid, const Intersection &intersection )
395  {
396  return HostTwistUtility::twistInSelf( grid.hostGrid(), HostGridAccess::hostIntersection( intersection ) );
397  }
398 
400  template< class Intersection >
401  static int twistInNeighbor ( const GridType &grid, const Intersection &intersection )
402  {
403  return HostTwistUtility::twistInNeighbor( grid.hostGrid(), HostGridAccess::hostIntersection( intersection ) );
404  }
405 
407  template< class Intersection >
408  static GeometryType elementGeometry ( const Intersection &intersection, bool inside )
409  {
410  return HostTwistUtility::elementGeometry( HostGridAccess::hostIntersection( intersection ), inside );
411  }
412  };
413 
414  } // namespace Fem
415 
416 } // namespace Dune
417 
418 #endif // #ifndef DUNE_FEM_TWISTUTILITY_HH
GeometryGrid< HostGrid, CoordFunction, Allocator > GridType
Definition: twistutility.hh:381
Definition: griddeclaration.hh:41
Definition: griddeclaration.hh:38
Utility to get twist from IntersectionIterator, if provided by grid (i.e. AlbertaGrid, ALUGrid) otherwise return default values (correct for YASP/SGRID).
Definition: twistutility.hh:83
static GeometryType elementGeometry(const Intersection &intersection, bool inside)
return element geometry type of inside or outside entity
Definition: twistutility.hh:408
Definition: griddeclaration.hh:44
static GeometryType elementGeometry(const Intersection &intersection, const bool inside)
return geometry type of inside or outside entity
Definition: twistutility.hh:46
static int twistInSelf(const GridType &, const Intersection &)
return 0 for inner face
Definition: twistutility.hh:32
GridType::Traits::LevelIntersectionIterator LevelIntersectionIterator
Definition: twistutility.hh:384
Definition: boundaryidprovider.hh:21
static int twistInNeighbor(const GridType &grid, const Intersection &intersection)
return twist for outer face
Definition: twistutility.hh:401
static int twistInSelf(const GridType &grid, const Intersection &intersection)
return twist for inner face
Definition: twistutility.hh:394
Double abs(const Double &a)
Definition: double.hh:860
Dune::EntityPointer< Grid, Implementation >::Entity make_entity(const Dune::EntityPointer< Grid, Implementation > &entityPointer)
Definition: compatibility.hh:23
Definition: griddeclaration.hh:35
Definition: coordinate.hh:4
Grid GridType
Definition: twistutility.hh:28
GridType::Traits::LeafIntersectionIterator LeafIntersectionIterator
Definition: twistutility.hh:382
static int twistInNeighbor(const GridType &, const Intersection &)
return 0 for outer face
Definition: twistutility.hh:39
LevelIntersectionIterator::Intersection LevelIntersection
Definition: twistutility.hh:385
LeafIntersectionIterator::Intersection LeafIntersection
Definition: twistutility.hh:383
TwistFreeTwistUtility provides the default implementation for twistfree grid such as Cartesian grids...
Definition: twistutility.hh:26