My Project
Loading...
Searching...
No Matches
Intersection.hpp
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"
53#include "OrientedEntityTable.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 };
77 typedef double ctype;
78 typedef FieldVector<ctype, 2> LocalCoordinate;
79 typedef FieldVector<ctype, 3> GlobalCoordinate;
80
85 : pgrid_(0),
86 index_(-1),
87 subindex_(-1),
88 faces_of_cell_(),
89 nbcell_(-1), // Init to self, which is invalid.
90 is_on_boundary_(false)
91 {
92 }
96 Intersection(const CpGridData& grid, const EntityRep<0>& cell, int subindex, bool update_now = true);
97
102 bool operator==(const Intersection& other) const
103 {
104 return subindex_ == other.subindex_ && index_ == other.index_ && pgrid_ == other.pgrid_;
105 }
106
111 bool operator!=(const Intersection& other) const
112 {
113 return !operator==(other);
114 }
115
120 bool boundary() const
121 {
122 return is_on_boundary_;
123 }
124
126 int boundaryId() const;
127
128
130 int boundarySegmentIndex() const;
131
135 bool neighbor() const
136 {
137 return !boundary() && nbcell_!=std::numeric_limits<int>::max();
138 }
139
143 Entity inside() const;
144
148 Entity outside() const;
149
153 bool conforming() const
154 {
155 return boundary(); // I.e. we are assuming all nonconforming interior.
156 }
157
158 // Geometrical information about this intersection in
159 // local coordinates of the inside() entity.
164 {
165 OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
166 }
167
168 // Geometrical information about this intersection in
169 // local coordinates of the outside() entity.
174 {
175 if (boundary()) {
176 OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary.");
177 }
178 OPM_THROW(std::runtime_error, "This intersection class does not support geometryInOutside().");
179 }
180
184 Geometry geometry() const;
185
189 GeometryType type() const
190 {
191 return geometry().type();
192 }
193
196 int indexInInside() const;
197
200 int indexInOutside() const
201 {
202 int in_inside = indexInInside();
203 if (in_inside == -1) {
204 // NNC face, return -1 here as well.
205 return -1;
206 }
207 return in_inside + ((in_inside % 2) ? -1 : 1);
208 }
209
214 FieldVector<ctype, 3> outerNormal(const FieldVector<ctype, 2>&) const;
215
220 FieldVector<ctype, 3> integrationOuterNormal(const FieldVector<ctype, 2>& unused) const;
221
226 FieldVector<ctype, 3> unitOuterNormal(const FieldVector<ctype, 2>&) const;
227
232 FieldVector<ctype, 3> centerUnitOuterNormal() const;
233
234 int id() const
235 {
236 const EntityRep<1>& face = faces_of_cell_[subindex_];
237 return face.index();
238 }
239
240 protected:
241 const CpGridData* pgrid_;
242 int index_;
243 int subindex_;
244 OrientedEntityTable<0,1>::row_type faces_of_cell_;
245 int nbcell_;
246 bool is_on_boundary_;
247
248 void increment();
249
250 void update();
251
252 void setAtEnd()
253 {
254 subindex_ = faces_of_cell_.size();
255 }
256
257 bool isAtEnd() const
258 {
259 return subindex_ == faces_of_cell_.size();
260 }
261
262 int nbcell() const
263 {
264 if (is_on_boundary_) {
265 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at boundary.");
266 }
267 if(nbcell_==std::numeric_limits<int>::max())
268 OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at processor boundary.");
269 return nbcell_;
270 }
271 };
272
273
274
275
276
278 {
279 public:
281
283 : Intersection()
284 {
285 }
286
287 IntersectionIterator(const CpGridData& grid, const EntityRep<0>& cell, bool at_end)
288 : Intersection(grid, cell, 0, !at_end)
289 {
290 if (at_end) {
291 Intersection::setAtEnd();
292 } else {
293 Intersection::update();
294 }
295 }
296
297 IntersectionIterator& operator++()
298 {
299 Intersection::increment();
300 return *this;
301 }
302
303 const Intersection* operator->() const
304 {
305 assert(!Intersection::isAtEnd());
306 return this;
307 }
308
309 const Intersection& operator*() const
310 {
311 assert(!Intersection::isAtEnd());
312 return *this;
313 }
314
315 };
316
317
318
319
320
321 } // namespace cpgrid
322} // namespace Dune
323
324#endif // OPM_INTERSECTION_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition CpGridData.hpp:135
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.
Definition EntityRep.hpp:126
Definition Entity.hpp:65
This class encapsulates geometry for vertices, intersections, and cells.
Definition Geometry.hpp:75
Definition Intersection.hpp:278
Definition Intersection.hpp:66
GeometryType type() const
Definition Intersection.hpp:189
const LocalGeometry & geometryInInside() const
Definition Intersection.hpp:163
int boundaryId() const
Returns the boundary id of this intersection.
Definition Intersection.cpp:47
bool neighbor() const
Definition Intersection.hpp:135
FieldVector< ctype, 3 > unitOuterNormal(const FieldVector< ctype, 2 > &) const
Definition Intersection.cpp:166
cpgrid::Entity< 0 > Entity
Definition Intersection.hpp:74
bool operator!=(const Intersection &other) const
Definition Intersection.hpp:111
int boundarySegmentIndex() const
Returns the boundary segment index of this intersection.
Definition Intersection.cpp:85
FieldVector< ctype, 3 > outerNormal(const FieldVector< ctype, 2 > &) const
Definition Intersection.cpp:155
Entity inside() const
Definition Intersection.cpp:176
bool operator==(const Intersection &other) const
Definition Intersection.hpp:102
const LocalGeometry & geometryInOutside() const
Definition Intersection.hpp:173
FieldVector< ctype, 3 > integrationOuterNormal(const FieldVector< ctype, 2 > &unused) const
Definition Intersection.cpp:160
FieldVector< ctype, 3 > centerUnitOuterNormal() const
Definition Intersection.cpp:171
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition Intersection.cpp:128
bool conforming() const
Definition Intersection.hpp:153
Intersection()
Definition Intersection.hpp:84
int indexInOutside() const
Local index of codim 1 entity in outside() entity where intersection is contained in.
Definition Intersection.hpp:200
Geometry geometry() const
Definition Intersection.cpp:186
bool boundary() const
Definition Intersection.hpp:120
Entity outside() const
Definition Intersection.cpp:181
Copyright 2019 Equinor AS.
Definition CartesianIndexMapper.hpp:10
Low-level corner-point processing routines and supporting data structures.