33 #ifndef __H__UG__CPU_ALGEBRA__DENSEMATRIX_SMALL_INVERSE_H__
34 #define __H__UG__CPU_ALGEBRA__DENSEMATRIX_SMALL_INVERSE_H__
56 if(mat(0,0) == 0.0)
return false;
57 inv(0,0) = 1/mat(0,0);
65 if(mat(0,0) == 0.0)
return false;
66 mat(0,0) = 1/mat(0,0);
80 template<
typename vector_t,
typename matrix_t>
84 if(A1(0,0) == 0.0)
return false;
86 dest[0] = beta1*w1[0]/A1(0,0);
102 UG_ASSERT(mat.num_rows() == 2 && mat.num_cols() == 2,
"only for 2x2-matrices");
103 return mat(0,0)*mat(1,1) - mat(1,0)*mat(0,1);
109 UG_ASSERT(&inv != &mat,
"inv and mat have to be different. Otherwise use Invert/Invert2");
112 if(invdet == 0.0)
return false;
114 inv(0,0) = mat(1,1) * invdet;
115 inv(1,1) = mat(0,0) * invdet;
116 inv(0,1) = mat(0,1) * -invdet;
117 inv(1,0) = mat(1,0) * -invdet;
126 if(invdet == 0.0)
return false;
129 std::swap(mat(0,0), mat(1,1));
149 template<
typename vector_t,
typename matrix_t>
156 if(det == 0.0)
return false;
157 dest[0] = beta * (mat(1,1)*vec[0] - mat(0,1)*vec[1]) / det;
158 dest[1] = beta * (-mat(1,0)*vec[0] + mat(0,0)*vec[1]) / det;
176 UG_ASSERT(mat.num_rows() == 3 && mat.num_cols() == 3,
"only for 3x3-matrices");
177 return mat(0,0)*mat(1,1)*mat(2,2) + mat(0,1)*mat(1,2)*mat(2,0) + mat(0,2)*mat(1,0)*mat(2,1)
178 - mat(0,0)*mat(1,2)*mat(2,1) - mat(0,1)*mat(1,0)*mat(2,2) - mat(0,2)*mat(1,1)*mat(2,0);
184 UG_ASSERT(&inv != &mat,
"inv and mat have to be different. Otherwise use Invert/Invert3");
187 if(invdet == 0.0)
return false;
190 inv(0,0) = ( mat(1,1)*mat(2,2) - mat(1,2)*mat(2,1)) * invdet;
191 inv(0,1) = (-mat(0,1)*mat(2,2) + mat(0,2)*mat(2,1)) * invdet;
192 inv(0,2) = ( mat(0,1)*mat(1,2) - mat(0,2)*mat(1,1)) * invdet;
193 inv(1,0) = (-mat(1,0)*mat(2,2) + mat(1,2)*mat(2,0)) * invdet;
194 inv(1,1) = ( mat(0,0)*mat(2,2) - mat(0,2)*mat(2,0)) * invdet;
195 inv(1,2) = (-mat(0,0)*mat(1,2) + mat(0,2)*mat(1,0)) * invdet;
196 inv(2,0) = ( mat(1,0)*mat(2,1) - mat(1,1)*mat(2,0)) * invdet;
197 inv(2,1) = (-mat(0,0)*mat(2,1) + mat(0,1)*mat(2,0)) * invdet;
198 inv(2,2) = ( mat(0,0)*mat(1,1) - mat(0,1)*mat(1,0)) * invdet;
229 template<
typename vector_t,
typename matrix_t>
236 if(det == 0.0)
return false;
237 dest[0] = ( ( mat(1,1)*mat(2,2) - mat(1,2)*mat(2,1)) *vec[0] +
238 (-mat(0,1)*mat(2,2) + mat(0,2)*mat(2,1)) *vec[1] +
239 ( mat(0,1)*mat(1,2) - mat(0,2)*mat(1,1)) *vec[2] ) * beta / det;
240 dest[1] = ( (-mat(1,0)*mat(2,2) + mat(1,2)*mat(2,0)) * vec[0] +
241 ( mat(0,0)*mat(2,2) - mat(0,2)*mat(2,0)) * vec[1] +
242 (-mat(0,0)*mat(1,2) + mat(0,2)*mat(1,0)) * vec[2] ) * beta / det;
243 dest[2] = ( ( mat(1,0)*mat(2,1) - mat(1,1)*mat(2,0)) * vec[0] +
244 (-mat(0,0)*mat(2,1) + mat(0,1)*mat(2,0)) * vec[1] +
245 ( mat(0,0)*mat(1,1) - mat(0,1)*mat(1,0)) * vec[2] ) * beta / det;
260 template<
typename vector_t,
typename matrix_t>
280 template<
typename vector_t,
typename matrix_t>
294 template<
typename T, eMatrixOrdering TOrdering>
297 return inv.set_as_inverse_of(mat);
300 template<
typename T,
size_t TBlockSize, eMatrixOrdering TOrdering>
303 return inv.set_as_inverse_of(mat);
310 switch(mat.num_rows())
319 template<
typename vector_t,
typename matrix_t>
330 template<
typename vector_t,
typename matrix_t>
334 switch(mat.num_rows())
Definition: densematrix.h:57
Definition: lapack_densematrix_inverse.h:51
void apply(DenseVector< vector_t > &vec) const
Definition: lapack_densematrix_inverse.h:115
Definition: densevector.h:101
Definition: fixed_array.h:56
Definition: fixed_array.h:135
Definition: variable_array.h:139
bool GetInverse3(DenseMatrix< T > &inv, const DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:182
bool InverseMatMultN(DenseVector< vector_t > &dest, double beta, const DenseMatrix< matrix_t > &mat, const DenseVector< vector_t > &vec)
Definition: densematrix_inverse.h:320
bool InverseMatMult3(DenseVector< vector_t > &dest, double beta, const DenseMatrix< matrix_t > &mat, const DenseVector< vector_t > &vec)
Definition: densematrix_inverse.h:230
bool GetInverse2(DenseMatrix< T > &inv, const DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:107
bool InverseMatMult1(DenseVector< vector_t > &dest, double beta1, const DenseMatrix< matrix_t > &A1, const DenseVector< vector_t > &w1)
Definition: densematrix_inverse.h:81
double GetDet2(const DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:100
bool InverseMatMult2(DenseVector< vector_t > &dest, double beta, const DenseMatrix< matrix_t > &mat, const DenseVector< vector_t > &vec)
Definition: densematrix_inverse.h:150
double GetDet3(const DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:174
bool GetInverse1(DenseMatrix< T > &inv, const DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:53
bool Invert1(DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:62
bool Invert3(DenseMatrix< FixedArray2< double, 3, 3 > > &mat)
Definition: densematrix_inverse.h:202
bool Invert2(DenseMatrix< T > &mat)
Definition: densematrix_inverse.h:122
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
bool GetInverse(block_traits< T >::inverse_type &inv, const T &m)
bool MatMultAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition: operations_mat.h:68
bool InvertNdyn(DenseMatrix< T > &mat)
Definition: lapack_invert.h:47
bool MatMult(vector_t &dest, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = beta1 * A1;
Definition: operations_mat.h:59
bool InverseMatMult(number &dest, const double &beta, const TMat &mat, const TVec &vec)
you can implement this function with GetInverse and MatMult
void VecScaleAssign(double &dest, double alpha1, const double &v1)
calculates dest = alpha1*v1. for doubles
Definition: operations_vec.h:49
Definition: communication_policies.h:58