dune-pdelab  2.0.0
crossproduct.hh
Go to the documentation of this file.
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 
6 #include <dune/common/fvector.hh>
7 #include <dune/common/static_assert.hh>
8 
9 namespace Dune {
10  namespace PDELab {
11 
13  //
14  // Cross product
15  //
16 
18 
26  template<unsigned dimB_, unsigned dimC_>
27  class CrossProduct {
28  dune_static_assert(AlwaysFalse<CrossProduct>::value,
29  "CrossProduct cannot be used unspecialized");
30  public:
32  static const unsigned dimA;
34  static const unsigned dimB;
36  static const unsigned dimC;
37 
39  template<typename AType, typename BType, typename CType>
40  CrossProduct(AType& A, const BType& B, const CType& C);
41  };
42 
44 
57  template<>
58  struct CrossProduct<3, 3> {
60  static const unsigned dimA = 3;
62  static const unsigned dimB = 3;
64  static const unsigned dimC = 3;
65 
67  template<typename AType, typename BType, typename CType>
68  CrossProduct(AType& A, const BType& B, const CType& C) {
69  for(unsigned i = 0; i < 3; ++i) {
70  unsigned j = (i+1)%3;
71  unsigned k = (i+2)%3;
72  A[i] = B[j]*C[k] - B[k]*C[j];
73  }
74  }
75  };
76 
78 
97  template<>
98  struct CrossProduct<2, 2> {
100  static const unsigned dimA = 1;
102  static const unsigned dimB = 2;
104  static const unsigned dimC = 2;
105 
107  template<typename AType, typename BType, typename CType>
108  CrossProduct(AType& A, const BType& B, const CType& C) {
109  A[0] = B[0]*C[1] - B[1]*C[0];
110  }
111  };
112 
114 
134  template<>
135  struct CrossProduct<2, 1> {
137  static const unsigned dimA = 2;
139  static const unsigned dimB = 2;
141  static const unsigned dimC = 1;
142 
144  template<typename AType, typename BType, typename CType>
145  CrossProduct(AType& A, const BType& B, const CType& C) {
146  A[0] = B[1]*C[0];
147  A[1] = - B[0]*C[0];
148  }
149  };
150 
152 
172  template<>
173  struct CrossProduct<1, 2> {
175  static const unsigned dimA = 2;
177  static const unsigned dimB = 1;
179  static const unsigned dimC = 2;
180 
182  template<typename AType, typename BType, typename CType>
183  CrossProduct(AType& A, const BType& B, const CType& C) {
184  A[0] = - B[0]*C[1];
185  A[1] = B[0]*C[0];
186  }
187  };
188 
190  //
191  // Free-standing cross product functions for FieldVectors
192  //
193 
195 
203  template<typename T, int dimB, int dimC>
204  void crossproduct(const FieldVector<T, dimB>& b,
205  const FieldVector<T, dimC>& c,
206  FieldVector<T, (CrossProduct<dimB, dimC>::dimA)>& a) {
208  }
209 
211 
214  template<typename T, int dimB, int dimC>
215  FieldVector<T, CrossProduct<dimB, dimC>::dimA>
216  crossproduct(const FieldVector<T, dimB>& b,
217  const FieldVector<T, dimC>& c) {
218  FieldVector<T, CrossProduct<dimB, dimC>::dimA> a;
219  crossproduct(b,c,a);
220  return a;
221  }
222 
223  } // namespace PDELab
224 } //namespace Dune
225 
226 #endif // DUNE_PDELAB_COMMON_CROSSPRODUCT_HH
227 
static const unsigned dimA
dimension of
Definition: crossproduct.hh:32
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:68
static const unsigned dimC
dimension of
Definition: crossproduct.hh:36
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:145
static const unsigned dimB
dimension of
Definition: crossproduct.hh:34
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:108
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:183
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
Calculate cross product.
Definition: crossproduct.hh:27
void crossproduct(const FieldVector< T, dimB > &b, const FieldVector< T, dimC > &c, FieldVector< T,(CrossProduct< dimB, dimC >::dimA)> &a)
calculate crossproduct
Definition: crossproduct.hh:204