DerivativeGridFunction.hpp 1.71 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <type_traits>

#include <dune/functions/common/defaultderivativetraits.hh>

Praetorius, Simon's avatar
Praetorius, Simon committed
7
8
#include <dune/amdis/gridfunctions/GridFunctionConcepts.hpp>

9
10
11
namespace AMDiS
{
  /**
Praetorius, Simon's avatar
Praetorius, Simon committed
12
    * \addtogroup GridFunctions
13
14
15
16
17
18
19
20
21
22
23
24
25
    * @{
    **/

  /// \brief A Gridfunction that returns the derivative when calling localFunction
  template <class GridFct>
  class DerivativeGridFunction
  {
    using GridFctRange = typename GridFct::Range;
    using GridFctDomain = typename GridFct::Domain;

  public:
    using Range = typename Dune::Functions::DefaultDerivativeTraits<GridFctRange(GridFctDomain)>::Range;
    using Domain = GridFctDomain;
Praetorius, Simon's avatar
Praetorius, Simon committed
26
    using LocalFunction = std::decay_t<decltype(derivative(localFunction(std::declval<GridFct>())))>;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

    using EntitySet = typename GridFct::EntitySet;

  public:
    explicit DerivativeGridFunction(GridFct const& gridFct)
      : gridFct_(gridFct)
    {}

    Range operator()(Domain const& x) const
    {
      error_exit("Not implemented");
      return Range(0);
    }

    friend LocalFunction localFunction(DerivativeGridFunction const& gf)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
45
46
47
48
      return derivative(localFunction(gf.gridFct_));
    }

    friend int order(DerivativeGridFunction const& gf)
    {
      return std::max(0, order(gf.gridFct_)-1);
49
50
51
52
53
54
55
56
57
58
59
60
61
    }

    EntitySet const& entitySet() const
    {
      return gridFct_.entitySet();
    }

  private:
    GridFct gridFct_;
  };


  /// Generator function for \ref DerivativeGridFunction expressions
Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
64
65
  template <class GridFct,
    REQUIRES(not Concepts::HasDerivative<GridFct> &&
                 Concepts::HasLocalFunctionDerivative<GridFct>)>
  auto derivative(GridFct const& gridFct)
66
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
67
    return DerivativeGridFunction<GridFct>{gridFct};
68
69
70
71
72
  }

  /** @} **/

} // end namespace AMDiS