DUNE-ACFEM (unstable)

divergenceloadmodel.hh
1 #ifndef __DUNE_ACFEM_MODELS_MODULES_DIVERGENCELOADMODEL_HH__
2 #define __DUNE_ACFEM_MODELS_MODULES_DIVERGENCELOADMODEL_HH__
3 
4 #include <dune/fem/function/localfunction/const.hh>
5 
6 #include "../../expressions/terminal.hh"
7 #include "../../functions/localfunctiontraits.hh"
8 #include "../modelbase.hh"
9 #include "../expressiontraits.hh"
10 
11 namespace Dune {
12 
13  namespace ACFem::PDEModel {
14 
43  template<class GridFunction>
45  : public ModelBase<typename std::decay_t<GridFunction>::FunctionSpaceType::ScalarFunctionSpaceType>
46  , public Expressions::SelfExpression<DivergenceLoadModel<GridFunction> >
47  , public MPL::UniqueTags<ConditionalType<IsConstantExprArg<GridFunction>::value, ConstantExpression, void>,
48  ConditionalType<IsTypedValue<GridFunction>::value, TypedValueExpression, void> >
49  {
50  public:
51  using GridFunctionType = std::decay_t<GridFunction>;
52  private:
54  "GridFunction must provide a local function");
55 
58  protected:
59  using LocalFunctionType = Fem::ConstLocalFunction<GridFunctionType>;
60  public:
61  using typename BaseType::RangeType;
62  using BaseType::dimDomain;
63  using BaseType::dimRange;
64 
65  static constexpr auto dimWorld = dimDomain;
66 
67  static_assert(GridFunctionType::FunctionSpaceType::dimRange
68  ==
69  GridFunctionType::FunctionSpaceType::dimDomain,
70  "The divergence model is only for dimDomain-valued grid-functions defined");
71 
72  static_assert(dimRange == 1 && dimDomain == dimWorld,
73  "This is meant for dimRange = 1, i.e. velocity divergences and such.");
74 
75  template<class FctArg, std::enable_if_t<std::is_constructible<LocalFunctionType, FctArg>::value, int> = 0>
76  DivergenceLoadModel(FctArg&& function, const std::string& name = "")
77  : localFunction_(std::forward<FctArg>(function))
78  , name_(name == "" ? "(div " + localFunction_.gridFunction().name() + ")" : name)
79  {}
80 
81  std::string name() const
82  {
83  return name_;
84  }
85 
86  // Interface methods that need to be reimplemented
87 
89  template<class Entity>
90  void bind(const Entity& entity)
91  {
92  localFunction_.bind(entity);
93  }
94 
96  void unbind()
97  {
98  localFunction_.unbind();
99  }
100 
102  template<class Quadrature>
103  RangeType source(const QuadraturePoint<Quadrature> &x) const
104  {
105  return trace(localFunction_.jacobian(x));
106  }
107 
108  protected:
109  LocalFunctionType localFunction_;
110  std::string name_;
111  };
112 
114 
115 
124  template<class GridFunction>
125  constexpr auto
126  divergenceLoadModel(GridFunction&& f, const std::string& name = "")
127  {
128  typedef DivergenceLoadModel<GridFunction> ModelType;
129  return expressionClosure(ModelType(std::forward<GridFunction>(f), name));
130  }
131 
132  template<class GridFunction, std::enable_if_t<ExpressionTraits<GridFunction>::isZero, int> = 0>
133  constexpr auto
134  divergenceLoadModel(GridFunction&& f, const std::string& name = "")
135  {
136  using FunctionSpaceType = typename std::decay_t<GridFunction>::FunctionSpaceType::ScalarFunctionSpaceType;
137  return zeroModel(FunctionSpaceType{}, name);
138  }
139 
141 
143 
145 
146  } // namespace ACFem::PDEModel
147 
148  namespace ACFem {
149 
150  using PDEModel::divergenceLoadModel;
151 
152  }
153 
154 } //Namespace Dune
155 
156 
157 #endif // __DUNE_ACFEM_MODELS_MODULES_DIVERGENCELOADMODEL_HH__
For a given grid-function define a model implementing the weak divergence.
Definition: divergenceloadmodel.hh:49
constexpr decltype(auto) expressionClosure(T &&t)
Do-nothing default implementation for pathologic cases.
Definition: interface.hh:93
void bind(const Entity &entity)
Bind to the given entity.
Definition: divergenceloadmodel.hh:90
void unbind()
Unbind from the previously bound entity.
Definition: divergenceloadmodel.hh:96
constexpr auto divergenceLoadModel(GridFunction &&f, const std::string &name="")
Generate a divergence model which only contributes to the load-vector.
Definition: divergenceloadmodel.hh:126
RangeType source(const QuadraturePoint< Quadrature > &x) const
The zero-order term as function of local coordinates.
Definition: divergenceloadmodel.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
constexpr auto trace(T &&t)
Trace is the contraction over all indices with the eye tensor.
Definition: expressions.hh:145
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::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)