4#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_INTERPOLATE_HH
5#define DUNE_PDELAB_GRIDFUNCTIONSPACE_INTERPOLATE_HH
12#include <dune/localfunctions/common/interfaceswitch.hh>
13#include <dune/localfunctions/common/virtualinterface.hh>
15#include <dune/typetree/typetree.hh>
16#include <dune/typetree/pairtraversal.hh>
18#include <dune/pdelab/function/localfunction.hh>
19#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
20#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
30 template<
typename LF,
typename XG>
31 struct InterpolateLeafFromScalarVisitor
32 :
public TypeTree::TreeVisitor
33 ,
public TypeTree::DynamicTraversal
36 template<
typename LFS,
typename TreePath>
37 void leaf(
const LFS& lfs, TreePath
treePath)
const
39 std::vector<typename XG::ElementType> xl(lfs.size());
46 xg.write_sub_container(lfs,xl);
49 InterpolateLeafFromScalarVisitor(
const LF& lf_, XG& xg_)
59 template<
typename LF,
typename XG>
60 struct InterpolateLeafFromVectorVisitor
61 :
public TypeTree::TreeVisitor
62 ,
public TypeTree::DynamicTraversal
64 using Domain =
typename Functions::SignatureTraits<LF>::Domain;
65 using Range =
typename Functions::SignatureTraits<LF>::Range;
66 using RangeField =
typename FieldTraits<Range>::field_type;
68 template<
typename LFS,
typename TreePath>
69 void leaf(
const LFS& lfs, TreePath
treePath)
const
71 std::vector<typename XG::ElementType> xl(lfs.size());
73 using LFSRange =
typename LFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType;
74 static_assert(std::is_convertible<LFSRange, typename FieldTraits< LFSRange >::field_type>::value,
75 "only interpolation into scalar leaf function spaces is implemented");
78 auto f = [&](
const Domain& x) -> RangeField {
return lf(x)[index]; };
84 xg.write_sub_container(lfs,xl);
90 InterpolateLeafFromVectorVisitor(
const LF& lf_, XG& xg_)
97 mutable std::size_t index;
102 template<
typename E,
typename XG>
103 struct InterpolateVisitor
104 :
public TypeTree::TreePairVisitor
105 ,
public TypeTree::DynamicTraversal
108 template<
typename F,
typename LFS,
typename TreePath>
109 typename std::enable_if<F::isLeaf && LFS::isLeaf>::type
110 leaf(
const F& f,
const LFS& lfs, TreePath
treePath)
const
115 std::vector<typename XG::ElementType> xl(lfs.size());
121 xg.write_sub_container(lfs, xl);
125 template<
typename F,
typename LFS,
typename TreePath,
126 typename Range =
typename Functions::SignatureTraits<F>::Range>
127 typename std::enable_if<F::isLeaf &&
128 std::is_convertible<Range, typename FieldTraits< Range >::field_type>::value &&
129 (!LFS::isLeaf)>::type
130 leaf(
const F& f,
const LFS& lfs, TreePath
treePath)
const
137 template<
typename F,
typename LFS,
typename TreePath,
138 typename Range =
typename Functions::SignatureTraits<F>::Range>
139 typename std::enable_if<F::isLeaf &&
140 (!std::is_convertible<Range, typename FieldTraits< Range >::field_type>::value) &&
141 (!LFS::isLeaf)>::type
142 leaf(
const F& f,
const LFS& lfs, TreePath
treePath)
const
145 "Number of leaves and dimension of range type " \
146 "must match for automatic interpolation of " \
147 "vector-valued function");
152 InterpolateVisitor(
const E& e_, XG& xg_)
176 template<
typename F,
typename GFS,
typename XG>
182 using EntitySet =
typename GFS::Traits::EntitySet;
183 using Element =
typename EntitySet::Element;
185 auto entity_set = gfs.entitySet();
188 auto lf = makeLocalFunctionTree(f, gfs.gridView());
193 typedef LFSIndexCache<LFS> LFSCache;
194 LFSCache lfs_cache(lfs);
195 typedef typename XG::template LocalView<LFSCache> XView;
200 for (
const auto& element : elements(entity_set))
206 x_view.bind(lfs_cache);
A few common exception classes.
void interpolate(const F &f, const GFS &gfs, XG &xg)
interpolation from a given grid function
Definition: interpolate.hh:177
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
void applyToTreePair(Tree1 &&tree1, Tree2 &&tree2, Visitor &&visitor)
Apply visitor to a pair of TypeTrees.
Definition: pairtraversal.hh:126
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:237
Dune namespace.
Definition: alignedallocator.hh:11
static const Interpolation & interpolation(const FiniteElement &fe)
access interpolation
Definition: interfaceswitch.hh:40
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:183