DUNE-ACFEM (unstable)

weakdivergenceloadmodel.hh
1 #ifndef __DUNE_ACFEM_MODELS_MODULES_WEAKDIVERGENCELOADMODEL_HH__
2 #define __DUNE_ACFEM_MODELS_MODULES_WEAKDIVERGENCELOADMODEL_HH__
3 
4 #include <dune/fem/function/localfunction/const.hh>
5 
6 #include "../../expressions/terminal.hh"
7 #include "../../functions/functions.hh"
8 #include "../modelbase.hh"
9 
10 namespace Dune {
11 
12  namespace ACFem::PDEModel {
13 
51  template<class GridFunction>
53  : public ModelBase<typename std::decay_t<GridFunction>::FunctionSpaceType::ScalarFunctionSpaceType>
54  , public Expressions::SelfExpression<WeakDivergenceLoadModel<GridFunction> >
55  , public MPL::UniqueTags<ConditionalType<ExpressionTraits<GridFunction>::isVolatile, VolatileExpression, void>,
56  ConditionalType<IsConstantExprArg<GridFunction>::value, ConstantExpression, void>,
57  ConditionalType<IsTypedValue<GridFunction>::value, TypedValueExpression, void> >
58  {
60  "GridFunction must provide a local function");
61 
64  using GridFunctionDecay = std::decay_t<GridFunction>;
65  using LocalFunctionType = Fem::ConstLocalFunction<GridFunctionDecay>;
66  public:
67  using GridFunctionType = GridFunction;
68 
69  using typename BaseType::RangeType;
70  using typename BaseType::DomainType;
71  using typename BaseType::JacobianRangeType;
72  using BaseType::dimDomain;
73  using BaseType::dimRange;
74 
75  enum {
76  dimWorld = GridFunctionDecay::GridPartType::dimensionworld
77  };
78 
79  static_assert(dimRange == 1 && dimDomain == dimWorld,
80  "This is only meant for dimRange == 1 and dimDomain == dimWorld.");
81 
82  template<class FunctionArg, std::enable_if_t<std::is_constructible<LocalFunctionType, FunctionArg>::value, int> = 0>
83  WeakDivergenceLoadModel(FunctionArg&& function, const std::string& name = "")
84  : localFunction_(std::forward<FunctionArg>(function))
85  , name_(name == "" ? "(div " + localFunction_.gridFunction().name() + ")" : name)
86  {}
87 
88  std::string name() const
89  {
90  return name_;
91  }
92 
93  // Interface methods that need to be reimplemented
94 
96  template<class Entity>
97  void bind(const Entity& entity)
98  {
99  localFunction_.bind(entity);
100  }
101 
103  void unbind()
104  {
105  localFunction_.unbind();
106  }
107 
109  template<class Quadrature>
110  JacobianRangeType flux(const QuadraturePoint<Quadrature> &x) const
111  {
112  const DomainType dataValue = localFunction_.evaluate(x);
113 
114  JacobianRangeType flux = 0;
115  // value * IdentityMatrix
116  for (int i = 0; i < dimRange; ++i) {
117  flux[i] -= dataValue;
118  }
119  return flux;
120  }
121 
125  template<class Quadrature>
127  {
128  const auto divergenceData = localFunction_.jacobian(x);
129 
130  RangeType result = 0;
131  for (int i = 0; i < dimWorld; ++i) {
132  result[0] += divergenceData[i][i];
133  }
134  return result;
135  }
136 
137  protected:
138  LocalFunctionType localFunction_;
139  std::string name_;
140  };
141 
143 
144 
149  template<class GridFunction>
150  constexpr auto weakDivergenceModel(GridFunction&& f, const std::string& name = "")
151  {
153  "GridFunction is not suitable for Fem::ConstLocalFunction");
154 
155  return expressionClosure(WeakDivergenceLoadModel<GridFunction>(std::forward<GridFunction>(f), name));
156  }
157 
158  template<class GridFunction, std::enable_if_t<ExpressionTraits<GridFunction>::isZero, int> = 0>
159  constexpr auto weakDivergenceModel(GridFunction&& f, const std::string& name = "")
160  {
161  using FunctionSpaceType = typename std::decay_t<GridFunction>::FunctionSpaceType::ScalarFunctionSpaceType;
162  return zeroModel(FunctionSpaceType{});
163  }
164 
166 
168 
170 
171  } // namespace ACFem
172 
173 } //Namespace Dune
174 
175 
176 #endif // __DUNE_ACFEM_MODELS_MODULES_WEAKDIVERGENCELOADMODEL_HH__
For a given grid-function define a model implementing the weak divergence.
Definition: weakdivergenceloadmodel.hh:58
constexpr decltype(auto) expressionClosure(T &&t)
Do-nothing default implementation for pathologic cases.
Definition: interface.hh:93
std::is_base_of< Tag, std::decay_t< A > > HasTag
Evaluate to std::true_type if std::decay_t<A> is derived from Tag, otherwise to std::false_type.
Definition: tags.hh:176
auto fluxDivergence(const QuadraturePoint< Quadrature > &x) const
Compute the point-wise value of the flux-part of the operator, meaning the part of the differential o...
Definition: weakdivergenceloadmodel.hh:126
JacobianRangeType flux(const QuadraturePoint< Quadrature > &x) const
Evaluate in local coordinates.
Definition: weakdivergenceloadmodel.hh:110
void bind(const Entity &entity)
Bind to the given entity.
Definition: weakdivergenceloadmodel.hh:97
void unbind()
Unbind from the previously bound entity.
Definition: weakdivergenceloadmodel.hh:103
auto zeroModel(const T &t, const std::string &name, F closure=F{})
Generate a zero model fitting the specified object.
Definition: zeromodel.hh:77
Fem::QuadraturePointWrapper< Quadrature > QuadraturePoint
Shortcut.
Definition: quadraturepoint.hh:23
Terminals may derive from this class to express that they are expressions.
Definition: terminal.hh:25
A structure defining some basic default types and methods.
Definition: modelbase.hh:41
typename FunctionSpaceType::JacobianRangeType JacobianRangeType
The type returned by classifyBoundary().
Definition: modelbase.hh:63
typename FunctionSpaceType::DomainType DomainType
The type returned by classifyBoundary().
Definition: modelbase.hh:61
typename FunctionSpaceType::RangeType RangeType
The type returned by classifyBoundary().
Definition: modelbase.hh:62
static constexpr int dimRange
The type returned by classifyBoundary().
Definition: modelbase.hh:86
static constexpr int dimDomain
The type returned by classifyBoundary().
Definition: modelbase.hh:85
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)