3#ifndef DUNE_ALBERTA_ALGEBRA_HH
4#define DUNE_ALBERTA_ALGEBRA_HH
16 inline static FieldVector< K, 3 >
17 vectorProduct (
const FieldVector< K, 3 > &u,
const FieldVector< K, 3 > &v )
19 FieldVector< K, 3 > w;
20 w[ 0 ] = u[ 1 ] * v[ 2 ] - u[ 2 ] * v[ 1 ];
21 w[ 1 ] = u[ 2 ] * v[ 0 ] - u[ 0 ] * v[ 2 ];
22 w[ 2 ] = u[ 0 ] * v[ 1 ] - u[ 1 ] * v[ 0 ];
27 template<
class K,
int m >
28 inline static K determinant ( [[maybe_unused]]
const FieldMatrix< K, 0, m > &matrix )
34 inline static K determinant (
const FieldMatrix< K, 1, 1 > &matrix )
36 return matrix[ 0 ][ 0 ];
39 template<
class K,
int m >
40 inline static K determinant (
const FieldMatrix< K, 1, m > &matrix )
43 K sum = matrix[ 0 ][ 0 ] * matrix[ 0 ][ 0 ];
44 for(
int i = 1; i < m; ++i )
45 sum += matrix[ 0 ][ i ] * matrix[ 0 ][ i ];
50 inline static K determinant (
const FieldMatrix< K, 2, 2 > &matrix )
52 return matrix[ 0 ][ 0 ] * matrix[ 1 ][ 1 ] - matrix[ 0 ][ 1 ] * matrix[ 1 ][ 0 ];
56 inline static K determinant (
const FieldMatrix< K, 2, 3 > &matrix )
58 return vectorProduct( matrix[ 0 ], matrix[ 1 ] ).two_norm();
61 template<
class K,
int m >
62 inline static K determinant (
const FieldMatrix< K, 2, m > &matrix )
65 const K tmpA = matrix[ 0 ].two_norm2();
66 const K tmpB = matrix[ 1 ].two_norm2();
67 const K tmpC = matrix[ 0 ] * matrix[ 1 ];
68 return sqrt( tmpA * tmpB - tmpC * tmpC );
72 inline static K determinant (
const FieldMatrix< K, 3, 3 > &matrix )
74 return matrix[ 0 ] * vectorProduct( matrix[ 1 ], matrix[ 2 ] );
78 template<
class K,
int m >
79 inline static K invert ( [[maybe_unused]]
const FieldMatrix< K, 0, m > &matrix,
80 [[maybe_unused]] FieldMatrix< K, m, 0 > &inverse )
86 inline static K invert (
const FieldMatrix< K, 1, 1 > &matrix,
87 FieldMatrix< K, 1, 1 > &inverse )
89 inverse[ 0 ][ 0 ] = K( 1 ) / matrix[ 0 ][ 0 ];
90 return matrix[ 0 ][ 0 ];
93 template<
class K,
int m >
94 inline static K invert (
const FieldMatrix< K, 1, m > &matrix,
95 FieldMatrix< K, m, 1 > &inverse )
98 K detSqr = matrix[ 0 ].two_norm2();
99 K invDetSqr = K( 1 ) / detSqr;
100 for(
int i = 0; i < m; ++i )
101 inverse[ i ][ 0 ] = invDetSqr * matrix[ 0 ][ i ];
102 return sqrt( detSqr );
106 inline static K invert (
const FieldMatrix< K, 2, 2 > &matrix,
107 FieldMatrix< K, 2, 2 > &inverse )
109 K det = determinant( matrix );
110 K invDet = K( 1 ) / det;
111 inverse[ 0 ][ 0 ] = invDet * matrix[ 1 ][ 1 ];
112 inverse[ 0 ][ 1 ] = - invDet * matrix[ 0 ][ 1 ];
113 inverse[ 1 ][ 0 ] = - invDet * matrix[ 1 ][ 0 ];
114 inverse[ 1 ][ 1 ] = invDet * matrix[ 0 ][ 0 ];
118 template<
class K,
int m >
119 inline static K invert (
const FieldMatrix< K, 2, m > &matrix,
120 FieldMatrix< K, m, 2 > &inverse )
123 const K tmpA = matrix[ 0 ].two_norm2();
124 const K tmpB = matrix[ 1 ].two_norm2();
125 const K tmpC = matrix[ 0 ] * matrix[ 1 ];
126 const K detSqr = tmpA * tmpB - tmpC * tmpC;
127 const K invDetSqr = K( 1 ) / detSqr;
128 for(
int i = 0; i < m; ++i )
130 inverse[ i ][ 0 ] = invDetSqr * (tmpB * matrix[ 0 ][ i ] - tmpC * matrix[ 1 ][ i ]);
131 inverse[ i ][ 1 ] = invDetSqr * (tmpA * matrix[ 1 ][ i ] - tmpC * matrix[ 0 ][ i ]);
133 return sqrt( detSqr );
137 inline static K invert (
const FieldMatrix< K, 3, 3 > &matrix,
138 FieldMatrix< K, 3, 3 > &inverse )
140 return FMatrixHelp::invertMatrix( matrix, inverse );
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:11