51 void preAdapt(Basis
const& basis, Container
const& coeff,
bool mightCoarsen)
53 CoefficientVector interpolationCoeff;
54 auto localView = basis.localView();
55 auto interpol = [&](
auto const& lf,
auto& localCoeff) {
56 localCoeff.resize(localView.size());
57 Traversal::forEachLeafNode(localView.tree(), [&](
auto const& node,
auto const& tp)
59 auto lf_at_tp = HierarchicNodeWrapper{tp,lf};
60 node.finiteElement().localInterpolation().interpolate(lf_at_tp, interpolationCoeff);
61 assert(node.size() == interpolationCoeff.size());
62 for (std::size_t i = 0; i < node.size(); ++i)
63 localCoeff[node.localIndex(i)] = interpolationCoeff[i];
68 auto c_gf = Dune::Functions::FineFunctionOnCoarseGridView{coeffFct, basis.gridView()};
69 auto c_lf = localFunction(c_gf);
70 auto const& idSet = basis.gridView().grid().localIdSet();
71 for (
auto const& e : entitySet(basis))
76 coeff.gather(localView, persistentStorage_[idSet.id(e)]);
80 if (e.mightVanish()) {
82 while (father.hasFather()) {
83 father = father.father();
84 auto [it,inserted] = persistentStorage_.try_emplace(idSet.id(father));
87 interpol(c_lf, it->second);
90 if (!inserted || !father.mightVanish())
99 void adapt(Basis
const& basis, Container& coeff)
101 coeff.init(basis,
false);
102 auto localView = basis.localView();
104 CoefficientVector interpolationCoeff;
105 auto interpol = [&](
auto const& local,
auto const& localCoeff) {
106 Traversal::forEachLeafNode(localView.tree(), [&](
auto const& node,
auto const& tp)
108 auto const& localFE = node.finiteElement();
109 auto const& localBasis = localFE.localBasis();
110 auto const& localInterpolation = localFE.localInterpolation();
112 using LocalBasis = TYPEOF(localBasis);
113 using RangeType = typename LocalBasis::Traits::RangeType;
114 std::vector<RangeType> shapeValues;
115 localInterpolation.interpolate([&](auto const& x) {
116 localBasis.evaluateFunction(local(x), shapeValues);
117 auto range = localCoeff[node.localIndex(0)] * shapeValues[0];
118 assert(node.size() == shapeValues.size());
119 for (std::size_t i = 1; i < shapeValues.size(); ++i)
120 range.axpy(localCoeff[node.localIndex(i)], shapeValues[i]);
122 }, interpolationCoeff);
127 auto const& idSet = basis.gridView().grid().localIdSet();
128 for (
const auto& e : entitySet(basis))
134 std::function<Domain(Domain
const&)> local = [](Domain
const& x) {
return x; };
135 [[maybe_unused]]
bool found =
false;
136 while (father.hasFather()) {
138 local = [local, geo=father.geometryInFather()](Domain
const& x) {
139 return geo.global(local(x));
141 father = father.father();
144 auto it = persistentStorage_.find(idSet.id(father));
145 if (it != persistentStorage_.end()) {
146 interpol(local, it->second);
154 auto it = persistentStorage_.find(idSet.id(e));
155 test_exit(it != persistentStorage_.end(),
156 "Element should be in persistent storage but isn't.");
157 coeff.scatter(localView, it->second, Assigner::assign{});