My Project
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/grid/utility/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"
54 namespace 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  global_geom_(),
90 // in_inside_geom_(),
91  nbcell_(-1), // Init to self, which is invalid.
92  is_on_boundary_(false)
93  {
94  }
98  Intersection(const CpGridData& grid, const EntityRep<0>& cell, int subindex, bool update_now = true);
99 
104  bool operator==(const Intersection& other) const
105  {
106  return subindex_ == other.subindex_ && index_ == other.index_ && pgrid_ == other.pgrid_;
107  }
108 
113  bool operator!=(const Intersection& other) const
114  {
115  return !operator==(other);
116  }
117 
122  bool boundary() const
123  {
124  return is_on_boundary_;
125  }
126 
128  int boundaryId() const;
129 
130 
132  int boundarySegmentIndex() const;
133 
137  bool neighbor() const
138  {
139  return !boundary() && nbcell_!=std::numeric_limits<int>::max();
140  }
141 
145  Entity inside() const;
146 
150  Entity outside() const;
151 
155  bool conforming() const
156  {
157  return boundary(); // I.e. we are assuming all nonconforming interior.
158  }
159 
160  // Geometrical information about this intersection in
161  // local coordinates of the inside() entity.
166  {
167  OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
168 // return in_inside_geom_;
169  }
170 
171  // Geometrical information about this intersection in
172  // local coordinates of the outside() entity.
177  {
178  if (boundary()) {
179  OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary.");
180  }
181  OPM_THROW(std::runtime_error, "This intersection class does not support geometryInOutside().");
182 // return in_outside_geom_;
183  }
184 
188  const Geometry& geometry() const
189  {
190  return global_geom_;
191  }
192 
196  GeometryType type() const
197  {
198  return geometry().type();
199  }
200 
203  int indexInInside() const;
204 
207  int indexInOutside() const
208  {
209  int in_inside = indexInInside();
210  if (in_inside == -1) {
211  // NNC face, return -1 here as well.
212  return -1;
213  }
214  return in_inside + ((in_inside % 2) ? -1 : 1);
215  }
216 
221  FieldVector<ctype, 3> outerNormal(const FieldVector<ctype, 2>&) const;
222 
227  FieldVector<ctype, 3> integrationOuterNormal(const FieldVector<ctype, 2>& unused) const;
228 
233  FieldVector<ctype, 3> unitOuterNormal(const FieldVector<ctype, 2>&) const;
234 
239  FieldVector<ctype, 3> centerUnitOuterNormal() const;
240 
241  int id() const
242  {
243  const EntityRep<1>& face = faces_of_cell_[subindex_];
244  return face.index();
245  }
246 
247  protected:
248  const CpGridData* pgrid_;
249  int index_;
250  int subindex_;
251  OrientedEntityTable<0,1>::row_type faces_of_cell_;
252  Geometry global_geom_;
253 // LocalGeometry in_inside_geom_;
254 // LocalGeometry in_outside_geom_;
255  int nbcell_;
256  bool is_on_boundary_;
257 
258  void increment();
259 
260  void update();
261 
262  void setAtEnd()
263  {
264  subindex_ = faces_of_cell_.size();
265  }
266 
267  bool isAtEnd() const
268  {
269  return subindex_ == faces_of_cell_.size();
270  }
271 
272  int nbcell() const
273  {
274  if (is_on_boundary_) {
275  OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at boundary.");
276  }
277  if(nbcell_==std::numeric_limits<int>::max())
278  OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at processor boundary.");
279  return nbcell_;
280  }
281  };
282 
283 
284 
285 
286 
288  {
289  public:
291 
293  : Intersection()
294  {
295  }
296 
297  IntersectionIterator(const CpGridData& grid, const EntityRep<0>& cell, bool at_end)
298  : Intersection(grid, cell, 0, !at_end)
299  {
300  if (at_end) {
301  Intersection::setAtEnd();
302  } else {
303  Intersection::update();
304  }
305  }
306 
307  IntersectionIterator& operator++()
308  {
309  Intersection::increment();
310  return *this;
311  }
312 
313  const Intersection* operator->() const
314  {
315  assert(!Intersection::isAtEnd());
316  return this;
317  }
318 
319  const Intersection& operator*() const
320  {
321  assert(!Intersection::isAtEnd());
322  return *this;
323  }
324 
325  };
326 
327 
328 
329 
330 
331  } // namespace cpgrid
332 } // namespace Dune
333 
334 #endif // OPM_INTERSECTION_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:123
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.
Definition: EntityRep.hpp:125
Definition: Intersection.hpp:288
Definition: Intersection.hpp:66
GeometryType type() const
Definition: Intersection.hpp:196
const LocalGeometry & geometryInOutside() const
Definition: Intersection.hpp:176
int boundaryId() const
Returns the boundary id of this intersection.
Definition: Intersection.cpp:51
bool neighbor() const
Definition: Intersection.hpp:137
FieldVector< ctype, 3 > unitOuterNormal(const FieldVector< ctype, 2 > &) const
Definition: Intersection.cpp:174
cpgrid::Entity< 0 > Entity
Definition: Intersection.hpp:74
const LocalGeometry & geometryInInside() const
Definition: Intersection.hpp:165
bool operator!=(const Intersection &other) const
Definition: Intersection.hpp:113
int boundarySegmentIndex() const
Returns the boundary segment index of this intersection.
Definition: Intersection.cpp:89
FieldVector< ctype, 3 > outerNormal(const FieldVector< ctype, 2 > &) const
Definition: Intersection.cpp:163
Entity inside() const
Definition: Intersection.cpp:184
bool operator==(const Intersection &other) const
Definition: Intersection.hpp:104
const Geometry & geometry() const
Definition: Intersection.hpp:188
FieldVector< ctype, 3 > integrationOuterNormal(const FieldVector< ctype, 2 > &unused) const
Definition: Intersection.cpp:168
FieldVector< ctype, 3 > centerUnitOuterNormal() const
Definition: Intersection.cpp:179
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: Intersection.cpp:137
bool conforming() const
Definition: Intersection.hpp:155
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:207
bool boundary() const
Definition: Intersection.hpp:122
Entity outside() const
Definition: Intersection.cpp:189
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Low-level corner-point processing routines and supporting data structures.