DerivativeGridFunction.hpp 2.31 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
  /// A Gridfunction that returns the derivative when calling localFunction
17
18
19
20
21
22
23
24
25
  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

    using EntitySet = typename GridFct::EntitySet;

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

35
    /// no global derivative available
36
37
38
39
40
41
42
43
    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
44
45
46
      return derivative(localFunction(gf.gridFct_));
    }

47
48
49
50
51
52
53
54
55
    EntitySet const& entitySet() const
    {
      return gridFct_.entitySet();
    }

  private:
    GridFct gridFct_;
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
56
  template <class GridFct,
57
58
  REQUIRES(not Concepts::HasDerivative<GridFct> &&
                Concepts::HasLocalFunctionDerivative<GridFct>)>
Praetorius, Simon's avatar
Praetorius, Simon committed
59
  auto derivative(GridFct const& gridFct)
60
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
61
    return DerivativeGridFunction<GridFct>{gridFct};
62
63
  }

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

  template <class Expr>
  struct DerivativePreGridFunction
  {
    Expr expr;
  };

  namespace Traits
  {
    template <class Expr>
    struct IsPreGridFunction<DerivativePreGridFunction<Expr>>
      : std::true_type {};
  }


  /// Generator function for \ref DerivativeGridFunction expressions
  template <class Expr>
  auto gradientAtQP(Expr const& expr)
  {
    return DerivativePreGridFunction<Expr>{expr};
  }

  /// Generator function for \ref AnalyticGridFunction expressions from \ref AnalyticPreGridFunction.
  template <class Expr, class GridView>
  auto makeGridFunction(DerivativePreGridFunction<Expr> const& pre, GridView const& gridView, Dune::PriorityTag<3>)
  {
    return derivative(makeGridFunction(pre.expr, gridView, Dune::PriorityTag<42>{}));
  }

93
94
95
  /** @} **/

} // end namespace AMDiS