36#ifndef OPM_INDEXSETS_HEADER
37#define OPM_INDEXSETS_HEADER
39#include <dune/geometry/type.hh>
40#include <opm/common/ErrorMacros.hpp>
41#include "GlobalIdMapping.hpp"
42#include "Intersection.hpp"
44#include <unordered_map>
71 typedef std::vector<GeometryType>
Types;
78 IndexSet(std::size_t numCells, std::size_t numPoints)
80 geom_types_[0].emplace_back(Dune::GeometryTypes::cube(3));
81 geom_types_[3].emplace_back(Dune::GeometryTypes::cube(0));
82 size_codim_map_[0] = numCells;
83 size_codim_map_[3] = numPoints;
96 return geom_types_[codim];
105 return geom_types_[codim];
112 int size(GeometryType type)
const
115 return size(3 - type.dim());
128 return size_codim_map_[codim];
148 template<
class EntityType>
162 return index(e.template subEntity<cc>(i));
176 DUNE_THROW(NotImplemented,
"subIndex not implemented for codim"
177 << codim <<
"entities.");
184 template <
class EntityType>
188 return index(e) >= 0 &&
index(e) < this->
size(EntityType::codimension);
193 Types geom_types_[4];
194 std::array<int,4> size_codim_map_{0,0,0,0};
215 template<
class EntityType>
216 IdType id(
const EntityType& e)
const
224 return intersection.id();
230 return id(e.template subEntity<cc>(i));
235 template<
class EntityType>
236 IdType computeId(
const EntityType& e)
const
239 for(
int c=0; c<EntityType::codimension; ++c )
241 return myId + e.index();
243 const CpGridData& grid_;
254 void swap(std::vector<int>& cellMapping,
255 std::vector<int>& faceMapping,
256 std::vector<int>& pointMapping)
264 : idSet_(ids), view_(view)
272 assert(view_ == e.pgrid_);
279 return idSet_->id(e);
281 return this->
template getMapping<codim>()[e.
index()];
287 assert(view_ == e.pgrid_);
288 return id(e.template subEntity<cc>(i));
293 std::shared_ptr<const IdSet> idSet_;
307 using IdType =
typename LevelGlobalIdSet::IdType;
314 return levelIdSet(e.pgrid_).id(e);
320 return levelIdSet(e.pgrid_).template subId<cc>(e, i);
325 void insertIdSet(
const CpGridData& view);
328 const LevelGlobalIdSet& levelIdSet(
const CpGridData*
const data)
const
330 auto candidate = idSets_.find(data);
331 assert(candidate != idSets_.end());
332 return *candidate->second;
335 std::map<const CpGridData* const, std::shared_ptr<const LevelGlobalIdSet>> idSets_;
345 grid_ = &(idSet.idSet_->grid_);
349 mapping_.reset(
new std::unordered_map<int,int>);
351 for (
const auto& globalId: idSet.template getMapping<3>())
352 (*mapping_)[globalId] = localId++;
355 int operator[](
int i)
const
359 return(*mapping_)[i];
363 return i - grid_->
size(0) - grid_->
size(1) - grid_->
size(2);
366 OPM_THROW(std::runtime_error,
"No grid or mapping. Should not be here!");
370 mapping_.reset(
nullptr);
373 std::unique_ptr<std::unordered_map<int,int> > mapping_;
Struct that hods all the data needed to represent a Cpgrid.
Definition: CpGridData.hpp:122
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:394
Represents an entity of a given codim, with positive or negative orientation.
Definition: EntityRep.hpp:99
int index() const
The (positive) index of an entity.
Definition: EntityRep.hpp:126
Definition: Entity.hpp:64
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:304
typename LevelGlobalIdSet::IdType IdType
The type of the id.
Definition: Indexsets.hpp:307
Definition: Indexsets.hpp:199
IdType id(const cpgrid::Intersection &intersection) const
return id of intersection (here face number)
Definition: Indexsets.hpp:222
Definition: Indexsets.hpp:55
bool contains(const EntityType &e) const
Definition: Indexsets.hpp:185
int size(int codim) const
Definition: Indexsets.hpp:126
IndexType subIndex(const cpgrid::Entity< 0 > &e, int i) const
Definition: Indexsets.hpp:160
const Types & types(int codim) const
Definition: Indexsets.hpp:103
~IndexSet()
Destructor.
Definition: Indexsets.hpp:87
std::vector< GeometryType > Types
Definition: Indexsets.hpp:71
IndexType index(const EntityType &e) const
Definition: Indexsets.hpp:149
IndexType index(const cpgrid::Entity< cd > &e) const
Definition: Indexsets.hpp:138
int size(GeometryType type) const
Definition: Indexsets.hpp:112
IndexSet()
Definition: Indexsets.hpp:76
const Types & geomTypes(int codim) const
Definition: Indexsets.hpp:94
int IndexType
Definition: Indexsets.hpp:60
Definition: Intersection.hpp:66
Definition: Indexsets.hpp:248
Definition: Indexsets.hpp:339
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
Export the type of the entity used as parameter in the index(...) method.
Definition: Indexsets.hpp:65