3 #ifndef DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH 4 #define DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH 8 #include <unordered_map> 10 #include <dune/common/typetraits.hh> 11 #include <dune/geometry/dimension.hh> 12 #include <dune/geometry/typeindex.hh> 13 #include <dune/grid/common/gridenums.hh> 14 #include <dune/grid/common/capabilities.hh> 15 #include <dune/grid/common/partitionset.hh> 26 template<
typename GFS>
32 typedef typename GFS::Traits::GridView
GridView;
33 typedef typename GridView::Grid
Grid;
37 typedef typename GFS::Traits::GridView::Grid::GlobalIdSet::IdType
id_type;
41 :
public std::pair<std::size_t,std::size_t>
50 :
std::pair<size_type,size_type>(gt_index,entity_index)
79 typedef std::unordered_map<
86 , _entity_set(gfs.entitySet())
93 _border_entities.resize(GlobalGeometryTypeIndex::size(Grid::dimension));
94 _index_to_id.resize(GlobalGeometryTypeIndex::size(Grid::dimension));
96 auto& index_set = _entity_set.indexSet();
99 for (
int codim = 1; codim <= Grid::dimension; ++codim)
101 if (!_gfs.ordering().contains(codim))
104 for (
auto gt : index_set.types(codim))
106 _border_entities[GlobalGeometryTypeIndex::index(gt)].resize(index_set.size(gt));
107 _index_to_id[GlobalGeometryTypeIndex::index(gt)];
110 create_for_codim<Grid::dimension>();
115 return _border_entities[gt_index][entity_index];
118 id_type
id(std::size_t gt_index,index_type entity_index)
const 120 typename IndexToIdMap::value_type::const_iterator it = _index_to_id[gt_index].find(entity_index);
121 if (it == _index_to_id[gt_index].end())
123 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
130 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
131 if (it == _id_to_index.end())
133 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
138 std::pair<bool,EntityIndex>
findIndex(id_type entity_id)
const 140 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
141 if (it == _id_to_index.end())
144 return std::make_pair(
true,it->second);
156 typename std::enable_if<
157 (codim > 0) && Capabilities::hasEntity<Grid,codim>::v
161 auto& index_set = _entity_set.indexSet();
162 auto& id_set = _entity_set.gridView().grid().globalIdSet();
164 if (_gfs.ordering().contains(codim))
166 for (
const auto&
e : entities(_entity_set,Codim<codim>{},Partitions::interiorBorder))
168 index_type
index = index_set.index(
e);
169 size_type gt_index = GlobalGeometryTypeIndex::index(
e.type());
171 bool border_entity = _border_entities[gt_index][
index] = (
e.partitionType() == BorderEntity);
175 id_type
id = id_set.id(
e);
177 _index_to_id[gt_index][
index] =
id;
181 create_for_codim<codim-1>();
185 typename std::enable_if<
186 (codim > 0) && !Capabilities::hasEntity<Grid,codim>::v
190 if (_gfs.ordering().contains(codim))
191 DUNE_THROW(Dune::Exception,
"Required codim " << codim <<
" not supported by grid!");
192 create_for_codim<codim-1>();
196 typename std::enable_if<
207 #endif // DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH id_type id(std::size_t gt_index, index_type entity_index) const
Definition: borderindexidcache.hh:118
std::size_t size_type
Definition: borderindexidcache.hh:35
GridView::Grid Grid
Definition: borderindexidcache.hh:33
std::size_t size_type
Definition: borderindexidcache.hh:44
Definition: borderindexidcache.hh:27
GFS::Traits::GridView::Grid::GlobalIdSet::IdType id_type
Definition: borderindexidcache.hh:37
impl::EntitySet< G > EntitySet
the entity set of this function space.
Definition: gridfunctionspace.hh:120
typename GridFunctionSpace::Traits::EntitySet EntitySet
Definition: borderindexidcache.hh:31
EntityIndex(size_type gt_index, size_type entity_index)
Definition: borderindexidcache.hh:49
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:113
EntityIndex()
Definition: borderindexidcache.hh:46
void update()
Definition: borderindexidcache.hh:91
size_type entityIndex() const
Definition: borderindexidcache.hh:58
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:138
size_type geometryTypeIndex() const
Definition: borderindexidcache.hh:53
std::vector< std::unordered_map< index_type, id_type > > IndexToIdMap
Definition: borderindexidcache.hh:77
GFS GridFunctionSpace
Definition: borderindexidcache.hh:30
BorderIndexIdCache(const GFS &gfs)
Definition: borderindexidcache.hh:84
std::unordered_map< id_type, EntityIndex > IdToIndexMap
Definition: borderindexidcache.hh:82
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:128
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
GFS::Traits::GridView GridView
Definition: borderindexidcache.hh:32
const Entity & e
Definition: localfunctionspace.hh:111
typename EntitySet::Traits::Index index_type
Definition: borderindexidcache.hh:36
Definition: borderindexidcache.hh:40
std::vector< std::vector< bool > > BorderEntitySet
Definition: borderindexidcache.hh:70