CoordsGridFunction.hpp 2.44 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once

#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/identitymatrix.hh>
#include <dune/common/typeutilities.hh>

namespace AMDiS
{
  /**
    * \addtogroup GridFunctions
    * @{
    **/

  struct CoordsFunction
  {
    struct Derivative
    {
      template <class T, int N>
      Dune::IdentityMatrix<T, N> const& operator()(Dune::FieldVector<T, N> const& x) const
      {
        return Dune::IdentityMatrix<T,N>{};
      }
    };

    template <class T, int N>
    Dune::FieldVector<T, N> const& operator()(Dune::FieldVector<T, N> const& x) const
    {
      return x;
    }

    friend Derivative derivative(CoordsFunction const& /*f*/)
    {
      return Derivative{};
    }

    friend int order(CoordsFunction const& /*f*/)
    {
      return 1;
    }
  };


  struct CoordsCompFunction
  {
    struct Derivative
    {
      explicit Derivative(int comp)
        : comp_(comp)
      {}

      template <class T, int N>
      Dune::FieldVector<T, N> const& operator()(Dune::FieldVector<T, N> const& x) const
      {
        Dune::FieldVector<T, N> result(0);
        result[comp_] = T(1);

        return result;
      }

    private:
      int comp_;
    };

    explicit CoordsCompFunction(int comp)
      : comp_(comp)
    {}

    template <class T, int N>
    T const& operator()(Dune::FieldVector<T, N> const& x) const
    {
      return x[comp_];
    }

    friend Derivative derivative(CoordsCompFunction const& f)
    {
      return Derivative{f.comp_};
    }

    friend int order(CoordsCompFunction const& /*f*/)
    {
      return 1;
    }

  private:
    int comp_;
  };

  namespace Concepts { namespace Definition
  {
    template <>
    struct IsPreGridFunction<CoordsFunction>
      : std::true_type {};

    template <>
    struct IsPreGridFunction<CoordsCompFunction>
      : std::true_type {};
  }}

  /// Generator for \ref CoordsFunction
  inline auto X()
  {
    return CoordsFunction{};
  }

  /// Generator for \ref CoordsCompFunction
  inline auto X(int comp)
  {
    return CoordsCompFunction{comp};
  }


  template <class GridView>
  auto makeGridFunction(CoordsFunction const& f, GridView const& gridView, Dune::PriorityTag<1>)
  {
    return makeAnalyticGridFunction(f, gridView);
  }

  template <class GridView>
  auto makeGridFunction(CoordsCompFunction const& f, GridView const& gridView, Dune::PriorityTag<1>)
  {
    return makeAnalyticGridFunction(f, gridView);
  }

  /** @} **/

} // end namespace AMDiS