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
40
41
42#include <dune/grid/common/gridenums.hh>
43
44#include <opm/common/ErrorMacros.hpp>
45
46// The next statement is a layering violation: we only #include
47// preprocess.h to get at its "enum face_tag" definition. Enum
48// face_tag is needed in method Intersection::boundaryId(). This hack
49// is in dire need of a better solution!
51
52#include "Geometry.hpp"
54namespace Dune
55{
56 namespace cpgrid
57 {
58 template<int>
59 class Entity;
60 class CpGridData;
61
66 {
67 public:
70 enum { dimension = 3 };
71 enum { dimensionworld = 3 };
72 enum { mydimension = 2 };
78 typedef double ctype;
79 typedef FieldVector<ctype, 2> LocalCoordinate;
80 typedef FieldVector<ctype, 3> GlobalCoordinate;
81
86 : pgrid_(0),
87 index_(-1),
88 subindex_(-1),
90 nbcell_(-1), // Init to self, which is invalid.
91 is_on_boundary_(false)
92 {
93 }
97 Intersection(const CpGridData& grid, const EntityRep<0>& cell, int subindex, bool update_now = true);
98
103 bool operator==(const Intersection& other) const
104 {
105 return subindex_ == other.subindex_ && index_ == other.index_ && pgrid_ == other.pgrid_;
106 }
107
112 bool operator!=(const Intersection& other) const
113 {
114 return !operator==(other);
115 }
116
121 bool boundary() const
122 {
123 return is_on_boundary_;
124 }
125
127 int boundaryId() const;
128
129
132
136 bool neighbor() const
137 {
138 return !boundary() && nbcell_!=std::numeric_limits<int>::max();
139 }
140
144 Entity inside() const;
145
150
154 bool conforming() const
155 {
156 return boundary(); // I.e. we are assuming all nonconforming interior.
157 }
158
159 // Geometrical information about this intersection in
160 // local coordinates of the inside() entity.
165 {
166 OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
167 }
168
169 // Geometrical information about this intersection in
170 // local coordinates of the outside() entity.
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 }
181
186
190 GeometryType type() const
191 {
192 return geometry().type();
193 }
194
197 int indexInInside() const;
198
201 int indexInOutside() const
202 {
203 int in_inside = indexInInside();
204 if (in_inside == -1) {
205 // NNC face, return -1 here as well.
206 return -1;
207 }
208 return in_inside + ((in_inside % 2) ? -1 : 1);
209 }
210
215 FieldVector<ctype, 3> outerNormal(const FieldVector<ctype, 2>&) const;
216
221 FieldVector<ctype, 3> integrationOuterNormal(const FieldVector<ctype, 2>& unused) const;
222
227 FieldVector<ctype, 3> unitOuterNormal(const FieldVector<ctype, 2>&) const;
228
233 FieldVector<ctype, 3> centerUnitOuterNormal() const;
234
235 int id() const
236 {
238 return face.index();
239 }
240
241 protected:
248
249 void increment();
250
251 void update();
252
253 void setAtEnd()
254 {
256 }
257
258 bool isAtEnd() const
259 {
260 return subindex_ == faces_of_cell_.size();
261 }
262
263 int nbcell() const
264 {
265 if (is_on_boundary_) {
266 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at boundary.");
267 }
268 if(nbcell_==std::numeric_limits<int>::max())
269 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at processor boundary.");
270 return nbcell_;
271 }
272 };
273
274
275
276
277
279 {
280 public:
282
284 : Intersection()
285 {
286 }
287
288 IntersectionIterator(const CpGridData& grid, const EntityRep<0>& cell, bool at_end)
289 : Intersection(grid, cell, 0, !at_end)
290 {
291 if (at_end) {
293 } else {
295 }
296 }
297
299 {
301 return *this;
302 }
303
305 {
306 IntersectionIterator tmp(*this);
307 ++(*this);
308 return tmp;
309 }
310
312 {
313 assert(!Intersection::isAtEnd());
314 return this;
315 }
316
317 const Intersection& operator*() const
318 {
319 assert(!Intersection::isAtEnd());
320 return *this;
321 }
322
323 };
324
325
326
327
328
329 } // namespace cpgrid
330} // namespace Dune
331
332namespace std
333{
334 template<>
335 struct iterator_traits< Dune::cpgrid::IntersectionIterator >
336 {
338 typedef ptrdiff_t difference_type;
342 typedef forward_iterator_tag iterator_category;
343 };
344
345} // namespace std
346
347#endif // OPM_INTERSECTION_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:138
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:99
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:126
Definition: Intersection.hpp:279
IntersectionIterator & operator++()
Definition: Intersection.hpp:298
IntersectionIterator operator++(int)
Definition: Intersection.hpp:304
IntersectionIterator(const CpGridData &grid, const EntityRep< 0 > &cell, bool at_end)
Definition: Intersection.hpp:288
cpgrid::Intersection Intersection
Definition: Intersection.hpp:281
const Intersection * operator->() const
Definition: Intersection.hpp:311
IntersectionIterator()
Definition: Intersection.hpp:283
const Intersection & operator*() const
Definition: Intersection.hpp:317
Definition: Intersection.hpp:66
GeometryType type() const
Definition: Intersection.hpp:190
cpgrid::Geometry< 2, 3 > Geometry
Definition: Intersection.hpp:76
FieldVector< ctype, 3 > integrationOuterNormal(const FieldVector< ctype, 2 > &unused) const
int id() const
Definition: Intersection.hpp:235
const LocalGeometry & geometryInInside() const
Definition: Intersection.hpp:164
int index_
Definition: Intersection.hpp:243
FieldVector< ctype, 3 > unitOuterNormal(const FieldVector< ctype, 2 > &) const
bool isAtEnd() const
Definition: Intersection.hpp:258
int nbcell_
Definition: Intersection.hpp:246
int boundaryId() const
Returns the boundary id of this intersection.
bool neighbor() const
Definition: Intersection.hpp:136
cpgrid::Entity< 0 > Entity
Definition: Intersection.hpp:75
bool is_on_boundary_
Definition: Intersection.hpp:247
@ mydimension
Definition: Intersection.hpp:72
bool operator!=(const Intersection &other) const
Definition: Intersection.hpp:112
@ dimension
Definition: Intersection.hpp:70
@ dimensionworld
Definition: Intersection.hpp:71
int boundarySegmentIndex() const
Returns the boundary segment index of this intersection.
double ctype
Definition: Intersection.hpp:78
const CpGridData * pgrid_
Definition: Intersection.hpp:242
int nbcell() const
Definition: Intersection.hpp:263
cpgrid::Geometry< 2, 3 > LocalGeometry
Definition: Intersection.hpp:77
bool operator==(const Intersection &other) const
Definition: Intersection.hpp:103
Geometry geometry() const
const LocalGeometry & geometryInOutside() const
Definition: Intersection.hpp:174
int subindex_
Definition: Intersection.hpp:244
void setAtEnd()
Definition: Intersection.hpp:253
FieldVector< ctype, 3 > outerNormal(const FieldVector< ctype, 2 > &) const
FieldVector< ctype, 3 > centerUnitOuterNormal() const
bool conforming() const
Definition: Intersection.hpp:154
Intersection()
Definition: Intersection.hpp:85
int indexInOutside() const
Definition: Intersection.hpp:201
FieldVector< ctype, 2 > LocalCoordinate
Definition: Intersection.hpp:79
Intersection(const CpGridData &grid, const EntityRep< 0 > &cell, int subindex, bool update_now=true)
bool boundary() const
Definition: Intersection.hpp:121
FieldVector< ctype, 3 > GlobalCoordinate
Definition: Intersection.hpp:80
OrientedEntityTable< 0, 1 >::row_type faces_of_cell_
Definition: Intersection.hpp:245
Represents the topological relationships between sets of entities, for example cells and faces.
Definition: OrientedEntityTable.hpp:139
int size() const
Returns the number of rows in the table.
Definition: SparseTable.hpp:121
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:339
Dune::cpgrid::IntersectionIterator Iterator
Definition: Intersection.hpp:337
forward_iterator_tag iterator_category
Definition: Intersection.hpp:342
value_type & reference
Definition: Intersection.hpp:341
value_type * pointer
Definition: Intersection.hpp:340
ptrdiff_t difference_type
Definition: Intersection.hpp:338