dune-grid  2.8.0
common/geometry.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_GRID_COMMON_GEOMETRY_HH
4 #define DUNE_GRID_COMMON_GEOMETRY_HH
5 
10 #include <cassert>
11 
12 #include <dune/common/fmatrix.hh>
13 #include <dune/common/typetraits.hh>
14 
15 #include <dune/geometry/referenceelements.hh>
16 
17 namespace Dune
18 {
19 
20  // External Forward Declarations
21  // -----------------------------
22 
23  template< int dim, int dimworld, class ct, class GridFamily >
24  class GridDefaultImplementation;
25 
26 
27 
28  //*****************************************************************************
29  //
30  // Geometry
31  // forwards the interface to the implementation
32  //
33  //*****************************************************************************
34 
65  template< int mydim, int cdim, class GridImp, template< int, int, class > class GeometryImp >
66  class Geometry
67  {
68  public:
74  typedef GeometryImp< mydim, cdim, GridImp > Implementation;
75 
87  const Implementation &impl () const { return realGeometry; }
88 
90  enum { mydimension=mydim };
92  enum { coorddimension=cdim };
93 
95  typedef typename GridImp::ctype ctype;
96 
98  typedef FieldVector<ctype, mydim> LocalCoordinate;
99 
101  typedef FieldVector< ctype, cdim > GlobalCoordinate;
102 
104  typedef decltype(std::declval<Implementation>().volume()) Volume;
105 
116 
127 
131  GeometryType type () const { return impl().type(); }
132 
134  bool affine() const { return impl().affine(); }
135 
142  int corners () const { return impl().corners(); }
143 
156  GlobalCoordinate corner ( int i ) const
157  {
158  return impl().corner( i );
159  }
160 
166  {
167  return impl().global( local );
168  }
169 
175  {
176  return impl().local( global );
177  }
178 
203  {
204  return impl().integrationElement( local );
205  }
206 
208  Volume volume () const
209  {
210  return impl().volume();
211  }
212 
224  {
225  return impl().center();
226  }
227 
240  {
241  return impl().jacobianTransposed( local );
242  }
243 
266  {
267  return impl().jacobianInverseTransposed(local);
268  }
269  //===========================================================
273  //===========================================================
274 
276  explicit Geometry ( const Implementation &impl )
277  : realGeometry( impl )
278  {}
279 
281 
283  const Geometry &operator= ( const Geometry &rhs ) = delete;
284 
285  protected:
286 
288  };
289 
290 
291 
292  //************************************************************************
293  // GEOMETRY Default Implementations
294  //*************************************************************************
295  //
296  // --GeometryDefault
297  //
299  template<int mydim, int cdim, class GridImp, template<int,int,class> class GeometryImp>
301  {
302  public:
303  static const int mydimension = mydim;
304  static const int coorddimension = cdim;
305 
306  // save typing
307  typedef typename GridImp::ctype ctype;
308 
309  typedef FieldVector< ctype, mydim > LocalCoordinate;
310  typedef FieldVector< ctype, cdim > GlobalCoordinate;
311 
313  typedef ctype Volume;
314 
316  typedef FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed;
317 
319  typedef FieldMatrix< ctype, mydim, cdim > JacobianTransposed;
320 
322  Volume volume () const
323  {
324  GeometryType type = asImp().type();
325 
326  // get corresponding reference element
327  auto refElement = referenceElement< ctype , mydim >(type);
328 
329  LocalCoordinate localBaryCenter ( 0 );
330  // calculate local bary center
331  const int corners = refElement.size(0,0,mydim);
332  for(int i=0; i<corners; ++i) localBaryCenter += refElement.position(i,mydim);
333  localBaryCenter *= (ctype) (1.0/corners);
334 
335  // volume is volume of reference element times integrationElement
336  return refElement.volume() * asImp().integrationElement(localBaryCenter);
337  }
338 
341  {
342  GeometryType type = asImp().type();
343 
344  // get corresponding reference element
345  auto refElement = referenceElement< ctype , mydim >(type);
346 
347  // center is (for now) the centroid of the reference element mapped to
348  // this geometry.
349  return asImp().global(refElement.position(0,0));
350  }
351 
352  private:
354  GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
355  const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
356  }; // end GeometryDefault
357 
358  template<int cdim, class GridImp, template<int,int,class> class GeometryImp>
359  class GeometryDefaultImplementation<0,cdim,GridImp,GeometryImp>
360  {
361  // my dimension
362  enum { mydim = 0 };
363 
364  public:
365  static const int mydimension = mydim;
366  static const int coorddimension = cdim;
367 
368  // save typing
369  typedef typename GridImp::ctype ctype;
370 
371  typedef FieldVector< ctype, mydim > LocalCoordinate;
372  typedef FieldVector< ctype, cdim > GlobalCoordinate;
373  typedef ctype Volume;
374 
376  typedef FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed;
377 
379  typedef FieldMatrix< ctype, mydim, cdim > JacobianTransposed;
380 
382  FieldVector<ctype, cdim> global (const FieldVector<ctype, mydim>& local) const
383  {
384  return asImp().corner(0);
385  }
386 
388  FieldVector<ctype, mydim> local (const FieldVector<ctype, cdim>& ) const
389  {
390  return FieldVector<ctype, mydim>();
391  }
392 
394  Volume volume () const
395  {
396  return Volume(1.0);
397  }
398 
400  FieldVector<ctype, cdim> center () const
401  {
402  return asImp().corner(0);
403  }
404 
405  private:
406  // Barton-Nackman trick
407  GeometryImp<mydim,cdim,GridImp>& asImp () {return static_cast<GeometryImp<mydim,cdim,GridImp>&>(*this);}
408  const GeometryImp<mydim,cdim,GridImp>& asImp () const {return static_cast<const GeometryImp<mydim,cdim,GridImp>&>(*this);}
409  }; // end GeometryDefault
410 
411 
412 
413  // referenceElement
414  // ----------------
415 
416  template< int mydim, int cdim, class GridImp, template< int, int, class > class GeometryImp>
418  -> decltype(referenceElement(geo,geo.impl()))
419  {
420  return referenceElement(geo,geo.impl());
421  }
422 
424 
439  template< int mydim, int cdim, class GridImp, template< int, int, class > class GeometryImp, typename Impl>
441  -> decltype(referenceElement<typename GridImp::ctype,mydim>(geo.type()))
442  {
444  return referenceElement<typename Geo::ctype,Geo::mydimension>(geo.type());
445  }
446 
447 } // namespace Dune
448 
449 #endif // DUNE_GRID_COMMON_GEOMETRY_HH
Include standard header files.
Definition: agrid.hh:58
auto referenceElement(const Geometry< mydim, cdim, GridImp, GeometryImp > &geo) -> decltype(referenceElement(geo, geo.impl()))
Definition: common/geometry.hh:417
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
Wrapper class for geometries.
Definition: common/geometry.hh:67
const Implementation & impl() const
access to the underlying implementation
Definition: common/geometry.hh:87
FieldVector< ctype, cdim > GlobalCoordinate
type of the global coordinates
Definition: common/geometry.hh:101
JacobianTransposed jacobianTransposed(const LocalCoordinate &local) const
Return the transposed of the Jacobian.
Definition: common/geometry.hh:239
GeometryType type() const
Return the type of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/geometry.hh:131
const Geometry & operator=(const Geometry &rhs)=delete
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the map .
Definition: common/geometry.hh:165
Geometry(const Implementation &impl)
copy constructor from implementation
Definition: common/geometry.hh:276
@ mydimension
Definition: common/geometry.hh:90
Implementation::JacobianTransposed JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:126
Implementation::JacobianInverseTransposed JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:115
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: common/geometry.hh:156
decltype(std::declval< Implementation >().volume()) typedef Volume
Number type used for the geometry volume.
Definition: common/geometry.hh:104
int corners() const
Return the number of corners of the reference element.
Definition: common/geometry.hh:142
Volume volume() const
return volume of geometry
Definition: common/geometry.hh:208
GridImp::ctype ctype
define type used for coordinates in grid module
Definition: common/geometry.hh:95
ctype integrationElement(const LocalCoordinate &local) const
Return the factor appearing in the integral transformation formula.
Definition: common/geometry.hh:202
Implementation & impl()
access to the underlying implementation
Definition: common/geometry.hh:81
FieldVector< ctype, mydim > LocalCoordinate
type of local coordinates
Definition: common/geometry.hh:98
Implementation realGeometry
Definition: common/geometry.hh:287
GlobalCoordinate center() const
return center of geometry
Definition: common/geometry.hh:223
bool affine() const
Return true if the geometry mapping is affine and false otherwise.
Definition: common/geometry.hh:134
auto referenceElement(const Geometry< mydim, cdim, GridImp, GeometryImp > &geo, const Impl &) -> decltype(referenceElement< typename GridImp::ctype, mydim >(geo.type()))
Second-level dispatch to select the correct reference element for a grid geometry.
Definition: common/geometry.hh:440
@ coorddimension
Definition: common/geometry.hh:92
GeometryImp< mydim, cdim, GridImp > Implementation
type of underlying implementation
Definition: common/geometry.hh:74
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Return inverse of transposed of Jacobian.
Definition: common/geometry.hh:265
Default implementation for class Geometry.
Definition: common/geometry.hh:301
FieldVector< ctype, cdim > GlobalCoordinate
Definition: common/geometry.hh:310
static const int mydimension
Definition: common/geometry.hh:303
Volume volume() const
return volume of the geometry
Definition: common/geometry.hh:322
FieldVector< ctype, mydim > LocalCoordinate
Definition: common/geometry.hh:309
GlobalCoordinate center() const
return center of the geometry
Definition: common/geometry.hh:340
FieldMatrix< ctype, mydim, cdim > JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:319
GridImp::ctype ctype
Definition: common/geometry.hh:307
FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:316
static const int coorddimension
Definition: common/geometry.hh:304
ctype Volume
Number type used for the geometry volume.
Definition: common/geometry.hh:313
GridImp::ctype ctype
Definition: common/geometry.hh:369
FieldVector< ctype, cdim > GlobalCoordinate
Definition: common/geometry.hh:372
FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:376
FieldVector< ctype, mydim > LocalCoordinate
Definition: common/geometry.hh:371
FieldMatrix< ctype, mydim, cdim > JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:379
FieldVector< ctype, cdim > center() const
return center of the geometry
Definition: common/geometry.hh:400
Volume volume() const
return volume of the geometry
Definition: common/geometry.hh:394