dune-mmesh (unstable)

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// External forward declarations
23template <class Grid>
24struct HostGridAccess;
25
34template <class GridImp>
36 friend class MMeshLeafIntersectionIterator<GridImp>;
37
38 friend struct HostGridAccess<typename std::remove_const<GridImp>::type>;
39
40 enum { dim = GridImp::dimension };
41
42 enum { dimworld = GridImp::dimensionworld };
43
44 // The type used to store coordinates
45 typedef typename GridImp::ctype ctype;
46
47 typedef typename GridImp::template HostGridEntity<0> HostGridEntity;
48 typedef typename GridImp::template HostGridEntity<1> HostLeafIntersection;
49
50 public:
51 enum { dimension = GridImp::dimension };
52 enum { dimensionworld = GridImp::dimensionworld };
53 typedef typename GridImp::template Codim<1>::Geometry Geometry;
54 typedef typename GridImp::template Codim<1>::LocalGeometry LocalGeometry;
55 typedef typename GridImp::template Codim<1>::LocalGeometry::Implementation
56 LocalGeometryImpl;
57 typedef typename GridImp::template Codim<0>::Entity Entity;
58 typedef FieldVector<ctype, dimworld> NormalVector;
59
61
62 MMeshLeafIntersection(const GridImp* mMesh, const HostGridEntity& hostEntity,
63 const int index)
64 : mMesh_(mMesh), hostIntersection_(hostEntity, index) {}
65
66 MMeshLeafIntersection(const GridImp* mMesh,
67 HostLeafIntersection&& hostIntersection)
68 : mMesh_(mMesh), hostIntersection_(std::move(hostIntersection)) {}
69
71 bool equals(const MMeshLeafIntersection& other) const {
72 return hostIntersection_ == other.hostIntersection_;
73 }
74
77 Entity inside() const {
78 return MMeshEntity<0, dim, GridImp>(mMesh_, hostIntersection_.first);
79 }
80
83 Entity outside() const {
84 assert(neighbor());
85 auto neighborHostEntity =
86 (hostIntersection_.first)->neighbor(hostIntersection_.second);
87 return MMeshEntity<0, dim, GridImp>(mMesh_, neighborHostEntity);
88 }
89
91 bool boundary() const {
92 auto neighborHostEntity =
93 (hostIntersection_.first)->neighbor(hostIntersection_.second);
94 return mMesh_->getHostGrid().is_infinite(neighborHostEntity);
95 }
96
102 NormalVector centerUnitOuterNormal() const {
103 return unitOuterNormal(FieldVector<ctype, dim - 1>(0));
104 }
105
107 bool neighbor() const { return !boundary(); }
108
110 std::size_t boundarySegmentIndex() const {
111 HostGridEntity cell = hostIntersection_.first;
112 const auto& facetIdx = hostIntersection_.second;
113
114 std::vector<std::size_t> vertices;
115 for (std::size_t i = 0; i < dim; ++i)
116 vertices.push_back(
117 cell->vertex((facetIdx + i + 1) % (dim + 1))->info().id);
118 std::sort(vertices.begin(), vertices.end());
119
120 auto it = mMesh_->boundarySegments().find(vertices);
121 if (it == mMesh_->boundarySegments().end()) return 0; // default to 0
122
123 return it->second;
124 }
125
127 std::size_t boundaryId() const {
128 auto it = mMesh_->boundaryIds().find(boundarySegmentIndex());
129 if (it == mMesh_->boundaryIds().end()) return 0; // default
130
131 return it->second;
132 }
133
135 bool conforming() const {
136 // we are always conforming
137 return true;
138 }
139
141 GeometryType type() const { return GeometryTypes::simplex(dim - 1); }
142
147 LocalGeometry geometryInInside() const {
148 LocalGeometryImpl impl(indexInInside());
149 return LocalGeometry(impl);
150 }
151
155 LocalGeometry geometryInOutside() const {
156 assert(neighbor());
157 LocalGeometryImpl impl(indexInOutside());
158 return LocalGeometry(impl);
159 }
160
164 Geometry geometry() const { return Geometry(hostIntersection_); }
165
167 int indexInInside() const {
168 return MMeshImpl::cgalFacetToDuneFacet<dim, HostLeafIntersection>(
169 hostIntersection_);
170 }
171
173 int indexInOutside() const {
174 const auto& neighbor =
175 hostIntersection_.first->neighbor(hostIntersection_.second);
176 const auto& second = mMesh_->getHostGrid().mirror_index(
177 hostIntersection_.first, hostIntersection_.second);
178 HostLeafIntersection facetFromOutside({neighbor, second});
179 return MMeshImpl::cgalFacetToDuneFacet<dim, HostLeafIntersection>(
180 facetFromOutside);
181 }
182
184 FieldVector<ctype, GridImp::dimensionworld> outerNormal(
185 const FieldVector<ctype, GridImp::dimension - 1>& local) const {
186 return integrationOuterNormal(local);
187 }
188
190 template <int d = dim>
191 typename std::enable_if_t<d == 2, NormalVector> integrationOuterNormal(
192 const FieldVector<ctype, dim - 1>& local) const {
193 HostGridEntity face = hostIntersection_.first;
194 const auto& edgeIdx = hostIntersection_.second;
195
196 const auto& p1 = face->vertex(face->cw(edgeIdx))->point();
197 const auto& p2 = face->vertex(face->ccw(edgeIdx))->point();
198
199 return NormalVector({p1.y() - p2.y(), -p1.x() + p2.x()});
200 }
201
202 template <int d = dim>
203 typename std::enable_if_t<d == 3, NormalVector> integrationOuterNormal(
204 const FieldVector<ctype, dim - 1>& local) const {
205 HostGridEntity cell = hostIntersection_.first;
206 const auto& facetIdx = hostIntersection_.second;
207
208 const auto& p1 = cell->vertex((facetIdx + 1) % 4)->point();
209 const auto& p2 = cell->vertex((facetIdx + 2) % 4)->point();
210 const auto& p3 = cell->vertex((facetIdx + 3) % 4)->point();
211
212 return makeFieldVector((facetIdx % 2 == 0) ? CGAL::normal(p1, p2, p3)
213 : CGAL::normal(p1, p3, p2));
214 }
215
217 FieldVector<ctype, GridImp::dimensionworld> unitOuterNormal(
218 const FieldVector<ctype, GridImp::dimension - 1>& local) const {
219 NormalVector n = integrationOuterNormal(local);
220 n /= n.two_norm();
221 return n;
222 }
223
224 const HostLeafIntersection& getHostIntersection() const {
225 return hostIntersection_;
226 }
227
228 private:
230 const GridImp* mMesh_;
231 HostLeafIntersection hostIntersection_;
232};
233
234} // namespace Dune
235
236#endif
The implementation of entities in MMesh.
Definition: entity.hh:399
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition: intersectioniterator.hh:28
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition: intersections.hh:35
bool conforming() const
Return true if this is a conforming intersection.
Definition: intersections.hh:135
std::size_t boundarySegmentIndex() const
return the boundary segment index
Definition: intersections.hh:110
Entity outside() const
Definition: intersections.hh:83
NormalVector centerUnitOuterNormal() const
Return unit outer normal (length == 1)
Definition: intersections.hh:102
LocalGeometry geometryInOutside() const
Definition: intersections.hh:155
bool boundary() const
return true if intersection is with boundary.
Definition: intersections.hh:91
GeometryType type() const
Geometry type of an intersection.
Definition: intersections.hh:141
bool equals(const MMeshLeafIntersection &other) const
returns true if the host entities are equal
Definition: intersections.hh:71
std::size_t boundaryId() const
return the boundary id
Definition: intersections.hh:127
FieldVector< ctype, GridImp::dimensionworld > outerNormal(const FieldVector< ctype, GridImp::dimension - 1 > &local) const
return outer normal
Definition: intersections.hh:184
bool neighbor() const
return true if across the edge an neighbor on this level exists
Definition: intersections.hh:107
Geometry geometry() const
Definition: intersections.hh:164
FieldVector< ctype, GridImp::dimensionworld > unitOuterNormal(const FieldVector< ctype, GridImp::dimension - 1 > &local) const
return unit outer normal
Definition: intersections.hh:217
int indexInOutside() const
local number of codim 1 entity in neighbor where intersection is contained
Definition: intersections.hh:173
int indexInInside() const
local number of codim 1 entity in self where intersection is contained in
Definition: intersections.hh:167
Entity inside() const
Definition: intersections.hh:77
LocalGeometry geometryInInside() const
Definition: intersections.hh:147
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:191
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 (Sep 5, 22:35, 2025)