Intersection.hpp
Go to the documentation of this file.
1//===========================================================================
2//
3// File: Intersection.hpp
4//
5// Created: Tue Jun 9 11:17:13 2009
6//
7// Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8// Bård Skaflestad <bard.skaflestad@sintef.no>
9//
10// $Date$
11//
12// $Revision$
13//
14//===========================================================================
15
16/*
17 Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
18 Copyright 2009, 2010, 2022 Equinor ASA.
19
20 This file is part of The Open Porous Media project (OPM).
21
22 OPM is free software: you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation, either version 3 of the License, or
25 (at your option) any later version.
26
27 OPM is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 along with OPM. If not, see <http://www.gnu.org/licenses/>.
34*/
35
36#ifndef OPM_INTERSECTION_HEADER
37#define OPM_INTERSECTION_HEADER
38
39#include <dune/grid/common/gridenums.hh>
41
42// The next statement is a layering violation: we only #include
43// preprocess.h to get at its "enum face_tag" definition. Enum
44// face_tag is needed in method Intersection::boundaryId(). This hack
45// is in dire need of a better solution!
47
48#include "Geometry.hpp"
50
51namespace Dune
52{
53 namespace cpgrid
54 {
55 template<int>
56 class Entity;
57 class CpGridData;
58
63 {
64 public:
67 enum { dimension = 3 };
68 enum { dimensionworld = 3 };
69 enum { mydimension = 2 };
75 typedef double ctype;
76 typedef FieldVector<ctype, 2> LocalCoordinate;
77 typedef FieldVector<ctype, 3> GlobalCoordinate;
78
83 : pgrid_(0),
84 index_(-1),
85 subindex_(-1),
87 nbcell_(-1), // Init to self, which is invalid.
88 is_on_boundary_(false)
89 {
90 }
94 Intersection(const CpGridData& grid, const EntityRep<0>& cell, int subindex, bool update_now = true);
95
100 bool operator==(const Intersection& other) const
101 {
102 return subindex_ == other.subindex_ && index_ == other.index_ && pgrid_ == other.pgrid_;
103 }
104
109 bool operator!=(const Intersection& other) const
110 {
111 return !operator==(other);
112 }
113
118 bool boundary() const
119 {
120 return is_on_boundary_;
121 }
122
124 int boundaryId() const;
125
126
129
133 bool neighbor() const
134 {
136 }
137
141 Entity inside() const;
142
147
151 bool conforming() const
152 {
153 return boundary(); // I.e. we are assuming all nonconforming interior.
154 }
155
156 // Geometrical information about this intersection in
157 // local coordinates of the inside() entity.
161 [[noreturn]] const LocalGeometry& geometryInInside() const
162 {
163 OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
164#if defined(__CUDACC__)
165 __builtin_unreachable();
166#endif
167 }
168
169 // Geometrical information about this intersection in
170 // local coordinates of the outside() entity.
174 [[noreturn]] const LocalGeometry& geometryInOutside() const
175 {
176 if (boundary()) {
177 OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary.");
178 }
179 OPM_THROW(std::runtime_error, "This intersection class does not support geometryInOutside().");
180#if defined(__CUDACC__)
181 __builtin_unreachable();
182#endif
183 }
184
189
193 GeometryType type() const
194 {
195 return geometry().type();
196 }
197
200 int indexInInside() const;
201
204 int indexInOutside() const
205 {
206 int in_inside = indexInInside();
207 if (in_inside == -1) {
208 // NNC face, return -1 here as well.
209 return -1;
210 }
211 return in_inside + ((in_inside % 2) ? -1 : 1);
212 }
213
218 FieldVector<ctype, 3> outerNormal(const FieldVector<ctype, 2>&) const;
219
224 FieldVector<ctype, 3> integrationOuterNormal(const FieldVector<ctype, 2>& unused) const;
225
230 FieldVector<ctype, 3> unitOuterNormal(const FieldVector<ctype, 2>&) const;
231
236 FieldVector<ctype, 3> centerUnitOuterNormal() const;
237
238 int id() const
239 {
241 return face.index();
242 }
243
244 protected:
251
252 void increment();
253
254 void update();
255
256 void setAtEnd()
257 {
258 subindex_ = faces_of_cell_.size();
259 }
260
261 bool isAtEnd() const
262 {
263 return subindex_ == faces_of_cell_.size();
264 }
265
266 int nbcell() const
267 {
268 if (is_on_boundary_) {
269 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at boundary.");
270 }
272 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at processor boundary.");
273 return nbcell_;
274 }
275 };
276
277
278
279
280
282 {
283 public:
285
287 : Intersection()
288 {
289 }
290
291 IntersectionIterator(const CpGridData& grid, const EntityRep<0>& cell, bool at_end)
292 : Intersection(grid, cell, 0, !at_end)
293 {
294 if (at_end) {
296 } else {
298 }
299 }
300
302 {
304 return *this;
305 }
306
308 {
309 IntersectionIterator tmp(*this);
310 ++(*this);
311 return tmp;
312 }
313
315 {
316 assert(!Intersection::isAtEnd());
317 return this;
318 }
319
320 const Intersection& operator*() const
321 {
322 assert(!Intersection::isAtEnd());
323 return *this;
324 }
325
326 };
327
328
329
330
331
332 } // namespace cpgrid
333} // namespace Dune
334
335namespace std
336{
337 template<>
338 struct iterator_traits< Dune::cpgrid::IntersectionIterator >
339 {
341 typedef ptrdiff_t difference_type;
345 typedef forward_iterator_tag iterator_category;
346 };
347
348} // namespace std
349
350#endif // OPM_INTERSECTION_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:144
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:98
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:125
Definition: Intersection.hpp:282
IntersectionIterator & operator++()
Definition: Intersection.hpp:301
IntersectionIterator operator++(int)
Definition: Intersection.hpp:307
IntersectionIterator(const CpGridData &grid, const EntityRep< 0 > &cell, bool at_end)
Definition: Intersection.hpp:291
cpgrid::Intersection Intersection
Definition: Intersection.hpp:284
const Intersection * operator->() const
Definition: Intersection.hpp:314
IntersectionIterator()
Definition: Intersection.hpp:286
const Intersection & operator*() const
Definition: Intersection.hpp:320
Definition: Intersection.hpp:63
GeometryType type() const
Definition: Intersection.hpp:193
cpgrid::Geometry< 2, 3 > Geometry
Definition: Intersection.hpp:73
FieldVector< ctype, 3 > integrationOuterNormal(const FieldVector< ctype, 2 > &unused) const
int id() const
Definition: Intersection.hpp:238
const LocalGeometry & geometryInInside() const
Definition: Intersection.hpp:161
int index_
Definition: Intersection.hpp:246
FieldVector< ctype, 3 > unitOuterNormal(const FieldVector< ctype, 2 > &) const
bool isAtEnd() const
Definition: Intersection.hpp:261
int nbcell_
Definition: Intersection.hpp:249
int boundaryId() const
Returns the boundary id of this intersection.
bool neighbor() const
Definition: Intersection.hpp:133
cpgrid::Entity< 0 > Entity
Definition: Intersection.hpp:72
bool is_on_boundary_
Definition: Intersection.hpp:250
@ mydimension
Definition: Intersection.hpp:69
bool operator!=(const Intersection &other) const
Definition: Intersection.hpp:109
@ dimension
Definition: Intersection.hpp:67
@ dimensionworld
Definition: Intersection.hpp:68
int boundarySegmentIndex() const
Returns the boundary segment index of this intersection.
double ctype
Definition: Intersection.hpp:75
const CpGridData * pgrid_
Definition: Intersection.hpp:245
int nbcell() const
Definition: Intersection.hpp:266
cpgrid::Geometry< 2, 3 > LocalGeometry
Definition: Intersection.hpp:74
bool operator==(const Intersection &other) const
Definition: Intersection.hpp:100
Geometry geometry() const
const LocalGeometry & geometryInOutside() const
Definition: Intersection.hpp:174
int subindex_
Definition: Intersection.hpp:247
void setAtEnd()
Definition: Intersection.hpp:256
FieldVector< ctype, 3 > outerNormal(const FieldVector< ctype, 2 > &) const
FieldVector< ctype, 3 > centerUnitOuterNormal() const
bool conforming() const
Definition: Intersection.hpp:151
Intersection()
Definition: Intersection.hpp:82
int indexInOutside() const
Definition: Intersection.hpp:204
FieldVector< ctype, 2 > LocalCoordinate
Definition: Intersection.hpp:76
Intersection(const CpGridData &grid, const EntityRep< 0 > &cell, int subindex, bool update_now=true)
bool boundary() const
Definition: Intersection.hpp:118
FieldVector< ctype, 3 > GlobalCoordinate
Definition: Intersection.hpp:77
OrientedEntityTable< 0, 1 >::row_type faces_of_cell_
Definition: Intersection.hpp:248
Represents the topological relationships between sets of entities, for example cells and faces.
Definition: OrientedEntityTable.hpp:144
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
STL namespace.
Iterator::Intersection value_type
Definition: Intersection.hpp:342
Dune::cpgrid::IntersectionIterator Iterator
Definition: Intersection.hpp:340
forward_iterator_tag iterator_category
Definition: Intersection.hpp:345
value_type & reference
Definition: Intersection.hpp:344
value_type * pointer
Definition: Intersection.hpp:343
ptrdiff_t difference_type
Definition: Intersection.hpp:341