dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
grid/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
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
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
103 return unitOuterNormal(FieldVector<ctype, dim - 1>(0));
104 }
105
107 bool neighbor() const { return !boundary(); }
108
111 HostGridEntity cell = hostIntersection_.first;
112 const auto& facetIdx = hostIntersection_.second;
113
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
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
149 return LocalGeometry(impl);
150 }
151
156 assert(neighbor());
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 {
187 }
188
190 template <int d = dim>
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>
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 {
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
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.
STL namespace.
size_type dim() const
std::ptrdiff_t index() const
LocalIndex & local()
static FieldVector< typename Kernel::RT, 2 > makeFieldVector(const CGAL::Point_2< Kernel > &p)
Helper function to create DUNE::FieldVector from CGAL::Point_2.
Definition pointfieldvector.hh:20
StackAllocator< U, S > other
Iterator over all element neighborsMesh entities of codimension 0 ("elements") allow to visit all nei...
Definition grid/intersectioniterator.hh:28
An intersection with a leaf neighbor elementMesh entities of codimension 0 ("elements") allow to visi...
Definition grid/intersections.hh:35
bool conforming() const
Return true if this is a conforming intersection.
Definition grid/intersections.hh:135
FieldVector< ctype, dimworld > NormalVector
Definition grid/intersections.hh:58
std::size_t boundarySegmentIndex() const
return the boundary segment index
Definition grid/intersections.hh:110
Entity outside() const
Definition grid/intersections.hh:83
NormalVector centerUnitOuterNormal() const
Return unit outer normal (length == 1)
Definition grid/intersections.hh:102
LocalGeometry geometryInOutside() const
Definition grid/intersections.hh:155
bool boundary() const
return true if intersection is with boundary.
Definition grid/intersections.hh:91
GeometryType type() const
Geometry type of an intersection.
Definition grid/intersections.hh:141
bool equals(const MMeshLeafIntersection &other) const
returns true if the host entities are equal
Definition grid/intersections.hh:71
MMeshLeafIntersection(const GridImp *mMesh, HostLeafIntersection &&hostIntersection)
Definition grid/intersections.hh:66
@ dimension
Definition grid/intersections.hh:51
MMeshLeafIntersection(const GridImp *mMesh, const HostGridEntity &hostEntity, const int index)
Definition grid/intersections.hh:62
GridImp::template Codim< 1 >::Geometry Geometry
Definition grid/intersections.hh:53
std::size_t boundaryId() const
return the boundary id
Definition grid/intersections.hh:127
std::enable_if_t< d==3, NormalVector > integrationOuterNormal(const FieldVector< ctype, dim - 1 > &local) const
Definition grid/intersections.hh:203
FieldVector< ctype, GridImp::dimensionworld > outerNormal(const FieldVector< ctype, GridImp::dimension - 1 > &local) const
return outer normal
Definition grid/intersections.hh:184
const HostLeafIntersection & getHostIntersection() const
Definition grid/intersections.hh:224
GridImp::template Codim< 1 >::LocalGeometry::Implementation LocalGeometryImpl
Definition grid/intersections.hh:56
GridImp::template Codim< 0 >::Entity Entity
Definition grid/intersections.hh:57
bool neighbor() const
return true if across the edge an neighbor on this level exists
Definition grid/intersections.hh:107
Geometry geometry() const
Definition grid/intersections.hh:164
FieldVector< ctype, GridImp::dimensionworld > unitOuterNormal(const FieldVector< ctype, GridImp::dimension - 1 > &local) const
return unit outer normal
Definition grid/intersections.hh:217
int indexInOutside() const
local number of codim 1 entity in neighbor where intersection is contained
Definition grid/intersections.hh:173
GridImp::template Codim< 1 >::LocalGeometry LocalGeometry
Definition grid/intersections.hh:54
int indexInInside() const
local number of codim 1 entity in self where intersection is contained in
Definition grid/intersections.hh:167
Entity inside() const
Definition grid/intersections.hh:77
LocalGeometry geometryInInside() const
Definition grid/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 grid/intersections.hh:191
MMeshLeafIntersection()
Definition grid/intersections.hh:60
@ dimensionworld
Definition grid/intersections.hh:52
The MMeshEntity class.
The MMeshLeafIterator class.
T sort(T... args)