3#ifndef DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
4#define DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
8#include <unordered_map>
11#include <dune/geometry/dimension.hh>
13#include <dune/grid/common/gridenums.hh>
15#include <dune/grid/common/partitionset.hh>
26 template<
typename GFS>
27 struct BorderIndexIdCache
30 typedef GFS GridFunctionSpace;
32 typedef typename GFS::Traits::GridView GridView;
35 typedef std::size_t size_type;
36 using index_type =
typename EntitySet::Traits::Index;
37 typedef typename GFS::Traits::GridView::Grid::GlobalIdSet::IdType id_type;
41 :
public std::pair<std::size_t,std::size_t>
44 typedef std::size_t size_type;
49 EntityIndex(size_type gt_index, size_type entity_index)
50 :
std::pair<size_type,size_type>(gt_index,entity_index)
53 size_type geometryTypeIndex()
const
58 size_type entityIndex()
const
79 typedef std::unordered_map<
84 BorderIndexIdCache(
const GFS& gfs)
86 , _entity_set(gfs.entitySet())
96 auto& index_set = _entity_set.indexSet();
101 if (!_gfs.ordering().contains(codim))
104 for (
auto gt : index_set.types(codim))
110 create_for_codim<Grid::dimension>();
113 bool isBorderEntity(std::size_t gt_index, std::size_t entity_index)
const
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())
128 EntityIndex index(id_type entity_id)
const
130 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
131 if (it == _id_to_index.end())
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())
142 return std::make_pair(
false,EntityIndex());
144 return std::make_pair(
true,it->second);
150 EntitySet _entity_set;
151 BorderEntitySet _border_entities;
152 IndexToIdMap _index_to_id;
153 IdToIndexMap _id_to_index;
156 typename std::enable_if<
157 (codim > 0) && Capabilities::hasEntityIterator<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))
168 index_type index = index_set.index(e);
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;
178 _id_to_index[id] = EntityIndex(gt_index,index);
181 create_for_codim<codim-1>();
185 typename std::enable_if<
186 (codim > 0) && !Capabilities::hasEntityIterator<Grid,codim>::v
190 if (_gfs.ordering().contains(codim))
192 create_for_codim<codim-1>();
196 typename std::enable_if<
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
static constexpr std::size_t index(const GeometryType >)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:138
static constexpr std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:125
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
A set of traits classes to store static information about grid implementation.
Traits for type conversions and type information.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
Traits::Grid Grid
type of the grid
Definition: gridview.hh:83
impl::EntitySet< G > EntitySet
the entity set of this function space.
Definition: gridfunctionspace.hh:133
constexpr InteriorBorder interiorBorder
PartitionSet for the interior and border partitions.
Definition: partitionset.hh:286
Dune namespace.
Definition: alignedallocator.hh:13
Helper classes to provide indices for geometrytypes for use in a vector.