dune-functions  2.6-dev
gridfunction.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_GRID_FUNCTION_HH
4 #define DUNE_FUNCTIONS_GRIDFUNCTIONS_GRID_FUNCTION_HH
5 
6 #include <type_traits>
7 
8 #include <dune/common/typeutilities.hh>
9 
17 
18 
19 
20 namespace Dune {
21 namespace Functions {
22 
23 
24 
25 /*
26  * Default implementation is empty
27  * The actual implementation is only given if Signature is an type
28  * describing a function signature as Range(Domain).
29  */
30 template<class Signature, class EntitySet, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
32 {};
33 
34 
35 
36 namespace Imp
37 {
38 
40  template<class S, class ES, template<class> class DerivativeTraits, size_t bufferSize>
41  struct GridFunctionTraits :
42  DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>
43  {
44  protected:
45  using Base=DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>;
46 
47  public:
49  using EntitySet = ES;
50 
52  using Element = typename EntitySet::Element;
53 
55  using DerivativeSignature = typename Base::DerivativeSignature;
56 
59 
61  using LocalSignature = typename Base::Range(typename EntitySet::LocalCoordinate);
62 
63  template<class R>
65 
67  using LocalFunctionTraits = typename Dune::Functions::Imp::LocalFunctionTraits<LocalSignature, Element, LocalDerivativeTraits, bufferSize>;
68 
71 
73  using Concept = GridFunctionWrapperInterface<S, DerivativeInterface, LocalFunctionInterface, ES>;
74 
76  template<class B>
77  using Model = GridFunctionWrapperImplementation<S, DerivativeInterface, LocalFunctionInterface, ES, B>;
78  };
79 }
80 
81 
82 
94 template<class Range, class Domain, class ES, template<class> class DerivativeTraits, size_t bufferSize>
95 class GridFunction<Range(Domain), ES, DerivativeTraits, bufferSize> :
96  public TypeErasureBase<
97  typename Imp::GridFunctionTraits<Range(Domain), ES, DerivativeTraits, bufferSize>::Concept,
98  Imp::GridFunctionTraits<Range(Domain), ES, DerivativeTraits, bufferSize>::template Model>
99 {
100  using Traits = Imp::GridFunctionTraits<Range(Domain), ES, DerivativeTraits, bufferSize>;
101 
103 
104  using DerivativeInterface = typename Traits::DerivativeInterface;
105 
106  using LocalFunctionInterface = typename Traits::LocalFunctionInterface;
107 
108  using EntitySet = typename Traits::EntitySet;
109 
110 public:
111 
123  template<class F, disableCopyMove<GridFunction, F> = 0 >
124  GridFunction(F&& f) :
125  Base(std::forward<F>(f))
126  {
127  static_assert(Dune::Functions::Concept::isGridFunction<F, Range(Domain), EntitySet, DerivativeTraits>(), "Trying to construct a GridFunction from type that does not model the GridFunction concept");
128  }
129 
130  GridFunction() = default;
131 
135  Range operator() (const Domain& x) const
136  {
137  return this->asInterface().operator()(x);
138  }
139 
143  friend DerivativeInterface derivative(const GridFunction& t)
144  {
145  return t.asInterface().derivative();
146  }
147 
157  friend LocalFunctionInterface localFunction(const GridFunction& t)
158  {
159  return t.asInterface().wrappedLocalFunction();
160  }
161 
167  const EntitySet& entitySet() const
168  {
169  return this->asInterface().wrappedEntitySet();
170  }
171 };
172 
173 
174 
175 }} // namespace Dune::Functions
176 
177 
178 
179 #endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_GRID_FUNCTION_HH
Dune::Functions::GridFunction
Definition: gridfunction.hh:31
Dune
Definition: polynomial.hh:7
Dune::Functions::GridFunction< Range(Domain), ES, DerivativeTraits, bufferSize >::derivative
friend DerivativeInterface derivative(const GridFunction &t)
Definition: gridfunction.hh:143
gridfunction_imp.hh
Dune::Functions::GridFunction< Range(Domain), ES, DerivativeTraits, bufferSize >::entitySet
const EntitySet & entitySet() const
Get associated EntitySet.
Definition: gridfunction.hh:167
defaultderivativetraits.hh
Dune::Functions::GridFunction< Range(Domain), ES, DerivativeTraits, bufferSize >::localFunction
friend LocalFunctionInterface localFunction(const GridFunction &t)
Get local function of wrapped function.
Definition: gridfunction.hh:157
Dune::Functions::TypeErasureBase
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:164
localderivativetraits.hh
differentiablefunction.hh
Dune::Functions::Concept::isGridFunction
static constexpr bool isGridFunction()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:228
Dune::Functions::GridFunction< Range(Domain), ES, DerivativeTraits, bufferSize >::GridFunction
GridFunction(F &&f)
Construct from function.
Definition: gridfunction.hh:124
localfunction.hh
Dune::Functions::LocalFunction
Definition: localfunction.hh:29
functionconcepts.hh
typeerasure.hh
Dune::Functions::LocalDerivativeTraits
Derivative traits for local functions.
Definition: localderivativetraits.hh:27