dune-pdelab  2.7-git
localfunction.hh
Go to the documentation of this file.
1 //-*- tab-width: 4; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 #ifndef DUNE_PDELAB_FUNCTION_LOCALFUNCTION_HH
3 #define DUNE_PDELAB_FUNCTION_LOCALFUNCTION_HH
4 
5 #include <array>
6 #include <type_traits>
7 
11 #include <dune/functions/common/signature.hh>
12 #include <dune/functions/gridfunctions/gridviewfunction.hh>
13 
14 namespace Dune {
15 namespace PDELab {
16 
17  template<class F, std::size_t k>
19  : public TypeTree::PowerNode<F,k>
20  {
21  typedef TypeTree::PowerNode<F,k> NodeType;
22  public:
24 
26  template <typename TT>
27  void setTime(TT time){
29  TypeTree::applyToTree(*this,visitor);
30  }
31 
32  template <typename Entity>
33  void bind(const Entity & e){
34  Imp::PowerCompositeBindVisitor<Entity> visitor(e);
35  TypeTree::applyToTree(*this,visitor);
36  }
37 
38  void unbind(){
39  Imp::PowerCompositeUnbindVisitor visitor;
40  TypeTree::applyToTree(*this,visitor);
41  }
42 
45  {}
46 
49  : NodeType(f) {}
50 
57  template<typename C0, typename C1, typename... Children>
58  PowerLocalFunction (C0&& c0, C1&& c1, Children&&... children)
59  : NodeType(std::forward(c0), std::forward(c1), std::forward(children)...)
60  {
61  }
62 
64  PowerLocalFunction(const std::array<std::shared_ptr<F>,k>& children)
65  : NodeType(children)
66  {}
67 
68  };
69 
70  template<typename... Children>
72  : public TypeTree::CompositeNode<Children...>
73  {
74  typedef TypeTree::CompositeNode<Children...> NodeType;
75  public:
77 
79  template <typename TT>
80  void setTime(TT time){
82  TypeTree::applyToTree(*this,visitor);
83  }
84 
85  template <typename Entity>
86  void bind(const Entity & e){
87  Imp::PowerCompositeBindVisitor<Entity> visitor(e);
88  TypeTree::applyToTree(*this,visitor);
89  }
90 
91  void unbind(){
92  Imp::PowerCompositeUnbindVisitor visitor;
93  TypeTree::applyToTree(*this,visitor);
94  }
95 
98  {}
99 
101  template<typename... Args, typename = typename std::enable_if<(sizeof...(Args) == sizeof...(Children))>::type>
102  CompositeLocalFunction(Args&&... args)
103  : NodeType(std::forward<Args>(args)...)
104  {}
105 
106  };
107 
119  template<class F, class GV,
120  typename std::enable_if<
121  // case (a)
122  models< Dune::Functions::Imp::HasFreeLocalFunction, F>()
123  and
124  not(TypeTree::has_node_tag<typename std::decay<F>::type>::value), int>::type = 0>
125  auto makeLocalFunctionTree(const F& f, const GV & gv)
126  -> Imp::LocalFunctionLeafNodeWrapper< decltype(localFunction(f)) >
127  {
128  return Imp::LocalFunctionLeafNodeWrapper< decltype(localFunction(f)) >(localFunction(f));
129  }
130 
131  template<class F, class GV,
132  // case (b)
133  typename std::enable_if<
134  Dune::Functions::Concept::isCallable<F, typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()
135  and
136  not(models< Dune::Functions::Imp::HasFreeLocalFunction, F>())
137  and
138  not(TypeTree::has_node_tag<typename std::decay<F>::type>::value), int>::type = 0>
139  auto makeLocalFunctionTree(const F& f, const GV & gv)
140  -> decltype(makeLocalFunctionTree(Functions::makeGridViewFunction(f,gv), gv))
141  {
142  return makeLocalFunctionTree(Functions::makeGridViewFunction(f,gv), gv);
143  }
144 
145  template<class F, class GV,
146  typename std::enable_if<
147  // case (c)
148  models< Dune::Functions::Imp::HasFreeLocalFunction, F>()
149  and
150  TypeTree::has_node_tag<typename std::decay<F>::type>::value, int>::type = 0>
151  auto makeLocalFunctionTree(F&& f, const GV & gv)
152  -> decltype(localView(f))
153  {
154  return localView(std::forward(f));
155  }
156 
158 
159  template<typename LeafNode>
160  Dune::TypeTree::GenericLeafNodeTransformation<LeafNode,GridFunctionToLocalViewTransformation, Imp::LocalGridViewFunctionAdapter<LeafNode> >
162 
163  template<typename PowerNode>
164  Dune::TypeTree::SimplePowerNodeTransformation<PowerNode,GridFunctionToLocalViewTransformation,PowerLocalFunction>
166 
167  template<typename CompositeNode>
168  Dune::TypeTree::SimpleCompositeNodeTransformation<CompositeNode,GridFunctionToLocalViewTransformation,CompositeLocalFunction>
170 
171  template<class F, class GV,
172  typename std::enable_if<
173  // case (d)
174  IsGridFunction<F>::value, int>::type = 0>
175  auto makeLocalFunctionTree(const F& f, const GV & gv)
176  -> typename Dune::TypeTree::TransformTree<typename std::decay<F>::type,
177  GridFunctionToLocalViewTransformation>::transformed_type
178  {
179  // call the transformation
180  return Dune::TypeTree::TransformTree<typename std::decay<F>::type,
182  }
183 
184  template<class F, class GV,
185  typename std::enable_if<
186  // case (e)
188  &&
189  std::is_same<TypeTree::NodeTag<F>,TypeTree::LeafNodeTag>::value, int>::type = 0>
191  -> Imp::LocalGridViewFunctionAdapter<F>
192  {
193  // call the transformation
194  return Imp::LocalGridViewFunctionAdapter<F>(static_cast<const F&>(f));
195  }
196 
197 } // end namespace PDELab
198 } // end namespace Dune
199 
200 #endif // DUNE_PDELAB_FUNCTION_LOCALFUNCTION_HH
const P & p
Definition: constraints.hh:148
const Entity & e
Definition: localfunctionspace.hh:121
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
std::integral_constant< bool, impl::IsGridFunction< std::decay_t< T > >::value > IsGridFunction
Definition: typetraits.hh:45
auto makeLocalFunctionTree(const F &f, const GV &gv) -> Imp::LocalFunctionLeafNodeWrapper< decltype(localFunction(f)) >
turn a given function tree into a local function tree
Definition: localfunction.hh:125
Dune::TypeTree::GenericLeafNodeTransformation< LeafNode, GridFunctionToLocalViewTransformation, Imp::LocalGridViewFunctionAdapter< LeafNode > > registerNodeTransformation(LeafNode *l, GridFunctionToLocalViewTransformation *t, GridFunctionTag *tag)
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:190
Definition: function.hh:288
Visitor for Power- and CompositeGridFunctions calling the setTime() method on the leafs of the corres...
Definition: function.hh:346
Definition: function.hh:357
Definition: function.hh:525
Definition: localfunction.hh:20
PowerDifferentiableFunctionLocalViewTag ImplementationTag
Definition: localfunction.hh:23
void unbind()
Definition: localfunction.hh:38
PowerLocalFunction(const std::array< std::shared_ptr< F >, k > &children)
Transformation Constructor, taking the set of new children.
Definition: localfunction.hh:64
PowerLocalFunction()
Default Constructor.
Definition: localfunction.hh:44
void bind(const Entity &e)
Definition: localfunction.hh:33
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: localfunction.hh:27
PowerLocalFunction(F &f)
Construct a PowerGridFunction with k clones of the function t.
Definition: localfunction.hh:48
PowerLocalFunction(C0 &&c0, C1 &&c1, Children &&... children)
Initialize all children with different function objects.
Definition: localfunction.hh:58
Definition: localfunction.hh:73
CompositeLocalFunction()
Default Constructor.
Definition: localfunction.hh:97
CompositeDifferentiableFunctionLocalViewTag ImplementationTag
Definition: localfunction.hh:76
void setTime(TT time)
Set the time in all leaf nodes of this function tree.
Definition: localfunction.hh:80
void unbind()
Definition: localfunction.hh:91
void bind(const Entity &e)
Definition: localfunction.hh:86
CompositeLocalFunction(Args &&... args)
Initialize all children with the passed-in objects.
Definition: localfunction.hh:102
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139