5#ifndef DUNE_GRID_COMMON_GEOMETRY_HH
6#define DUNE_GRID_COMMON_GEOMETRY_HH
14#include <dune/common/fmatrix.hh>
15#include <dune/common/typetraits.hh>
16#include <dune/common/transpose.hh>
17#include <dune/common/std/type_traits.hh>
19#include <dune/geometry/referenceelements.hh>
27 template<
int dim,
int dimworld,
class ct,
class Gr
idFamily >
28 class GridDefaultImplementation;
69 template<
int mydim,
int cdim,
class Gr
idImp,
template<
int,
int,
class >
class GeometryImp >
100 typedef typename GridImp::ctype
ctype;
109 typedef decltype(std::declval<Implementation>().volume())
Volume;
135 template<
class Implementation_T>
136 using JacobianInverseOfImplementation =
decltype(
typename Implementation_T::JacobianInverse{std::declval<Implementation_T>().jacobianInverse(std::declval<LocalCoordinate>())});
138 using JacobianInverseDefault =
decltype(transpose(std::declval<JacobianInverseTransposed>()));
140 template<
class Implementation_T>
141 using JacobianOfImplementation =
decltype(
typename Implementation_T::Jacobian{std::declval<Implementation_T>().jacobian(std::declval<LocalCoordinate>())});
143 using JacobianDefault =
decltype(transpose(std::declval<JacobianTransposed>()));
145 auto jacobianImpl (
const LocalCoordinate &local, std::true_type )
const
147 return impl().jacobian(local);
150 [[deprecated(
"Geometry implementatons are required to provide a jacobian(local) method. The default implementation is deprecated and will be removed after release 2.9")]]
151 auto jacobianImpl (
const LocalCoordinate &local, std::false_type )
const
156 auto jacobianInverseImpl (
const LocalCoordinate &local, std::true_type )
const
158 return impl().jacobianInverse(local);
161 [[deprecated(
"Geometry implementatons are required to provide a jacobianInverse(local) method. The default implementation is deprecated and will be removed after release 2.9")]]
162 auto jacobianInverseImpl (
const LocalCoordinate &local, std::false_type )
const
178 using JacobianInverse = Std::detected_or_t<JacobianInverseDefault, JacobianInverseOfImplementation, Implementation>;
189 using Jacobian = Std::detected_or_t<JacobianDefault, JacobianOfImplementation, Implementation>;
221 return impl().corner( i );
230 return impl().global( local );
267 return impl().integrationElement( local );
273 return impl().volume();
288 return impl().center();
304 return impl().jacobianTransposed( local );
330 return impl().jacobianInverseTransposed(local);
346 auto implDetected = Std::is_detected<JacobianOfImplementation, Implementation>{};
347 return jacobianImpl(local, implDetected);
373 auto implDetected = Std::is_detected<JacobianInverseOfImplementation, Implementation>{};
374 return jacobianInverseImpl(local, implDetected);
404 template<
int mydim,
int cdim,
class Gr
idImp,
template<
int,
int,
class>
class GeometryImp>
412 typedef typename GridImp::ctype
ctype;
430 typedef FieldMatrix< ctype, cdim, mydim >
Jacobian;
438 auto refElement = referenceElement< ctype , mydim >(type);
442 const int corners = refElement.size(0,0,mydim);
443 for(
int i=0; i<corners; ++i) localBaryCenter += refElement.position(i,mydim);
444 localBaryCenter *= (
ctype) (1.0/corners);
447 return refElement.volume() * asImp().integrationElement(localBaryCenter);
456 auto refElement = referenceElement< ctype , mydim >(type);
460 return asImp().global(refElement.position(0,0));
466 return asImp().jacobianTransposed(local).transposed();
472 return asImp().jacobianInverseTransposed(local).transposed();
477 GeometryImp<mydim,cdim,GridImp>& asImp () {
return static_cast<GeometryImp<mydim,cdim,GridImp>&
>(*this);}
478 const GeometryImp<mydim,cdim,GridImp>& asImp ()
const {
return static_cast<const GeometryImp<mydim,cdim,GridImp>&
>(*this);}
481 template<
int cdim,
class Gr
idImp,
template<
int,
int,
class>
class GeometryImp>
485 constexpr static int mydim = 0;
492 typedef typename GridImp::ctype
ctype;
508 typedef FieldMatrix< ctype, cdim, mydim >
Jacobian;
511 FieldVector<ctype, cdim> global (
const FieldVector<ctype, mydim>& local)
const
513 return asImp().corner(0);
517 FieldVector<ctype, mydim> local (
const FieldVector<ctype, cdim>& )
const
519 return FieldVector<ctype, mydim>();
531 return asImp().corner(0);
537 return asImp().jacobianTransposed(local).transposed();
543 return asImp().jacobianInverseTransposed(local).transposed();
548 GeometryImp<mydim,cdim,GridImp>& asImp () {
return static_cast<GeometryImp<mydim,cdim,GridImp>&
>(*this);}
549 const GeometryImp<mydim,cdim,GridImp>& asImp ()
const {
return static_cast<const GeometryImp<mydim,cdim,GridImp>&
>(*this);}
557 template<
int mydim,
int cdim,
class Gr
idImp,
template<
int,
int,
class >
class GeometryImp>
580 template<
int mydim,
int cdim,
class Gr
idImp,
template<
int,
int,
class >
class GeometryImp,
typename Impl>
582 ->
decltype(referenceElement<typename GridImp::ctype,mydim>(geo.type()))
585 return referenceElement<typename Geo::ctype,Geo::mydimension>(geo.type());
Include standard header files.
Definition: agrid.hh:60
auto referenceElement(const Geometry< mydim, cdim, GridImp, GeometryImp > &geo) -> decltype(referenceElement(geo, geo.impl()))
Definition: common/geometry.hh:558
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Wrapper class for geometries.
Definition: common/geometry.hh:71
Volume integrationElement(const LocalCoordinate &local) const
Return the factor appearing in the integral transformation formula.
Definition: common/geometry.hh:265
Jacobian jacobian(const LocalCoordinate &local) const
Return the Jacobian.
Definition: common/geometry.hh:344
FieldVector< ctype, cdim > GlobalCoordinate
type of the global coordinates
Definition: common/geometry.hh:106
JacobianTransposed jacobianTransposed(const LocalCoordinate &local) const
Return the transposed of the Jacobian.
Definition: common/geometry.hh:302
Implementation & impl()
access to the underlying implementation
Definition: common/geometry.hh:85
GeometryType type() const
Return the type of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: common/geometry.hh:194
GlobalCoordinate global(const LocalCoordinate &local) const
Evaluate the map .
Definition: common/geometry.hh:228
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
Return inverse of Jacobian.
Definition: common/geometry.hh:371
Geometry(const Implementation &impl)
copy constructor from implementation
Definition: common/geometry.hh:384
Implementation::JacobianTransposed JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:131
Implementation::JacobianInverseTransposed JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:120
GlobalCoordinate corner(int i) const
Obtain a corner of the geometry.
Definition: common/geometry.hh:219
int corners() const
Return the number of corners of the reference element.
Definition: common/geometry.hh:205
Volume volume() const
return volume of geometry
Definition: common/geometry.hh:271
static constexpr int coorddimension
dimension of embedding coordinate system
Definition: common/geometry.hh:97
Std::detected_or_t< JacobianInverseDefault, JacobianInverseOfImplementation, Implementation > JacobianInverse
type of jacobian inverse
Definition: common/geometry.hh:178
decltype(std::declval< Implementation >().volume()) Volume
Number type used for the geometry volume.
Definition: common/geometry.hh:109
GridImp::ctype ctype
define type used for coordinates in grid module
Definition: common/geometry.hh:100
const Implementation & impl() const
access to the underlying implementation
Definition: common/geometry.hh:91
FieldVector< ctype, mydim > LocalCoordinate
type of local coordinates
Definition: common/geometry.hh:103
Implementation realGeometry
Definition: common/geometry.hh:392
GlobalCoordinate center() const
return center of geometry
Definition: common/geometry.hh:286
bool affine() const
Return true if the geometry mapping is affine and false otherwise.
Definition: common/geometry.hh:197
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:581
Std::detected_or_t< JacobianDefault, JacobianOfImplementation, Implementation > Jacobian
type of jacobian
Definition: common/geometry.hh:189
static constexpr int mydimension
geometry dimension
Definition: common/geometry.hh:94
GeometryImp< mydim, cdim, GridImp > Implementation
type of underlying implementation
Definition: common/geometry.hh:78
JacobianInverseTransposed jacobianInverseTransposed(const LocalCoordinate &local) const
Return inverse of transposed of Jacobian.
Definition: common/geometry.hh:328
Default implementation for class Geometry.
Definition: common/geometry.hh:406
FieldVector< ctype, cdim > GlobalCoordinate
Definition: common/geometry.hh:415
static const int mydimension
Definition: common/geometry.hh:408
Volume volume() const
return volume of the geometry
Definition: common/geometry.hh:433
FieldVector< ctype, mydim > LocalCoordinate
Definition: common/geometry.hh:414
GlobalCoordinate center() const
return center of the geometry
Definition: common/geometry.hh:451
FieldMatrix< ctype, cdim, mydim > Jacobian
type of jacobian
Definition: common/geometry.hh:430
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
Return inverse of Jacobian.
Definition: common/geometry.hh:470
FieldMatrix< ctype, mydim, cdim > JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:424
Jacobian jacobian(const LocalCoordinate &local) const
Return the Jacobian.
Definition: common/geometry.hh:464
GridImp::ctype ctype
Definition: common/geometry.hh:412
FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:421
static const int coorddimension
Definition: common/geometry.hh:409
FieldMatrix< ctype, mydim, cdim > JacobianInverse
type of jacobian inverse
Definition: common/geometry.hh:427
ctype Volume
Number type used for the geometry volume.
Definition: common/geometry.hh:418
GridImp::ctype ctype
Definition: common/geometry.hh:492
FieldVector< ctype, cdim > GlobalCoordinate
Definition: common/geometry.hh:495
FieldMatrix< ctype, cdim, mydim > JacobianInverseTransposed
type of jacobian inverse transposed
Definition: common/geometry.hh:499
FieldMatrix< ctype, mydim, cdim > JacobianInverse
type of jacobian inverse
Definition: common/geometry.hh:505
ctype Volume
Definition: common/geometry.hh:496
FieldMatrix< ctype, cdim, mydim > Jacobian
type of jacobian
Definition: common/geometry.hh:508
Jacobian jacobian(const LocalCoordinate &local) const
Return the Jacobian.
Definition: common/geometry.hh:535
JacobianInverse jacobianInverse(const LocalCoordinate &local) const
Return inverse of Jacobian.
Definition: common/geometry.hh:541
FieldVector< ctype, cdim > center() const
return center of the geometry
Definition: common/geometry.hh:529
FieldVector< ctype, mydim > LocalCoordinate
Definition: common/geometry.hh:494
FieldMatrix< ctype, mydim, cdim > JacobianTransposed
type of jacobian transposed
Definition: common/geometry.hh:502
Volume volume() const
return volume of the geometry
Definition: common/geometry.hh:523