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 Statoil 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  template<int>
61  class EntityPointer;
62  class CpGridData;
63 
68  {
69  public:
72  enum { dimension = 3 };
73  enum { dimensionworld = 3 };
80  typedef double ctype;
81  typedef FieldVector<ctype, 2> LocalCoordinate;
82  typedef FieldVector<ctype, 3> GlobalCoordinate;
83 
88  : pgrid_(0),
89  index_(-1),
90  subindex_(-1),
91  faces_of_cell_(),
92  global_geom_(),
93 // in_inside_geom_(),
94  nbcell_(-1), // Init to self, which is invalid.
95  is_on_boundary_(false)
96  {
97  }
101  Intersection(const CpGridData& grid, const EntityRep<0>& cell, int subindex, bool update_now = true);
102 
107  bool operator==(const Intersection& other) const
108  {
109  return subindex_ == other.subindex_ && index_ == other.index_ && pgrid_ == other.pgrid_;
110  }
111 
116  bool operator!=(const Intersection& other) const
117  {
118  return !operator==(other);
119  }
120 
125  bool boundary() const
126  {
127  return is_on_boundary_;
128  }
129 
131  int boundaryId() const;
132 
133 
135  int boundarySegmentIndex() const;
136 
140  bool neighbor() const
141  {
142  return !boundary() && nbcell_!=std::numeric_limits<int>::max();
143  }
144 
148  EntityPointer inside() const;
149 
153  EntityPointer outside() const;
154 
158  bool conforming() const
159  {
160  return boundary(); // I.e. we are assuming all nonconforming interior.
161  }
162 
163  // Geometrical information about this intersection in
164  // local coordinates of the inside() entity.
169  {
170  OPM_THROW(std::runtime_error, "This intersection class does not support geometryInInside().");
171 // return in_inside_geom_;
172  }
173 
174  // Geometrical information about this intersection in
175  // local coordinates of the outside() entity.
180  {
181  if (boundary()) {
182  OPM_THROW(std::runtime_error, "Cannot access geometryInOutside(), intersection is at a boundary.");
183  }
184  OPM_THROW(std::runtime_error, "This intersection class does not support geometryInOutside().");
185 // return in_outside_geom_;
186  }
187 
191  const Geometry& geometry() const
192  {
193  return global_geom_;
194  }
195 
199  GeometryType type() const
200  {
201  return geometry().type();
202  }
203 
206  int indexInInside() const;
207 
210  int indexInOutside() const
211  {
212  int in_inside = indexInInside();
213  if (in_inside == -1) {
214  // NNC face, return -1 here as well.
215  return -1;
216  }
217  return in_inside + ((in_inside % 2) ? -1 : 1);
218  }
219 
224  FieldVector<ctype, 3> outerNormal(const FieldVector<ctype, 2>&) const;
225 
230  FieldVector<ctype, 3> integrationOuterNormal(const FieldVector<ctype, 2>& unused) const;
231 
236  FieldVector<ctype, 3> unitOuterNormal(const FieldVector<ctype, 2>&) const;
237 
242  FieldVector<ctype, 3> centerUnitOuterNormal() const;
243 
244  int id() const
245  {
246  const EntityRep<1>& face = faces_of_cell_[subindex_];
247  return face.index();
248  }
249 
250  protected:
251  const CpGridData* pgrid_;
252  int index_;
253  int subindex_;
254  OrientedEntityTable<0,1>::row_type faces_of_cell_;
255  Geometry global_geom_;
256 // LocalGeometry in_inside_geom_;
257 // LocalGeometry in_outside_geom_;
258  int nbcell_;
259  bool is_on_boundary_;
260 
261  void increment();
262 
263  void update();
264 
265  void setAtEnd()
266  {
267  subindex_ = faces_of_cell_.size();
268  }
269 
270  bool isAtEnd() const
271  {
272  return subindex_ == faces_of_cell_.size();
273  }
274 
275  int nbcell() const
276  {
277  if (is_on_boundary_) {
278  OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at boundary.");
279  }
280  if(nbcell_==std::numeric_limits<int>::max())
281  OPM_THROW(std::runtime_error, "There is no outside cell, intersection is at processor boundary.");
282  return nbcell_;
283  }
284  };
285 
286 
287 
288 
289 
291  {
292  public:
294 
296  : Intersection()
297  {
298  }
299 
300  IntersectionIterator(const CpGridData& grid, const EntityRep<0>& cell, bool at_end)
301  : Intersection(grid, cell, 0, !at_end)
302  {
303  if (at_end) {
304  Intersection::setAtEnd();
305  } else {
306  Intersection::update();
307  }
308  }
309 
310  IntersectionIterator& operator++()
311  {
312  Intersection::increment();
313  return *this;
314  }
315 
316  const Intersection* operator->() const
317  {
318  assert(!Intersection::isAtEnd());
319  return this;
320  }
321 
322  const Intersection& operator*() const
323  {
324  assert(!Intersection::isAtEnd());
325  return *this;
326  }
327 
328  };
329 
330 
331 
332 
333 
334  } // namespace cpgrid
335 } // namespace Dune
336 
337 #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: Entity.hpp:70
Definition: Intersection.hpp:291
Definition: Intersection.hpp:68
GeometryType type() const
Definition: Intersection.hpp:199
const LocalGeometry & geometryInOutside() const
Definition: Intersection.hpp:179
EntityPointer inside() const
Definition: Intersection.cpp:165
int boundaryId() const
Returns the boundary id of this intersection.
Definition: Intersection.cpp:32
bool neighbor() const
Definition: Intersection.hpp:140
FieldVector< ctype, 3 > unitOuterNormal(const FieldVector< ctype, 2 > &) const
Definition: Intersection.cpp:155
cpgrid::Entity< 0 > Entity
Definition: Intersection.hpp:76
const LocalGeometry & geometryInInside() const
Definition: Intersection.hpp:168
bool operator!=(const Intersection &other) const
Definition: Intersection.hpp:116
int boundarySegmentIndex() const
Returns the boundary segment index of this intersection.
Definition: Intersection.cpp:70
FieldVector< ctype, 3 > outerNormal(const FieldVector< ctype, 2 > &) const
Definition: Intersection.cpp:144
EntityPointer outside() const
Definition: Intersection.cpp:170
bool operator==(const Intersection &other) const
Definition: Intersection.hpp:107
const Geometry & geometry() const
Definition: Intersection.hpp:191
FieldVector< ctype, 3 > integrationOuterNormal(const FieldVector< ctype, 2 > &unused) const
Definition: Intersection.cpp:149
FieldVector< ctype, 3 > centerUnitOuterNormal() const
Definition: Intersection.cpp:160
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: Intersection.cpp:118
bool conforming() const
Definition: Intersection.hpp:158
Intersection()
Definition: Intersection.hpp:87
int indexInOutside() const
Local index of codim 1 entity in outside() entity where intersection is contained in.
Definition: Intersection.hpp:210
bool boundary() const
Definition: Intersection.hpp:125
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Low-level corner-point processing routines and supporting data structures.