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/typeindex.hh>
12 #include <dune/grid/common/gridenums.hh>
13 #include <dune/grid/common/capabilities.hh>
24 template<
typename GFS>
29 typedef typename GFS::Traits::GridView
GridView;
30 typedef typename GridView::Grid
Grid;
33 typedef typename GFS::Traits::GridView::IndexSet::IndexType
index_type;
34 typedef typename GFS::Traits::GridView::Grid::GlobalIdSet::IdType
id_type;
38 :
public std::pair<std::size_t,std::size_t>
47 :
std::pair<size_type,size_type>(gt_index,entity_index)
76 typedef std::unordered_map<
83 , _grid_view(gfs.gridView())
90 _border_entities.resize(GlobalGeometryTypeIndex::size(Grid::dimension));
91 _index_to_id.resize(GlobalGeometryTypeIndex::size(Grid::dimension));
93 const typename GridView::IndexSet& index_set = _grid_view.indexSet();
96 for (
int codim = 1; codim <= Grid::dimension; ++codim)
98 if (!_gfs.ordering().contains(codim))
101 for (
auto gt : index_set.types(codim))
103 _border_entities[GlobalGeometryTypeIndex::index(gt)].resize(index_set.size(gt));
104 _index_to_id[GlobalGeometryTypeIndex::index(gt)];
107 create_for_codim<Grid::dimension>();
112 return _border_entities[gt_index][entity_index];
115 id_type
id(std::size_t gt_index,index_type entity_index)
const
117 typename IndexToIdMap::value_type::const_iterator it = _index_to_id[gt_index].find(entity_index);
118 if (it == _index_to_id[gt_index].end())
120 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
125 EntityIndex
index(id_type entity_id)
const
127 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
128 if (it == _id_to_index.end())
130 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
135 std::pair<bool,EntityIndex>
findIndex(id_type entity_id)
const
137 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
138 if (it == _id_to_index.end())
139 return std::make_pair(
false,EntityIndex());
141 return std::make_pair(
true,it->second);
154 (codim > 0) && Capabilities::hasEntity<Grid,codim>::v
158 const typename GridView::IndexSet& index_set = _grid_view.indexSet();
159 const typename Grid::GlobalIdSet& id_set = _grid_view.grid().globalIdSet();
161 if (_gfs.ordering().contains(codim))
163 for (
const auto&
e : entities(_grid_view,Codim<codim>{},Partitions::interiorBorder))
165 index_type
index = index_set.index(
e);
166 size_type gt_index = GlobalGeometryTypeIndex::index(
e.type());
168 bool border_entity = _border_entities[gt_index][
index] = (
e.partitionType() == BorderEntity);
172 id_type
id = id_set.id(
e);
174 _index_to_id[gt_index][
index] =
id;
175 _id_to_index[
id] = EntityIndex(gt_index,index);
178 create_for_codim<codim-1>();
183 (codim > 0) && !Capabilities::hasEntity<Grid,codim>::v
187 if (_gfs.ordering().contains(codim))
188 DUNE_THROW(Dune::Exception,
"Required codim " << codim <<
" not supported by grid!");
189 create_for_codim<codim-1>();
204 #endif // DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:135
id_type id(std::size_t gt_index, index_type entity_index) const
Definition: borderindexidcache.hh:115
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:125
std::vector< std::vector< bool > > BorderEntitySet
Definition: borderindexidcache.hh:67
std::unordered_map< id_type, EntityIndex > IdToIndexMap
Definition: borderindexidcache.hh:79
GFS::Traits::GridView::Grid::GlobalIdSet::IdType id_type
Definition: borderindexidcache.hh:34
Definition: borderindexidcache.hh:25
void update()
Definition: borderindexidcache.hh:88
const E & e
Definition: interpolate.hh:172
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:110
GFS::Traits::GridView GridView
Definition: borderindexidcache.hh:29
size_type entityIndex() const
Definition: borderindexidcache.hh:55
EntityIndex()
Definition: borderindexidcache.hh:43
std::vector< std::unordered_map< index_type, id_type > > IndexToIdMap
Definition: borderindexidcache.hh:74
std::size_t size_type
Definition: borderindexidcache.hh:32
GridView::Grid Grid
Definition: borderindexidcache.hh:30
std::size_t size_type
Definition: borderindexidcache.hh:41
Definition: adaptivity.hh:27
GFS::Traits::GridView::IndexSet::IndexType index_type
Definition: borderindexidcache.hh:33
EntityIndex(size_type gt_index, size_type entity_index)
Definition: borderindexidcache.hh:46
BorderIndexIdCache(const GFS &gfs)
Definition: borderindexidcache.hh:81
size_type geometryTypeIndex() const
Definition: borderindexidcache.hh:50
GFS GridFunctionSpace
Definition: borderindexidcache.hh:28
Definition: borderindexidcache.hh:37