37#ifndef OPM_ENTITY_HEADER
38#define OPM_ENTITY_HEADER
40#include <dune/common/version.hh>
41#include <dune/geometry/type.hh>
42#include <dune/geometry/referenceelements.hh>
43#include <dune/grid/common/gridenums.hh>
45#include "PartitionTypeIndicator.hpp"
46#include <opm/grid/cpgrid/DefaultGeometryPolicy.hpp>
50 const std::vector<std::array<int,3>>&,
51 const std::vector<std::array<int,3>>&,
52 const std::vector<std::array<int,3>>&,
53 const std::vector<std::string>&);
75#if DUNE_VERSION_LT(DUNE_GRID, 2, 11)
96template<
int,PartitionIteratorType>
class Iterator;
108 friend class LevelGlobalIdSet;
109 friend class GlobalIdSet;
110 friend class HierarchicIterator;
111 friend class CpGridData;
113 const std::vector<std::array<int,3>>&,
114 const std::vector<std::array<int,3>>&,
115 const std::vector<std::array<int,3>>&,
116 const std::vector<std::string>&);
122 static constexpr int dimension = 3;
123 static constexpr int mydimension = dimension -
codimension;
124 static constexpr int dimensionworld = 3;
127 typedef Entity EntitySeed;
134 typedef Geometry LocalGeometry;
140 typedef double ctype;
159 :
EntityRep<codim>(entityrep), pgrid_(&grid)
164 Entity(
const CpGridData& grid,
int index_arg,
bool orientation_arg)
165 :
EntityRep<codim>(index_arg, orientation_arg), pgrid_(&grid)
170 Entity(
int index_arg,
bool orientation_arg)
171 :
EntityRep<codim>(index_arg, orientation_arg), pgrid_()
192 return EntitySeed(
impl() );
225 return Dune::GeometryTypes::cube(3 - codim);
253 HierarchicIterator
hend(
int)
const;
326 int getIdxInParentCell()
const;
329 const CpGridData* pgrid_;
336 return Dune::referenceElement<double,3-codim>(Dune::GeometryTypes::cube(3-codim));
345#include "Iterators.hpp"
346#include "Intersection.hpp"
354 static_assert(codim == 0,
"");
355 return LevelIntersectionIterator(*pgrid_, *
this,
false);
361 static_assert(codim == 0,
"");
362 return LevelIntersectionIterator(*pgrid_, *
this,
true);
368 static_assert(codim == 0,
"");
369 return LeafIntersectionIterator(*pgrid_, *
this,
false);
375 static_assert(codim == 0,
"");
376 return LeafIntersectionIterator(*pgrid_, *
this,
true);
384 return HierarchicIterator(*
this, maxLevel);
392 return HierarchicIterator(maxLevel);
398 return pgrid_->partition_type_indicator_->getPartitionType(*
this);
405#include <opm/grid/cpgrid/CpGridData.hpp>
416 else if ( codim == 0 ){
421 DUNE_THROW(NotImplemented,
"subEntities not implemented for this codimension");
427 return pgrid_->geomVector<codim>()[*
this];
434 static_assert(codim == 0,
"");
437 typename Codim<cc>::Entity se(*pgrid_, this->index(), this->orientation());
439 }
else if (cc == 3) {
440 assert(i >= 0 && i < 8);
441 int corner_index = pgrid_->cell_to_point_[this->index()][i];
442 typename Codim<cc>::Entity se(*pgrid_, corner_index,
true);
446 OPM_THROW(std::runtime_error,
447 "No subentity exists of codimension " + std::to_string(cc));
456 typedef LeafIntersectionIterator Iter;
458 for (Iter it =
ileafbegin(); it != end; ++it) {
459 if (it->boundary())
return true;
485 return pgrid_->leaf_to_level_cells_.empty()? pgrid_->level_ : pgrid_->leaf_to_level_cells_[this->
index()][0];
499 if (pgrid_ -> parent_to_children_cells_.empty()){
503 return (std::get<0>((pgrid_ -> parent_to_children_cells_)[this->
index()]) == -1);
510 int data_count = pgrid_->level_data_ptr_->size();
511 if (data_count == 1) {
515 assert(data_count >= 2);
520 return isLeaf() && (pgrid_->refinement_max_level_ == data_count - 2);
533 if ((pgrid_ -> child_to_parent_cells_.empty()) || (pgrid_ -> child_to_parent_cells_[this->index()][0] == -1)){
545 const int& coarser_level = pgrid_ -> child_to_parent_cells_[this->
index()][0];
546 const int& parent_cell_index = pgrid_ -> child_to_parent_cells_[this->
index()][1];
547 return Entity<0>( *((*(pgrid_ -> level_data_ptr_))[coarser_level].get()), parent_cell_index,
true);
550 OPM_THROW(std::logic_error,
"Entity has no father.");
555int Dune::cpgrid::Entity<codim>::getIdxInParentCell()
const
557 return pgrid_ -> cell_to_idxInParentCell_[this->index()];
565 OPM_THROW(std::logic_error,
"Entity has no father.");
569 static constexpr std::array<int,8> in_father_reference_elem_corner_indices = {0,1,2,3,4,5,6,7};
573 auto idx_in_parent_cell = pgrid_ -> cell_to_idxInParentCell_[this->
index()];
574 if (idx_in_parent_cell !=-1) {
575 const auto& cells_per_dim = (*(pgrid_ -> level_data_ptr_))[this->
level()] -> cells_per_dim_;
576 const auto& auxArr = pgrid_ -> getReferenceRefinedCorners(idx_in_parent_cell, cells_per_dim);
577 FieldVector<double, 3> corners_in_father_reference_elem_temp[8] =
578 { auxArr[0], auxArr[1], auxArr[2], auxArr[3], auxArr[4], auxArr[5], auxArr[6], auxArr[7]};
579 auto in_father_reference_elem_corners = std::make_shared<EntityVariable<cpgrid::Geometry<0, 3>, 3>>();
582 mutable_in_father_reference_elem_corners.assign(corners_in_father_reference_elem_temp,
583 corners_in_father_reference_elem_temp + 8);
585 Dune::FieldVector<double, 3> center_in_father_reference_elem = {0., 0.,0.};
586 for (
int corn = 0; corn < 8; ++corn) {
587 for (
int c = 0; c < 3; ++c)
589 center_in_father_reference_elem[c] += corners_in_father_reference_elem_temp[corn][c]/8.;
593 double volume_in_father_reference_elem = double(1)/(cells_per_dim[0]*cells_per_dim[1]*cells_per_dim[2]);
596 in_father_reference_elem_corners, in_father_reference_elem_corner_indices.data());
599 OPM_THROW(std::logic_error,
"Entity has no father.");
608 auto ancestor = this->
father();
609 while (ancestor.hasFather()){
610 ancestor = ancestor.father();
612 assert(ancestor.level() == 0);
615 else if (!(pgrid_ -> leaf_to_level_cells_.empty())) {
618 const int&
level = pgrid_->leaf_to_level_cells_[this->
index()][0];
620 const int& levelElemIdx = pgrid_->leaf_to_level_cells_[this->
index()][1];
634 if (!(pgrid_ -> leaf_to_level_cells_.empty()))
636 const int& entityLevelIdx = pgrid_->leaf_to_level_cells_[this->
index()][1];
647 const auto& level_data = (*(pgrid_ -> level_data_ptr_))[
level()].get();
648 return level_data -> global_cell_[
getLevelElem().index()];
[ provides Dune::Grid ]
Definition CpGrid.hpp:203
Struct that hods all the data needed to represent a Cpgrid.
Definition CpGridData.hpp:118
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
EntityRep()
Default constructor.
Definition EntityRep.hpp:103
Base class for EntityVariable and SignedEntityVariable.
Definition EntityRep.hpp:218
Definition Entity.hpp:107
bool mightVanish() const
Indicates whether the entity may be removed in the next call to adapt().
Definition Entity.hpp:525
Entity< 0 > father() const
ONLY FOR CELLS (Entity<0>).
Definition Entity.hpp:542
unsigned int subEntities(const unsigned int cc) const
Return the number of all subentities of the entity of a given codimension cc.
Definition Entity.hpp:411
LeafIntersectionIterator ileafend() const
End leaf-iterator for the cell-cell intersections of this entity.
Definition Entity.hpp:373
EntitySeed seed() const
Return an entity seed (light-weight entity).
Definition Entity.hpp:190
int getLevelCartesianIdx() const
Get Cartesian Index in the level grid view where the Entity was born.
Definition Entity.hpp:645
HierarchicIterator hend(int) const
Iterator end over the children/beyond last child iterator.
Definition Entity.hpp:389
const Geometry & geometry() const
Return the geometry of the entity (does not depend on its orientation).
Definition Entity.hpp:425
Entity(const CpGridData &grid, int index_arg, bool orientation_arg)
Constructor taking a grid, entity index, and orientation.
Definition Entity.hpp:164
bool hasFather() const
ONLY FOR CELLS (Entity<0>) Check if the entity comes from an LGR, i.e., it has been created via refin...
Definition Entity.hpp:531
bool isValid() const
isValid method for EntitySeed
Definition Entity.hpp:465
Entity< 0 > getOrigin() const
Returns (1) oldest ancestor, i.e., oldest parent entity in the level-grid 0, if the entity was born i...
Definition Entity.hpp:604
bool operator==(const Entity &other) const
Equality.
Definition Entity.hpp:176
bool isRegular() const
Refinement is not defined for CpGrid.
Definition Entity.hpp:209
static constexpr int codimension
Definition Entity.hpp:121
Entity()
Constructor taking a grid and an integer entity representation.
Definition Entity.hpp:152
HierarchicIterator hbegin(int) const
Iterator begin over the children. [If requested, also over descendants more than one generation away....
Definition Entity.hpp:381
const Entity & impl() const
Access the actual implementation class behind Entity interface class.
Definition Entity.hpp:297
PartitionType partitionType() const
In serial run, the only partitionType() is InteriorEntity.
Definition Entity.hpp:396
Dune::cpgrid::Geometry< 3, 3 > geometryInFather() const
Return LocalGeometry representing the embedding of the entity into its father (when hasFather() is tr...
Definition Entity.hpp:562
typename Impl::CodimTraits< cd > Codim
Definition Entity.hpp:131
Entity(int index_arg, bool orientation_arg)
Constructor taking a entity index, and orientation.
Definition Entity.hpp:170
LeafIntersectionIterator ileafbegin() const
Start leaf-iterator for the cell-cell intersections of this entity.
Definition Entity.hpp:366
Entity(const CpGridData &grid, EntityRep< codim > entityrep)
Constructor taking a grid and an entity representation.
Definition Entity.hpp:158
LevelIntersectionIterator ilevelend() const
End level-iterator for the cell-cell intersections of this entity.
Definition Entity.hpp:359
bool isNew() const
Returns true, if the entity has been created during the last call to adapt().
Definition Entity.hpp:508
Entity< 0 > getLevelElem() const
Get equivalent element on the level grid where the entity was born, if grid = leaf-grid-view....
Definition Entity.hpp:629
LevelIntersectionIterator ilevelbegin() const
Start level-iterator for the cell-cell intersections of this entity.
Definition Entity.hpp:352
GeometryType type() const
Return marker object (GeometryType object) representing the reference element of the entity.
Definition Entity.hpp:223
int level() const
Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid.
Definition Entity.hpp:473
bool isLeaf() const
Check if the entity is in the leafview.
Definition Entity.hpp:497
bool operator!=(const Entity &other) const
Inequality.
Definition Entity.hpp:182
bool hasBoundaryIntersections() const
Returns true if any of my intersections are on the boundary.
Definition Entity.hpp:452
Codim< cc >::Entity subEntity(int i) const
Obtain subentity.
This class encapsulates geometry for vertices, intersections, and cells.
Definition Geometry.hpp:76
Only needs to provide interface for doing nothing.
Definition Iterators.hpp:118
Definition Intersection.hpp:276
Iterator intended to be used as LeafIterator and LevelIterator (no difference due to no adaptivity) f...
Definition Iterators.hpp:60
Definition Indexsets.hpp:367
Copyright 2019 Equinor AS.
Definition GridPartitioning.cpp:673
The namespace Dune is the main namespace for all Dune code.
Definition CartesianIndexMapper.hpp:10