DUNE-FEM (unstable)

intersection.hh
1#ifndef DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_INTERSECTION_HH
2#define DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_INTERSECTION_HH
3
4#include <type_traits>
5
7
8#include <dune/geometry/referenceelements.hh>
10#include <dune/geometry/referenceelements.hh>
11#include <dune/fem/misc/boundaryidprovider.hh>
12
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 // GeometryGridPartIntersection
20 // ----------------------------
21
22 template< class GridFamily >
23 class GeometryGridPartIntersection
24 {
25 typedef GeometryGridPartIntersection<GridFamily> This;
26 typedef typename std::remove_const< GridFamily >::type::Traits Traits;
27
28 public:
29 typedef typename std::remove_const< GridFamily >::type::ctype ctype;
30
31 static const int dimension = std::remove_const< GridFamily >::type::dimension;
32 static const int dimensionworld = std::remove_const< GridFamily >::type::dimensionworld;
33
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;
38
39 typedef typename Traits::GridFunctionType GridFunctionType;
40
41 typedef FieldVector< ctype, dimensionworld > GlobalCoordinate;
42 typedef FieldVector< ctype, dimension-1 > LocalCoordinate;
43
44 private:
45 typedef typename Geometry::Implementation GeometryImplType;
46
47 typedef typename Traits::HostGridPartType HostGridPartType;
48 typedef typename HostGridPartType::IntersectionType HostIntersectionType;
49
50 public:
51 GeometryGridPartIntersection () = default;
52 GeometryGridPartIntersection ( const GridFunctionType &gridFunction, const typename ElementGeometry::Implementation &insideGeo, HostIntersectionType hostIntersection )
53 : hostIntersection_( std::move( hostIntersection ) ), gridFunction_( &gridFunction ), insideGeo_( insideGeo )
54 {}
55
56 operator bool () const { return bool( hostIntersection_ ); }
57
58 Entity inside () const { return Entity( typename Entity::Implementation( gridFunction(), hostIntersection().inside() )); }
59 Entity outside () const { return Entity( typename Entity::Implementation( gridFunction(), hostIntersection().outside() )); }
60
61 int boundaryId () const {
62 return Dune::Fem::BoundaryIdProvider< typename HostGridPartType::GridType > :: boundaryId( hostIntersection() );
63 }
64
65 bool boundary () const { return hostIntersection().boundary(); }
66
67 bool conforming () const { return hostIntersection().conforming(); }
68
69 int twistInSelf() const { return hostIntersection().impl().twistInSelf(); }
70
71 int twistInNeighbor() const { return hostIntersection().impl().twistInNeighbor(); }
72
73 bool neighbor () const { return hostIntersection().neighbor(); }
74
75 std::size_t boundarySegmentIndex () const { return hostIntersection().boundarySegmentIndex(); }
76
77 LocalGeometry geometryInInside () const { return hostIntersection().geometryInInside(); }
78 LocalGeometry geometryInOutside () const { return hostIntersection().geometryInOutside(); }
79
80 Geometry geometry () const
81 {
82 typedef typename Geometry::Implementation Impl;
83 return Geometry( Impl( insideGeo_, geometryInInside(), 2*insideGeo_.impl().localFunction().order()+1 ) );
84 }
85
86 bool equals ( const This &other ) const { return hostIntersection() == other.hostIntersection(); }
87
88 GeometryType type () const { return hostIntersection().type(); }
89
90 int indexInInside () const { return hostIntersection().indexInInside(); }
91 int indexInOutside () const { return hostIntersection().indexInOutside(); }
92
93 GlobalCoordinate integrationOuterNormal ( const LocalCoordinate &local ) const
94 {
95 const auto &refElement = ReferenceElements< ctype, dimension >::general( insideGeo_.type() );
96 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
97
98 const auto jit = insideGeo_.jacobianInverseTransposed( geometryInInside().global( local ) );
99
100 GlobalCoordinate normal;
101 jit.mv( refNormal, normal );
102 // double det = std::sqrt( GeometryGridPartGeometryType::MatrixHelper::template detATA<dimensionworld,dimension>( jit ) );
103 // return normal *= ctype( 1 ) / sqrt(det);
104 return normal *= geometry().integrationElement( local ) / normal.two_norm();
105
106#if 0
108FieldVector< ctype, dimension > x( geometryInInside().global( local ) );
109FieldVector< ctype, dimensionworld > normal, tau, nu;
110FieldMatrix< ctype, 1, dimensionworld > tauT = geometry().jacobianTransposed(local);
111
112for (int i = 0; i != dimensionworld; ++i)
113 tau[i] = tauT[0][i];
114
115tau /= tau.two_norm();
116
117FieldMatrix< ctype, dimensionworld, dimensionworld > localFnGrad, localFnGradT;
118gridFunction().localFunction(*hostIntersection().inside()).jacobian(x, localFnGrad);
119
120for (int i = 0; i != dimensionworld; ++i)
121 for (int j = 0; j != dimensionworld; ++j )
122 localFnGradT[i][j] = localFnGrad[j][i];
123
124crossProduct(localFnGradT[0], localFnGradT[1], nu );
125nu /= nu.two_norm();
126
127/*
128nu = insideGeo_.global(x);
129nu /= nu.two_norm();
130*/
131
132crossProduct(nu, tau, normal);
133
134// get conormal in same direction as discrete conormal
135if (normal*hostIntersection().integrationOuterNormal(local) < 0)
136 normal *= -1;
137
138// normal /= normal.two_norm();
139// normal *= GeometryImplType(insideGeo_, gridFunction_, hostIntersection_, affineGeometry).integrationElement(local);
140normal *= geometry().integrationElement(local)/normal.two_norm();
141 // return hostIntersection().integrationOuterNormal(local);
142 return normal;
143#endif
144 }
145
146#if 0
147 void crossProduct(const FieldVector< ctype, dimensionworld > &vec1, const FieldVector< ctype, dimensionworld > &vec2, FieldVector< ctype, dimensionworld > &ret) const
148 {
149 assert( dimensionworld == 3 );
150
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];
154 }
155#endif
156
157 GlobalCoordinate outerNormal ( const LocalCoordinate &local ) const
158 {
159 const auto &refElement = Dune::ReferenceElements< ctype, dimension >::general( insideGeo_.type() );
160 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
161
162 GlobalCoordinate normal;
163 insideGeo_.jacobianInverseTransposed( geometryInInside().global( local ) ).mv( refNormal, normal );
164 return normal;
165 }
166
167 GlobalCoordinate unitOuterNormal ( const LocalCoordinate &local ) const
168 {
169 GlobalCoordinate normal = outerNormal( local );
170 return normal *= (ctype( 1 ) / normal.two_norm());
171 }
172
173 GlobalCoordinate centerUnitOuterNormal () const
174 {
175 const auto &refElement = Dune::ReferenceElements< ctype, dimension >::general( insideGeo_.type() );
176 const auto &refNormal = refElement.integrationOuterNormal( indexInInside() );
177
178 GlobalCoordinate normal;
179 insideGeo_.jacobianInverseTransposed( geometryInInside().center() ).mv( refNormal, normal );
180 return normal *= (ctype( 1 ) / normal.two_norm());
181 }
182
183 const HostIntersectionType &hostIntersection () const { return hostIntersection_; }
184
185 const GridFunctionType &gridFunction () const
186 {
187 assert( gridFunction_ );
188 return *gridFunction_;
189 }
190
191 private:
192 HostIntersectionType hostIntersection_;
193 const GridFunctionType *gridFunction_ = nullptr;
194 typename ElementGeometry::Implementation insideGeo_;
195 };
196
197 } // namespace Fem
198
199} // namespace Dune
200
201#endif // #ifndef DUNE_FEM_GRIDPART_GEOMETRYGRIDPART_INTERSECTION_HH
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
STL namespace.
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)