AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
SimpleInterpolator.hpp
1#pragma once
2
3#include <vector>
4
5#include <amdis/common/FakeContainer.hpp>
6#include <amdis/common/FieldMatVec.hpp>
7#include <amdis/functions/EntitySet.hpp>
8#include <amdis/functions/HierarchicNodeToRangeMap.hpp>
9#include <amdis/functions/NodeIndices.hpp>
10#include <amdis/linearalgebra/Traits.hpp>
11#include <amdis/operations/Assigner.hpp>
12#include <amdis/typetree/Traversal.hpp>
13
14#include <dune/common/typetree/childaccess.hh>
15#include <dune/common/typetree/treepath.hh>
16
17namespace AMDiS
18{
19 namespace tag
20 {
21 struct assign {};
22 }
23
24 template <class Basis,
25 class TreePath = Dune::TypeTree::TreePath<>>
27 {
28 template <class Coeff, class GridFct, class BitVector>
29 void operator()(Coeff& coeff, GridFct const& gf, BitVector const& bitVec) const
30 {
31 // Obtain a local view of the gridFunction
32 auto lf = localFunction(gf);
33 auto localView = basis_.localView();
34
35 std::vector<typename Coeff::value_type> localCoeff;
36
37 for (const auto& e : entitySet(basis_))
38 {
39 localView.bind(e);
40 lf.bind(e);
41
42 auto&& subTree = Dune::TypeTree::child(localView.tree(),treePath_);
43 Traversal::forEachLeafNode(subTree, [&](auto const& node, auto const& tp)
44 {
45 auto bitVecRange = mappedRangeView(Dune::range(node.size()), [&](std::size_t i) -> bool {
46 return bitVec[localView.index(node.localIndex(i))];
47 });
48
49 // check whether there is a local contribution
50 std::vector<bool> mask(bitVecRange.begin(), bitVecRange.end());
51 if (std::all_of(mask.begin(), mask.end(), [](bool m) { return !m; }))
52 return;
53
54 // compute local interpolation coefficients
55 node.finiteElement().localInterpolation().interpolate(HierarchicNodeWrapper{tp,lf}, localCoeff);
56
57 // assign local coefficients to global vector
58 coeff.scatter(localView, node, localCoeff, mask, Assigner::assign{});
59 });
60
61 lf.unbind();
62 }
63 coeff.finish();
64 }
65
66 template <class Coeff, class GridFct>
67 void operator()(Coeff& coeff, GridFct const& gf) const
68 {
69 (*this)(coeff, gf, FakeContainer<bool,true>{});
70 }
71
72 SimpleInterpolator(Basis const& basis, TreePath treePath = {})
73 : basis_{basis}
74 , treePath_{treePath}
75 {}
76
77 Basis const& basis_;
78 TreePath treePath_ = {};
79 };
80
81
82 template <class Tag>
84
85 template <>
86 struct InterpolatorFactory<tag::assign>
87 {
88 template <class Basis,
89 class TreePath = Dune::TypeTree::TreePath<>>
90 static auto create(Basis const& basis, TreePath treePath = {})
91 {
92 return SimpleInterpolator<Basis,TreePath>{basis, treePath};
93 }
94 };
95
96} // end namespace AMDiS
A container-like data-structure not storing anything and with empty implementations in many container...
Definition FakeContainer.hpp:36
Definition Assigner.hpp:8
Definition HierarchicNodeToRangeMap.hpp:42
Definition SimpleInterpolator.hpp:83
Definition SimpleInterpolator.hpp:27
Definition SimpleInterpolator.hpp:21