dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
persistentcontainer.hh
Go to the documentation of this file.
1#ifndef DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
2#define DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
3
4#include <dune/grid/utility/persistentcontainer.hh>
6#include <unordered_map>
7
8namespace Dune {
9
10template <class HostGrid, int dim, class T>
11class PersistentContainer<MMesh<HostGrid, dim>, T>
13 MMesh<HostGrid, dim>, typename MMesh<HostGrid, dim>::LocalIdSet,
14 std::unordered_map<typename MMesh<HostGrid, dim>::LocalIdSet::IdType,
15 T> > {
16 typedef MMesh<HostGrid, dim> G;
18 G, typename G::LocalIdSet,
20 Base;
21 typedef typename MMesh<HostGrid, dim>::LocalIdSet IdSet;
23 T>
24 Map;
25
26 public:
27 typedef typename Base::Grid Grid;
28 typedef typename Base::Value Value;
29
30 PersistentContainer(const Grid &grid, int codim, const Value &value = Value())
31 : Base(grid, codim, grid.localIdSet(), value) {}
32
33 using Base::codimension;
34 using Base::migrateLevel;
35
36 void resize(const Value &value = Value()) {
37 if (sequence_ != this->grid_->sequence()) {
39 [&](auto i) {
40 if (i == this->codimension())
41 this->template resize<i>(value);
42 });
43 sequence_ = this->grid_->sequence();
44 }
45 }
46
47 template <int codim>
48 void resize(const Value &value) {
50 hasEntity;
51 assert(codim == codimension());
52
53 // add one id for caching entity during adaptation
54 if constexpr (codim == 0) {
56 {std::size_t(-4), std::size_t(-3), std::size_t(-2)});
57 this->data_.insert(std::make_pair(id, value));
58 }
59
60 // add one id for a every caching codim 1 entity during adaptation
61 if constexpr (codim == 1) {
63 this->data_.insert(std::make_pair(eid0, value));
65 this->data_.insert(std::make_pair(eid1, value));
67 this->data_.insert(std::make_pair(eid2, value));
68 }
69
70 // add one id for every caching vertex during adaptation
71 if constexpr (codim == dim) {
73 this->data_.insert(std::make_pair(vid0, value));
75 this->data_.insert(std::make_pair(vid1, value));
77 this->data_.insert(std::make_pair(vid2, value));
78 }
79
80 // create empty map, but keep old data
81 Map data;
82
83 // add new entries
84 this->template migrateLevel<codim>(0, value, data, hasEntity);
85 }
86
87 private:
88 int sequence_ = -1;
89};
90
91template <class MMesh, class T>
100 G, typename G::LocalIdSet,
102 Base;
103 typedef typename MMeshInterfaceGrid<MMesh>::LocalIdSet IdSet;
104 typedef std::unordered_map<
106 Map;
107 static constexpr int dim = MMesh::dimensionworld - 1;
108
109 public:
110 typedef typename Base::Grid Grid;
111 typedef typename Base::Value Value;
112
113 PersistentContainer(const Grid &grid, int codim, const Value &value = Value())
114 : Base(grid, codim, grid.localIdSet(), value) {}
115
116 using Base::codimension;
117 using Base::migrateLevel;
118
119 void resize(const Value &value = Value()) {
120 if (sequence_ != this->grid_->sequence()) {
122 [&](auto i) {
123 if (i == this->codimension())
124 this->template resize<i>(value);
125 });
126 sequence_ = this->grid_->sequence();
127 }
128 }
129
130 template <int codim>
131 void resize(const Value &value) {
133 hasEntity;
134 assert(codim == codimension());
135
136 // add one id for caching entity during adaptation
137 if constexpr (codim == 0) {
139 this->data_.insert(std::make_pair(id, value));
140 }
141
142 // add one id for every caching vertex during adaptation
143 if constexpr (codim == dim) {
145 this->data_.insert(std::make_pair(vid0, value));
147 this->data_.insert(std::make_pair(vid1, value));
148 }
149
150 // create empty map, but keep old data
151 Map data;
152
153 // add new entries
154 this->template migrateLevel<codim>(0, value, data, hasEntity);
155 }
156
157 private:
158 int sequence_ = -1;
159};
160
161} // namespace Dune
162
163#endif // #ifndef DUNE_MMESH_MISC_PERSISTENTCONTAINER_HH
int id()
constexpr void forEach(Range &&range, F &&f)
size_type dim() const
const Grid & grid() const
std::map< G::LocalIdSet::IdType, T > data_
The MMesh class templatized by the CGAL host grid type and the dimension. .
Definition grid/mmesh.hh:158
Definition multiid.hh:15
Provides a DUNE grid interface class for the interface of a MMesh interface grid .
Definition mmesh/interface/grid.hh:90
Base::Value Value
Definition persistentcontainer.hh:28
void resize(const Value &value)
Definition persistentcontainer.hh:48
PersistentContainer(const Grid &grid, int codim, const Value &value=Value())
Definition persistentcontainer.hh:30
Base::Grid Grid
Definition persistentcontainer.hh:27
void resize(const Value &value=Value())
Definition persistentcontainer.hh:36
void resize(const Value &value)
Definition persistentcontainer.hh:131
PersistentContainer(const Grid &grid, int codim, const Value &value=Value())
Definition persistentcontainer.hh:113
Base::Value Value
Definition persistentcontainer.hh:111
void resize(const Value &value=Value())
Definition persistentcontainer.hh:119
Base::Grid Grid
Definition persistentcontainer.hh:110
T insert(T... args)
T make_pair(T... args)