dune-mmesh (1.4)

intersections.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_MMESH_GRID_INTERSECTIONS_HH
4#define DUNE_MMESH_GRID_INTERSECTIONS_HH
5
6#include <unordered_set>
7
8// Dune MMesh includes
12#include <dune/mmesh/misc/twistutility.hh>
13
14// local includes
15
20namespace Dune
21{
22
23 // External forward declarations
24 template< class Grid >
25 struct HostGridAccess;
26
35 template<class GridImp>
37 {
38 friend class MMeshLeafIntersectionIterator<GridImp>;
39
40 friend struct HostGridAccess< typename std::remove_const< GridImp >::type >;
41
42 enum {dim=GridImp::dimension};
43
44 enum {dimworld=GridImp::dimensionworld};
45
46 // The type used to store coordinates
47 typedef typename GridImp::ctype ctype;
48
49 typedef typename GridImp::template HostGridEntity<0> HostGridEntity;
50 typedef typename GridImp::template HostGridEntity<1> HostLeafIntersection;
51
52 public:
53 enum {dimension=GridImp::dimension};
54 enum {dimensionworld=GridImp::dimensionworld};
55 typedef typename GridImp::template Codim<1>::Geometry Geometry;
56 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
57 typedef typename GridImp::template Codim<1>::LocalGeometry::Implementation LocalGeometryImpl;
58 typedef typename GridImp::template Codim<0>::Entity Entity;
59 typedef FieldVector<ctype, dimworld> NormalVector;
60
62 {}
63
64 MMeshLeafIntersection(const GridImp* mMesh,
65 const HostGridEntity& hostEntity,
66 const int index)
67 : mMesh_(mMesh)
68 , hostIntersection_(hostEntity, index)
69 {}
70
71 MMeshLeafIntersection(const GridImp* mMesh,
72 HostLeafIntersection&& hostIntersection)
73 : mMesh_(mMesh)
74 , hostIntersection_(std::move(hostIntersection))
75 {}
76
78 bool equals(const MMeshLeafIntersection& other) const
79 {
80 return hostIntersection_ == other.hostIntersection_;
81 }
82
85 Entity inside() const {
86 return MMeshEntity<0,dim,GridImp>(mMesh_, hostIntersection_.first);
87 }
88
91 Entity outside() const {
92 assert( neighbor() );
93 auto neighborHostEntity = (hostIntersection_.first)->neighbor(hostIntersection_.second);
94 return MMeshEntity<0,dim,GridImp>(mMesh_, neighborHostEntity);
95 }
96
98 bool boundary () const {
99 auto neighborHostEntity = (hostIntersection_.first)->neighbor(hostIntersection_.second);
100 return mMesh_->getHostGrid().is_infinite(neighborHostEntity);
101 }
102
108 NormalVector centerUnitOuterNormal () const {
109 return unitOuterNormal( FieldVector<ctype, dim-1> ( 0 ) );
110 }
111
113 bool neighbor() const {
114 return !boundary();
115 }
116
118 std::size_t boundarySegmentIndex() const
119 {
120 HostGridEntity cell = hostIntersection_.first;
121 const auto& facetIdx = hostIntersection_.second;
122
123 std::vector< std::size_t > vertices;
124 for( std::size_t i = 0; i < dim; ++i )
125 vertices.push_back( cell->vertex( (facetIdx+i+1)%(dim+1) )->info().id );
126 std::sort(vertices.begin(), vertices.end());
127
128 auto it = mMesh_->boundarySegments().find( vertices );
129 if( it == mMesh_->boundarySegments().end() )
130 return 0; // default to 0
131
132 return it->second;
133 }
134
136 std::size_t boundaryId() const
137 {
138 auto it = mMesh_->boundaryIds().find( boundarySegmentIndex() );
139 if( it == mMesh_->boundaryIds().end() )
140 return 0; // default
141
142 return it->second;
143 }
144
146 bool conforming () const {
147 // we are always conforming
148 return true;
149 }
150
152 GeometryType type () const {
153 return GeometryTypes::simplex(dim-1);
154 }
155
160 LocalGeometry geometryInInside () const
161 {
162 LocalGeometryImpl impl( indexInInside() );
163 return LocalGeometry( impl );
164 }
165
168 LocalGeometry geometryInOutside () const
169 {
170 assert( neighbor() );
171 LocalGeometryImpl impl( indexInOutside() );
172 return LocalGeometry( impl );
173 }
174
177 Geometry geometry () const
178 {
179 return Geometry( hostIntersection_ );
180 }
181
183 int indexInInside () const {
184 return MMeshImpl::cgalFacetToDuneFacet<dim, HostLeafIntersection>( hostIntersection_ );
185 }
186
188 int indexInOutside () const {
189 const auto& neighbor = hostIntersection_.first->neighbor( hostIntersection_.second );
190 const auto& second = mMesh_->getHostGrid().mirror_index( hostIntersection_.first, hostIntersection_.second );
191 HostLeafIntersection facetFromOutside ( { neighbor, second } );
192 return MMeshImpl::cgalFacetToDuneFacet<dim, HostLeafIntersection>( facetFromOutside );
193 }
194
196 FieldVector<ctype, GridImp::dimensionworld> outerNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
197 return integrationOuterNormal( local );
198 }
199
201 template< int d = dim >
202 typename std::enable_if_t< d == 2, NormalVector >
203 integrationOuterNormal (const FieldVector<ctype, dim-1>& local) const
204 {
205 HostGridEntity face = hostIntersection_.first;
206 const auto& edgeIdx = hostIntersection_.second;
207
208 const auto& p1 = face->vertex( face->cw ( edgeIdx ) )->point();
209 const auto& p2 = face->vertex( face->ccw( edgeIdx ) )->point();
210
211 return NormalVector ( { p1.y() - p2.y(), - p1.x() + p2.x() } );
212 }
213
214 template< int d = dim >
215 typename std::enable_if_t< d == 3, NormalVector >
216 integrationOuterNormal (const FieldVector<ctype, dim-1>& local) const
217 {
218 HostGridEntity cell = hostIntersection_.first;
219 const auto& facetIdx = hostIntersection_.second;
220
221 const auto& p1 = cell->vertex( (facetIdx+1)%4 )->point();
222 const auto& p2 = cell->vertex( (facetIdx+2)%4 )->point();
223 const auto& p3 = cell->vertex( (facetIdx+3)%4 )->point();
224
225 return makeFieldVector(
226 ( facetIdx % 2 == 0) ?
227 CGAL::normal(p1, p2, p3) :
228 CGAL::normal(p1, p3, p2)
229 );
230 }
231
233 FieldVector<ctype, GridImp::dimensionworld> unitOuterNormal (const FieldVector<ctype, GridImp::dimension-1>& local) const {
234 NormalVector n = integrationOuterNormal( local );
235 n /= n.two_norm();
236 return n;
237 }
238
239 const HostLeafIntersection& getHostIntersection() const
240 {
241 return hostIntersection_;
242 }
243
244 private:
246 const GridImp* mMesh_;
247 HostLeafIntersection hostIntersection_;
248 };
249
250} // namespace Dune
251
252#endif
The implementation of entities in MMesh.
Definition: entity.hh:448
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: intersectioniterator.hh:30
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: intersections.hh:37
std::enable_if_t< d==2, NormalVector > integrationOuterNormal(const FieldVector< ctype, dim-1 > &local) const
return outer normal multiplied by the integration element
Definition: intersections.hh:203
bool conforming() const
Return true if this is a conforming intersection.
Definition: intersections.hh:146
std::size_t boundarySegmentIndex() const
return the boundary segment index
Definition: intersections.hh:118
Entity outside() const
Definition: intersections.hh:91
NormalVector centerUnitOuterNormal() const
Return unit outer normal (length == 1)
Definition: intersections.hh:108
LocalGeometry geometryInOutside() const
Definition: intersections.hh:168
FieldVector< ctype, GridImp::dimensionworld > unitOuterNormal(const FieldVector< ctype, GridImp::dimension-1 > &local) const
return unit outer normal
Definition: intersections.hh:233
bool boundary() const
return true if intersection is with boundary.
Definition: intersections.hh:98
GeometryType type() const
Geometry type of an intersection.
Definition: intersections.hh:152
bool equals(const MMeshLeafIntersection &other) const
returns true if the host entities are equal
Definition: intersections.hh:78
FieldVector< ctype, GridImp::dimensionworld > outerNormal(const FieldVector< ctype, GridImp::dimension-1 > &local) const
return outer normal
Definition: intersections.hh:196
std::size_t boundaryId() const
return the boundary id
Definition: intersections.hh:136
bool neighbor() const
return true if across the edge an neighbor on this level exists
Definition: intersections.hh:113
Geometry geometry() const
Definition: intersections.hh:177
int indexInOutside() const
local number of codim 1 entity in neighbor where intersection is contained
Definition: intersections.hh:188
int indexInInside() const
local number of codim 1 entity in self where intersection is contained in
Definition: intersections.hh:183
Entity inside() const
Definition: intersections.hh:85
LocalGeometry geometryInInside() const
Definition: intersections.hh:160
The MMeshEntity class.
The MMeshLeafIterator class.
STL namespace.
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 6, 22:49, 2025)