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 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_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> class EntityPointer;
52  template<int,int> class Geometry;
53  template<int,PartitionIteratorType> class Iterator;
54  class IntersectionIterator;
55  class HierarchicIterator;
56  class CpGridData;
57  class LevelGlobalIdSet;
58 
62  template <int codim> class EntityPointer;
63 
64 
68  template <int codim>
69  class Entity : public EntityRep<codim>
70  {
71  friend class LevelGlobalIdSet;
72  friend class GlobalIdSet;
73 
74  public:
77  enum { codimension = codim };
78  enum { dimension = 3 };
79  enum { mydimension = dimension - codimension };
80  enum { dimensionworld = 3 };
81 
82 
84 
85  // the official DUNE names
88 
92  template <int cd>
93  struct Codim
94  {
96  typedef cpgrid::Entity<cd> Entity;
97  };
98 
99 
100  typedef cpgrid::Geometry<3-codim,3> Geometry;
101  typedef Geometry LocalGeometry;
102 
106 
107  typedef double ctype;
108 
113 // Entity(const CpGridData& grid, int entityrep)
114 // : EntityRep<codim>(entityrep), pgrid_(&grid)
115 // {
116 // }
117 
120  : EntityRep<codim>(), pgrid_( 0 )
121  {
122  }
123 
125  Entity(const CpGridData& grid, EntityRep<codim> entityrep)
126  : EntityRep<codim>(entityrep), pgrid_(&grid)
127  {
128  }
129 
131  Entity(const CpGridData& grid, int index_arg, bool orientation_arg)
132  : EntityRep<codim>(index_arg, orientation_arg), pgrid_(&grid)
133  {
134  }
135 
137  bool operator==(const Entity& other) const
138  {
139  return EntityRep<codim>::operator==(other) && pgrid_ == other.pgrid_;
140  }
141 
143  bool operator!=(const Entity& other) const
144  {
145  return !operator==(other);
146  }
147 
150  EntitySeed seed() const
151  {
152  return EntitySeed( impl() );
153  }
154 
156  const Geometry& geometry() const;
157 
159  int level() const
160  {
161  return 0;
162  }
163 
165  bool isLeaf() const
166  {
167  return true;
168  }
169 
171  bool isRegular() const
172  {
173  return true;
174  }
175 
177  PartitionType partitionType() const;
178 
180  GeometryType type() const
181  {
182  return Dune::GeometryTypes::cube(3 - codim);
183  }
184 
186  unsigned int subEntities ( const unsigned int cc ) const;
187 
189  template <int cc>
190  int count() const { return subEntities( cc ); }
191 
193  template <int cc>
194  typename Codim<cc>::EntityPointer subEntity(int i) const;
195 
197  inline LevelIntersectionIterator ilevelbegin() const;
198 
200  inline LevelIntersectionIterator ilevelend() const;
201 
203  inline LeafIntersectionIterator ileafbegin() const;
204 
206  inline LeafIntersectionIterator ileafend() const;
207 
209  HierarchicIterator hbegin(int) const;
210 
212  HierarchicIterator hend(int) const;
213 
215  bool isNew() const
216  {
217  return false;
218  }
219 
221  bool mightVanish() const
222  {
223  return false;
224  }
225 
227  bool hasFather() const
228  {
229  return false;
230  }
231 
232 
235  {
236  return EntityPointerType(*this);
237  }
238 
239 
242  {
243  return LocalGeometry();
244  }
245 
250  bool hasBoundaryIntersections() const;
251 
252  // Mimic Dune entity wrapper
253 
254  const Entity& impl() const
255  {
256  return *this;
257  }
258 
259  Entity& impl()
260  {
261  return *this;
262  }
263 
266  bool isValid () const;
267 
268  protected:
269  const CpGridData* pgrid_;
270  };
271 
272 
273 
274 
281  template <int codim>
282  class EntityPointer : public cpgrid::Entity<codim>
283  {
284  friend class LevelGlobalIdSet;
285  public:
287  typedef const Entity& Reference;
288 
291  {
292  }
293 
295  explicit EntityPointer(const Entity& e)
296  : Entity(e)
297  {
298  }
299 
301  EntityPointer(const CpGridData& grid, EntityRep<codim> entityrep)
302  : Entity(grid, entityrep)
303  {
304  }
305 
307  EntityPointer(const CpGridData& grid, int index_arg, bool orientation_arg)
308  : Entity(grid, index_arg, orientation_arg)
309  {
310  }
311 
313  const Entity* operator->() const
314  {
315  assert(Entity::isValid());
316  return (this);
317  }
318 
320  const Entity& operator*() const
321  {
322  assert(Entity::isValid());
323  return (*this);
324  }
325 
326 
329  void compactify()
330  {
331  }
332  };
333  } // namespace cpgrid
334 } // namespace Dune
335 
336 // now we include the Iterators.hh We need to do this here because for hbegin/hend the compiler
337 // needs to know the size of hierarchicIterator
338 #include "Iterators.hpp"
339 #include "Entity.hpp"
340 #include "Intersection.hpp"
341 namespace Dune
342 {
343  namespace cpgrid
344  {
345  template<int codim>
347  {
348  static_assert(codim == 0, "");
349  return LevelIntersectionIterator(*pgrid_, *this, false);
350  }
351 
352  template<int codim>
354  {
355  static_assert(codim == 0, "");
356  return LevelIntersectionIterator(*pgrid_, *this, true);
357  }
358 
359  template<int codim>
361  {
362  static_assert(codim == 0, "");
363  return LeafIntersectionIterator(*pgrid_, *this, false);
364  }
365 
366  template<int codim>
368  {
369  static_assert(codim == 0, "");
370  return LeafIntersectionIterator(*pgrid_, *this, true);
371  }
372 
373 
374  template<int codim>
376  {
377  return HierarchicIterator(*pgrid_);
378  }
379 
381  template<int codim>
383  {
384  return HierarchicIterator(*pgrid_);
385  }
386 
387  template <int codim>
388  PartitionType Entity<codim>::partitionType() const
389  {
390  return pgrid_->partition_type_indicator_->getPartitionType(*this);
391  }
392  } // namespace cpgrid
393 } // namespace Dune
394 
395 #include <opm/grid/cpgrid/CpGridData.hpp>
396 #include <opm/grid/cpgrid/Intersection.hpp>
397 
398 namespace Dune {
399 namespace cpgrid {
400 
401 namespace Detail
402 {
403 inline unsigned int numFaces(const OrientedEntityTable<0, 1>& cell_to_face,
404  const Entity<0>& e)
405 {
406  return cell_to_face[e].size();
407 }
408 
409 template<int codim>
410 unsigned int numFaces(const OrientedEntityTable<0, 1>&, const Entity<codim>&)
411 {
412  return 0;
413 }
414 } // end namespace Detail
415 
416 template<int codim>
417 unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
418 {
419  // static_assert(codim == 0, "");
420  if (cc == 0) {
421  return 1;
422  } else if ( codim == 0 ){
423  if ( cc == 1 ) {
424  return Detail::numFaces(pgrid_->cell_to_face_, *this);
425  } else if ( cc == 3 ) {
426  return 8;
427  }
428  }
429  return 0;
430 }
431 
432 template <int codim>
434 {
435  return pgrid_->geomVector<codim>()[*this];
436 }
437 
438 template <int codim>
439 template <int cc>
440 typename Entity<codim>::template Codim<cc>::EntityPointer Entity<codim>::subEntity(int i) const
441 {
442  static_assert(codim == 0, "");
443  if (cc == 0) {
444  assert(i == 0);
445  typename Codim<cc>::EntityPointer se(*pgrid_, EntityRep<codim>::index(), EntityRep<codim>::orientation());
446  return se;
447  } else if (cc == 3) {
448  assert(i >= 0 && i < 8);
449  int corner_index = pgrid_->cell_to_point_[EntityRep<codim>::index()][i];
450  typename Codim<cc>::EntityPointer se(*pgrid_, corner_index, true);
451  return se;
452  } else {
453  OPM_THROW(std::runtime_error, "No subentity exists of codimension " << cc);
454  }
455 }
456 
457 template <int codim>
459 {
460  // Copied implementation from EntityDefaultImplementation,
461  // except for not checking LevelIntersectionIterators.
462  typedef LeafIntersectionIterator Iter;
463  Iter end = ileafend();
464  for (Iter it = ileafbegin(); it != end; ++it) {
465  if (it->boundary()) return true;
466  }
467  return false;
468 }
469 
470 template <int codim>
472 {
473  return pgrid_ ? EntityRep<codim>::index() < pgrid_->size(codim) : false;
474 }
475 
476 }}
477 
478 
479 #endif // OPM_ENTITY_HEADER
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:123
Class representing a pointer to an entity.
Definition: Entity.hpp:283
EntityPointer(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition: Entity.hpp:301
void compactify()
Minimizes memory usage.
Definition: Entity.hpp:329
const Entity & operator*() const
Const dereferencing operator.
Definition: Entity.hpp:320
EntityPointer(const Entity &e)
Construction from entity.
Definition: Entity.hpp:295
EntityPointer(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index and orientation.
Definition: Entity.hpp:307
EntityPointer()
Construction empty entity pointer.
Definition: Entity.hpp:290
const Entity * operator->() const
Const member by pointer operator.
Definition: Entity.hpp:313
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:70
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). Dummy.
Definition: Entity.hpp:221
unsigned int subEntities(const unsigned int cc) const
The count of subentities of codimension cc.
Definition: Entity.hpp:417
LeafIntersectionIterator ileafend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:367
LocalGeometry geometryInFather() const
Dummy, returning default geometry.
Definition: Entity.hpp:241
EntitySeed seed() const
Return an entity seed.
Definition: Entity.hpp:150
HierarchicIterator hend(int) const
Dummy beyond last child iterator.
Definition: Entity.hpp:382
EntityPointerType father() const
Dummy, returning this.
Definition: Entity.hpp:234
const Geometry & geometry() const
Returns the geometry of the entity (does not depend on its orientation).
Definition: Entity.hpp:433
Entity(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index and orientation.
Definition: Entity.hpp:131
bool hasFather() const
No hierarchy in this grid.
Definition: Entity.hpp:227
bool isValid() const
isValid method for EntitySeed
Definition: Entity.hpp:471
bool operator==(const Entity &other) const
Equality.
Definition: Entity.hpp:137
bool isRegular() const
Refinement is not defined for CpGrid.
Definition: Entity.hpp:171
int count() const
The count of subentities of codimension cc.
Definition: Entity.hpp:190
Entity()
Constructor taking a grid and an integer entity representation.
Definition: Entity.hpp:119
HierarchicIterator hbegin(int) const
Dummy first child iterator.
Definition: Entity.hpp:375
Codim< cc >::EntityPointer subEntity(int i) const
Obtain subentity.
PartitionType partitionType() const
For now, the grid is serial and the only partitionType() is InteriorEntity.
Definition: Entity.hpp:388
LeafIntersectionIterator ileafbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:360
Entity(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition: Entity.hpp:125
LevelIntersectionIterator ilevelend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:353
bool isNew() const
Returns true, if the entity has been created during the last call to adapt(). Dummy.
Definition: Entity.hpp:215
LevelIntersectionIterator ilevelbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:346
GeometryType type() const
Using the cube type for all entities now (cells and vertices).
Definition: Entity.hpp:180
int level() const
We do not support refinement, so level() is always 0.
Definition: Entity.hpp:159
bool isLeaf() const
The entity is always on the leaf grid, since we have no refinement.
Definition: Entity.hpp:165
bool operator!=(const Entity &other) const
Inequality.
Definition: Entity.hpp:143
bool hasBoundaryIntersections() const
Returns true if any of my intersections are on the boundary.
Definition: Entity.hpp:458
This class encapsulates geometry for both vertices, intersections and cells.
Definition: Geometry.hpp:68
The global id set for Dune.
Definition: Indexsets.hpp:325
Only needs to provide interface for doing nothing.
Definition: Iterators.hpp:89
Definition: Intersection.hpp:291
Definition: Indexsets.hpp:257
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Definition: Entity.hpp:94