DUNE-ACFEM (unstable)

localfunctionplaceholder.hh
1#ifndef __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONPLACEHOLDER_HH__
2#define __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONPLACEHOLDER_HH__
3
4#include <dune/fem/function/localfunction/const.hh>
5
6#include "../policy.hh"
7#include "../localfunctiontraits.hh"
8#include "../../tensors/operations/placeholder.hh"
9#include "../../tensors/bindings/dune/fieldtensor.hh"
10
11namespace Dune {
12
13 namespace ACFem {
14
15 namespace GridFunction {
16
17 using namespace Literals;
18 using Tensor::PlaceholderTensor;
19 using Tensor::FieldVectorTensor;
20 using Tensor::ScalarDecayFieldTensor;
21
36 template<class LocalFunction, std::size_t IndeterminateId = Policy::indeterminateId()>
38 : public PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::RangeType>, LocalFunctionPlaceholder<LocalFunction, IndeterminateId> >
39 {
41 using BaseType = PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::RangeType>, ThisType>;
42 public:
43 using LocalFunctionType = std::decay_t<LocalFunction>;
44 using GridFunctionType = typename LocalFunctionType::GridFunctionType;
45 using RangeType = typename LocalFunctionType::RangeType;
46 using DomainType = typename LocalFunctionType::DomainType;
47 using TensorType = ScalarDecayFieldTensor<RangeType>;
48 using GridPartType = typename LocalFunctionType::GridPartType;
49 using EntityType = typename LocalFunctionType::EntityType;
50
52 "LocalFunction placeholders cannot be built from const qualified local functions");
53
54 static constexpr std::size_t indeterminateId_ = IndeterminateId;
55
56 using BaseType::operand;
57
58 template<class Arg, std::enable_if_t<std::is_constructible<LocalFunctionType, Arg>::value, int> = 0>
60 : BaseType(TensorType(), Expressions::Functor<BaseType>{})
61 , localFunction_(std::forward<Arg>(localFunction))
62 {}
63
64 constexpr unsigned int order() const
65 {
66 return localFunction_.gridFunction().order();
67 }
68
76 template<class Point,
77 std::enable_if_t<(IsQuadraturePoint<Point>::value || IsFieldVector<Point>::value), int> = 0>
78 void setValue(const Point& point)
79 {
80 assert(localFunction_.entity() != EntityType());
81 operand(0_c) = localFunction_.evaluate(point);
82 }
83
88 void bind(const EntityType& entity)
89 {
90 localFunction_.bind(entity);
91 }
92
96 void unbind()
97 {
98 localFunction_.unbind();
99 }
100
104 LocalFunction localFunction() &&
105 {
106 return localFunction_;
107 }
108
111 {
112 return localFunction_;
113 }
114
116 const auto& localFunction() const&
117 {
118 return localFunction_;
119 }
120
122 const auto& gridFunction() const
123 {
124 return localFunction_.gridFunction();
125 }
126
128 const auto& gridPart() const
129 {
130 return localFunction_.gridFunction().gridPart();
131 }
132
136 static constexpr auto indeterminateId()
137 {
139 }
140
141 std::string name() const
142 {
143 // use gridFunction name
144 return localFunction_.gridFunction().name() + "(X["+toString(indeterminateId_)+"])";
145 }
146
147 private:
148 LocalFunction localFunction_;
149 };
150
155 template<class T>
157 : FalseType
158 {};
159
160 template<class T>
163 {};
164
165 template<class T>
168 {};
169
170 template<class LocalFunction>
171 struct IsLocalFunctionPlaceholder<LocalFunctionPlaceholder<LocalFunction> >
172 : TrueType
173 {};
174
190 template<class F, std::size_t IndeterminateId = Policy::indeterminateId(), class Closure = Expressions::Closure,
191 std::enable_if_t<IsConstLocalFunction<F>::value, int> = 0>
193 {
194 static_assert(!RefersConst<F>::value, "F must not be const.");
195
196 return closure(LocalFunctionPlaceholder<F, IndeterminateId>(std::forward<F>(f)));
197 }
198
200 template<class F, std::size_t IndeterminateId = Policy::indeterminateId(), class Closure = Expressions::Closure,
201 std::enable_if_t<IsWrappableByConstLocalFunction<F>::value, int> = 0>
202 auto localFunctionPlaceholder(F&& f, IndexConstant<IndeterminateId> id = IndexConstant<IndeterminateId>{}, Closure closure = Closure{})
203 {
204 return localFunctionPlaceholder(ensureConstLocalFunction(std::forward<F>(f)), id, Closure{});
205 }
206
208
209 } // NS GridFunction
210
211 using GridFunction::IsLocalFunctionPlaceholder;
213
214 } // NS ACFem
215
219 template<class LocalFunction, std::size_t IndeterminateId>
220 struct FieldTraits<ACFem::GridFunction::LocalFunctionPlaceholder<LocalFunction, IndeterminateId> >
221 : FieldTraits<ACFem::GridFunction::PlaceholderTensor<ACFem::GridFunction::FieldVectorTensor<typename std::decay_t<LocalFunction>::RangeType>, ACFem::GridFunction::LocalFunctionPlaceholder<LocalFunction, IndeterminateId> > >
222 {};
223
224} // NS Dune
225
226#endif // __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONPLACEHOLDER_HH__
A placeholder tensor which wraps a Dune::Fem LocalFunction.
Definition: localfunctionplaceholder.hh:39
const auto & gridFunction() const
Return the wrapped grid-function.
Definition: localfunctionplaceholder.hh:122
const auto & gridPart() const
Return the gridPart of the wrapped function.
Definition: localfunctionplaceholder.hh:128
LocalFunction localFunction() &&
Return the wrapped LocalFunction while maintaining its reference and const qualification.
Definition: localfunctionplaceholder.hh:104
const auto & localFunction() const &
Return the wrapped LocalFunction as a const reference.
Definition: localfunctionplaceholder.hh:116
void setValue(const Point &point)
Trigger the update of the stored values by evaluating the wrapped localfunction.
Definition: localfunctionplaceholder.hh:78
void unbind()
Unbind the wrapped LocalFunction from any Entity it is bound to.
Definition: localfunctionplaceholder.hh:96
void bind(const EntityType &entity)
Bind the wrapped LocalFunction to the given entity.
Definition: localfunctionplaceholder.hh:88
static constexpr auto indeterminateId()
Return the id of the indeterminate the placeholder is assumed to depend on.
Definition: localfunctionplaceholder.hh:136
auto & localFunction() &
Return the wrapped LocalFunction as a mutable reference.
Definition: localfunctionplaceholder.hh:110
auto localFunctionPlaceholder(F &&f, IndexConstant< IndeterminateId > id=IndexConstant< IndeterminateId >{}, Closure closure=Closure{})
Generate a LocalFunctionPlaceholder for a Fem::ConstLocalFunction.
Definition: localfunctionplaceholder.hh:192
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
BoolConstant<(std::is_const< T >::value||std::is_const< std::remove_reference_t< T > >::value)> RefersConst
TrueType if const or a reference to a const.
Definition: types.hh:133
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
std::true_type if T is a LocalFunctionPlaceholder.
Definition: localfunctionplaceholder.hh:158
Definition: quadraturepoint.hh:29
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)