DUNE-ACFEM (unstable)

gradientloadmodel.hh
1 #ifndef __DUNE_ACFEM_MODELS_MODULES_GRADIENTLOADMODEL_HH__
2 #define __DUNE_ACFEM_MODELS_MODULES_GRADIENTLOADMODEL_HH__
3 
4 #include <dune/fem/function/localfunction/const.hh>
5 
6 #include "../modelbase.hh"
7 #include "../expressiontraits.hh"
8 
9 namespace Dune {
10 
11  namespace ACFem::PDEModel {
12 
50  template<class GridFunction>
52  : public ModelBase<typename Fem::ToNewDimRangeFunctionSpace<typename std::decay_t<GridFunction>::FunctionSpaceType,
53  std::decay_t<GridFunction>::FunctionSpaceType::dimDomain>::Type>
54  , public Expressions::SelfExpression<GradientLoadModel<GridFunction> >
55  , public MPL::UniqueTags<ConditionalType<IsConstantExprArg<GridFunction>::value, ConstantExpression, void>,
56  ConditionalType<IsTypedValue<GridFunction>::value, TypedValueExpression, void> >
57  {
59  "GridFunction must provide a local function");
60 
63  std::decay_t<GridFunction>::FunctionSpaceType::dimDomain>::Type>;
64  protected:
65  using LocalFunctionType = Fem::ConstLocalFunction<std::decay_t<GridFunction> >;
66  public:
67  using GridFunctionType = GridFunction;
68  using typename BaseType::DomainType;
69  using typename BaseType::RangeRangeType;
70  using typename BaseType::RangeJacobianRangeType;
71 
72  using BaseType::dimDomain;
73  using BaseType::dimRange;
74 
75  enum {
76  dimWorld = dimDomain
77  };
78 
79  static_assert(dimDomain == dimRange && dimDomain == dimWorld,
80  "This is meant for dimDomain == dimRange, i.e. pressure gradients and such.");
81  static_assert(std::decay_t<GridFunction>::FunctionSpaceType::dimRange == 1,
82  "This is only meant for real gradients (not Jacobians), i.e. dimRange of function == 1");
83 
84  template<class FunctionArg, std::enable_if_t<std::is_constructible<LocalFunctionType, FunctionArg>::value, int> = 0>
85  GradientLoadModel(FunctionArg&& function, const std::string& name = "")
86  : localFunction_(function)
87  , name_(name == "" ? "(grad " + localFunction_.gridFunction().name() + ")" : name)
88  {}
89 
90  std::string name() const
91  {
92  return name_;
93  }
94 
95  // Interface methods that need to be reimplemented
96 
98  template<class Entity>
99  void bind(const Entity& entity)
100  {
101  localFunction_.bind(entity);
102  }
103 
105  void unbind()
106  {
107  localFunction_.unbind();
108  }
109 
111  template<class Quadrature>
112  auto flux(const QuadraturePoint<Quadrature> &x) const
113  {
114  auto scalarValue = localFunction_.evaluate(x);
115 
116  RangeJacobianRangeType flux(0);
117 
118  // value * IdentityMatrix
119  for (int i = 0; i < dimDomain; ++i) {
120  flux[i][i] -= scalarValue;
121  }
122  return flux;
123  }
124 
126  template<class Quadrature>
128  {
129  return localFunction_.jacobian(x)[0];
130  }
131 
132  template<class Quadrature>
133  auto robinFlux(const QuadraturePoint<Quadrature> &x,
134  const DomainType& unitOuterNormal) const
135  {
136  return RangeRangeType(unitOuterNormal) *= localFunction_.evaluate(x);
137  }
138 
140  template<class Intersection>
141  auto classifyBoundary(const Intersection& intersection) const
142  {
143  // true is correct as higher-level code has to take care of
144  // the Dirichlet-(non-Dirichlet) splitting of the boundary.
145  return std::make_pair(true, std::bitset<dimRange>());
146  }
147 
148  protected:
149  LocalFunctionType localFunction_;
150  std::string name_;
151  };
152 
154 
155 
165  template<class GridFunction>
166  constexpr auto
167  gradientLoadModel(GridFunction&& f, const std::string& name = "")
168  {
169  return expressionClosure(GradientLoadModel<GridFunction>(std::forward<GridFunction>(f), name));
170  }
171 
172  template<class GridFunction, std::enable_if_t<ExpressionTraits<GridFunction>::isZero, int> = 0>
173  constexpr auto
174  gradientLoadModel(GridFunction&& f, const std::string& name = "")
175  {
176  using FunctionSpace =
177  typename Fem::ToNewDimRangeFunctionSpace<typename std::decay_t<GridFunction>::FunctionSpaceType,
178  std::decay_t<GridFunction>::FunctionSpaceType::dimDomain>::Type;
179 
180  return zeroModel(FunctionSpace{}, name);
181  }
182 
184 
186 
188 
189  } // namespace ACFem::PDEModel
190 
191  namespace ACFem {
192 
193  using PDEModel::gradientLoadModel;
194 
195  }
196 
197 } //Namespace Dune
198 
199 #endif // __DUNE_ACFEM_MODELS_MODULES_GRADIENTLOADMODEL_HH__
For a given grid-function define a model implementing the weak gradient.
Definition: gradientloadmodel.hh:57
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 classifyBoundary(const Intersection &intersection) const
Bind to the given intersection and classify the components w.r.t.
Definition: gradientloadmodel.hh:141
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: gradientloadmodel.hh:127
auto flux(const QuadraturePoint< Quadrature > &x) const
Evaluate in local coordinates.
Definition: gradientloadmodel.hh:112
void bind(const Entity &entity)
Bind to the given entity.
Definition: gradientloadmodel.hh:99
void unbind()
Unbind from the previously bound entity.
Definition: gradientloadmodel.hh:105
auto zeroModel(const T &t, const std::string &name, F closure=F{})
Generate a zero model fitting the specified object.
Definition: zeromodel.hh:77
constexpr auto gradientLoadModel(GridFunction &&f, const std::string &name="")
Generate a Gradient-model as contribution to the load vector from the given grid-function.
Definition: gradientloadmodel.hh:167
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 RangeFunctionSpaceType::RangeType RangeRangeType
The type returned by classifyBoundary().
Definition: modelbase.hh:77
typename FunctionSpaceType::DomainType DomainType
The type returned by classifyBoundary().
Definition: modelbase.hh:61
static constexpr int dimRange
The type returned by classifyBoundary().
Definition: modelbase.hh:86
typename RangeFunctionSpaceType::JacobianRangeType RangeJacobianRangeType
The type returned by classifyBoundary().
Definition: modelbase.hh:79
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)