DUNE-ACFEM (2.5.1)

gradientmodel.hh
1#ifndef __DUNE_ACFEM_MODELS_MODULES_GRADIENTMODEL_HH__
2#define __DUNE_ACFEM_MODELS_MODULES_GRADIENTMODEL_HH__
3
4#include "../operatorparts/modeladapter.hh"
5
6namespace Dune {
7
8 namespace ACFem {
9
47 template<class GridFunction>
49 : public OperatorPartsExpression<GradientOperatorParts<GridFunction> >
50 {
55 typedef typename GridFunction::LocalFunctionType LocalFunctionType;
56 public:
57 typedef GridFunction GradientFunctionType;
58 typedef typename GradientFunctionType::DiscreteFunctionSpaceType::FunctionSpaceType GradientFunctionSpaceType;
59 typedef typename TraitsType::FunctionSpaceType FunctionSpaceType;
60
61 typedef typename FunctionSpaceType::DomainType DomainType;
62 typedef typename FunctionSpaceType::RangeType RangeType;
63 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
64 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
65
66 enum {
67 dimDomain = FunctionSpaceType::dimDomain,
68 dimRange = FunctionSpaceType::dimRange,
69 dimWorld = dimDomain, // GridPartType::dimensionworld
70 };
71
72 static_assert(dimDomain == dimRange && dimDomain == dimWorld,
73 "This is meant for dimDomain == dimRange, i.e. pressure gradients and such.");
74
75 GradientOperatorParts(const Fem::Function<GradientFunctionSpaceType, GradientFunctionType>& function,
76 const std::string& name = "")
77 : function_(function),
78 localFunction_(function_()),
79 name_(name == "" ? "(grad " + function_().name() + ")" : name)
80 {}
81
82 std::string name() const
83 {
84 return name_;
85 }
86
87 // Interface methods that need to be reimplemented
88
89 template<class Entity>
90 void setEntity(const Entity& entity) const
91 {
92 localFunction_.init(entity);
93 }
94
96 template<class Entity, class Point>
97 void flux(const Entity& entity,
98 const Point &x,
99 const RangeType& value,
100 const JacobianRangeType& jacobian,
101 JacobianRangeType& flux) const
102 {
103 typename GradientFunctionType::RangeType scalarValue;
104 localFunction_.evaluate(x, scalarValue);
105
106 flux = 0.;
107
108 // value * IdentityMatrix
109 for (int i = 0; i < FunctionSpaceType::dimDomain; ++i) {
110 flux[i][i] -= scalarValue;
111 }
112 }
113
115 template<class Entity, class Point>
116 void linearizedFlux (const RangeType& uBar,
117 const JacobianRangeType& DuBar,
118 const Entity& entity,
119 const Point &x,
120 const RangeType& value,
121 const JacobianRangeType& jacobian,
122 JacobianRangeType& flux) const
123 {
124 flux = 0.;
125 }
126
130 template<class Entity, class Point>
131 void fluxDivergence(const Entity& entity,
132 const Point &x,
133 const RangeType& value,
134 const JacobianRangeType& jacobian,
135 const HessianRangeType& hessian,
136 RangeType& result) const
137 {
138 typename GradientFunctionType::JacobianRangeType gradient;
139 localFunction_.jacobian(x, gradient);
140
141 result = gradient[0];
142 }
143
144 protected:
146 mutable LocalFunctionType localFunction_;
147 const std::string name_;
148 };
149
150 template<class GridFunction>
151 struct OperatorPartsTraits<GradientOperatorParts<GridFunction> >
152 : public DefaultOperatorPartsTraits<typename Fem::ToNewDimRangeFunctionSpace<typename GridFunction::FunctionSpaceType,
153 GridFunction::FunctionSpaceType::dimDomain>::Type>
154 {
155 //Only for scalar GridFunction classes
156 static_assert(GridFunction::DiscreteFunctionSpaceType::FunctionSpaceType::dimRange == 1,
157 "The gradient model is only for scalar grid-functions defined");
158
161 {
162 isLinear = true, // it is even constant
163 isSymmetric = true, // it is even constant
164 isSemiDefinite = true // it is even constant
165 };
166
169 hasFlux = true, // tested by gradient of test functions
170 hasSources = false, // none, after integration by parts
171 hasRobinFlux = false,
172 };
173 };
174
176
177
186 template<class GridFunction>
187 static inline
188 GradientOperatorParts<GridFunction>
189 gradientOperatorParts(const Fem::Function<typename GridFunction::FunctionSpaceType, GridFunction>& f,
190 const std::string& name = "")
191 {
193 }
194
195 template<class GridFunction>
196 static inline
197 OperatorPartsAdapterModel<GradientOperatorParts<GridFunction>,
198 typename GridFunction::GridPartType>
199 gradientModel(const Fem::Function<typename GridFunction::FunctionSpaceType, GridFunction>& f,
200 const std::string& name = "")
201 {
202 typedef GradientOperatorParts<GridFunction> OperatorPartsType;
203 typedef typename GridFunction::GridPartType GridPartType;
204 return OperatorPartsAdapterModel<OperatorPartsType, GridPartType>(OperatorPartsType(f, name));
205 }
206
208
210
212
213 } // namespace ACFem
214
215} //Namespace Dune
216
217
218#endif // __DUNE_ACFEM_MODELS_MODULES_GRADIENTMODEL_HH__
Default model implementation.
Definition: operatorparts.hh:387
For a given grid-function define a model implementing the weak gradient.
Definition: gradientmodel.hh:50
Interface class for second order elliptic models.
Definition: operatorparts.hh:92
LocalFunctionWrapper< LocalGradientAdapter< GridFunction >, typename GridFunction::GridPartType > gradient(const Fem::Function< typename GridFunction::FunctionSpaceType, GridFunction > &f_, const std::string &name="")
Take the gradient of a given function.
Definition: basicfunctions.hh:145
void fluxDivergence(const Entity &entity, const Point &x, const RangeType &value, const JacobianRangeType &jacobian, const HessianRangeType &hessian, RangeType &result) const
Compute the point-wise value of the flux-part of the operator, meaning the part of the differential o...
Definition: gradientmodel.hh:131
void linearizedFlux(const RangeType &uBar, const JacobianRangeType &DuBar, const Entity &entity, const Point &x, const RangeType &value, const JacobianRangeType &jacobian, JacobianRangeType &flux) const
Evaluate the linearized flux in local coordinates.
Definition: gradientmodel.hh:116
StructureFlags
Static flags for the overall structure of the operator.
Definition: gradientmodel.hh:161
void flux(const Entity &entity, const Point &x, const RangeType &value, const JacobianRangeType &jacobian, JacobianRangeType &flux) const
Evaluate in local coordinates.
Definition: gradientmodel.hh:97
static GradientOperatorParts< GridFunction > gradientOperatorParts(const Fem::Function< typename GridFunction::FunctionSpaceType, GridFunction > &f, const std::string &name="")
Generate a Gradient-model fitting the specified object.
Definition: gradientmodel.hh:189
ConstituentFlags
Provide information about the constituents of the model.
Definition: gradientmodel.hh:168
Traits-template which has to be specialized for each individual model.
Definition: operatorparts.hh:36
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)