4 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_INTERPOLATE_HH 5 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_INTERPOLATE_HH 9 #include<dune/common/exceptions.hh> 11 #include <dune/localfunctions/common/interfaceswitch.hh> 13 #include <dune/typetree/typetree.hh> 14 #include <dune/typetree/pairtraversal.hh> 30 template<
typename FE,
typename ElemFunction,
typename XL>
31 void interpolate(
const FE &fe,
const ElemFunction &elemFunction,
34 FiniteElementInterfaceSwitch<FE>::interpolation(fe).
41 template<
typename IB,
typename LF,
typename XG>
42 struct InterpolateLeafFromScalarVisitor
43 :
public TypeTree::TreeVisitor
44 ,
public TypeTree::DynamicTraversal
47 template<
typename LFS,
typename TreePath>
48 void leaf(
const LFS& lfs, TreePath treePath)
const 50 std::vector<typename XG::ElementType> xl(lfs.size());
53 ib.interpolate(lfs.finiteElement(),
lf, xl);
56 xg.write_sub_container(lfs,xl);
59 InterpolateLeafFromScalarVisitor(
const IB& ib_,
const LF& lf_, XG& xg_)
72 template<
typename IB,
typename LF,
typename XG>
73 struct InterpolateLeafFromVectorVisitor
74 :
public TypeTree::TreeVisitor
75 ,
public TypeTree::DynamicTraversal
78 template<
typename LFS,
typename TreePath>
79 void leaf(
const LFS& lfs, TreePath treePath)
const 81 std::vector<typename XG::ElementType> xl(lfs.size());
85 typedef SelectComponentAdapter<LF> LFCOMP;
87 LFCOMP localfcomp(
lf,treePath.back());
88 ib.interpolate(lfs.finiteElement(), localfcomp, xl);
91 xg.write_sub_container(lfs,xl);
94 InterpolateLeafFromVectorVisitor(
const IB& ib_,
const LF& lf_, XG& xg_)
107 template<
typename IB,
typename E,
typename XG>
108 struct InterpolateVisitor
109 :
public TypeTree::TreePairVisitor
110 ,
public TypeTree::DynamicTraversal
113 template<
typename F,
typename LFS,
typename TreePath>
114 typename std::enable_if<F::isLeaf && LFS::isLeaf>::type
115 leaf(
const F& f,
const LFS& lfs, TreePath treePath)
const 117 std::vector<typename XG::ElementType> xl(lfs.size());
120 ib.interpolate(lfs.finiteElement(),
121 GridFunctionToLocalFunctionAdapter<F>(f,
e), xl);
124 xg.write_sub_container(lfs,xl);
128 template<
typename F,
typename LFS,
typename TreePath>
129 typename std::enable_if<F::isLeaf && F::Traits::dimRange == 1
130 && (!LFS::isLeaf)>::type
131 leaf(
const F& f,
const LFS& lfs, TreePath treePath)
const 133 static_assert((TypeTree::TreeInfo<LFS>::depth == 2),
134 "Automatic interpolation of vector-valued function " \
135 "is restricted to trees of depth 1");
137 typedef GridFunctionToLocalFunctionAdapter<F> LF;
140 TypeTree::applyToTree(lfs,InterpolateLeafFromScalarVisitor<IB,LF,XG>(
ib,localf,
xg));
145 template<
typename F,
typename LFS,
typename TreePath>
146 typename std::enable_if<F::isLeaf && (F::Traits::dimRange > 1) &&
147 (!LFS::isLeaf)>::type
148 leaf(
const F& f,
const LFS& lfs, TreePath treePath)
const 150 static_assert((TypeTree::TreeInfo<LFS>::depth == 2),
151 "Automatic interpolation of vector-valued function " \
152 "is restricted to trees of depth 1");
154 "Number of children and dimension of range type " \
155 "must match for automatic interpolation of " \
156 "vector-valued function");
158 typedef GridFunctionToLocalFunctionAdapter<F> LF;
161 TypeTree::applyToTree(lfs,InterpolateLeafFromVectorVisitor<IB,LF,XG>(
ib,localf,
xg));
164 InterpolateVisitor(IB ib_,
const E& e_, XG& xg_)
190 template<
typename F,
typename GFS,
typename XG>
196 using EntitySet =
typename GFS::Traits::EntitySet;
197 using Element =
typename EntitySet::Element;
199 auto entity_set = gfs.entitySet();
205 LFSCache lfs_cache(lfs);
206 typedef typename XG::template LocalView<LFSCache> XView;
211 for (
const auto& element : elements(entity_set))
216 x_view.bind(lfs_cache);
219 TypeTree::applyToTreePair(f,lfs,InterpolateVisitor<InterpolateBackendStandard,Element,XView>(
InterpolateBackendStandard(),element,x_view));
231 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_INTERPOLATE_HH const LF & lf
Definition: interpolate.hh:66
Definition: interpolate.hh:28
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
void interpolate(const FE &fe, const ElemFunction &elemFunction, XL &xl) const
Definition: interpolate.hh:31
const IB & ib
Definition: interpolate.hh:65
const Entity & e
Definition: localfunctionspace.hh:111
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
XG & xg
Definition: interpolate.hh:67