AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
CoordsGridFunction.hpp
1 #pragma once
2 
3 #include <dune/common/fvector.hh>
4 #include <dune/common/fmatrix.hh>
5 #include <dune/common/diagonalmatrix.hh>
6 #include <dune/common/typeutilities.hh>
7 
8 #include <amdis/common/DerivativeTraits.hpp>
9 #include <amdis/gridfunctions/AnalyticGridFunction.hpp>
10 
11 namespace AMDiS
12 {
13  namespace Operation
14  {
19  struct CoordsFunction
21  {
22  using Self = CoordsFunction;
23 
24  struct Creator
25  {
26  template <class GridView>
27  static auto create(Self const& f, GridView const& gridView)
28  {
29  return AnalyticGridFunction<Self, GridView>{f, gridView};
30  }
31  };
32 
33  template <class T, int N>
34  Dune::FieldVector<T, N> const& operator()(Dune::FieldVector<T, N> const& x) const
35  {
36  return x;
37  }
38 
39  friend int order(CoordsFunction /*f*/, int /*d*/)
40  {
41  return 1;
42  }
43 
44  struct Derivative
45  {
46  template <class T, int N>
47  Dune::DiagonalMatrix<T, N> const& operator()(Dune::FieldVector<T, N> const& /*x*/) const
48  {
49  return Dune::DiagonalMatrix<T,N>{T(1)};
50  }
51  };
53  {
54  return Derivative{};
55  }
56  };
57 
58 
61  {
62  using Self = CoordsCompFunction;
63 
64  struct Creator
65  {
66  template <class GridView>
67  static auto create(Self const& f, GridView const& gridView)
68  {
69  return AnalyticGridFunction<Self, GridView>{f, gridView};
70  }
71  };
72 
73  public:
75  explicit CoordsCompFunction(int comp)
76  : comp_(comp)
77  {}
78 
79  template <class T, int N>
80  T const& operator()(Dune::FieldVector<T, N> const& x) const
81  {
82  return x[comp_];
83  }
84 
85  friend int order(CoordsCompFunction /*f*/, int /*d*/)
86  {
87  return 1;
88  }
89 
90  struct Derivative
91  {
92  explicit Derivative(int comp)
93  : comp_(comp)
94  {}
95 
96  template <class T, int N>
97  Dune::FieldVector<T, N> operator()(Dune::FieldVector<T, N> const& /*x*/) const
98  {
99  Dune::FieldVector<T, N> result(0);
100  result[comp_] = T(1);
101 
102  return result;
103  }
104 
105  private:
106  int comp_;
107  };
108 
109  friend Derivative derivativeOf(Self const& f, tag::gradient)
110  {
111  return Derivative{f.comp_};
112  }
113 
114  private:
115  int comp_;
116  };
117 
120  } // end namespace Operation
121 
123  inline auto X()
124  {
125  return Operation::CoordsFunction{};
126  }
127 
129  inline auto X(int comp)
130  {
131  return Operation::CoordsCompFunction{comp};
132  }
133 
134  namespace Traits
135  {
136  template <>
137  struct IsPreGridFunction<Operation::CoordsFunction>
138  : std::true_type {};
139 
140  template <>
141  struct IsPreGridFunction<Operation::CoordsCompFunction>
142  : std::true_type {};
143  }
144 
145 } // end namespace AMDiS
Definition: CoordsGridFunction.hpp:24
Definition: GridFunction.hpp:26
A functor that evaluates to the global coordinates.
Definition: CoordsGridFunction.hpp:20
CoordsCompFunction(int comp)
Constructor. Stores the component comp of the coordinates.
Definition: CoordsGridFunction.hpp:75
A functor that evaluates to a component of the global coordinates.
Definition: CoordsGridFunction.hpp:60
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Definition: CoordsGridFunction.hpp:44
Definition: DerivativeTraits.hpp:20
auto order(F const &f) -> decltype(&F::operator(), f.order())
polynomial order of functions
Definition: Order.hpp:11
Definition: CoordsGridFunction.hpp:64
A Gridfunction that evaluates a function with global coordinates.
Definition: AnalyticGridFunction.hpp:128
auto derivativeOf(AnalyticLocalFunction< R(D), LC, F > const &lf, Type const &type)
Definition: AnalyticGridFunction.hpp:103
Definition: CoordsGridFunction.hpp:90
auto X()
Generator for CoordsFunction.
Definition: CoordsGridFunction.hpp:123