DUNE PDELab (git)

localfunction.hh
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
8#include <dune/pdelab/function/tags.hh>
9#include <dune/pdelab/function/localfunctionhelper.hh>
10#include <dune/pdelab/function/oldinterfaceadapter.hh>
11#include <dune/functions/common/signature.hh>
12#include <dune/functions/gridfunctions/gridviewfunction.hh>
13
14namespace Dune {
15namespace PDELab {
16
17 template<class F, std::size_t k>
18 class PowerLocalFunction
19 : public TypeTree::PowerNode<F,k>
20 {
21 typedef TypeTree::PowerNode<F,k> NodeType;
22 public:
23 typedef PowerDifferentiableFunctionLocalViewTag ImplementationTag;
24
26 template <typename TT>
27 void setTime(TT time){
28 PowerCompositeSetTimeVisitor<TT> visitor(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
44 PowerLocalFunction()
45 {}
46
48 PowerLocalFunction (F& f)
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>
71 class CompositeLocalFunction
72 : public TypeTree::CompositeNode<Children...>
73 {
74 typedef TypeTree::CompositeNode<Children...> NodeType;
75 public:
76 typedef CompositeDifferentiableFunctionLocalViewTag ImplementationTag;
77
79 template <typename TT>
80 void setTime(TT time){
81 PowerCompositeSetTimeVisitor<TT> visitor(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
97 CompositeLocalFunction()
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
157 struct GridFunctionToLocalViewTransformation {};
158
159 template<typename LeafNode>
160 Dune::TypeTree::GenericLeafNodeTransformation<LeafNode,GridFunctionToLocalViewTransformation, Imp::LocalGridViewFunctionAdapter<LeafNode> >
161 registerNodeTransformation(LeafNode* l, GridFunctionToLocalViewTransformation* t, GridFunctionTag* tag);
162
163 template<typename PowerNode>
164 Dune::TypeTree::SimplePowerNodeTransformation<PowerNode,GridFunctionToLocalViewTransformation,PowerLocalFunction>
165 registerNodeTransformation(PowerNode* p, GridFunctionToLocalViewTransformation* t, PowerGridFunctionTag* tag);
166
167 template<typename CompositeNode>
168 Dune::TypeTree::SimpleCompositeNodeTransformation<CompositeNode,GridFunctionToLocalViewTransformation,CompositeLocalFunction>
169 registerNodeTransformation(CompositeNode* c, GridFunctionToLocalViewTransformation* t, CompositeGridFunctionTag* tag);
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)
177 GridFunctionToLocalViewTransformation>::transformed_type
178 {
179 // call the transformation
181 GridFunctionToLocalViewTransformation>::transform(f);
182 }
183
184 template<class F, class GV,
185 typename std::enable_if<
186 // case (e)
187 not(IsGridFunction<F>::value)
188 &&
189 std::is_same<TypeTree::NodeTag<F>,TypeTree::LeafNodeTag>::value, int>::type = 0>
190 auto makeLocalFunctionTree(const GridFunctionInterface<typename F::Traits,F>& f, const GV & gv)
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
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition: nodeinterface.hh:74
void registerNodeTransformation(SourceNode *, Transformation *, Tag *)
Register transformation descriptor to transform SourceNode with Transformation.
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:239
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Transform a TypeTree.
Definition: transformation.hh:96
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)