9#include <dune/common/concept.hh>
10#include <dune/common/shared_ptr.hh>
11#include <amdis/Observer.hpp>
20 template <
class G,
class T =
double>
39 using Data = std::vector<T>;
48 , data_(grid->size(0), value)
59 return grid_->leafGridView();
77 data_.resize(grid_->size(0));
83 data_.resize(grid_->size(0));
84 std::fill(data_.begin(), data_.end(), T(0));
92 persistentData_.emplace();
95 auto const& indexSet = grid_->leafIndexSet();
96 auto const& idSet = grid_->localIdSet();
97 for (
auto const& e : elements(grid_->leafGridView())) {
98 (*persistentData_)[idSet.id(e)] = data_[indexSet.index(e)];
101 if (e.mightVanish() && e.hasFather()) {
102 T value = data_[indexSet.index(e)];
103 auto father = e.father();
104 for (; ; father = father.father()) {
105 (*persistentData_)[idSet.id(father)] = value;
106 if (!father.hasFather())
119 auto const& indexSet = grid_->leafIndexSet();
120 auto const& idSet = grid_->localIdSet();
121 for (
auto const& e : elements(grid_->leafGridView()))
125 if (e.isNew() && e.hasFather())
128 for (; ; father = father.father()) {
129 auto it = persistentData_->find(idSet.id(father));
130 if (it != persistentData_->end()) {
134 if (!father.hasFather())
138 data_[indexSet.index(e)] = value;
145 persistentData_.reset();
149 std::shared_ptr<Grid const> grid_;
152 std::optional<std::map<typename Grid::LocalIdSet::IdType, T>> persistentData_;
An adaptive container that stores a value per grid element.
Definition: ElementVector.hpp:25
void updateImpl(event::preAdapt e) override
Implementation of Observer update(event::preAdapt) method.
Definition: ElementVector.hpp:90
void resize()
Resize the internal data without interpolating.
Definition: ElementVector.hpp:75
std::vector< T > Data
The data container for the ElementVector.
Definition: ElementVector.hpp:39
void updateImpl(event::postAdapt) override
Implementation of Observer update(event::postAdapt) method.
Definition: ElementVector.hpp:143
G Grid
Type of the grid.
Definition: ElementVector.hpp:30
auto gridView() const
Return the GridView the data is defined on.
Definition: ElementVector.hpp:57
void resizeZero()
Resize the internal data without interpolating and set all values to 0.
Definition: ElementVector.hpp:81
ElementVector(std::shared_ptr< G const > const &grid, T value=0)
(1) Constructor. Stores the shared_ptr of the grid.
Definition: ElementVector.hpp:43
ElementVector(G const &grid, T value=0)
(2) Constructor. Forwards to (1) by wrapping into a shared_ptr.
Definition: ElementVector.hpp:52
Data const & data() const
Get a const-ref to the internal data vector.
Definition: ElementVector.hpp:63
void updateImpl(event::adapt e) override
Implementation of Observer update(event::adapt) method.
Definition: ElementVector.hpp:114
Data & data()
Get a ref to the internal data vector.
Definition: ElementVector.hpp:69
std::size_t size_type
The index/size - type.
Definition: ElementVector.hpp:33
T value_type
The type of the elements of the ElementVector.
Definition: ElementVector.hpp:36
Implementation of the ObserverInterface.
Definition: Observer.hpp:104
Definition: Observer.hpp:25
Definition: Observer.hpp:30
Definition: Observer.hpp:19