DUNE-ACFEM (unstable)

localfunctionjacobianplaceholder.hh
1#ifndef __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONJACOBIANPLACEHOLDER_HH__
2#define __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONJACOBIANPLACEHOLDER_HH__
3
4#include "../policy.hh"
5#include "../localfunctiontraits.hh"
6#include "../../tensors/operations/indeterminate.hh"
7#include "../../tensors/operations/placeholder.hh"
8#include "../../tensors/bindings/dune/fieldtensor.hh"
9
10namespace Dune {
11
12 namespace ACFem {
13
14 namespace GridFunction {
15
16 using namespace Literals;
17 using Tensor::PlaceholderTensor;
18 using Tensor::FieldVectorTensor;
19 using Tensor::ScalarDecayFieldTensor;
20
25 template<class LocalFunction, std::size_t IndeterminateId = Policy::indeterminateId()>
26 class LocalFunctionJacobianPlaceholder
27 : public PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::JacobianRangeType>, LocalFunctionJacobianPlaceholder<LocalFunction, IndeterminateId> >
28 {
29 using ThisType = LocalFunctionJacobianPlaceholder;
30 using BaseType = PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::JacobianRangeType>, ThisType>;
31 public:
32 using LocalFunctionType = std::decay_t<LocalFunction>;
33 using DomainType = typename LocalFunctionType::DomainType;
34 using JacobianRangeType = typename LocalFunctionType::JacobianRangeType;
35 using TensorType = ScalarDecayFieldTensor<JacobianRangeType>;
36 using GridPartType = typename LocalFunctionType::GridPartType;
37 using EntityType = typename LocalFunctionType::EntityType;
38
39 static constexpr std::size_t indeterminateId_ = IndeterminateId;
40
41 using BaseType::operand;
42
43 template<class Arg, std::enable_if_t<std::is_constructible<LocalFunction, Arg>::value, int> = 0>
44 LocalFunctionJacobianPlaceholder(Arg&& localFunction)
45 : BaseType(TensorType(), Expressions::Functor<BaseType>{})
46 , localFunction_(std::forward<Arg>(localFunction))
47 {}
48
49 constexpr unsigned int order() const
50 {
51 return localFunction_.gridFunction().order() - 1;
52 }
53
54 template<class Point,
55 std::enable_if_t<(IsQuadraturePoint<Point>::value || IsFieldVector<Point>::value), int> = 0>
56 void setValue(const Point& point)
57 {
58 assert(localFunction_.entity() != EntityType());
59 if constexpr ((TensorTraits<JacobianRangeType>::rank - TensorTraits<TensorType>::rank) == 1
60 && TensorTraits<JacobianRangeType>::template dim<0>() == 1)
61 operand(0_c) = localFunction_.jacobian(point)[0];
62 else
63 operand(0_c) = localFunction_.jacobian(point);
64 }
65
66 void bind(const EntityType& entity)
67 {
68 localFunction_.bind(entity);
69 }
70
71 void unbind()
72 {
73 localFunction_.unbind();
74 }
75
76 LocalFunction localFunction() &&
77 {
78 return localFunction_;
79 }
80
81 auto& localFunction() &
82 {
83 return localFunction_;
84 }
85
86 const auto& localFunction() const&
87 {
88 return localFunction_;
89 }
90
92 const auto& gridPart() const
93 {
94 return localFunction_.gridFunction().gridPart();
95 }
96
97 static constexpr std::size_t indeterminateId()
98 {
99 return indeterminateId_;
100 }
101
102 std::string name() const
103 {
104 // use gridfunction name
105 return "D"+localFunction_.gridFunction().name() +"(X["+toString(indeterminateId_)+"])";
106 }
107
108 private:
109 LocalFunction localFunction_;
110 };
111
112 template<class T, class SFINAE = void>
113 struct IsLocalFunctionJacobianPlaceholder
114 : FalseType
115 {};
116
117 template<class T>
118 struct IsLocalFunctionJacobianPlaceholder<T, std::enable_if_t<!IsDecay<T>::value> >
119 : IsLocalFunctionJacobianPlaceholder<std::decay_t<T> >
120 {};
121
122 template<class LocalFunction, std::size_t IndeterminateId>
123 struct IsLocalFunctionJacobianPlaceholder<LocalFunctionJacobianPlaceholder<LocalFunction, IndeterminateId> >
124 : TrueType
125 {};
126
127 template<class F,
128 std::size_t IndeterminateId = Policy::indeterminateId(),
129 class Closure = Expressions::Closure,
130 std::enable_if_t<IsConstLocalFunction<F>::value, int> = 0>
131 auto localFunctionJacobianPlaceholder(F&& f, IndexConstant<IndeterminateId> id = IndexConstant<IndeterminateId>{}, Closure closure = Closure{})
132 {
133 return closure(LocalFunctionJacobianPlaceholder<F, IndeterminateId>(std::forward<F>(f)));
134 }
135
136 template<
137 class F,
138 std::size_t IndeterminateId = Policy::indeterminateId(),
139 class Closure = Expressions::Closure,
140 std::enable_if_t<IsWrappableByConstLocalFunction<F>::value, int> = 0>
141 auto localFunctionJacobianPlaceholder(F&& f, IndexConstant<IndeterminateId> id = IndexConstant<IndeterminateId>{})
142 {
143 return localFunctionJacobianPlaceholder(ensureConstLocalFunction(std::forward<F>(f)), id, Closure{});
144 }
145
147
148 } // NS GridFunction
149
150 } // NS ACFem
151
155 template<class LocalFunction, std::size_t IndeterminateId>
156 struct FieldTraits<ACFem::GridFunction::LocalFunctionJacobianPlaceholder<LocalFunction, IndeterminateId> >
157 : FieldTraits<ACFem::GridFunction::PlaceholderTensor<ACFem::Tensor::FieldVectorTensor<typename std::decay_t<LocalFunction>::JacobianRangeType>, ACFem::GridFunction::LocalFunctionJacobianPlaceholder<LocalFunction, IndeterminateId> > >
158 {};
159
160} // NS Dune
161
162#endif // __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONJACOBIANPLACEHOLDER_HH__
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)