AMDiS 2.10
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
11namespace AMDiS
12{
13 namespace Operation
14 {
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
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 };
52 friend Derivative derivativeOf(CoordsFunction const& /*f*/, tag::gradient)
53 {
54 return Derivative{};
55 }
56 };
57
58
61 {
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
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
A Gridfunction that evaluates a function with global coordinates.
Definition: AnalyticGridFunction.hpp:151
Definition: CoordsGridFunction.hpp:65
Definition: CoordsGridFunction.hpp:91
A functor that evaluates to a component of the global coordinates.
Definition: CoordsGridFunction.hpp:61
CoordsCompFunction(int comp)
Constructor. Stores the component comp of the coordinates.
Definition: CoordsGridFunction.hpp:75
Definition: CoordsGridFunction.hpp:25
Definition: CoordsGridFunction.hpp:45
A functor that evaluates to the global coordinates.
Definition: CoordsGridFunction.hpp:21
Definition: GridFunction.hpp:27
Definition: DerivativeTraits.hpp:19