AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
FieldMatVec.hpp
1#pragma once
2
3#include <amdis/common/FieldMatVec.hpp>
4#include <amdis/operations/Arithmetic.hpp>
5#include <amdis/operations/Basic.hpp>
6#include <amdis/operations/CMath.hpp>
7#include <amdis/operations/Composer.hpp>
8
9namespace AMDiS
10{
11 namespace Operation
12 {
18 struct Dot
19 {
20 template <class T0, class T1, int N>
21 constexpr auto operator()(Dune::FieldVector<T0,N> const& lhs, Dune::FieldVector<T1,N> const& rhs) const
22 {
23 return lhs.dot(rhs);
24 }
25
26 friend constexpr int order(Dot const&, int d1, int d2)
27 {
28 return d1 + d2;
29 }
30
31 friend constexpr auto partial(Dot const&, index_t<0>)
32 {
33 return Arg<1>{};
34 }
35
36 friend constexpr auto partial(Dot const&, index_t<1>)
37 {
38 return Arg<0>{};
39 }
40 };
41
42 // -------------------------------------------------------------------------
43
45 struct UnaryDot
46 {
47 template <class V>
48 constexpr auto operator()(V const& vec) const
49 {
50 using Dune::unary_dot;
51 return unary_dot(vec);
52 }
53
54 friend constexpr int order(UnaryDot const&, int d)
55 {
56 return 2*d;
57 }
58
59 friend auto partial(UnaryDot const&, index_t<0>)
60 {
61 return compose(Multiplies{}, StaticConstant<int,2>{}, Id{});
62 }
63 };
64
65 // -------------------------------------------------------------------------
66
68 struct TwoNorm
69 : public Composer<Sqrt, UnaryDot>
70 {
71 constexpr TwoNorm()
73 {}
74
75 template <class V>
76 constexpr auto operator()(V const& vec) const
77 {
78 using Dune::two_norm;
79 return two_norm(vec);
80 }
81 };
82
83 // -------------------------------------------------------------------------
84
85 struct Trans
86 {
87 template <class M>
88 constexpr auto operator()(M const& mat) const
89 {
90 using Dune::trans;
91 return trans(mat);
92 }
93
94 friend constexpr int order(Trans const&, int d)
95 {
96 return d;
97 }
98 };
99
101 struct Mv
102 {
103 template <class T1, int M, int N, class T2>
104 constexpr auto operator()(Dune::FieldMatrix<T1,M,N> const& lhs, Dune::FieldVector<T2,N> const& rhs) const
105 {
106 using T = typename Dune::PromotionTraits<T1,T2>::PromotedType;
107 Dune::FieldVector<T,M> result;
108 lhs.mv(rhs, result);
109 return result;
110 }
111
112 friend constexpr int order(Mv const&, int d1, int d2)
113 {
114 return d1 + d2;
115 }
116
117 friend constexpr auto partial(Mv const&, index_t<0>)
118 {
119 return Arg<1>{};
120 }
121
122 friend constexpr auto partial(Mv const&, index_t<1>)
123 {
124 return Arg<0>{};
125 }
126 };
127
128
130 struct Mtv
131 {
132 template <class T1, int M, int N, class T2>
133 constexpr auto operator()(Dune::FieldMatrix<T1,M,N> const& lhs, Dune::FieldVector<T2,M> const& rhs) const
134 {
135 using T = typename Dune::PromotionTraits<T1,T2>::PromotedType;
136 Dune::FieldVector<T,N> result;
137 lhs.mtv(rhs, result);
138 return result;
139 }
140
141 friend constexpr int order(Mtv const&, int d1, int d2)
142 {
143 return d1 + d2;
144 }
145
146 friend constexpr auto partial(Mtv const&, index_t<0>)
147 {
148 return Arg<1>{};
149 }
150
151 friend constexpr auto partial(Mtv const&, index_t<1>)
152 {
153 return Arg<0>{};
154 }
155 };
156
159 } // end namespace Operation
160} // end namespace AMDiS
Definition Basic.hpp:174
Composition of Functors.
Definition Composer.hpp:30
(Binary-)Functor representing the euclidean dot-product
Definition FieldMatVec.hpp:19
(Unary-)Functor representing the identity
Definition Basic.hpp:74
(Binary-)Functor representing the matrix^T-vector
Definition FieldMatVec.hpp:131
Functor that represents A*B.
Definition Arithmetic.hpp:101
(Binary-)Functor representing the matrix-vector
Definition FieldMatVec.hpp:102
Functor representing a static constant value.
Definition Basic.hpp:47
Definition FieldMatVec.hpp:86
(Unary-)Functor representing the euclidean 2-norm
Definition FieldMatVec.hpp:70
(Unary-)Functor representing the euclidean dot-product
Definition FieldMatVec.hpp:46