DUNE PDELab (2.7)

crossproduct.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3#ifndef DUNE_PDELAB_COMMON_CROSSPRODUCT_HH
4#define DUNE_PDELAB_COMMON_CROSSPRODUCT_HH
5
7
8namespace Dune {
9 namespace PDELab {
10
12 //
13 // Cross product
14 //
15
17
25 template<unsigned dimB_, unsigned dimC_>
28 "CrossProduct cannot be used unspecialized");
29 public:
31 static const unsigned dimA;
33 static const unsigned dimB;
35 static const unsigned dimC;
36
38 template<typename AType, typename BType, typename CType>
39 CrossProduct(AType& A, const BType& B, const CType& C);
40 };
41
43
56 template<>
57 struct CrossProduct<3, 3> {
59 static const unsigned dimA = 3;
61 static const unsigned dimB = 3;
63 static const unsigned dimC = 3;
64
66 template<typename AType, typename BType, typename CType>
67 CrossProduct(AType& A, const BType& B, const CType& C) {
68 for(unsigned i = 0; i < 3; ++i) {
69 unsigned j = (i+1)%3;
70 unsigned k = (i+2)%3;
71 A[i] = B[j]*C[k] - B[k]*C[j];
72 }
73 }
74 };
75
77
96 template<>
97 struct CrossProduct<2, 2> {
99 static const unsigned dimA = 1;
101 static const unsigned dimB = 2;
103 static const unsigned dimC = 2;
104
106 template<typename AType, typename BType, typename CType>
107 CrossProduct(AType& A, const BType& B, const CType& C) {
108 A[0] = B[0]*C[1] - B[1]*C[0];
109 }
110 };
111
113
133 template<>
134 struct CrossProduct<2, 1> {
136 static const unsigned dimA = 2;
138 static const unsigned dimB = 2;
140 static const unsigned dimC = 1;
141
143 template<typename AType, typename BType, typename CType>
144 CrossProduct(AType& A, const BType& B, const CType& C) {
145 A[0] = B[1]*C[0];
146 A[1] = - B[0]*C[0];
147 }
148 };
149
151
171 template<>
172 struct CrossProduct<1, 2> {
174 static const unsigned dimA = 2;
176 static const unsigned dimB = 1;
178 static const unsigned dimC = 2;
179
181 template<typename AType, typename BType, typename CType>
182 CrossProduct(AType& A, const BType& B, const CType& C) {
183 A[0] = - B[0]*C[1];
184 A[1] = B[0]*C[0];
185 }
186 };
187
189 //
190 // Free-standing cross product functions for FieldVectors
191 //
192
194
202 template<typename T, int dimB, int dimC>
203 void crossproduct(const FieldVector<T, dimB>& b,
204 const FieldVector<T, dimC>& c,
205 FieldVector<T, (CrossProduct<dimB, dimC>::dimA)>& a) {
206 CrossProduct<dimB,dimC>(a,b,c);
207 }
208
210
213 template<typename T, int dimB, int dimC>
214 FieldVector<T, CrossProduct<dimB, dimC>::dimA>
215 crossproduct(const FieldVector<T, dimB>& b,
216 const FieldVector<T, dimC>& c) {
217 FieldVector<T, CrossProduct<dimB, dimC>::dimA> a;
218 crossproduct(b,c,a);
219 return a;
220 }
221
222 } // namespace PDELab
223} //namespace Dune
224
225#endif // DUNE_PDELAB_COMMON_CROSSPRODUCT_HH
Calculate cross product.
Definition: crossproduct.hh:26
static const unsigned dimB
dimension of
Definition: crossproduct.hh:33
static const unsigned dimC
dimension of
Definition: crossproduct.hh:35
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
static const unsigned dimA
dimension of
Definition: crossproduct.hh:31
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:14
template which always yields a false value
Definition: typetraits.hh:126
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)