All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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/geometry/type.hh>
40 #include <dune/grid/common/gridenums.hh>
41 
42 #include "PartitionTypeIndicator.hpp"
43 #include "EntityRep.hpp"
44 
45 namespace Dune
46 {
47  namespace cpgrid
48  {
49 
50  template <int> class EntityPointer;
51  template<int,int> class Geometry;
52  template<int,PartitionIteratorType> class Iterator;
54  class HierarchicIterator;
55  class CpGridData;
56 
60  template <int codim> class EntityPointer;
61 
62 
66  template <int codim>
67  class Entity : public EntityRep<codim>
68  {
69  public:
72  enum { codimension = codim };
73  enum { dimension = 3 };
74  enum { mydimension = dimension - codimension };
75  enum { dimensionworld = 3 };
76 
77 
78  typedef cpgrid::EntityPointer<codim> EntityPointerType;
79 
80  // the official DUNE names
81  typedef EntityPointerType EntityPointer;
82  typedef EntityPointerType EntitySeed;
83 
87  template <int cd>
88  struct Codim
89  {
91  typedef cpgrid::Entity<cd> Entity;
92  };
93 
94 
95  typedef cpgrid::Geometry<3-codim,3> Geometry;
96  typedef Geometry LocalGeometry;
97 
101 
102  typedef double ctype;
103 
108 // Entity(const CpGridData& grid, int entityrep)
109 // : EntityRep<codim>(entityrep), pgrid_(&grid)
110 // {
111 // }
112 
115  : EntityRep<codim>(), pgrid_( 0 )
116  {
117  }
118 
120  Entity(const CpGridData& grid, EntityRep<codim> entityrep)
121  : EntityRep<codim>(entityrep), pgrid_(&grid)
122  {
123  }
124 
126  Entity(const CpGridData& grid, int index_arg, bool orientation_arg)
127  : EntityRep<codim>(index_arg, orientation_arg), pgrid_(&grid)
128  {
129  }
130 
132  bool operator==(const Entity& other) const
133  {
134  return EntityRep<codim>::operator==(other) && pgrid_ == other.pgrid_;
135  }
136 
138  bool operator!=(const Entity& other) const
139  {
140  return !operator==(other);
141  }
142 
145  EntitySeed seed() const
146  {
147  return EntitySeed( impl() );
148  }
149 
151  const Geometry& geometry() const;
152 
154  int level() const
155  {
156  return 0;
157  }
158 
160  bool isLeaf() const
161  {
162  return true;
163  }
164 
166  bool isRegular() const
167  {
168  return true;
169  }
170 
172  PartitionType partitionType() const;
173 
175  GeometryType type() const
176  {
177  GeometryType t;
178  t.makeCube(3 - codim);
179  return t;
180  }
181 
183  unsigned int subEntities ( const unsigned int cc ) const;
184 
186  template <int cc>
187  int count() const { return subEntities( cc ); }
188 
190  template <int cc>
191  typename Codim<cc>::EntityPointer subEntity(int i) const;
192 
194  inline LevelIntersectionIterator ilevelbegin() const;
195 
197  inline LevelIntersectionIterator ilevelend() const;
198 
200  inline LeafIntersectionIterator ileafbegin() const;
201 
203  inline LeafIntersectionIterator ileafend() const;
204 
206  HierarchicIterator hbegin(int) const;
207 
209  HierarchicIterator hend(int) const;
210 
212  bool isNew() const
213  {
214  return false;
215  }
216 
218  bool mightVanish() const
219  {
220  return false;
221  }
222 
224  bool hasFather() const
225  {
226  return false;
227  }
228 
229 
232  {
233  return EntityPointerType(*this);
234  }
235 
236 
239  {
240  return LocalGeometry();
241  }
242 
247  bool hasBoundaryIntersections() const;
248 
249  // Mimic Dune entity wrapper
250 
251  const Entity& impl() const
252  {
253  return *this;
254  }
255 
256  Entity& impl()
257  {
258  return *this;
259  }
260 
263  bool isValid () const;
264 
265  protected:
266  const CpGridData* pgrid_;
267  };
268 
269 
270 
271 
278  template <int codim>
279  class EntityPointer : public cpgrid::Entity<codim>
280  {
281  public:
282  typedef cpgrid::Entity<codim> Entity;
283  typedef const Entity& Reference;
284 
287  {
288  }
289 
291  explicit EntityPointer(const Entity& e)
292  : Entity(e)
293  {
294  }
295 
297  EntityPointer(const CpGridData& grid, EntityRep<codim> entityrep)
298  : Entity(grid, entityrep)
299  {
300  }
301 
303  EntityPointer(const CpGridData& grid, int index_arg, bool orientation_arg)
304  : Entity(grid, index_arg, orientation_arg)
305  {
306  }
307 
309  const Entity* operator->() const
310  {
311  assert(Entity::isValid());
312  return (this);
313  }
314 
316  const Entity& operator*() const
317  {
318  assert(Entity::isValid());
319  return (*this);
320  }
321 
322 
325  void compactify()
326  {
327  }
328  };
329  } // namespace cpgrid
330 } // namespace Dune
331 
332 // now we include the Iterators.hh We need to do this here because for hbegin/hend the compiler
333 // needs to know the size of hierarchicIterator
334 #include "Iterators.hpp"
335 #include "Entity.hpp"
336 #include "Intersection.hpp"
337 namespace Dune
338 {
339  namespace cpgrid
340  {
341  template<int codim>
343  {
344  static_assert(codim == 0, "");
345  return LevelIntersectionIterator(*pgrid_, *this, false);
346  }
347 
348  template<int codim>
350  {
351  static_assert(codim == 0, "");
352  return LevelIntersectionIterator(*pgrid_, *this, true);
353  }
354 
355  template<int codim>
357  {
358  static_assert(codim == 0, "");
359  return LeafIntersectionIterator(*pgrid_, *this, false);
360  }
361 
362  template<int codim>
364  {
365  static_assert(codim == 0, "");
366  return LeafIntersectionIterator(*pgrid_, *this, true);
367  }
368 
369 
370  template<int codim>
372  {
373  return HierarchicIterator(*pgrid_);
374  }
375 
377  template<int codim>
379  {
380  return HierarchicIterator(*pgrid_);
381  }
382 
383  template <int codim>
384  PartitionType Entity<codim>::partitionType() const
385  {
386  return pgrid_->partition_type_indicator_->getPartitionType(*this);
387  }
388  } // namespace cpgrid
389 } // namespace Dune
390 
391 #include <dune/grid/cpgrid/CpGridData.hpp>
392 #include <dune/grid/cpgrid/Intersection.hpp>
393 
394 namespace Dune {
395 namespace cpgrid {
396 
397 namespace Detail
398 {
399 inline unsigned int numFaces(const OrientedEntityTable<0, 1>& cell_to_face,
400  const Entity<0>& e)
401 {
402  return cell_to_face[e].size();
403 }
404 
405 template<int codim>
406 unsigned int numFaces(const OrientedEntityTable<0, 1>&, const Entity<codim>&)
407 {
408  return 0;
409 }
410 } // end namespace Detail
411 
412 template<int codim>
413 unsigned int Entity<codim>::subEntities ( const unsigned int cc ) const
414 {
415  // static_assert(codim == 0, "");
416  if (cc == 0) {
417  return 1;
418  } else if ( codim == 0 ){
419  if ( cc == 1 ) {
420  return Detail::numFaces(pgrid_->cell_to_face_, *this);
421  } else if ( cc == 3 ) {
422  return 8;
423  }
424  }
425  return 0;
426 }
427 
428 template <int codim>
430 {
431  return pgrid_->geomVector<codim>()[*this];
432 }
433 
434 template <int codim>
435 template <int cc>
436 typename Entity<codim>::template Codim<cc>::EntityPointer Entity<codim>::subEntity(int i) const
437 {
438  static_assert(codim == 0, "");
439  if (cc == 0) {
440  assert(i == 0);
441  typename Codim<cc>::EntityPointer se(*pgrid_, EntityRep<codim>::index(), EntityRep<codim>::orientation());
442  return se;
443  } else if (cc == 3) {
444  assert(i >= 0 && i < 8);
445  int corner_index = pgrid_->cell_to_point_[EntityRep<codim>::index()][i];
446  typename Codim<cc>::EntityPointer se(*pgrid_, corner_index, true);
447  return se;
448  } else {
449  OPM_THROW(std::runtime_error, "No subentity exists of codimension " << cc);
450  }
451 }
452 
453 template <int codim>
455 {
456  // Copied implementation from EntityDefaultImplementation,
457  // except for not checking LevelIntersectionIterators.
458  typedef LeafIntersectionIterator Iter;
459  Iter end = ileafend();
460  for (Iter it = ileafbegin(); it != end; ++it) {
461  if (it->boundary()) return true;
462  }
463  return false;
464 }
465 
466 template <int codim>
468 {
469  return pgrid_ ? EntityRep<codim>::index() < pgrid_->size(codim) : false;
470 }
471 
472 }}
473 
474 
475 #endif // OPM_ENTITY_HEADER
EntitySeed seed() const
Return an entity seed.
Definition: Entity.hpp:145
HierarchicIterator hbegin(int) const
Dummy first child iterator.
Definition: Entity.hpp:371
Definition: Entity.hpp:88
LeafIntersectionIterator ileafbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:356
bool hasBoundaryIntersections() const
Returns true if any of my intersections are on the boundary.
Definition: Entity.hpp:454
int index() const
The (positive) index of an entity.
Definition: EntityRep.hpp:126
Entity()
Constructor taking a grid and an integer entity representation.
Definition: Entity.hpp:114
LevelIntersectionIterator ilevelend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:349
bool isNew() const
Returns true, if the entity has been created during the last call to adapt(). Dummy.
Definition: Entity.hpp:212
This class encapsulates geometry for both vertices, intersections and cells.
Definition: CpGridData.hpp:92
EntityPointer(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition: Entity.hpp:297
unsigned int subEntities(const unsigned int cc) const
The count of subentities of codimension cc.
Definition: Entity.hpp:413
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:105
Iterator intended to be used as LeafIterator and LevelIterator (no difference due to no adaptivity) f...
Definition: Entity.hpp:52
EntityPointer()
Construction empty entity pointer.
Definition: Entity.hpp:286
LeafIntersectionIterator ileafend() const
End iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:363
EntityPointerType father() const
Dummy, returning this.
Definition: Entity.hpp:231
PartitionType partitionType() const
For now, the grid is serial and the only partitionType() is InteriorEntity.
Definition: Entity.hpp:384
const Entity * operator->() const
Const member by pointer operator.
Definition: Entity.hpp:309
void compactify()
Minimizes memory usage.
Definition: Entity.hpp:325
Entity(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index and orientation.
Definition: Entity.hpp:126
EntityPointer(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index and orientation.
Definition: Entity.hpp:303
bool operator==(const EntityRep &other) const
Equality operator.
Definition: EntityRep.hpp:174
bool isLeaf() const
The entity is always on the leaf grid, since we have no refinement.
Definition: Entity.hpp:160
bool operator==(const Entity &other) const
Equality.
Definition: Entity.hpp:132
bool hasFather() const
No hierarchy in this grid.
Definition: Entity.hpp:224
bool isRegular() const
Refinement is not defined for CpGrid.
Definition: Entity.hpp:166
LocalGeometry geometryInFather() const
Dummy, returning default geometry.
Definition: Entity.hpp:238
const Geometry & geometry() const
Returns the geometry of the entity (does not depend on its orientation).
Definition: Entity.hpp:429
Class representing a pointer to an entity.
Definition: Entity.hpp:50
LevelIntersectionIterator ilevelbegin() const
Start iterator for the cell-cell intersections of this entity.
Definition: Entity.hpp:342
const Entity & operator*() const
Const dereferencing operator.
Definition: Entity.hpp:316
Only needs to provide interface for doing nothing.
Definition: Iterators.hpp:88
Codim< cc >::EntityPointer subEntity(int i) const
Obtain subentity.
int count() const
The count of subentities of codimension cc.
Definition: Entity.hpp:187
Represents an entity of a given codim, with positive or negative orientation.
Definition: CpGridData.hpp:94
bool isValid() const
isValid method for EntitySeed
Definition: Entity.hpp:467
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt(). Dummy.
Definition: Entity.hpp:218
int level() const
We do not support refinement, so level() is always 0.
Definition: Entity.hpp:154
GeometryType type() const
Using the cube type for all entities now (cells and vertices).
Definition: Entity.hpp:175
Definition: Intersection.hpp:286
EntityPointer(const Entity &e)
Construction from entity.
Definition: Entity.hpp:291
bool operator!=(const Entity &other) const
Inequality.
Definition: Entity.hpp:138
Entity(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition: Entity.hpp:120
HierarchicIterator hend(int) const
Dummy beyond last child iterator.
Definition: Entity.hpp:378