1#ifndef DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_INTERSECTION_HH
2#define DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_INTERSECTION_HH
8#include <dune/geometry/referenceelements.hh>
10#include <dune/geometry/referenceelements.hh>
11#include <dune/fem/misc/boundaryidprovider.hh>
22 template<
class Gr
idFamily >
23 class GeometryGridPartIntersection
25 typedef GeometryGridPartIntersection<GridFamily> This;
26 typedef typename std::remove_const< GridFamily >::type::Traits Traits;
29 typedef typename std::remove_const< GridFamily >::type::ctype ctype;
31 static const int dimension = std::remove_const< GridFamily >::type::dimension;
32 static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
34 typedef typename Traits::template Codim< 0 >::Entity Entity;
35 typedef typename Traits::template Codim< 0 >::Geometry ElementGeometry;
36 typedef typename Traits::template Codim< 1 >::Geometry Geometry;
37 typedef typename Traits::template Codim< 1 >::LocalGeometry LocalGeometry;
39 typedef typename Traits::GridFunctionType GridFunctionType;
41 typedef FieldVector< ctype, dimensionworld > GlobalCoordinate;
42 typedef FieldVector< ctype, dimension-1 > LocalCoordinate;
47 typedef typename Traits::HostGridPartType HostGridPartType;
48 typedef typename HostGridPartType::IntersectionType HostIntersectionType;
51 GeometryGridPartIntersection () =
default;
52 GeometryGridPartIntersection (
const GridFunctionType &gridFunction,
const typename ElementGeometry::Implementation &insideGeo, HostIntersectionType hostIntersection )
53 : hostIntersection_(
std::move( hostIntersection ) ), gridFunction_( &gridFunction ), insideGeo_( insideGeo )
56 operator bool ()
const {
return bool( hostIntersection_ ); }
58 Entity inside ()
const {
return Entity(
typename Entity::Implementation( gridFunction(), hostIntersection().inside() )); }
59 Entity outside ()
const {
return Entity(
typename Entity::Implementation( gridFunction(), hostIntersection().outside() )); }
61 int boundaryId ()
const {
62 return Dune::Fem::BoundaryIdProvider< typename HostGridPartType::GridType > :: boundaryId( hostIntersection() );
65 bool boundary ()
const {
return hostIntersection().boundary(); }
67 bool conforming ()
const {
return hostIntersection().conforming(); }
69 int twistInSelf()
const {
return hostIntersection().impl().twistInSelf(); }
71 int twistInNeighbor()
const {
return hostIntersection().impl().twistInNeighbor(); }
73 bool neighbor ()
const {
return hostIntersection().neighbor(); }
75 std::size_t boundarySegmentIndex ()
const {
return hostIntersection().boundarySegmentIndex(); }
77 LocalGeometry geometryInInside ()
const {
return hostIntersection().geometryInInside(); }
78 LocalGeometry geometryInOutside ()
const {
return hostIntersection().geometryInOutside(); }
80 Geometry geometry ()
const
83 return Geometry( Impl( insideGeo_, geometryInInside(), 2*insideGeo_.impl().localFunction().order()+1 ) );
86 bool equals (
const This &other )
const {
return hostIntersection() == other.hostIntersection(); }
88 GeometryType type ()
const {
return hostIntersection().type(); }
90 int indexInInside ()
const {
return hostIntersection().indexInInside(); }
91 int indexInOutside ()
const {
return hostIntersection().indexInOutside(); }
93 GlobalCoordinate integrationOuterNormal (
const LocalCoordinate &local )
const
96 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
98 const auto jit = insideGeo_.jacobianInverseTransposed( geometryInInside().global( local ) );
100 GlobalCoordinate normal;
101 jit.mv( refNormal, normal );
104 return normal *= geometry().integrationElement( local ) / normal.two_norm();
108FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
109FieldVector< ctype, dimensionworld > normal, tau, nu;
110FieldMatrix< ctype, 1, dimensionworld > tauT = geometry().jacobianTransposed(local);
112for (
int i = 0; i != dimensionworld; ++i)
115tau /= tau.two_norm();
117FieldMatrix< ctype, dimensionworld, dimensionworld > localFnGrad, localFnGradT;
118gridFunction().localFunction(*hostIntersection().inside()).jacobian(x, localFnGrad);
120for (
int i = 0; i != dimensionworld; ++i)
121 for (
int j = 0; j != dimensionworld; ++j )
122 localFnGradT[i][j] = localFnGrad[j][i];
124crossProduct(localFnGradT[0], localFnGradT[1], nu );
132crossProduct(nu, tau, normal);
135if (normal*hostIntersection().integrationOuterNormal(local) < 0)
140normal *= geometry().integrationElement(local)/normal.two_norm();
147 void crossProduct(
const FieldVector< ctype, dimensionworld > &vec1,
const FieldVector< ctype, dimensionworld > &vec2, FieldVector< ctype, dimensionworld > &ret)
const
149 assert( dimensionworld == 3 );
151 ret[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1];
152 ret[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2];
153 ret[2] = vec1[0]*vec2[1] - vec1[1]*vec2[0];
157 GlobalCoordinate outerNormal (
const LocalCoordinate &local )
const
160 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
162 GlobalCoordinate normal;
163 insideGeo_.jacobianInverseTransposed( geometryInInside().global( local ) ).mv( refNormal, normal );
167 GlobalCoordinate unitOuterNormal (
const LocalCoordinate &local )
const
169 GlobalCoordinate normal = outerNormal( local );
170 return normal *= (ctype( 1 ) / normal.two_norm());
173 GlobalCoordinate centerUnitOuterNormal ()
const
176 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
178 GlobalCoordinate normal;
179 insideGeo_.jacobianInverseTransposed( geometryInInside().center() ).mv( refNormal, normal );
180 return normal *= (ctype( 1 ) / normal.two_norm());
183 const HostIntersectionType &hostIntersection ()
const {
return hostIntersection_; }
185 const GridFunctionType &gridFunction ()
const
187 assert( gridFunction_ );
188 return *gridFunction_;
192 HostIntersectionType hostIntersection_;
193 const GridFunctionType *gridFunction_ =
nullptr;
194 typename ElementGeometry::Implementation insideGeo_;
An implementation of the Geometry interface for affine geometries.
EntityImp< cd, dim, GridImp > Implementation
type of underlying implementation
Definition: entity.hh:73
GeometryImp< mydim, cdim, GridImp > Implementation
type of underlying implementation
Definition: geometry.hh:78
Various macros to work with Dune module version numbers.
@ conforming
Output conforming data.
Definition: common.hh:73
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156