My Project
Entity.hpp
1 //===========================================================================
2 //
3 // File: Entity.hpp
4 //
5 // Created: Fri May 29 20:26:48 2009
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Brd 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_ENTITY_HEADER
37 #define OPM_ENTITY_HEADER
38 
39 #include <dune/common/version.hh>
40 #include <dune/geometry/type.hh>
41 #include <dune/grid/common/gridenums.hh>
42 
43 #include "PartitionTypeIndicator.hpp"
44 #include "EntityRep.hpp"
45 
46 namespace Dune
47 {
48  namespace cpgrid
49  {
50 
51  template<int,int> class Geometry;
52  template<int,PartitionIteratorType> class Iterator;
53  class IntersectionIterator;
54  class HierarchicIterator;
55  class CpGridData;
56  class LevelGlobalIdSet;
57 
58 
62  template <int codim>
63  class Entity : public EntityRep<codim>
64  {
65  friend class LevelGlobalIdSet;
66  friend class GlobalIdSet;
67 
68  public:
71  enum { codimension = codim };
72  enum { dimension = 3 };
73  enum { mydimension = dimension - codimension };
74  enum { dimensionworld = 3 };
75 
76  // the official DUNE names
77  typedef Entity EntitySeed;
78 
82  template <int cd>
83  struct Codim
84  {
85  typedef cpgrid::Entity<cd> Entity;
86  };
87 
88 
89  typedef cpgrid::Geometry<3-codim,3> Geometry;
90  typedef Geometry LocalGeometry;
91 
95 
96  typedef double ctype;
97 
102 // Entity(const CpGridData& grid, int entityrep)
103 // : EntityRep<codim>(entityrep), pgrid_(&grid)
104 // {
105 // }
106 
109  : EntityRep<codim>(), pgrid_( 0 )
110  {
111  }
112 
114  Entity(const CpGridData& grid, EntityRep<codim> entityrep)
115  : EntityRep<codim>(entityrep), pgrid_(&grid)
116  {
117  }
118 
120  Entity(const CpGridData& grid, int index_arg, bool orientation_arg)
121  : EntityRep<codim>(index_arg, orientation_arg), pgrid_(&grid)
122  {
123  }
124 
126  bool operator==(const Entity& other) const
127  {
128  return EntityRep<codim>::operator==(other) && pgrid_ == other.pgrid_;
129  }
130 
132  bool operator!=(const Entity& other) const
133  {
134  return !operator==(other);
135  }
136 
139  EntitySeed seed() const
140  {
141  return EntitySeed( impl() );
142  }
143 
145  const Geometry& geometry() const;
146 
148  int level() const
149  {
150  return 0;
151  }
152 
154  bool isLeaf() const
155  {
156  return true;
157  }
158 
160  bool isRegular() const
161  {
162  return true;
163  }
164 
166  PartitionType partitionType() const;
167 
169  GeometryType type() const
170  {
171  return Dune::GeometryTypes::cube(3 - codim);
172  }
173 
175  unsigned int subEntities ( const unsigned int cc ) const;
176 
178  template <int cc>
179  int count() const { return subEntities( cc ); }
180 
182  template <int cc>
183  typename Codim<cc>::Entity subEntity(int i) const;
184 
187 
190 
193 
196 
199 
202 
204  bool isNew() const
205  {
206  return false;
207  }
208 
210  bool mightVanish() const
211  {
212  return false;
213  }
214 
216  bool hasFather() const
217  {
218  return false;
219  }
220 
221 
223  Entity father() const
224  {
225  return *this;
226  }
227 
228 
231  {
232  return LocalGeometry();
233  }
234 
240 
241  // Mimic Dune entity wrapper
242 
243  const Entity& impl() const
244  {
245  return *this;
246  }
247 
248  Entity& impl()
249  {
250  return *this;
251  }
252 
255  bool isValid () const;
256 
257  protected:
258  const CpGridData* pgrid_;
259  };
260 
261  } // namespace cpgrid
262 } // namespace Dune
263 
264 // now we include the Iterators.hh We need to do this here because for hbegin/hend the compiler
265 // needs to know the size of hierarchicIterator
266 #include "Iterators.hpp"
267 #include "Entity.hpp"
268 #include "Intersection.hpp"
269 namespace Dune
270 {
271  namespace cpgrid
272  {
273  template<int codim>
275  {
276  static_assert(codim == 0, "");
277  return LevelIntersectionIterator(*pgrid_, *this, false);
278  }
279 
280  template<int codim>
282  {
283  static_assert(codim == 0, "");
284  return LevelIntersectionIterator(*pgrid_, *this, true);
285  }
286 
287  template<int codim>
289  {
290  static_assert(codim == 0, "");
291  return LeafIntersectionIterator(*pgrid_, *this, false);
292  }
293 
294  template<int codim>
296  {
297  static_assert(codim == 0, "");
298  return LeafIntersectionIterator(*pgrid_, *this, true);
299  }
300 
301 
302  template<int codim>
304  {
305  return HierarchicIterator(*pgrid_);
306  }
307 
309  template<int codim>
311  {
312  return HierarchicIterator(*pgrid_);
313  }
314 
315  template <int codim>
316  PartitionType Entity<codim>::partitionType() const
317  {
318  return pgrid_->partition_type_indicator_->getPartitionType(*this);
319  }
320  } // namespace cpgrid
321 } // namespace Dune
322 
323 #include <opm/grid/cpgrid/CpGridData.hpp>
324 #include <opm/grid/cpgrid/Intersection.hpp>
325 
326 namespace Dune {
327 namespace cpgrid {
328 
329 namespace Detail
330 {
331 inline unsigned int numFaces(const OrientedEntityTable<0, 1>& cell_to_face,
332  const Entity<0>& e)
333 {
334  return cell_to_face[e].size();
335 }
336 
337 template<int codim>
338 unsigned int numFaces(const OrientedEntityTable<0, 1>&, const Entity<codim>&)
339 {
340  return 0;
341 }
342 } // end namespace Detail
343 
344 template<int codim>
345 unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
346 {
347  // static_assert(codim == 0, "");
348  if (cc == 0) {
349  return 1;
350  } else if ( codim == 0 ){
351  if ( cc == 1 ) {
352  return Detail::numFaces(pgrid_->cell_to_face_, *this);
353  } else if ( cc == 3 ) {
354  return 8;
355  }
356  }
357  return 0;
358 }
359 
360 template <int codim>
362 {
363  return pgrid_->geomVector<codim>()[*this];
364 }
365 
366 template <int codim>
367 template <int cc>
368 typename Entity<codim>::template Codim<cc>::Entity Entity<codim>::subEntity(int i) const
369 {
370  static_assert(codim == 0, "");
371  if (cc == 0) {
372  assert(i == 0);
373  typename Codim<cc>::Entity se(*pgrid_, EntityRep<codim>::index(), EntityRep<codim>::orientation());
374  return se;
375  } else if (cc == 3) {
376  assert(i >= 0 && i < 8);
377  int corner_index = pgrid_->cell_to_point_[EntityRep<codim>::index()][i];
378  typename Codim<cc>::Entity se(*pgrid_, corner_index, true);
379  return se;
380  } else {
381  OPM_THROW(std::runtime_error, "No subentity exists of codimension " << cc);
382  }
383 }
384 
385 template <int codim>
387 {
388  // Copied implementation from EntityDefaultImplementation,
389  // except for not checking LevelIntersectionIterators.
390  typedef LeafIntersectionIterator Iter;
391  Iter end = ileafend();
392  for (Iter it = ileafbegin(); it != end; ++it) {
393  if (it->boundary()) return true;
394  }
395  return false;
396 }
397 
398 template <int codim>
400 {
401  return pgrid_ ? EntityRep<codim>::index() < pgrid_->size(codim) : false;
402 }
403 
404 }}
405 
406 
407 #endif // OPM_ENTITY_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
bool operator==(const EntityRep &other) const
Equality operator.
Definition: EntityRep.hpp:178
int index() const
The (positive) index of an entity.
Definition: EntityRep.hpp:125
Definition: Entity.hpp:64
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). Dummy.
Definition: Entity.hpp:210
Codim< cc >::Entity subEntity(int i) const
Obtain subentity.
Entity father() const
Dummy, returning this.
Definition: Entity.hpp:223
unsigned int subEntities(const unsigned int cc) const
The count of subentities of codimension cc.
Definition: Entity.hpp:345
LeafIntersectionIterator ileafend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:295
LocalGeometry geometryInFather() const
Dummy, returning default geometry.
Definition: Entity.hpp:230
EntitySeed seed() const
Return an entity seed.
Definition: Entity.hpp:139
HierarchicIterator hend(int) const
Dummy beyond last child iterator.
Definition: Entity.hpp:310
const Geometry & geometry() const
Returns the geometry of the entity (does not depend on its orientation).
Definition: Entity.hpp:361
Entity(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index and orientation.
Definition: Entity.hpp:120
bool hasFather() const
No hierarchy in this grid.
Definition: Entity.hpp:216
bool isValid() const
isValid method for EntitySeed
Definition: Entity.hpp:399
bool operator==(const Entity &other) const
Equality.
Definition: Entity.hpp:126
bool isRegular() const
Refinement is not defined for CpGrid.
Definition: Entity.hpp:160
int count() const
The count of subentities of codimension cc.
Definition: Entity.hpp:179
Entity()
Constructor taking a grid and an integer entity representation.
Definition: Entity.hpp:108
HierarchicIterator hbegin(int) const
Dummy first child iterator.
Definition: Entity.hpp:303
PartitionType partitionType() const
For now, the grid is serial and the only partitionType() is InteriorEntity.
Definition: Entity.hpp:316
LeafIntersectionIterator ileafbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:288
Entity(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition: Entity.hpp:114
LevelIntersectionIterator ilevelend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:281
bool isNew() const
Returns true, if the entity has been created during the last call to adapt(). Dummy.
Definition: Entity.hpp:204
LevelIntersectionIterator ilevelbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:274
GeometryType type() const
Using the cube type for all entities now (cells and vertices).
Definition: Entity.hpp:169
int level() const
We do not support refinement, so level() is always 0.
Definition: Entity.hpp:148
bool isLeaf() const
The entity is always on the leaf grid, since we have no refinement.
Definition: Entity.hpp:154
bool operator!=(const Entity &other) const
Inequality.
Definition: Entity.hpp:132
bool hasBoundaryIntersections() const
Returns true if any of my intersections are on the boundary.
Definition: Entity.hpp:386
This class encapsulates geometry for both vertices, intersections and cells.
Definition: Geometry.hpp:71
The global id set for Dune.
Definition: Indexsets.hpp:325
Only needs to provide interface for doing nothing.
Definition: Iterators.hpp:104
Definition: Intersection.hpp:288
Definition: Indexsets.hpp:257
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Definition: Entity.hpp:84