AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
ConstantGridFunction.hpp
1 #pragma once
2 
3 #include <functional>
4 #include <type_traits>
5 
6 #include <dune/common/diagonalmatrix.hh>
7 #include <dune/common/fmatrix.hh>
8 #include <dune/common/fvector.hh>
9 
10 #include <amdis/common/DerivativeTraits.hpp>
11 #include <amdis/common/TypeTraits.hpp>
12 #include <amdis/gridfunctions/AnalyticGridFunction.hpp>
13 #include <amdis/gridfunctions/GridFunction.hpp>
14 
15 namespace AMDiS
16 {
17 #ifndef DOXYGEN
18  template <class Signature, class LocalContext, class Function>
20 #endif
21 
23  template <class R, class D, class LC, class T>
24  class ConstantLocalFunction<R(D), LC, T>
25  {
26  public:
28  using Domain = D;
29 
31  using Range = R;
32 
34  enum { hasDerivative = true };
35 
36  private:
37  using Geometry = typename LC::Geometry;
38 
39  public:
41  ConstantLocalFunction(T const& value)
42  : value_(value)
43  {}
44 
45  void bind(LC const& /*element*/) { /* do nothing */ }
46  void unbind() { /* do nothing */ }
47 
49  Range const& operator()(Domain const& /*local*/) const
50  {
51  return value_;
52  }
53 
56  template <class Type>
57  auto makeDerivative(Type const& /*type*/) const
58  {
59  using RawSignature = typename Dune::Functions::SignatureTraits<R(D)>::RawSignature;
60  using DerivativeRange = typename DerivativeTraits<RawSignature,Type>::Range;
61  DerivativeRange diff(0);
63  }
64 
66  int order() const
67  {
68  return 0;
69  }
70 
71  private:
72  T value_;
73  };
74 
75 
77 
85  template <class T, class GridView>
87  {
88  public:
89  using EntitySet = Dune::Functions::GridViewEntitySet<GridView, 0>;
90  using Domain = typename EntitySet::GlobalCoordinate;
91  using Range = Underlying_t<T>;
92 
93  enum { hasDerivative = false };
94 
95  private:
96  using Element = typename EntitySet::Element;
97  using LocalDomain = typename EntitySet::LocalCoordinate;
99 
100  public:
102  ConstantGridFunction(T const& value, GridView const& gridView)
103  : value_(value)
104  , entitySet_(gridView)
105  {}
106 
108  Range const& operator()(Domain const& /*x*/) const
109  {
110  return value_;
111  }
112 
113  EntitySet const& entitySet() const
114  {
115  return entitySet_;
116  }
117 
120  {
121  return {value_};
122  }
123 
124  private:
125  T value_;
126  EntitySet entitySet_;
127  };
128 
129 
130  namespace Concepts
131  {
136  namespace Definition
137  {
138  template <class T>
140  : std::is_arithmetic<T> {};
141 
142  template <class T>
143  struct ConstantToGridFunction<std::reference_wrapper<T>>
144  : ConstantToGridFunction<T> {};
145 
146  template <class T, int N>
147  struct ConstantToGridFunction<Dune::FieldVector<T, N>>
148  : ConstantToGridFunction<T> {};
149 
150  template <class T, int N, int M>
151  struct ConstantToGridFunction<Dune::FieldMatrix<T, N, M>>
152  : ConstantToGridFunction<T> {};
153 
154  template <class T, int N>
155  struct ConstantToGridFunction<Dune::DiagonalMatrix<T, N>>
156  : ConstantToGridFunction<T> {};
157 
158  } // end namespace Definition
159 
160 
164  template <class T>
165  constexpr bool ConstantToGridFunction =
167 
170  } // end namespace Concepts
171 
172 
173  template <class Value>
174  struct GridFunctionCreator<Value, std::enable_if_t<Concepts::ConstantToGridFunction<Value>>>
175  {
176  template <class GridView>
177  static auto create(Value const& value, GridView const& gridView)
178  {
179  return ConstantGridFunction<Value,GridView>{value, gridView};
180  }
181  };
182 
183 } // end namespace AMDiS
Range const & operator()(Domain const &) const
Return the constant value_
Definition: ConstantGridFunction.hpp:108
Definition: GridFunction.hpp:96
Definition: ConstantGridFunction.hpp:19
Definition: FieldMatVec.hpp:12
ConstantGridFunction(T const &value, GridView const &gridView)
Constructor. Stores the function fct and creates an EntitySet.
Definition: ConstantGridFunction.hpp:102
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Gridfunction returning a constant value.
Definition: ConstantGridFunction.hpp:86
Range const & operator()(Domain const &) const
Return the constant value_.
Definition: ConstantGridFunction.hpp:49
constexpr bool ConstantToGridFunction
Concepts that is true for all &#39;&#39;simple&#39;&#39; types that can be converted automatically to a GridFunction...
Definition: ConstantGridFunction.hpp:165
ConstantLocalFunction(T const &value)
Constructor. Stores the constant value.
Definition: ConstantGridFunction.hpp:41
auto makeDerivative(Type const &) const
Create a ConstantLocalFunction representing the derivative of a constant function, that ist, the value 0.
Definition: ConstantGridFunction.hpp:57
D Domain
The LocalDomain this LocalFunction can be evaluated in.
Definition: ConstantGridFunction.hpp:28
LocalFunction makeLocalFunction() const
Create an ConstantLocalFunction with the stores value_.
Definition: ConstantGridFunction.hpp:119
Definition: DerivativeTraits.hpp:29
R Range
The range type of the LocalFunction.
Definition: ConstantGridFunction.hpp:31
Definition: ConstantGridFunction.hpp:139
int order() const
Return the constant polynomial order 0.
Definition: ConstantGridFunction.hpp:66