dune-pdelab  2.5-dev
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 
8 namespace Dune {
9  namespace PDELab {
10 
12  //
13  // Cross product
14  //
15 
17 
25  template<unsigned dimB_, unsigned dimC_>
26  class CrossProduct {
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) {
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
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:182
static const unsigned dimA
dimension of
Definition: crossproduct.hh:28
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:144
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:107
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
Definition: crossproduct.hh:67
CrossProduct(AType &A, const BType &B, const CType &C)
calculate cross product of B and C
static const unsigned dimB
dimension of
Definition: crossproduct.hh:33
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
static const unsigned dimC
dimension of
Definition: crossproduct.hh:35
void crossproduct(const FieldVector< T, dimB > &b, const FieldVector< T, dimC > &c, FieldVector< T,(CrossProduct< dimB, dimC >::dimA)> &a)
calculate crossproduct
Definition: crossproduct.hh:203
Calculate cross product.
Definition: crossproduct.hh:26