DUNE-ACFEM (unstable)

localfunctionhessianplaceholder.hh
1#ifndef __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONHESSIANPLACEHOLDER_HH__
2#define __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONHESSIANPLACEHOLDER_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 LocalFunctionHessianPlaceholder
27 : public PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::HessianRangeType>, LocalFunctionHessianPlaceholder<LocalFunction, IndeterminateId> >
28 {
29 using ThisType = LocalFunctionHessianPlaceholder;
30 using BaseType = PlaceholderTensor<ScalarDecayFieldTensor<typename std::decay_t<LocalFunction>::HessianRangeType>, ThisType>;
31 public:
32 using LocalFunctionType = std::decay_t<LocalFunction>;
33 using DomainType = typename LocalFunctionType::DomainType;
34 using HessianRangeType = typename LocalFunctionType::HessianRangeType;
35 using TensorType = ScalarDecayFieldTensor<HessianRangeType>;
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 LocalFunctionHessianPlaceholder(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() - 2;
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<HessianRangeType>::rank - TensorTraits<TensorType>::rank) == 1
60 && TensorTraits<HessianRangeType>::template dim<0>() == 1)
61 operand(0_c) = localFunction_.hessian(point)[0];
62 else
63 operand(0_c) = localFunction_.hessian(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 "D2"+localFunction_.gridFunction().name() + "(X["+toString(indeterminateId_)+"])";
106 }
107
108 private:
109 LocalFunction localFunction_;
110 };
111
112 template<class T, class SFINAE = void>
113 struct IsLocalFunctionHessianPlaceholder
114 : FalseType
115 {};
116
117 template<class T>
118 struct IsLocalFunctionHessianPlaceholder<T, std::enable_if_t<!IsDecay<T>::value> >
119 : IsLocalFunctionHessianPlaceholder<std::decay_t<T> >
120 {};
121
122 template<class LocalFunction, std::size_t IndeterminateId>
123 struct IsLocalFunctionHessianPlaceholder<LocalFunctionHessianPlaceholder<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 localFunctionHessianPlaceholder(F&& f, IndexConstant<IndeterminateId> id = IndexConstant<IndeterminateId>{}, Closure closure = Closure{})
132 {
133 return closure(LocalFunctionHessianPlaceholder<F, IndeterminateId>(std::forward<F>(f)));
134 }
135
136 template<class F,
137 std::size_t IndeterminateId = Policy::indeterminateId(),
138 class Closure = Expressions::Closure,
139 std::enable_if_t<IsWrappableByConstLocalFunction<F>::value, int> = 0>
140 auto localFunctionHessianPlaceholder(F&& f, IndexConstant<IndeterminateId> id = IndexConstant<IndeterminateId>{}, Closure = Closure{})
141 {
142 return localFunctionHessianPlaceholder(ensureConstLocalFunction(std::forward<F>(f)), id, Closure{});
143 }
144
146
147 } // NS GridFunction
148
149 } // NS ACFem
150
154 template<class LocalFunction, std::size_t IndeterminateId>
155 struct FieldTraits<ACFem::GridFunction::LocalFunctionHessianPlaceholder<LocalFunction, IndeterminateId> >
156 : FieldTraits<ACFem::GridFunction::PlaceholderTensor<ACFem::Tensor::FieldVectorTensor<typename std::decay_t<LocalFunction>::HessianRangeType>, ACFem::GridFunction::LocalFunctionHessianPlaceholder<LocalFunction, IndeterminateId> > >
157 {};
158
159} // NS Dune
160
161#endif // __DUNE_ACFEM_FUNCTIONS_PLACEHOLDERS_LOCALFUNCTIONHESSIANPLACEHOLDER_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 (Mar 12, 23:28, 2025)