1#ifndef DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
2#define DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
4#include <dune/grid/utility/persistentcontainer.hh>
5#include <dune/grid/utility/persistentcontainermap.hh>
6#include <unordered_map>
10template <
class HostGr
id,
int dim,
class T>
11class PersistentContainer<MMesh<HostGrid, dim>, T>
12 :
public Dune::PersistentContainerMap<
13 MMesh<HostGrid, dim>, typename MMesh<HostGrid, dim>::LocalIdSet,
14 std::unordered_map<typename MMesh<HostGrid, dim>::LocalIdSet::IdType,
16 typedef MMesh<HostGrid, dim> G;
17 typedef PersistentContainerMap<
18 G,
typename G::LocalIdSet,
19 std::unordered_map<typename G::LocalIdSet::IdType, T> >
21 typedef typename MMesh<HostGrid, dim>::LocalIdSet IdSet;
22 typedef std::unordered_map<typename MMesh<HostGrid, dim>::LocalIdSet::IdType,
27 typedef typename Base::Grid Grid;
28 typedef typename Base::Value Value;
30 PersistentContainer(
const Grid &grid,
int codim,
const Value &value = Value())
31 : Base(grid, codim, grid.localIdSet(), value) {}
33 using Base::codimension;
34 using Base::migrateLevel;
36 void resize(
const Value &value = Value()) {
37 if (sequence_ != this->grid_->sequence()) {
38 Hybrid::forEach(std::make_index_sequence<Grid::dimension + 1>{},
40 if (i == this->codimension())
41 this->
template resize<i>(value);
43 sequence_ = this->grid_->sequence();
48 void resize(
const Value &value) {
49 std::integral_constant<bool, Capabilities::hasEntity<Grid, codim>::v>
51 assert(codim == codimension());
54 if constexpr (codim == 0) {
55 MMeshImpl::MultiId id(
56 {std::size_t(-4), std::size_t(-3), std::size_t(-2)});
57 this->data_.insert(std::make_pair(
id, value));
61 if constexpr (codim == 1) {
62 MMeshImpl::MultiId eid0({std::size_t(-4), std::size_t(-3)});
63 this->data_.insert(std::make_pair(eid0, value));
64 MMeshImpl::MultiId eid1({std::size_t(-4), std::size_t(-2)});
65 this->data_.insert(std::make_pair(eid1, value));
66 MMeshImpl::MultiId eid2({std::size_t(-3), std::size_t(-2)});
67 this->data_.insert(std::make_pair(eid2, value));
71 if constexpr (codim == dim) {
72 MMeshImpl::MultiId vid0(std::size_t(-4));
73 this->data_.insert(std::make_pair(vid0, value));
74 MMeshImpl::MultiId vid1(std::size_t(-3));
75 this->data_.insert(std::make_pair(vid1, value));
76 MMeshImpl::MultiId vid2(std::size_t(-2));
77 this->data_.insert(std::make_pair(vid2, value));
84 this->
template migrateLevel<codim>(0, value, data, hasEntity);
91template <
class MMesh,
class T>
92class PersistentContainer<MMeshInterfaceGrid<MMesh>, T>
93 :
public Dune::PersistentContainerMap<
94 MMeshInterfaceGrid<MMesh>,
95 typename MMeshInterfaceGrid<MMesh>::LocalIdSet,
97 typename MMeshInterfaceGrid<MMesh>::LocalIdSet::IdType, T> > {
98 typedef MMeshInterfaceGrid<MMesh> G;
99 typedef PersistentContainerMap<
100 G,
typename G::LocalIdSet,
101 std::unordered_map<typename G::LocalIdSet::IdType, T> >
103 typedef typename MMeshInterfaceGrid<MMesh>::LocalIdSet IdSet;
104 typedef std::unordered_map<
105 typename MMeshInterfaceGrid<MMesh>::LocalIdSet::IdType, T>
107 static constexpr int dim = MMesh::dimensionworld - 1;
110 typedef typename Base::Grid Grid;
111 typedef typename Base::Value Value;
113 PersistentContainer(
const Grid &grid,
int codim,
const Value &value = Value())
114 : Base(grid, codim, grid.localIdSet(), value) {}
116 using Base::codimension;
117 using Base::migrateLevel;
119 void resize(
const Value &value = Value()) {
120 if (sequence_ != this->grid_->sequence()) {
121 Hybrid::forEach(std::make_index_sequence<Grid::dimension + 1>{},
123 if (i == this->codimension())
124 this->
template resize<i>(value);
126 sequence_ = this->grid_->sequence();
131 void resize(
const Value &value) {
132 std::integral_constant<bool, Capabilities::hasEntity<Grid, codim>::v>
134 assert(codim == codimension());
137 if constexpr (codim == 0) {
138 MMeshImpl::MultiId id({std::size_t(-3), std::size_t(-2)});
139 this->data_.insert(std::make_pair(
id, value));
143 if constexpr (codim == dim) {
144 MMeshImpl::MultiId vid0(std::size_t(-3));
145 this->data_.insert(std::make_pair(vid0, value));
146 MMeshImpl::MultiId vid1(std::size_t(-2));
147 this->data_.insert(std::make_pair(vid1, value));
154 this->
template migrateLevel<codim>(0, value, data, hasEntity);