36 #ifndef OPM_INDEXSETS_HEADER
37 #define OPM_INDEXSETS_HEADER
39 #include <dune/geometry/type.hh>
40 #include <opm/grid/utility/ErrorMacros.hpp>
41 #include "GlobalIdMapping.hpp"
42 #include "Intersection.hpp"
44 #include <unordered_map>
69 typedef std::vector<GeometryType>
Types;
77 geom_types_[0].emplace_back(Dune::GeometryTypes::cube(3));
78 geom_types_[3].emplace_back(Dune::GeometryTypes::cube(0));
91 return geom_types_[codim];
100 return geom_types_[codim];
107 int size(GeometryType type)
const
109 return grid_.
size(type);
119 return grid_.
size(codim);
139 template<
class EntityType>
153 return index(e.template subEntity<cc>(i));
168 default: OPM_THROW(std::runtime_error,
"Codimension " << cc <<
" not supported.");
177 DUNE_THROW(NotImplemented,
"subIndex not implemented for codim"
178 << codim <<
"entities.");
185 template <
class EntityType>
188 return index(e) >= 0 &&
index(e) < grid_.
size(EntityType::codimension);
193 Types geom_types_[4];
214 template<
class EntityType>
215 IdType id(
const EntityType& e)
const
223 return intersection.id();
229 return id(e.template subEntity<cc>(i));
239 default: OPM_THROW(std::runtime_error,
"Cannot get subId of codimension " << cc);
244 template<
class EntityType>
245 IdType computeId(
const EntityType& e)
const
248 for(
int c=0; c<EntityType::codimension; ++c )
250 return myId + e.index();
252 const CpGridData& grid_;
263 void swap(std::vector<int>& cellMapping,
264 std::vector<int>& faceMapping,
265 std::vector<int>& pointMapping)
273 : idSet_(ids), view_(view)
281 assert(view_ == e.pgrid_);
288 return idSet_->id(e);
290 return this->
template getMapping<codim>()[e.
index()];
296 assert(view_ == e.pgrid_);
297 return id(e.template subEntity<cc>(i));
302 assert(view_ == e.pgrid_);
309 default: OPM_THROW(std::runtime_error,
"Cannot get subId of codimension " << cc);
328 using IdType =
typename LevelGlobalIdSet::IdType;
332 idSets_.insert(std::make_pair(&view,view.global_id_set_));
338 return levelIdSet(e.pgrid_).id(e);
344 return levelIdSet(e.pgrid_).template subId<cc>(e, i);
347 IdType subId(
const cpgrid::Entity<0>& e,
int i,
int cc)
const
349 return levelIdSet(e.pgrid_).subId(e, i, cc);
352 void insertIdSet(
const CpGridData& view)
354 idSets_.insert(std::make_pair(&view,view.global_id_set_));
358 const LevelGlobalIdSet& levelIdSet(
const CpGridData*
const data)
const
360 auto candidate = idSets_.find(data);
361 assert(candidate != idSets_.end());
362 return *candidate->second;
365 std::map<const CpGridData* const, const LevelGlobalIdSet*> idSets_;
375 grid_ = &(idSet.idSet_->grid_);
379 mapping_.reset(
new std::unordered_map<int,int>);
381 for (
const auto& globalId: idSet.template getMapping<3>())
382 (*mapping_)[globalId] = localId++;
385 int operator[](
int i)
const
389 return(*mapping_)[i];
393 return i - grid_->size(0) - grid_->size(1) - grid_->size(2);
396 OPM_THROW(std::runtime_error,
"No grid or mapping. Should not be here!");
400 mapping_.reset(
nullptr);
403 std::unique_ptr<std::unordered_map<int,int> > mapping_;
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:123
int size(int codim) const
number of leaf entities per codim in this process
Definition: CpGridData.cpp:144
const IndexSet & indexSet() const
Get the index set.
Definition: CpGridData.hpp:274
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:64
Codim< cc >::Entity subEntity(int i) const
Obtain subentity.
Class managing the mappings of local indices to global ids.
Definition: GlobalIdMapping.hpp:31
void swap(std::vector< int > &cellMapping, std::vector< int > &faceMapping, std::vector< int > &pointMapping)
Swap data for initialization.
Definition: GlobalIdMapping.hpp:38
The global id set for Dune.
Definition: Indexsets.hpp:325
typename LevelGlobalIdSet::IdType IdType
The type of the id.
Definition: Indexsets.hpp:328
Definition: Indexsets.hpp:198
IdType id(const cpgrid::Intersection &intersection) const
return id of intersection (here face number)
Definition: Indexsets.hpp:221
Definition: Indexsets.hpp:54
const Types & geomTypes(int codim) const
Definition: Indexsets.hpp:89
bool contains(const EntityType &e) const
Definition: Indexsets.hpp:186
int size(int codim) const
Definition: Indexsets.hpp:117
IndexType subIndex(const cpgrid::Entity< 0 > &e, int i) const
Definition: Indexsets.hpp:151
~IndexSet()
Destructor.
Definition: Indexsets.hpp:82
std::vector< GeometryType > Types
Definition: Indexsets.hpp:69
IndexType subIndex(const cpgrid::Entity< 0 > &e, int i, unsigned int cc) const
Definition: Indexsets.hpp:161
IndexSet(const CpGridData &grid)
Definition: Indexsets.hpp:74
IndexType index(const EntityType &e) const
Definition: Indexsets.hpp:140
IndexType index(const cpgrid::Entity< cd > &e) const
Definition: Indexsets.hpp:129
int size(GeometryType type) const
Definition: Indexsets.hpp:107
const Types & types(int codim) const
Definition: Indexsets.hpp:98
int IndexType
Definition: Indexsets.hpp:58
Definition: Intersection.hpp:66
Definition: Indexsets.hpp:257
Definition: Indexsets.hpp:369
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Export the type of the entity used as parameter in the index(...) method.
Definition: Indexsets.hpp:63