3 #ifndef DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
4 #define DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
9 #include <dune/common/typetraits.hh>
10 #include <dune/geometry/typeindex.hh>
11 #include <dune/grid/common/gridenums.hh>
12 #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>
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 const std::vector<GeometryType>& geometry_types = index_set.geomTypes(codim);
102 for (
typename std::vector<GeometryType>::const_iterator it = geometry_types.begin(),
103 end_it = geometry_types.end();
107 _border_entities[GlobalGeometryTypeIndex::index(*it)].resize(index_set.size(*it));
108 _index_to_id[GlobalGeometryTypeIndex::index(*it)];
111 create_for_codim<Grid::dimension>();
116 return _border_entities[gt_index][entity_index];
121 typename IndexToIdMap::value_type::const_iterator it = _index_to_id[gt_index].find(entity_index);
122 if (it == _index_to_id[gt_index].end())
124 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
131 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
132 if (it == _id_to_index.end())
134 DUNE_THROW(Dune::Exception,
"invalid argument (entity not in map)");
141 typename IdToIndexMap::const_iterator it = _id_to_index.find(entity_id);
142 if (it == _id_to_index.end())
143 return std::make_pair(
false,EntityIndex());
145 return std::make_pair(
true,it->second);
158 (codim > 0) && Capabilities::hasEntity<Grid,codim>::v
162 const typename GridView::IndexSet& index_set = _grid_view.indexSet();
163 const typename Grid::GlobalIdSet& id_set = _grid_view.grid().globalIdSet();
165 if (_gfs.ordering().contains(codim))
167 typedef typename GridView::template Codim<codim>::template Partition<InteriorBorder_Partition>::Iterator EntityIterator;
168 for (EntityIterator it = _grid_view.template begin<codim,InteriorBorder_Partition>(),
169 end_it = _grid_view.template end<codim,InteriorBorder_Partition>();
174 size_type gt_index = GlobalGeometryTypeIndex::index(it->type());
176 bool border_entity = _border_entities[gt_index][
index] = (it->partitionType() == BorderEntity);
182 _index_to_id[gt_index][
index] =
id;
183 _id_to_index[
id] = EntityIndex(gt_index,index);
186 create_for_codim<codim-1>();
191 (codim > 0) && !Capabilities::hasEntity<Grid,codim>::v
195 if (_gfs.ordering().contains(codim))
196 DUNE_THROW(Dune::Exception,
"Required codim " << codim <<
" not supported by grid!");
197 create_for_codim<codim-1>();
212 #endif // DUNE_PDELAB_COMMON_BORDERINDEXIDCACHE_HH
Definition: borderindexidcache.hh:37
std::size_t size_type
Definition: borderindexidcache.hh:32
Provide common name for std::unordered_map and std::unordered_multimap classes in Dune::PDELab namesp...
EntityIndex()
Definition: borderindexidcache.hh:43
std::vector< std::vector< bool > > BorderEntitySet
Definition: borderindexidcache.hh:67
bool isBorderEntity(std::size_t gt_index, std::size_t entity_index) const
Definition: borderindexidcache.hh:114
id_type id(std::size_t gt_index, index_type entity_index) const
Definition: borderindexidcache.hh:119
std::vector< unordered_map< index_type, id_type > > IndexToIdMap
Definition: borderindexidcache.hh:74
GFS::Traits::GridView GridView
Definition: borderindexidcache.hh:29
std::pair< bool, EntityIndex > findIndex(id_type entity_id) const
Definition: borderindexidcache.hh:139
size_type entityIndex() const
Definition: borderindexidcache.hh:55
unordered_map< id_type, EntityIndex > IdToIndexMap
Definition: borderindexidcache.hh:79
EntityIndex(size_type gt_index, size_type entity_index)
Definition: borderindexidcache.hh:46
GFS::Traits::GridView::Grid::GlobalIdSet::IdType id_type
Definition: borderindexidcache.hh:34
size_type geometryTypeIndex() const
Definition: borderindexidcache.hh:50
void update()
Definition: borderindexidcache.hh:88
std::size_t size_type
Definition: borderindexidcache.hh:41
Definition: borderindexidcache.hh:25
Definition: unordered_map.hh:46
GridView::Grid Grid
Definition: borderindexidcache.hh:30
GFS::Traits::GridView::IndexSet::IndexType index_type
Definition: borderindexidcache.hh:33
GFS GridFunctionSpace
Definition: borderindexidcache.hh:28
EntityIndex index(id_type entity_id) const
Definition: borderindexidcache.hh:129
BorderIndexIdCache(const GFS &gfs)
Definition: borderindexidcache.hh:81