DUNE MultiDomainGrid (unstable)

intersection.hh
1#ifndef DUNE_MULTIDOMAINGRID_SUBDOMAINGRID_INTERSECTION_HH
2#define DUNE_MULTIDOMAINGRID_SUBDOMAINGRID_INTERSECTION_HH
3
4#include <dune/grid/common/intersection.hh>
5
6namespace Dune {
7
8namespace mdgrid {
9
10namespace subdomain {
11
12template<int codim, int dim, typename GridImp>
13class EntityWrapper;
14
15template<typename GridImp,
16 typename IndexSet,
17 typename MultiDomainIntersection_
18 >
19class IntersectionWrapper {
20
21 template<class, class, class>
22 friend class Dune::IntersectionIterator;
23
24 template<class,class,class>
25 friend class IntersectionIteratorWrapper;
26
27 template<class, class>
28 friend class Dune::Intersection;
29
30 template<typename MDGrid>
31 friend class SubDomainGrid;
32
33 using MultiDomainIntersection = MultiDomainIntersection_;
34 using Entity = typename GridImp::Traits::template Codim<0>::Entity;
35 using Geometry = typename GridImp::Traits::template Codim<1>::Geometry;
36 using LocalGeometry = typename GridImp::Traits::template Codim<1>::LocalGeometry;
37 using EntityWrapper = Dune::mdgrid::subdomain::EntityWrapper<0,GridImp::dimension,GridImp>;
38
39 static const int dimension = GridImp::dimension;
40 static const int dimensionworld = GridImp::dimensionworld;
41
42 using ctype = typename GridImp::ctype;
43 using GlobalCoords = FieldVector<ctype,dimensionworld>;
44 using LocalCoords = FieldVector<ctype,dimension - 1>;
45
46 IntersectionWrapper()
47 : _indexSet(nullptr)
48 , _intersectionTypeTested(false)
49 {}
50
51 IntersectionWrapper(const IndexSet* indexSet, const MultiDomainIntersection& multiDomainIntersection)
52 : _indexSet(indexSet)
53 , _multiDomainIntersection(multiDomainIntersection)
54 , _intersectionTypeTested(false)
55 {}
56
57private:
58
59 const auto&
60 hostIntersection() const {
61 return _multiDomainIntersection.impl().hostIntersection();
62 }
63
64
65 bool equals(const IntersectionWrapper& rhs) const {
66 return _indexSet == rhs._indexSet && _multiDomainIntersection == rhs._multiDomainIntersection;
67 }
68
69 void checkIntersectionType() const {
70 if (!_intersectionTypeTested) {
71 if (_multiDomainIntersection.boundary()) {
72 _intersectionType = GridImp::boundary;
73 _intersectionTypeTested = true;
74 return;
75 }
76 if (!_multiDomainIntersection.neighbor()) {
77 _intersectionType = GridImp::processor;
78 _intersectionTypeTested = true;
79 return;
80 }
81 if (_indexSet->containsMultiDomainEntity(_multiDomainIntersection.outside())) {
82 _intersectionType = GridImp::neighbor;
83 _intersectionTypeTested = true;
84 return;
85 } else {
86 _intersectionType = GridImp::foreign;
87 _intersectionTypeTested = true;
88 return;
89 }
90 assert(false && "Should never get here - invalid intersection type!");
91 }
92 }
93
94 bool boundary() const {
95 checkIntersectionType();
96 return
97 _intersectionType == GridImp::boundary ||
98 _intersectionType == GridImp::foreign;
99 }
100
101 int boundaryId() const {
102 return _multiDomainIntersection.boundaryId();
103 }
104
105 std::size_t boundarySegmentIndex() const {
106 checkIntersectionType();
107 // FIXME: We need to do something about subdomain boundaries in the interior of
108 // the MultiDomainGrid
109 return _intersectionType == GridImp::boundary ? _multiDomainIntersection.boundarySegmentIndex() : 0;
110 }
111
112 bool neighbor() const {
113 checkIntersectionType();
114 return _intersectionType == GridImp::neighbor;
115 }
116
117 Entity inside() const {
118 return {EntityWrapper(&_indexSet->_grid,_multiDomainIntersection.inside())};
119 }
120
121 Entity outside() const {
122 checkIntersectionType();
123 assert(_intersectionType == GridImp::neighbor);
124 return {EntityWrapper(&_indexSet->_grid,_multiDomainIntersection.outside())};
125 }
126
127 bool conforming() const {
128 return _multiDomainIntersection.conforming();
129 }
130
131 LocalGeometry geometryInInside() const {
132 return LocalGeometry(hostIntersection().geometryInInside());
133 }
134
135 LocalGeometry geometryInOutside() const {
136 checkIntersectionType();
137 assert(_intersectionType == GridImp::neighbor);
138 return LocalGeometry(hostIntersection().geometryInOutside());
139 }
140
141 Geometry geometry() const {
142 return Geometry(hostIntersection().geometry());
143 }
144
145 GeometryType type() const {
146 return _multiDomainIntersection.type();
147 }
148
149 int indexInInside() const {
150 return _multiDomainIntersection.indexInInside();
151 }
152
153 int indexInOutside() const {
154 checkIntersectionType();
155 assert(_intersectionType == GridImp::neighbor);
156 return _multiDomainIntersection.indexInOutside();
157 }
158
159 GlobalCoords outerNormal(const LocalCoords& local) const {
160 return _multiDomainIntersection.outerNormal(local);
161 }
162
163 GlobalCoords integrationOuterNormal(const LocalCoords& local) const {
164 return _multiDomainIntersection.integrationOuterNormal(local);
165 }
166
167 GlobalCoords unitOuterNormal(const LocalCoords& local) const {
168 return _multiDomainIntersection.unitOuterNormal(local);
169 }
170
171 GlobalCoords centerUnitOuterNormal() const {
172 return _multiDomainIntersection.centerUnitOuterNormal();
173 }
174
175 typename GridImp::IntersectionType intersectionType() const {
176 checkIntersectionType();
177 return _intersectionType;
178 }
179
180 const MultiDomainIntersection& multiDomainIntersection() const
181 {
182 return _multiDomainIntersection;
183 }
184
185private:
186
187 const IndexSet* _indexSet;
188 MultiDomainIntersection _multiDomainIntersection;
189 mutable bool _intersectionTypeTested;
190 mutable typename GridImp::IntersectionType _intersectionType;
191
192};
193
194} // namespace subdomain
195
196} // namespace mdgrid
197
198} // namespace Dune
199
200#endif // DUNE_MULTIDOMAINGRID_SUBDOMAINGRID_INTERSECTION_HH
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 7, 22:57, 2025)