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 (
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 )
42 K sum = matrix[ 0 ][ 0 ] * matrix[ 0 ][ 0 ];
43 for(
int i = 1; i < m; ++i )
44 sum += matrix[ 0 ][ i ] * matrix[ 0 ][ i ];
49 inline static K determinant (
const FieldMatrix< K, 2, 2 > &matrix )
51 return matrix[ 0 ][ 0 ] * matrix[ 1 ][ 1 ] - matrix[ 0 ][ 1 ] * matrix[ 1 ][ 0 ];
55 inline static K determinant (
const FieldMatrix< K, 2, 3 > &matrix )
57 return vectorProduct( matrix[ 0 ], matrix[ 1 ] ).two_norm();
60 template<
class K,
int m >
61 inline static K determinant (
const FieldMatrix< K, 2, m > &matrix )
63 const K tmpA = matrix[ 0 ].two_norm2();
64 const K tmpB = matrix[ 1 ].two_norm2();
65 const K tmpC = matrix[ 0 ] * matrix[ 1 ];
66 return sqrt( tmpA * tmpB - tmpC * tmpC );
70 inline static K determinant (
const FieldMatrix< K, 3, 3 > &matrix )
72 return matrix[ 0 ] * vectorProduct( matrix[ 1 ], matrix[ 2 ] );
76 template<
class K,
int m >
77 inline static K invert (
const FieldMatrix< K, 0, m > &matrix,
78 FieldMatrix< K, m, 0 > &inverse )
84 inline static K invert (
const FieldMatrix< K, 1, 1 > &matrix,
85 FieldMatrix< K, 1, 1 > &inverse )
87 inverse[ 0 ][ 0 ] = K( 1 ) / matrix[ 0 ][ 0 ];
88 return matrix[ 0 ][ 0 ];
91 template<
class K,
int m >
92 inline static K invert (
const FieldMatrix< K, 1, m > &matrix,
93 FieldMatrix< K, m, 1 > &inverse )
95 K detSqr = matrix[ 0 ].two_norm2();
96 K invDetSqr = K( 1 ) / detSqr;
97 for(
int i = 0; i < m; ++i )
98 inverse[ i ][ 0 ] = invDetSqr * matrix[ 0 ][ i ];
99 return sqrt( detSqr );
103 inline static K invert (
const FieldMatrix< K, 2, 2 > &matrix,
104 FieldMatrix< K, 2, 2 > &inverse )
106 K det = determinant( matrix );
107 K invDet = K( 1 ) / det;
108 inverse[ 0 ][ 0 ] = invDet * matrix[ 1 ][ 1 ];
109 inverse[ 0 ][ 1 ] = - invDet * matrix[ 0 ][ 1 ];
110 inverse[ 1 ][ 0 ] = - invDet * matrix[ 1 ][ 0 ];
111 inverse[ 1 ][ 1 ] = invDet * matrix[ 0 ][ 0 ];
115 template<
class K,
int m >
116 inline static K invert (
const FieldMatrix< K, 2, m > &matrix,
117 FieldMatrix< K, m, 2 > &inverse )
119 const K tmpA = matrix[ 0 ].two_norm2();
120 const K tmpB = matrix[ 1 ].two_norm2();
121 const K tmpC = matrix[ 0 ] * matrix[ 1 ];
122 const K detSqr = tmpA * tmpB - tmpC * tmpC;
123 const K invDetSqr = K( 1 ) / detSqr;
124 for(
int i = 0; i < m; ++i )
126 inverse[ i ][ 0 ] = invDetSqr * (tmpB * matrix[ 0 ][ i ] - tmpC * matrix[ 1 ][ i ]);
127 inverse[ i ][ 1 ] = invDetSqr * (tmpA * matrix[ 1 ][ i ] - tmpC * matrix[ 0 ][ i ]);
129 return sqrt( detSqr );
133 inline static K invert (
const FieldMatrix< K, 3, 3 > &matrix,
134 FieldMatrix< K, 3, 3 > &inverse )
136 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: alignment.hh:11