21 #include <type_traits>
60 template<
class TDataType =
double>
84 static constexpr
double ZeroTolerance = std::numeric_limits<double>::epsilon();
104 return ZeroTolerance;
114 template<
bool TCheck>
121 const double s = 0.5 * (
a +
b +
c);
122 const double A2 = s * (s -
a) * (s -
b) * (s -
c);
123 if constexpr(TCheck) {
125 KRATOS_ERROR <<
"The square of area is negative, probably the triangle is in bad shape:" << A2 << std::endl;
127 return std::sqrt(A2);
130 return std::sqrt(std::abs(A2));
141 template<
class TMatrixType>
144 static_assert(std::is_same<typename TMatrixType::value_type, double>::value,
"Bad value type.");
146 KRATOS_ERROR_IF(rMat.size1() != rMat.size2() || rMat.size1() == 0) <<
"Bad matrix dimensions." << std::endl;
148 if (rMat.size1() == 1)
155 for (
unsigned k = 0;
k < rMat.size1(); ++
k)
160 for (
unsigned k = 0;
k < rMat.size2(); ++
k)
164 boost::numeric::ublas::matrix_indirect<const TMatrixType, IndirectArrayType> sub_mat(rMat, ia1, ia2);
165 const double first_minor = Det(sub_mat);
166 return ((
i +
j) % 2) ? -first_minor : first_minor;
174 template<
class TMatrixType>
177 static_assert(std::is_same<typename TMatrixType::value_type, double>::value,
"Bad value type.");
179 MatrixType cofactor_matrix(rMat.size1(), rMat.size2());
183 cofactor_matrix(
i,
j) = Cofactor(rMat,
i,
j);
185 return cofactor_matrix;
195 template<SizeType TDim>
199 double& rInputMatrixDet,
200 const double Tolerance = ZeroTolerance
206 rInputMatrixDet = Det(rInputMatrix);
208 if constexpr (TDim == 1) {
209 inverted_matrix(0,0) = 1.0/rInputMatrix(0,0);
210 rInputMatrixDet = rInputMatrix(0,0);
211 }
else if constexpr (TDim == 2) {
212 InvertMatrix2(rInputMatrix, inverted_matrix, rInputMatrixDet);
213 }
else if constexpr (TDim == 3) {
214 InvertMatrix3(rInputMatrix, inverted_matrix, rInputMatrixDet);
215 }
else if constexpr (TDim == 4) {
216 InvertMatrix4(rInputMatrix, inverted_matrix, rInputMatrixDet);
218 KRATOS_ERROR <<
"Size not implemented. Size: " << TDim << std::endl;
222 if (Tolerance > 0.0) {
223 CheckConditionNumber(rInputMatrix, inverted_matrix, Tolerance);
226 return inverted_matrix;
235 template<
class TMatrix1,
class TMatrix2>
237 const TMatrix1& rInputMatrix,
238 TMatrix2& rInvertedMatrix,
239 const double Tolerance = std::numeric_limits<double>::epsilon(),
240 const bool ThrowError =
true
244 const double max_condition_number = (1.0/Tolerance) * 1.0e-4;
248 const double inverted_matrix_norm =
norm_frobenius(rInvertedMatrix);
251 const double cond_number = input_matrix_norm * inverted_matrix_norm ;
253 if (cond_number > max_condition_number) {
256 KRATOS_ERROR <<
" Condition number of the matrix is too high!, cond_number = " << cond_number << std::endl;
273 template<
class TMatrix1,
class TMatrix2>
275 const TMatrix1& rInputMatrix,
276 TMatrix2& rInvertedMatrix,
277 double& rInputMatrixDet,
278 const double Tolerance = ZeroTolerance
281 const SizeType size_1 = rInputMatrix.size1();
282 const SizeType size_2 = rInputMatrix.size2();
284 if (size_1 == size_2) {
285 InvertMatrix(rInputMatrix, rInvertedMatrix, rInputMatrixDet, Tolerance);
286 }
else if (size_1 < size_2) {
287 if (rInvertedMatrix.size1() != size_2 || rInvertedMatrix.size2() != size_1) {
288 rInvertedMatrix.resize(size_2, size_1,
false);
292 InvertMatrix(aux, auxInv, rInputMatrixDet, Tolerance);
293 rInputMatrixDet = std::sqrt(rInputMatrixDet);
296 if (rInvertedMatrix.size1() != size_2 || rInvertedMatrix.size2() != size_1) {
297 rInvertedMatrix.resize(size_2, size_1,
false);
301 InvertMatrix(aux, auxInv, rInputMatrixDet, Tolerance);
302 rInputMatrixDet = std::sqrt(rInputMatrixDet);
327 template<
class TMatrix1,
class TMatrix2>
329 const TMatrix1& rInputMatrix,
330 TMatrix2& rInvertedMatrix,
331 double& rInputMatrixDet,
332 const double Tolerance = ZeroTolerance
337 const SizeType size = rInputMatrix.size2();
340 if(rInvertedMatrix.size1() != 1 || rInvertedMatrix.size2() != 1) {
341 rInvertedMatrix.resize(1,1,
false);
343 rInvertedMatrix(0,0) = 1.0/rInputMatrix(0,0);
344 rInputMatrixDet = rInputMatrix(0,0);
345 }
else if (size == 2) {
346 InvertMatrix2(rInputMatrix, rInvertedMatrix, rInputMatrixDet);
347 }
else if (size == 3) {
348 InvertMatrix3(rInputMatrix, rInvertedMatrix, rInputMatrixDet);
349 }
else if (size == 4) {
350 InvertMatrix4(rInputMatrix, rInvertedMatrix, rInputMatrixDet);
351 }
else if (std::is_same<TMatrix1, Matrix>::value) {
353 const SizeType size1 = rInputMatrix.size1();
354 const SizeType size2 = rInputMatrix.size2();
355 if(rInvertedMatrix.size1() != size1 || rInvertedMatrix.size2() != size2) {
356 rInvertedMatrix.resize(size1, size2,
false);
360 typedef permutation_matrix<SizeType> pmatrix;
361 pmatrix pm(
A.size1());
362 const int singular = lu_factorize(
A,pm);
364 KRATOS_ERROR_IF(singular == 1) <<
"Matrix is singular: " << rInputMatrix << std::endl;
365 lu_substitute(
A, pm, rInvertedMatrix);
368 rInputMatrixDet = 1.0;
372 rInputMatrixDet *= (ki == 0) ?
A(
i,
i) : -
A(
i,
i);
375 const SizeType size1 = rInputMatrix.size1();
376 const SizeType size2 = rInputMatrix.size2();
379 Matrix invA(rInvertedMatrix);
381 typedef permutation_matrix<SizeType> pmatrix;
383 const int singular = lu_factorize(
A,pm);
385 KRATOS_ERROR_IF(singular == 1) <<
"Matrix is singular: " << rInputMatrix << std::endl;
386 lu_substitute(
A, pm, invA);
389 rInputMatrixDet = 1.0;
393 rInputMatrixDet *= (ki == 0) ?
A(
i,
i) : -
A(
i,
i);
398 rInvertedMatrix(
i,
j) = invA(
i,
j);
404 if (Tolerance > 0.0) {
405 CheckConditionNumber(rInputMatrix, rInvertedMatrix, Tolerance);
415 template<
class TMatrix1,
class TMatrix2>
417 const TMatrix1& rInputMatrix,
418 TMatrix2& rInvertedMatrix,
419 double& rInputMatrixDet
426 if(rInvertedMatrix.size1() != 2 || rInvertedMatrix.size2() != 2) {
427 rInvertedMatrix.resize(2,2,
false);
430 rInputMatrixDet = rInputMatrix(0,0)*rInputMatrix(1,1)-rInputMatrix(0,1)*rInputMatrix(1,0);
432 rInvertedMatrix(0,0) = rInputMatrix(1,1);
433 rInvertedMatrix(0,1) = -rInputMatrix(0,1);
434 rInvertedMatrix(1,0) = -rInputMatrix(1,0);
435 rInvertedMatrix(1,1) = rInputMatrix(0,0);
437 rInvertedMatrix/=rInputMatrixDet;
448 template<
class TMatrix1,
class TMatrix2>
450 const TMatrix1& rInputMatrix,
451 TMatrix2& rInvertedMatrix,
452 double& rInputMatrixDet
459 if(rInvertedMatrix.size1() != 3 || rInvertedMatrix.size2() != 3) {
460 rInvertedMatrix.resize(3,3,
false);
465 rInvertedMatrix(0,0) = rInputMatrix(1,1)*rInputMatrix(2,2) - rInputMatrix(1,2)*rInputMatrix(2,1);
466 rInvertedMatrix(1,0) = -rInputMatrix(1,0)*rInputMatrix(2,2) + rInputMatrix(1,2)*rInputMatrix(2,0);
467 rInvertedMatrix(2,0) = rInputMatrix(1,0)*rInputMatrix(2,1) - rInputMatrix(1,1)*rInputMatrix(2,0);
470 rInvertedMatrix(0,1) = -rInputMatrix(0,1)*rInputMatrix(2,2) + rInputMatrix(0,2)*rInputMatrix(2,1);
471 rInvertedMatrix(1,1) = rInputMatrix(0,0)*rInputMatrix(2,2) - rInputMatrix(0,2)*rInputMatrix(2,0);
472 rInvertedMatrix(2,1) = -rInputMatrix(0,0)*rInputMatrix(2,1) + rInputMatrix(0,1)*rInputMatrix(2,0);
475 rInvertedMatrix(0,2) = rInputMatrix(0,1)*rInputMatrix(1,2) - rInputMatrix(0,2)*rInputMatrix(1,1);
476 rInvertedMatrix(1,2) = -rInputMatrix(0,0)*rInputMatrix(1,2) + rInputMatrix(0,2)*rInputMatrix(1,0);
477 rInvertedMatrix(2,2) = rInputMatrix(0,0)*rInputMatrix(1,1) - rInputMatrix(0,1)*rInputMatrix(1,0);
480 rInputMatrixDet = rInputMatrix(0,0)*rInvertedMatrix(0,0) + rInputMatrix(0,1)*rInvertedMatrix(1,0) + rInputMatrix(0,2)*rInvertedMatrix(2,0);
483 rInvertedMatrix /= rInputMatrixDet;
494 template<
class TMatrix1,
class TMatrix2>
496 const TMatrix1& rInputMatrix,
497 TMatrix2& rInvertedMatrix,
498 double& rInputMatrixDet
505 if (rInvertedMatrix.size1() != 4 || rInvertedMatrix.size2() != 4) {
506 rInvertedMatrix.resize(4, 4,
false);
511 rInvertedMatrix(0, 0) = -(rInputMatrix(1, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 1)) + rInputMatrix(1, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 1) + rInputMatrix(1, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 2) - rInputMatrix(1, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 2) - rInputMatrix(1, 2) * rInputMatrix(2, 1) * rInputMatrix(3, 3) + rInputMatrix(1, 1) * rInputMatrix(2, 2) * rInputMatrix(3, 3);
512 rInvertedMatrix(0, 1) = rInputMatrix(0, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 1) - rInputMatrix(0, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 1) - rInputMatrix(0, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 2) + rInputMatrix(0, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 2) + rInputMatrix(0, 2) * rInputMatrix(2, 1) * rInputMatrix(3, 3) - rInputMatrix(0, 1) * rInputMatrix(2, 2) * rInputMatrix(3, 3);
513 rInvertedMatrix(0, 2) = -(rInputMatrix(0, 3) * rInputMatrix(1, 2) * rInputMatrix(3, 1)) + rInputMatrix(0, 2) * rInputMatrix(1, 3) * rInputMatrix(3, 1) + rInputMatrix(0, 3) * rInputMatrix(1, 1) * rInputMatrix(3, 2) - rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(3, 2) - rInputMatrix(0, 2) * rInputMatrix(1, 1) * rInputMatrix(3, 3) + rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(3, 3);
514 rInvertedMatrix(0, 3) = rInputMatrix(0, 3) * rInputMatrix(1, 2) * rInputMatrix(2, 1) - rInputMatrix(0, 2) * rInputMatrix(1, 3) * rInputMatrix(2, 1) - rInputMatrix(0, 3) * rInputMatrix(1, 1) * rInputMatrix(2, 2) + rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(2, 2) + rInputMatrix(0, 2) * rInputMatrix(1, 1) * rInputMatrix(2, 3) - rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(2, 3);
517 rInvertedMatrix(1, 0) = rInputMatrix(1, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 0) - rInputMatrix(1, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 0) - rInputMatrix(1, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 2) + rInputMatrix(1, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 2) + rInputMatrix(1, 2) * rInputMatrix(2, 0) * rInputMatrix(3, 3) - rInputMatrix(1, 0) * rInputMatrix(2, 2) * rInputMatrix(3, 3);
518 rInvertedMatrix(1, 1) = -(rInputMatrix(0, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 0)) + rInputMatrix(0, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 0) + rInputMatrix(0, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 2) - rInputMatrix(0, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 2) - rInputMatrix(0, 2) * rInputMatrix(2, 0) * rInputMatrix(3, 3) + rInputMatrix(0, 0) * rInputMatrix(2, 2) * rInputMatrix(3, 3);
519 rInvertedMatrix(1, 2) = rInputMatrix(0, 3) * rInputMatrix(1, 2) * rInputMatrix(3, 0) - rInputMatrix(0, 2) * rInputMatrix(1, 3) * rInputMatrix(3, 0) - rInputMatrix(0, 3) * rInputMatrix(1, 0) * rInputMatrix(3, 2) + rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(3, 2) + rInputMatrix(0, 2) * rInputMatrix(1, 0) * rInputMatrix(3, 3) - rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(3, 3);
520 rInvertedMatrix(1, 3) = -(rInputMatrix(0, 3) * rInputMatrix(1, 2) * rInputMatrix(2, 0)) + rInputMatrix(0, 2) * rInputMatrix(1, 3) * rInputMatrix(2, 0) + rInputMatrix(0, 3) * rInputMatrix(1, 0) * rInputMatrix(2, 2) - rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(2, 2) - rInputMatrix(0, 2) * rInputMatrix(1, 0) * rInputMatrix(2, 3) + rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(2, 3);
523 rInvertedMatrix(2, 0) = -(rInputMatrix(1, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 0)) + rInputMatrix(1, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 0) + rInputMatrix(1, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 1) - rInputMatrix(1, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 1) - rInputMatrix(1, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 3) + rInputMatrix(1, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 3);
524 rInvertedMatrix(2, 1) = rInputMatrix(0, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 0) - rInputMatrix(0, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 0) - rInputMatrix(0, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 1) + rInputMatrix(0, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 1) + rInputMatrix(0, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 3) - rInputMatrix(0, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 3);
525 rInvertedMatrix(2, 2) = -(rInputMatrix(0, 3) * rInputMatrix(1, 1) * rInputMatrix(3, 0)) + rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(3, 0) + rInputMatrix(0, 3) * rInputMatrix(1, 0) * rInputMatrix(3, 1) - rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(3, 1) - rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(3, 3) + rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(3, 3);
526 rInvertedMatrix(2, 3) = rInputMatrix(0, 3) * rInputMatrix(1, 1) * rInputMatrix(2, 0) - rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(2, 0) - rInputMatrix(0, 3) * rInputMatrix(1, 0) * rInputMatrix(2, 1) + rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(2, 1) + rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(2, 3) - rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(2, 3);
529 rInvertedMatrix(3, 0) = rInputMatrix(1, 2) * rInputMatrix(2, 1) * rInputMatrix(3, 0) - rInputMatrix(1, 1) * rInputMatrix(2, 2) * rInputMatrix(3, 0) - rInputMatrix(1, 2) * rInputMatrix(2, 0) * rInputMatrix(3, 1) + rInputMatrix(1, 0) * rInputMatrix(2, 2) * rInputMatrix(3, 1) + rInputMatrix(1, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 2) - rInputMatrix(1, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 2);
530 rInvertedMatrix(3, 1) = -(rInputMatrix(0, 2) * rInputMatrix(2, 1) * rInputMatrix(3, 0)) + rInputMatrix(0, 1) * rInputMatrix(2, 2) * rInputMatrix(3, 0) + rInputMatrix(0, 2) * rInputMatrix(2, 0) * rInputMatrix(3, 1) - rInputMatrix(0, 0) * rInputMatrix(2, 2) * rInputMatrix(3, 1) - rInputMatrix(0, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 2) + rInputMatrix(0, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 2);
531 rInvertedMatrix(3, 2) = rInputMatrix(0, 2) * rInputMatrix(1, 1) * rInputMatrix(3, 0) - rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(3, 0) - rInputMatrix(0, 2) * rInputMatrix(1, 0) * rInputMatrix(3, 1) + rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(3, 1) + rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(3, 2) - rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(3, 2);
532 rInvertedMatrix(3, 3) = -(rInputMatrix(0, 2) * rInputMatrix(1, 1) * rInputMatrix(2, 0)) + rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(2, 0) + rInputMatrix(0, 2) * rInputMatrix(1, 0) * rInputMatrix(2, 1) - rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(2, 1) - rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(2, 2) + rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(2, 2);
535 rInputMatrixDet = rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 0) - rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 0) - rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(2, 2) * rInputMatrix(3, 1) + rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(2, 3) * rInputMatrix(3, 1) - rInputMatrix(0, 1) * rInputMatrix(1, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 2) + rInputMatrix(0, 0) * rInputMatrix(1, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 2) + rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 2) - rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 2) + rInputMatrix(0, 3) * (rInputMatrix(1, 2) * rInputMatrix(2, 1) * rInputMatrix(3, 0) - rInputMatrix(1, 1) * rInputMatrix(2, 2) * rInputMatrix(3, 0) - rInputMatrix(1, 2) * rInputMatrix(2, 0) * rInputMatrix(3, 1) + rInputMatrix(1, 0) * rInputMatrix(2, 2) * rInputMatrix(3, 1) + rInputMatrix(1, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 2) - rInputMatrix(1, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 2)) + (rInputMatrix(0, 1) * rInputMatrix(1, 2) * rInputMatrix(2, 0) - rInputMatrix(0, 0) * rInputMatrix(1, 2) * rInputMatrix(2, 1) - rInputMatrix(0, 1) * rInputMatrix(1, 0) * rInputMatrix(2, 2) + rInputMatrix(0, 0) * rInputMatrix(1, 1) * rInputMatrix(2, 2)) * rInputMatrix(3, 3) + rInputMatrix(0, 2) * (-(rInputMatrix(1, 3) * rInputMatrix(2, 1) * rInputMatrix(3, 0)) + rInputMatrix(1, 1) * rInputMatrix(2, 3) * rInputMatrix(3, 0) + rInputMatrix(1, 3) * rInputMatrix(2, 0) * rInputMatrix(3, 1) - rInputMatrix(1, 0) * rInputMatrix(2, 3) * rInputMatrix(3, 1) - rInputMatrix(1, 1) * rInputMatrix(2, 0) * rInputMatrix(3, 3) + rInputMatrix(1, 0) * rInputMatrix(2, 1) * rInputMatrix(3, 3));
538 rInvertedMatrix /= rInputMatrixDet;
548 template<
class TMatrixType>
549 static inline double Det2(
const TMatrixType& rA)
553 return (rA(0,0)*rA(1,1)-rA(0,1)*rA(1,0));
561 template<
class TMatrixType>
562 static inline double Det3(
const TMatrixType& rA)
567 const double a = rA(1,1)*rA(2,2) - rA(1,2)*rA(2,1);
568 const double b = rA(1,0)*rA(2,2) - rA(1,2)*rA(2,0);
569 const double c = rA(1,0)*rA(2,1) - rA(1,1)*rA(2,0);
571 return rA(0,0)*
a - rA(0,1)*
b + rA(0,2)*
c;
579 template<
class TMatrixType>
580 static inline double Det4(
const TMatrixType& rA)
584 const double det = rA(0,1)*rA(1,3)*rA(2,2)*rA(3,0)-rA(0,1)*rA(1,2)*rA(2,3)*rA(3,0)-rA(0,0)*rA(1,3)*rA(2,2)*rA(3,1)+rA(0,0)*rA(1,2)*rA(2,3)*rA(3,1)
585 -rA(0,1)*rA(1,3)*rA(2,0)*rA(3,2)+rA(0,0)*rA(1,3)*rA(2,1)*rA(3,2)+rA(0,1)*rA(1,0)*rA(2,3)*rA(3,2)-rA(0,0)*rA(1,1)*rA(2,3)*rA(3,2)+rA(0,3)*(rA(1,2)*rA(2,1)*rA(3,0)-rA(1,1)*rA(2,2)*rA(3,0)-rA(1,2)*rA(2,0)*rA(3,1)+rA(1,0)*rA(2,2)*rA(3,1)+rA(1,1)*rA(2,0)*rA(3,2)
586 -rA(1,0)*rA(2,1)*rA(3,2))+(rA(0,1)*rA(1,2)*rA(2,0)-rA(0,0)*rA(1,2)*rA(2,1)-rA(0,1)*rA(1,0)*rA(2,2)+rA(0,0)*rA(1,1)*rA(2,2))*rA(3,3)+rA(0,2)*(-(rA(1,3)*rA(2,1)*rA(3,0))+rA(1,1)*rA(2,3)*rA(3,0)+rA(1,3)*rA(2,0)*rA(3,1)-rA(1,0)*rA(2,3)*rA(3,1)-rA(1,1)*rA(2,0)*rA(3,3)+rA(1,0)*rA(2,1)*rA(3,3));
596 template<
class TMatrixType>
597 static inline double Det(
const TMatrixType& rA)
601 switch (rA.size1()) {
610 using namespace boost::numeric::ublas;
611 typedef permutation_matrix<SizeType> pmatrix;
613 pmatrix pm(Aux.size1());
614 bool singular = lu_factorize(Aux,pm);
622 det *= std::pow(-1.0, ki) * Aux(
i,
i);
633 template<
class TMatrixType>
636 if (rA.size1() == rA.size2()) {
638 }
else if (rA.size1() < rA.size2()) {
640 return std::sqrt(Det(AAT));
643 return std::sqrt(Det(ATA));
659 return (
a[0]*
b[0] +
a[1]*
b[1] +
a[2]*
b[2]);
670 const Vector& rFirstVector,
671 const Vector& rSecondVector
677 while(
i != rFirstVector.
end()) {
690 template<
class TVectorType>
691 static inline double Norm3(
const TVectorType&
a)
693 double temp = std::pow(
a[0],2) + std::pow(
a[1],2) + std::pow(
a[2],2);
707 while(
i !=
a.end()) {
711 return std::sqrt(
temp);
732 double sqr_sum_scaled {1};
734 for (
auto it =
a.begin(); it !=
a.end(); ++it) {
738 const double abs_x = std::abs(
x);
741 const double f = scale / abs_x;
742 sqr_sum_scaled = sqr_sum_scaled * (
f *
f) + 1.0;
746 sqr_sum_scaled +=
x *
x;
751 return scale * std::sqrt(sqr_sum_scaled);
769 c[0] =
a[1]*
b[2] -
a[2]*
b[1];
770 c[1] =
a[2]*
b[0] -
a[0]*
b[2];
771 c[2] =
a[0]*
b[1] -
a[1]*
b[0];
781 template<
class T1,
class T2>
782 static inline typename std::enable_if<std::is_same<T1, T2>::value,
bool>
::type CheckIsAlias(T1& value1, T2& value2)
784 return value1 == value2;
792 template<
class T1,
class T2>
793 static inline typename std::enable_if<!std::is_same<T1, T2>::value,
bool>
::type CheckIsAlias(T1& value1, T2& value2)
805 template<
class T1,
class T2 ,
class T3>
807 if (
c.size() != 3)
c.resize(3);
810 <<
"The size of the vectors is different of 3: "
811 <<
a <<
", " <<
b <<
" and " <<
c << std::endl;
813 <<
"Aliasing between the output parameter and the first "
814 <<
"input parameter" << std::endl;
816 <<
"the output parameter and the second input parameter" << std::endl;
818 c[0] =
a[1]*
b[2] -
a[2]*
b[1];
819 c[1] =
a[2]*
b[0] -
a[0]*
b[2];
820 c[2] =
a[0]*
b[1] -
a[1]*
b[0];
830 template<
class T1,
class T2 ,
class T3>
835 <<
"norm is 0 when making the UnitCrossProduct of the vectors "
836 <<
a <<
" and " <<
b << std::endl;
847 template<
class T1,
class T2 ,
class T3>
850 OrthonormalBasisHughesMoeller(
c,
a,
b);
852 OrthonormalBasisFrisvad(
c,
a,
b);
854 OrthonormalBasisNaive(
c,
a,
b);
864 template<
class T1,
class T2 ,
class T3>
868 if(std::abs(
c[0]) > std::abs(
c[2])) {
878 UnitCrossProduct(
a,
b ,
c);
888 template<
class T1,
class T2 ,
class T3>
891 if ((
c[2] + 1.0) > 1.0e4 * ZeroTolerance) {
892 a[0] = 1.0 - std::pow(
c[0], 2)/(1.0 +
c[2]);
893 a[1] = - (
c[0] *
c[1])/(1.0 +
c[2]);
895 const double norm_a =
norm_2(
a);
897 b[0] = - (
c[0] *
c[1])/(1.0 +
c[2]);
898 b[1] = 1.0 - std::pow(
c[1], 2)/(1.0 +
c[2]);
900 const double norm_b =
norm_2(
b);
919 template<
class T1,
class T2 ,
class T3>
934 UnitCrossProduct(
b,
c,
a);
942 template<
class T1,
class T2>
944 const T1 aux_1 = rV1 *
norm_2(rV2);
945 const T2 aux_2 =
norm_2(rV1) * rV2;
946 const double num =
norm_2(aux_1 - aux_2);
947 const double denom =
norm_2(aux_1 + aux_2);
948 return 2.0 * std::atan2( num , denom);
987 template<
class TMatrixType1,
class TMatrixType2>
989 TMatrixType1& rDestination,
990 const TMatrixType2& rInputMatrix,
999 rDestination(InitialRow+
i, InitialCol+
j) += rInputMatrix(
i,
j);
1012 template<
class TVectorType1,
class TVectorType2>
1014 TVectorType1& rDestination,
1015 const TVectorType2& rInputVector,
1022 rDestination[InitialIndex+
i] += rInputVector[
i];
1046 rDestination(InitialRow+
i, InitialCol+
j) -= rInputMatrix(
i,
j);
1073 rDestination(InitialRow+
i, InitialCol+
j) = rInputMatrix(
i,
j);
1094 const SizeType size = rReducedMatrix.size2();
1099 rowindex =
i * Dimension;
1101 colindex =
j * Dimension;
1102 for(
IndexType ii = 0; ii < Dimension; ++ii) {
1103 rDestination(rowindex+ii, colindex+ii) = rReducedMatrix(
i,
j);
1125 const SizeType size = rReducedMatrix.size2();
1130 rowindex =
i * Dimension;
1132 colindex =
j * Dimension;
1133 for(
IndexType ii = 0; ii < Dimension; ++ii) {
1134 rDestination(rowindex+ii, colindex+ii) += rReducedMatrix(
i,
j);
1173 template<
class TVector,
class TMatrixType = MatrixType>
1178 const SizeType matrix_size = rStressVector.size() == 3 ? 2 : 3;
1179 TMatrixType stress_tensor(matrix_size, matrix_size);
1181 if (rStressVector.size()==3) {
1182 stress_tensor(0,0) = rStressVector[0];
1183 stress_tensor(0,1) = rStressVector[2];
1184 stress_tensor(1,0) = rStressVector[2];
1185 stress_tensor(1,1) = rStressVector[1];
1186 }
else if (rStressVector.size()==4) {
1187 stress_tensor(0,0) = rStressVector[0];
1188 stress_tensor(0,1) = rStressVector[3];
1189 stress_tensor(0,2) = 0.0;
1190 stress_tensor(1,0) = rStressVector[3];
1191 stress_tensor(1,1) = rStressVector[1];
1192 stress_tensor(1,2) = 0.0;
1193 stress_tensor(2,0) = 0.0;
1194 stress_tensor(2,1) = 0.0;
1195 stress_tensor(2,2) = rStressVector[2];
1196 }
else if (rStressVector.size()==6) {
1197 stress_tensor(0,0) = rStressVector[0];
1198 stress_tensor(0,1) = rStressVector[3];
1199 stress_tensor(0,2) = rStressVector[5];
1200 stress_tensor(1,0) = rStressVector[3];
1201 stress_tensor(1,1) = rStressVector[1];
1202 stress_tensor(1,2) = rStressVector[4];
1203 stress_tensor(2,0) = rStressVector[5];
1204 stress_tensor(2,1) = rStressVector[4];
1205 stress_tensor(2,2) = rStressVector[2];
1208 return stress_tensor;
1224 template<
class TVector,
class TMatrixType = MatrixType>
1229 const SizeType matrix_size = rVector.size() == 3 ? 2 : 3;
1230 TMatrixType tensor(matrix_size, matrix_size);
1232 if (rVector.size() == 3) {
1233 tensor(0,0) = rVector[0];
1234 tensor(0,1) = rVector[2];
1235 tensor(1,0) = rVector[2];
1236 tensor(1,1) = rVector[1];
1237 }
else if (rVector.size() == 4) {
1238 tensor(0,0) = rVector[0];
1239 tensor(0,1) = rVector[3];
1241 tensor(1,0) = rVector[3];
1242 tensor(1,1) = rVector[1];
1246 tensor(2,2) = rVector[2];
1247 }
else if (rVector.size() == 6) {
1248 tensor(0,0) = rVector[0];
1249 tensor(0,1) = rVector[3];
1250 tensor(0,2) = rVector[5];
1251 tensor(1,0) = rVector[3];
1252 tensor(1,1) = rVector[1];
1253 tensor(1,2) = rVector[4];
1254 tensor(2,0) = rVector[5];
1255 tensor(2,1) = rVector[4];
1256 tensor(2,2) = rVector[2];
1269 static inline int Sign(
const double& ThisDataType)
1272 const double&
x = ThisDataType;
1273 return (
x > 0) ? 1 : ((
x < 0) ? -1 : 0);
1289 template<
class TVector,
class TMatrixType = MatrixType>
1294 const SizeType matrix_size = rStrainVector.size() == 3 ? 2 : 3;
1295 TMatrixType strain_tensor(matrix_size, matrix_size);
1297 if (rStrainVector.size()==3) {
1298 strain_tensor(0,0) = rStrainVector[0];
1299 strain_tensor(0,1) = 0.5*rStrainVector[2];
1300 strain_tensor(1,0) = 0.5*rStrainVector[2];
1301 strain_tensor(1,1) = rStrainVector[1];
1302 }
else if (rStrainVector.size()==4) {
1303 strain_tensor(0,0) = rStrainVector[0];
1304 strain_tensor(0,1) = 0.5*rStrainVector[3];
1305 strain_tensor(0,2) = 0;
1306 strain_tensor(1,0) = 0.5*rStrainVector[3];
1307 strain_tensor(1,1) = rStrainVector[1];
1308 strain_tensor(1,2) = 0;
1309 strain_tensor(2,0) = 0;
1310 strain_tensor(2,1) = 0;
1311 strain_tensor(2,2) = rStrainVector[2];
1312 }
else if (rStrainVector.size()==6) {
1313 strain_tensor(0,0) = rStrainVector[0];
1314 strain_tensor(0,1) = 0.5*rStrainVector[3];
1315 strain_tensor(0,2) = 0.5*rStrainVector[5];
1316 strain_tensor(1,0) = 0.5*rStrainVector[3];
1317 strain_tensor(1,1) = rStrainVector[1];
1318 strain_tensor(1,2) = 0.5*rStrainVector[4];
1319 strain_tensor(2,0) = 0.5*rStrainVector[5];
1320 strain_tensor(2,1) = 0.5*rStrainVector[4];
1321 strain_tensor(2,2) = rStrainVector[2];
1324 return strain_tensor;
1343 template<
class TMatrixType,
class TVector = Vector>
1345 const TMatrixType& rStrainTensor,
1352 if(rStrainTensor.size1() == 2) {
1354 }
else if(rStrainTensor.size1() == 3) {
1359 Vector strain_vector(rSize);
1362 strain_vector[0] = rStrainTensor(0,0);
1363 strain_vector[1] = rStrainTensor(1,1);
1364 strain_vector[2] = 2.0*rStrainTensor(0,1);
1365 }
else if (rSize == 4) {
1366 strain_vector[0] = rStrainTensor(0,0);
1367 strain_vector[1] = rStrainTensor(1,1);
1368 strain_vector[2] = rStrainTensor(2,2);
1369 strain_vector[3] = 2.0*rStrainTensor(0,1);
1370 }
else if (rSize == 6) {
1371 strain_vector[0] = rStrainTensor(0,0);
1372 strain_vector[1] = rStrainTensor(1,1);
1373 strain_vector[2] = rStrainTensor(2,2);
1374 strain_vector[3] = 2.0*rStrainTensor(0,1);
1375 strain_vector[4] = 2.0*rStrainTensor(1,2);
1376 strain_vector[5] = 2.0*rStrainTensor(0,2);
1379 return strain_vector;
1398 template<
class TMatrixType,
class TVector = Vector>
1400 const TMatrixType& rStressTensor,
1407 if(rStressTensor.size1() == 2) {
1409 }
else if(rStressTensor.size1() == 3) {
1414 TVector stress_vector(rSize);
1417 stress_vector[0] = rStressTensor(0,0);
1418 stress_vector[1] = rStressTensor(1,1);
1419 stress_vector[2] = rStressTensor(0,1);
1420 }
else if (rSize == 4) {
1421 stress_vector[0] = rStressTensor(0,0);
1422 stress_vector[1] = rStressTensor(1,1);
1423 stress_vector[2] = rStressTensor(2,2);
1424 stress_vector[3] = rStressTensor(0,1);
1425 }
else if (rSize == 6) {
1426 stress_vector[0] = rStressTensor(0,0);
1427 stress_vector[1] = rStressTensor(1,1);
1428 stress_vector[2] = rStressTensor(2,2);
1429 stress_vector[3] = rStressTensor(0,1);
1430 stress_vector[4] = rStressTensor(1,2);
1431 stress_vector[5] = rStressTensor(0,2);
1434 return stress_vector;
1450 template<
class TMatrixType,
class TVector = Vector>
1452 const TMatrixType& rTensor,
1459 if(rTensor.size1() == 2) {
1461 }
else if(rTensor.size1() == 3) {
1469 vector[0]= rTensor(0,0);
1470 vector[1]= rTensor(1,1);
1471 vector[2]= rTensor(0,1);
1473 }
else if (rSize==4) {
1474 vector[0]= rTensor(0,0);
1475 vector[1]= rTensor(1,1);
1476 vector[2]= rTensor(2,2);
1477 vector[3]= rTensor(0,1);
1478 }
else if (rSize==6) {
1479 vector[0]= rTensor(0,0);
1480 vector[1]= rTensor(1,1);
1481 vector[2]= rTensor(2,2);
1482 vector[3]= rTensor(0,1);
1483 vector[4]= rTensor(1,2);
1484 vector[5]= rTensor(0,2);
1501 template<
class TMatrixType1,
class TMatrixType2,
class TMatrixType3>
1504 const TMatrixType2& rD,
1505 const TMatrixType3& rB
1512 if (rA.size1() != size1 || rA.size2() != size2)
1513 rA.resize(size1, size2,
false);
1522 const double Dkl = rD(
k,
l);
1524 const double DklBlj = Dkl * rB(
l,
j);
1526 rA(
i,
j) += rB(
k,
i) * DklBlj;
1542 template<
class TMatrixType1,
class TMatrixType2,
class TMatrixType3>
1545 const TMatrixType2& rD,
1546 const TMatrixType3& rB
1553 if (rA.size1() != size1 || rA.size2() != size2)
1554 rA.resize(size1, size2,
false);
1563 const double Dkl = rD(
k,
l);
1565 const double DklBjl = Dkl * rB(
j,
l);
1567 rA(
i,
j) += rB(
i,
k) * DklBjl;
1586 template<
class TMatrixType1,
class TMatrixType2>
1588 const TMatrixType1& rA,
1589 TMatrixType2& rEigenVectorsMatrix,
1590 TMatrixType2& rEigenValuesMatrix,
1591 const double Tolerance = 1.0e-18,
1595 bool is_converged =
false;
1599 if (rEigenVectorsMatrix.size1() != size || rEigenVectorsMatrix.size2() != size)
1600 rEigenVectorsMatrix.resize(size, size,
false);
1601 if (rEigenValuesMatrix.size1() != size || rEigenValuesMatrix.size2() != size)
1602 rEigenValuesMatrix.resize(size, size,
false);
1605 noalias(rEigenVectorsMatrix) = identity_matrix;
1606 noalias(rEigenValuesMatrix) = rA;
1609 TMatrixType2 aux_A, aux_V_matrix, rotation_matrix;
1613 aux_A.resize(size,size,
false);
1614 aux_V_matrix.resize(size,size,
false);
1615 rotation_matrix.resize(size,size,
false);
1617 for(
IndexType iterations = 0; iterations < MaxIterations; ++iterations) {
1618 is_converged =
true;
1626 if((std::abs(rEigenValuesMatrix(
i,
j)) >
a ) && (std::abs(rEigenValuesMatrix(
i,
j)) > Tolerance)) {
1627 a = std::abs(rEigenValuesMatrix(
i,
j));
1630 is_converged =
false;
1640 gamma = (rEigenValuesMatrix(index2, index2)-rEigenValuesMatrix(index1, index1)) / (2 * rEigenValuesMatrix(index1, index2));
1643 if(std::abs(
gamma) > Tolerance && std::abs(
gamma)< (1.0/Tolerance)) {
1646 if (std::abs(
gamma) >= (1.0/Tolerance)) {
1651 c = 1.0 / (std::sqrt(1.0 +
u *
u));
1653 teta = s / (1.0 +
c);
1656 noalias(aux_A) = rEigenValuesMatrix;
1657 aux_A(index2, index2) = rEigenValuesMatrix(index2,index2) +
u * rEigenValuesMatrix(index1, index2);
1658 aux_A(index1, index1) = rEigenValuesMatrix(index1,index1) -
u * rEigenValuesMatrix(index1, index2);
1659 aux_A(index1, index2) = 0.0;
1660 aux_A(index2, index1) = 0.0;
1663 if((
i!= index1) && (
i!= index2)) {
1664 aux_A(index2,
i) = rEigenValuesMatrix(index2,
i) + s * (rEigenValuesMatrix(index1,
i)- teta * rEigenValuesMatrix(index2,
i));
1665 aux_A(
i, index2) = rEigenValuesMatrix(index2,
i) + s * (rEigenValuesMatrix(index1,
i)- teta * rEigenValuesMatrix(index2,
i));
1666 aux_A(index1,
i) = rEigenValuesMatrix(index1,
i) - s * (rEigenValuesMatrix(index2,
i) + teta * rEigenValuesMatrix(index1,
i));
1667 aux_A(
i, index1) = rEigenValuesMatrix(index1,
i) - s * (rEigenValuesMatrix(index2,
i) + teta * rEigenValuesMatrix(index1,
i));
1671 noalias(rEigenValuesMatrix) = aux_A;
1674 noalias(rotation_matrix) = identity_matrix;
1675 rotation_matrix(index2, index1) = -s;
1676 rotation_matrix(index1, index2) = s;
1677 rotation_matrix(index1, index1) =
c;
1678 rotation_matrix(index2, index2) =
c;
1685 aux_V_matrix(
i,
j) += rEigenVectorsMatrix(
i,
k) * rotation_matrix(
k,
j);
1689 noalias(rEigenVectorsMatrix) = aux_V_matrix;
1692 KRATOS_WARNING_IF(
"MathUtils::EigenSystem", !is_converged) <<
"Spectral decomposition not converged " << std::endl;
1694 return is_converged;
1709 template<SizeType TDim>
1710 KRATOS_DEPRECATED_MESSAGE(
"Please use GaussSeidelEigenSystem() instead. Note the resulting EigenVectors matrix is transposed respect GaussSeidelEigenSystem()")
1711 static inline
bool EigenSystem(
1719 const bool is_converged = GaussSeidelEigenSystem(rA, rEigenVectorsMatrix, rEigenValuesMatrix, Tolerance, MaxIterations);
1724 rEigenVectorsMatrix(
i,
j) = V_matrix(
j,
i);
1728 return is_converged;
1746 template<
class TMatrixType1,
class TMatrixType2>
1747 static inline bool MatrixSquareRoot(
1748 const TMatrixType1 &rA,
1749 TMatrixType2 &rMatrixSquareRoot,
1750 const double Tolerance = 1.0e-18,
1755 TMatrixType2 eigenvectors_matrix, eigenvalues_matrix;
1756 const bool is_converged = GaussSeidelEigenSystem(rA, eigenvectors_matrix, eigenvalues_matrix, Tolerance, MaxIterations);
1757 KRATOS_WARNING_IF(
"MatrixSquareRoot", !is_converged) <<
"GaussSeidelEigenSystem did not converge.\n";
1760 SizeType size = eigenvalues_matrix.size1();
1762 KRATOS_ERROR_IF(eigenvalues_matrix(
i,
i) < 0) <<
"Eigenvalue " <<
i <<
" is negative. Square root matrix cannot be computed" << std::endl;
1763 eigenvalues_matrix(
i,
i) = std::sqrt(eigenvalues_matrix(
i,
i));
1767 BDBtProductOperation(rMatrixSquareRoot, eigenvalues_matrix, eigenvectors_matrix);
1769 return is_converged;
1776 template<
class TIntegerType>
1777 static inline TIntegerType
Factorial(
const TIntegerType Number)
1782 TIntegerType
k = Number;
1783 for (TIntegerType
i = Number - 1;
i > 0; --
i){
1795 template<
class TMatrixType>
1797 const TMatrixType& rMatrix,
1798 TMatrixType& rExponentialMatrix,
1799 const double Tolerance = 1000.0*ZeroTolerance,
1808 TMatrixType exponent_matrix = rMatrix;
1809 TMatrixType aux_matrix;
1811 while (series_term < MaxTerms) {
1812 noalias(aux_matrix) =
prod(exponent_matrix, rMatrix);
1813 noalias(exponent_matrix) = aux_matrix;
1814 factorial = Factorial(series_term);
1815 noalias(rExponentialMatrix) += exponent_matrix / factorial;
1816 const double norm_series_term = std::abs(
norm_frobenius(exponent_matrix) / factorial);
1817 if (norm_series_term < Tolerance)
iterator end()
Definition: amatrix_interface.h:243
iterator begin()
Definition: amatrix_interface.h:241
AMatrix::RandomAccessIterator< const double > const_iterator
Definition: amatrix_interface.h:53
Various mathematical utilitiy functions.
Definition: math_utils.h:62
static void ExpandAndAddReducedMatrix(MatrixType &rDestination, const MatrixType &rReducedMatrix, const SizeType Dimension)
Performs the Kroneker product of the Reduced Matrix with the identity matrix of size "dimension" ADDI...
Definition: math_utils.h:1117
static void AddVector(TVectorType1 &rDestination, const TVectorType2 &rInputVector, const IndexType InitialIndex)
"rInputVector" is ADDED to "Destination" vector starting from InitialIndex of the destination matrix
Definition: math_utils.h:1013
static double Dot3(const Vector &a, const Vector &b)
Performs the dot product of two vectors of dimension 3.
Definition: math_utils.h:654
std::size_t SizeType
The size type.
Definition: math_utils.h:75
static TMatrixType VectorToSymmetricTensor(const TVector &rVector)
Transforms a vector into a symmetric matrix.
Definition: math_utils.h:1225
static void InvertMatrix4(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet)
It inverts matrices of order 4.
Definition: math_utils.h:495
static TIntegerType Factorial(const TIntegerType Number)
Calculates the Factorial of a number k, Factorial = k!
Definition: math_utils.h:1777
static double StableNorm(const Vector &a)
Calculates the norm of vector "a" while avoiding underflow and overflow.
Definition: math_utils.h:720
static void InvertMatrix3(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet)
It inverts matrices of order 3.
Definition: math_utils.h:449
static void GeneralizedInvertMatrix(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
It inverts non square matrices (https://en.wikipedia.org/wiki/Inverse_element#Matrices)
Definition: math_utils.h:274
std::size_t IndexType
The index type.
Definition: math_utils.h:78
static void ExpandReducedMatrix(MatrixType &rDestination, const MatrixType &rReducedMatrix, const SizeType Dimension)
Performs the Kroneker product of the Reduced Matrix with the identity matrix of size "dimension".
Definition: math_utils.h:1086
static TMatrixType StressVectorToTensor(const TVector &rStressVector)
Transforms a stess vector into a matrix. Stresses are assumed to be stored in the following way: for...
Definition: math_utils.h:1174
static double Norm3(const TVectorType &a)
Calculates the norm of vector "a" which is assumed to be of size 3.
Definition: math_utils.h:691
static void AddMatrix(TMatrixType1 &rDestination, const TMatrixType2 &rInputMatrix, const IndexType InitialRow, const IndexType InitialCol)
"rInputMatrix" is ADDED to "Destination" matrix starting from InitialRow and InitialCol of the destin...
Definition: math_utils.h:988
static void InvertMatrix2(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet)
It inverts matrices of order 2.
Definition: math_utils.h:416
static void InvertMatrix(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
It inverts matrices of order 2, 3 and 4.
Definition: math_utils.h:328
static Vector StrainTensorToVector(const TMatrixType &rStrainTensor, SizeType rSize=0)
Transforms a given symmetric Strain Tensor to Voigt Notation:
Definition: math_utils.h:1344
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
static void OrthonormalBasisFrisvad(const T1 &c, T2 &a, T3 &b)
This computes a orthonormal basis from a given vector (Frisvad method)
Definition: math_utils.h:889
static double DegreesToRadians(double AngleInDegrees)
Definition: math_utils.h:1824
static std::enable_if<!std::is_same< T1, T2 >::value, bool >::type CheckIsAlias(T1 &value1, T2 &value2)
Checks there is aliasing.
Definition: math_utils.h:793
static TVector StressTensorToVector(const TMatrixType &rStressTensor, SizeType rSize=0)
Transforms a given symmetric Stress Tensor to Voigt Notation:
Definition: math_utils.h:1399
static double Det(const TMatrixType &rA)
Calculates the determinant of a matrix of a square matrix of any size (no check performed on release ...
Definition: math_utils.h:597
static void UnitCrossProduct(T1 &c, const T2 &a, const T3 &b)
Performs the unitary cross product of the two input vectors a,b.
Definition: math_utils.h:831
static double Norm(const Vector &a)
Calculates the norm of vector "a".
Definition: math_utils.h:703
static double VectorsAngle(const T1 &rV1, const T2 &rV2)
Computes the angle between two vectors in 3D.
Definition: math_utils.h:943
static TMatrixType StrainVectorToTensor(const TVector &rStrainVector)
Transforms a strain vector into a matrix. Strains are assumed to be stored in the following way: for...
Definition: math_utils.h:1290
static void BtDBProductOperation(TMatrixType1 &rA, const TMatrixType2 &rD, const TMatrixType3 &rB)
Calculates the product operation B'DB.
Definition: math_utils.h:1502
static bool CheckConditionNumber(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, const double Tolerance=std::numeric_limits< double >::epsilon(), const bool ThrowError=true)
This method checks the condition number of amtrix.
Definition: math_utils.h:236
static double Cofactor(const TMatrixType &rMat, IndexType i, IndexType j)
Calculates the cofactor.
Definition: math_utils.h:142
static std::enable_if< std::is_same< T1, T2 >::value, bool >::type CheckIsAlias(T1 &value1, T2 &value2)
Checks there is aliasing.
Definition: math_utils.h:782
static MatrixType TensorProduct3(const Vector &a, const Vector &b)
Returns a matrix : A = a.tensorproduct.b.
Definition: math_utils.h:959
static double GeneralizedDet(const TMatrixType &rA)
Calculates the determinant of any matrix (no check performed on matrix size)
Definition: math_utils.h:634
static double Det3(const TMatrixType &rA)
Calculates the determinant of a matrix of dimension 3*3 (no check performed on matrix size)
Definition: math_utils.h:562
static TVector SymmetricTensorToVector(const TMatrixType &rTensor, SizeType rSize=0)
Transforms a given symmetric Tensor to Voigt Notation:
Definition: math_utils.h:1451
static void BDBtProductOperation(TMatrixType1 &rA, const TMatrixType2 &rD, const TMatrixType3 &rB)
Calculates the product operation BDB'.
Definition: math_utils.h:1543
static void OrthonormalBasis(const T1 &c, T2 &a, T3 &b, const IndexType Type=0)
This computes a orthonormal basis from a given vector (Frisvad method)
Definition: math_utils.h:848
static MatrixType CofactorMatrix(const TMatrixType &rMat)
Calculates the cofactor matrix.
Definition: math_utils.h:175
boost::numeric::ublas::indirect_array< DenseVector< std::size_t > > IndirectArrayType
The indirect array type.
Definition: math_utils.h:81
static double Det4(const TMatrixType &rA)
Calculates the determinant of a matrix of dimension 4*4 (no check performed on matrix size)
Definition: math_utils.h:580
static void CalculateExponentialOfMatrix(const TMatrixType &rMatrix, TMatrixType &rExponentialMatrix, const double Tolerance=1000.0 *ZeroTolerance, const SizeType MaxTerms=200)
Calculates the exponential of a matrix.
Definition: math_utils.h:1796
KRATOS_DEPRECATED_MESSAGE("Please use GaussSeidelEigenSystem() instead. Note the resulting EigenVectors matrix is transposed respect GaussSeidelEigenSystem()") static inline bool EigenSystem(const BoundedMatrix< double
Calculates the eigenvectors and eigenvalues of given symmetric TDimxTDim matrix.
static void WriteMatrix(MatrixType &rDestination, const MatrixType &rInputMatrix, const IndexType InitialRow, const IndexType InitialCol)
"rInputMatrix" is WRITTEN on "Destination" matrix starting from InitialRow and InitialCol of the dest...
Definition: math_utils.h:1062
static double Det2(const TMatrixType &rA)
Calculates the determinant of a matrix of dimension 2x2 (no check performed on matrix size)
Definition: math_utils.h:549
static void CrossProduct(T1 &c, const T2 &a, const T3 &b)
Performs the cross product of the two input vectors a,b.
Definition: math_utils.h:806
static int Sign(const double &ThisDataType)
Sign function.
Definition: math_utils.h:1269
static void VecAdd(Vector &rX, const double coeff, Vector &rY)
Performs rX += coeff*rY. no check on bounds is performed.
Definition: math_utils.h:1148
static double Dot(const Vector &rFirstVector, const Vector &rSecondVector)
Performs the dot product of two vectors of arbitrary size.
Definition: math_utils.h:669
static void SubtractMatrix(MatrixType &rDestination, const MatrixType &rInputMatrix, const IndexType InitialRow, const IndexType InitialCol)
"rInputMatrix" is SUBTRACTED to "rDestination" matrix starting from InitialRow and InitialCol of the ...
Definition: math_utils.h:1035
static bool GaussSeidelEigenSystem(const TMatrixType1 &rA, TMatrixType2 &rEigenVectorsMatrix, TMatrixType2 &rEigenValuesMatrix, const double Tolerance=1.0e-18, const SizeType MaxIterations=20)
Calculates the eigenvectors and eigenvalues of given symmetric matrix.
Definition: math_utils.h:1587
static double GetZeroTolerance()
This function returns the machine precision.
Definition: math_utils.h:102
static void OrthonormalBasisHughesMoeller(const T1 &c, T2 &a, T3 &b)
This computes a orthonormal basis from a given vector (Hughes Moeller method)
Definition: math_utils.h:865
static double Heron(double a, double b, double c)
In geometry, Heron's formula (sometimes called Hero's formula), named after Hero of Alexandria,...
Definition: math_utils.h:115
static void OrthonormalBasisNaive(const T1 &c, T2 &a, T3 &b)
This computes a orthonormal basis from a given vector (Naive method)
Definition: math_utils.h:920
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
constexpr double Pi
Definition: global_variables.h:25
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
AMatrix::IdentityMatrix< double > IdentityMatrix
Definition: amatrix_interface.h:564
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
TExpressionType::data_type norm_frobenius(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:687
list coeff
Definition: bombardelli_test.py:41
def CrossProduct(A, B)
Definition: define_wake_process_3d.py:13
f
Definition: generate_convection_diffusion_explicit_element.py:112
type
Definition: generate_gid_list_file.py:35
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
u
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:30
float gamma
Definition: generate_two_fluid_navier_stokes.py:131
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
tuple const
Definition: ode_solve.py:403
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
float temp
Definition: rotating_cone.py:85
A
Definition: sensitivityMatrix.py:70
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31