13 #if !defined(KRATOS_BEAM_MATH_UTILITIES)
14 #define KRATOS_BEAM_MATH_UTILITIES
56 template<
class TVector3>
67 (rQuaternion.
conjugate()).ToRotationMatrix(RotationMatrix);
69 rVector =
prod(RotationMatrix,rVector);
87 template<
class TVector3>
100 rVector =
prod(RotationMatrix,rVector);
117 template<
class TVector3>
123 if( rExponentialTensor.size1() != 3 )
124 rExponentialTensor.
resize(3, 3,
false);
141 template<
class TVector3>
147 if( rVector.size() != 3 )
148 rVector.resize(3,
false);
164 template<
class TVector3>
170 if( rCayleyTensor.size1() != 3 )
171 rCayleyTensor.
resize(3, 3,
false);
173 rCayleyTensor(0,0) = 0.5 * (4.0+rVector[0]*rVector[0]-rVector[1]*rVector[1]-rVector[2]*rVector[2]);
174 rCayleyTensor(1,1) = 0.5 * (4.0-rVector[0]*rVector[0]+rVector[1]*rVector[1]-rVector[2]*rVector[2]);
175 rCayleyTensor(2,2) = 0.5 * (4.0-rVector[0]*rVector[0]-rVector[1]*rVector[1]+rVector[2]*rVector[2]);
177 rCayleyTensor(0,1) = (rVector[0]*rVector[1]-2.0*rVector[2]);
178 rCayleyTensor(0,2) = (rVector[0]*rVector[2]+2.0*rVector[1]);
179 rCayleyTensor(1,2) = (rVector[1]*rVector[2]-2.0*rVector[0]);
181 rCayleyTensor(1,0) = (rVector[0]*rVector[1]+2.0*rVector[2]);
182 rCayleyTensor(2,0) = (rVector[0]*rVector[2]-2.0*rVector[1]);
183 rCayleyTensor(2,1) = (rVector[1]*rVector[2]+2.0*rVector[0]);
185 rCayleyTensor *= (2.0 / (4.0+rVector[0]*rVector[0]+rVector[1]*rVector[1]+rVector[2]*rVector[2]));
198 template<
class TVector3>
204 if( rVector.size() != 3 )
205 rVector.resize(3,
false);
208 Matrix CayI = rCayleyTensor + Identity;
209 Matrix CayII = rCayleyTensor - Identity;
215 Matrix SkewSymTensor = 2 *
prod( InvertCayI, CayII );
230 template<
class TVector3,
class TMatrix3>
236 if( rSkewSymmetricTensor.size1() != 3 )
237 rSkewSymmetricTensor.resize(3, 3,
false);
239 rSkewSymmetricTensor( 0, 0 ) = 0.0;
240 rSkewSymmetricTensor( 1, 1 ) = 0.0;
241 rSkewSymmetricTensor( 2, 2 ) = 0.0;
243 rSkewSymmetricTensor( 0, 1 ) = -rVector[2];
244 rSkewSymmetricTensor( 0, 2 ) = rVector[1];
245 rSkewSymmetricTensor( 1, 2 ) = -rVector[0];
247 rSkewSymmetricTensor( 1, 0 ) = rVector[2];
248 rSkewSymmetricTensor( 2, 0 ) = -rVector[1];
249 rSkewSymmetricTensor( 2, 1 ) = rVector[0];
261 template<
class TMatrix3,
class TVector3>
267 if( rVector.size() != 3 )
268 rVector.resize(3,
false);
270 rVector[0] = 0.5 * ( rSkewSymmetricTensor( 2, 1 ) - rSkewSymmetricTensor( 1, 2 ) );
271 rVector[1] = 0.5 * ( rSkewSymmetricTensor( 0, 2 ) - rSkewSymmetricTensor( 2, 0 ) );
272 rVector[2] = 0.5 * ( rSkewSymmetricTensor( 1, 0 ) - rSkewSymmetricTensor( 0, 1 ) );
312 if(
i==
j ||
j==
k ||
k==
i )
315 if( (
i==1 &&
j==2 &&
k==3) || (
i==2 &&
j==3 &&
k==1) || (
i==3 &&
j==1 &&
k==2) )
318 if( (
i==3 &&
j==2 &&
k==1) || (
i==1 &&
j==3 &&
k==2) || (
i==2 &&
j==1 &&
k==3) )
340 for(
unsigned int i=0;
i<rInputVector.size();
i++)
341 rOutputVector[InitialRow+
i] += rInputVector[
i];
360 for(
unsigned int i=0;
i<rInputVector.size();
i++)
361 rOutputVector[InitialRow+
i] -= rInputVector[
i];
378 template<
class TMatrix,
class TInputMatrix>
379 static inline void AddMatrix(TMatrix& rDestination,
const TInputMatrix& rInputMatrix,
const unsigned int rInitialRow,
const unsigned int rInitialCol)
382 for(
unsigned int i = 0;
i < rInputMatrix.size1();
i++)
384 for(
unsigned int j = 0;
j < rInputMatrix.size2();
j++)
386 rDestination(rInitialRow+
i, rInitialCol+
j) += rInputMatrix(
i,
j);
403 template<
class TMatrix,
class TInputMatrix>
404 static inline void SubtractMatrix(TMatrix& rDestination,
const TInputMatrix& rInputMatrix,
const unsigned int rInitialRow,
const unsigned int rInitialCol)
408 for(
unsigned int i = 0;
i<rInputMatrix.size1();
i++)
410 for(
unsigned int j = 0;
j<rInputMatrix.size2();
j++)
412 rDestination(rInitialRow+
i, rInitialCol+
j) -= rInputMatrix(
i,
j);
482 unsigned int MatSize = rMatrix.size1();
484 Matrix AuxiliarRotationMatrix(MatSize,MatSize);
488 for (
unsigned int kk=0; kk < MatSize; kk += 2)
490 for (
unsigned int i=0;
i<2;
i++)
492 for(
unsigned int j=0;
j<2;
j++)
494 AuxiliarRotationMatrix(
i+kk,
j+kk) = rLocalToGlobalMatrix(
i,
j);
500 Matrix aux_matrix(MatSize,MatSize);
501 noalias(aux_matrix) =
prod(AuxiliarRotationMatrix, rMatrix);
525 unsigned int MatSize = rVector.size();
527 Matrix AuxiliarRotationMatrix(MatSize,MatSize);
531 for (
unsigned int kk=0; kk < MatSize; kk += 2)
533 for (
unsigned int i=0;
i<2;
i++)
535 for(
unsigned int j=0;
j<2;
j++)
537 AuxiliarRotationMatrix(
i+kk,
j+kk) = rLocalToGlobalMatrix(
i,
j);
542 rVector =
prod(AuxiliarRotationMatrix, rVector);
610 unsigned int MatSize = rMatrix.size1();
612 Matrix AuxiliarRotationMatrix(MatSize,MatSize);
616 for (
unsigned int kk=0; kk < MatSize; kk += 3)
618 for (
unsigned int i=0;
i<3;
i++)
620 for(
unsigned int j=0;
j<3;
j++)
622 AuxiliarRotationMatrix(
i+kk,
j+kk) = rLocalToGlobalMatrix(
i,
j);
628 Matrix aux_matrix(MatSize,MatSize);
629 noalias(aux_matrix) =
prod(AuxiliarRotationMatrix, rMatrix);
653 unsigned int MatSize = rVector.size();
655 Matrix AuxiliarRotationMatrix(MatSize,MatSize);
659 for (
unsigned int kk=0; kk < MatSize; kk += 3)
661 for (
unsigned int i=0;
i<3;
i++)
663 for(
unsigned int j=0;
j<3;
j++)
665 AuxiliarRotationMatrix(
i+kk,
j+kk) = rLocalToGlobalMatrix(
i,
j);
670 rVector =
prod(AuxiliarRotationMatrix, rVector);
685 template<
class TVector3>
691 TVector3 LocalX = rLocalX;
698 if( rRotationMatrix.size1() != 3 )
699 rRotationMatrix.
resize(3, 3,
false);
702 for (
unsigned int i=0;
i<3;
i++)
704 rRotationMatrix(
i,0) = LocalX[
i];
705 rRotationMatrix(
i,1) = LocalY[
i];
706 rRotationMatrix(
i,2) = LocalZ[
i];
722 template<
class TVector3>
737 rLocalX /= VectorNorm;
740 double tolerance = 1.0/64.0;
741 if(fabs(rLocalX[0])< tolerance && fabs(rLocalX[1])< tolerance){
750 rLocalY /= VectorNorm;
756 if( VectorNorm != 0 )
757 rLocalZ /= VectorNorm;
773 template<
class TVector3>
779 TVector3 LocalX = rLocalX;
780 TVector3 LocalY = rLocalY;
786 if( rRotationMatrix.size1() != 3 )
787 rRotationMatrix.
resize(3, 3,
false);
790 for (
unsigned int i=0;
i<3;
i++)
792 rRotationMatrix(
i,0) = LocalX[
i];
793 rRotationMatrix(
i,1) = LocalY[
i];
794 rRotationMatrix(
i,2) = LocalZ[
i];
810 template<
class TVector3>
818 rLocalX /= VectorNorm;
823 rLocalY /= VectorNorm;
829 if( VectorNorm != 0 )
830 rLocalZ /= VectorNorm;
851 if( Determinant > 1.0001 || Determinant < 0.9999 ){
854 std::cout<<Name<<std::endl;
855 std::cout<<
" Warning Matrix is not orthogonal "<<Determinant<<std::endl;
856 std::cout<<
" Matrix: "<<rTensor<<std::endl;
857 std::cout<<
" Identity not matches "<<IdentitySearch<<std::endl;
Definition: beam_math_utilities.hpp:31
static void MapLocalToGlobal2D(const QuaternionType &rLocalToGlobalQuaternion, VectorType &rVector)
Definition: beam_math_utilities.hpp:452
Vector VectorType
Definition: beam_math_utilities.hpp:37
static void CalculateLocalAxesMatrix(const TVector3 &rLocalX, const TVector3 &rLocalY, MatrixType &rRotationMatrix)
Definition: beam_math_utilities.hpp:774
static void CalculateLocalAxisVector(TVector3 &rLocalX, TVector3 &rLocalY, TVector3 &rLocalZ)
Definition: beam_math_utilities.hpp:811
static void SubtractMatrix(TMatrix &rDestination, const TInputMatrix &rInputMatrix, const unsigned int rInitialRow, const unsigned int rInitialCol)
Definition: beam_math_utilities.hpp:404
static void CalculateLocalAxesMatrix(const TVector3 &rLocalX, MatrixType &rRotationMatrix)
Definition: beam_math_utilities.hpp:686
static void SkewSymmetricTensorToVector(const TMatrix3 &rSkewSymmetricTensor, TVector3 &rVector)
Definition: beam_math_utilities.hpp:262
MathUtils< TDataType > MathUtilsType
Definition: beam_math_utilities.hpp:40
static void MapLocalToGlobal2D(const MatrixType &rLocalToGlobalMatrix, MatrixType &rMatrix)
Definition: beam_math_utilities.hpp:477
static void MapLocalToGlobal3D(const MatrixType &rLocalToGlobalMatrix, VectorType &rVector)
Definition: beam_math_utilities.hpp:648
static double KroneckerDelta(int i, int j)
Definition: beam_math_utilities.hpp:286
Quaternion< double > QuaternionType
Definition: beam_math_utilities.hpp:39
static void CayleyTransform(const TVector3 &rVector, MatrixType &rCayleyTensor)
Definition: beam_math_utilities.hpp:165
static void CalculateLocalAxesVectors(TVector3 &rLocalX, TVector3 &rLocalY, TVector3 &rLocalZ)
Definition: beam_math_utilities.hpp:723
static TVector3 & MapToCurrentLocalFrame(QuaternionType &rQuaternion, TVector3 &rVector)
Definition: beam_math_utilities.hpp:57
static void InverseCayleyTransform(const MatrixType &rCayleyTensor, TVector3 &rVector)
Definition: beam_math_utilities.hpp:199
static void SubstractVector(const VectorType &rInputVector, VectorType &rOutputVector, const unsigned int InitialRow)
Definition: beam_math_utilities.hpp:356
static void AddVector(const VectorType &rInputVector, VectorType &rOutputVector, const unsigned int InitialRow)
Definition: beam_math_utilities.hpp:336
static void MapLocalToGlobal3D(const QuaternionType &rLocalToGlobalQuaternion, VectorType &rVector)
Definition: beam_math_utilities.hpp:581
static void MapLocalToGlobal3D(const QuaternionType &rLocalToGlobalQuaternion, MatrixType &rMatrix)
Definition: beam_math_utilities.hpp:558
static void VectorToSkewSymmetricTensor(const TVector3 &rVector, TMatrix3 &rSkewSymmetricTensor)
Definition: beam_math_utilities.hpp:231
static void MapLocalToGlobal3D(const MatrixType &rLocalToGlobalMatrix, MatrixType &rMatrix)
Definition: beam_math_utilities.hpp:605
static void InverseExponentialTransform(const MatrixType &rExponentialTensor, TVector3 &rVector)
Definition: beam_math_utilities.hpp:142
static double LeviCivitaEpsilon(int i, int j, int k)
Definition: beam_math_utilities.hpp:308
static void AddMatrix(TMatrix &rDestination, const TInputMatrix &rInputMatrix, const unsigned int rInitialRow, const unsigned int rInitialCol)
Definition: beam_math_utilities.hpp:379
static void MapLocalToGlobal2D(const MatrixType &rLocalToGlobalMatrix, VectorType &rVector)
Definition: beam_math_utilities.hpp:520
static bool CheckOrthogonality(const Matrix &rTensor, const std::string &Name, bool Verbose)
Definition: beam_math_utilities.hpp:844
static void ExponentialTransform(const TVector3 &rVector, MatrixType &rExponentialTensor)
Definition: beam_math_utilities.hpp:118
static TVector3 & MapToReferenceLocalFrame(QuaternionType &rQuaternion, TVector3 &rVector)
Definition: beam_math_utilities.hpp:88
Matrix MatrixType
Definition: beam_math_utilities.hpp:36
BeamMathUtils< TDataType > BeamMathUtilsType
Definition: beam_math_utilities.hpp:41
static void MapLocalToGlobal2D(const QuaternionType &rLocalToGlobalQuaternion, MatrixType &rMatrix)
Definition: beam_math_utilities.hpp:429
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
Various mathematical utilitiy functions.
Definition: math_utils.h:62
static void InvertMatrix3(const TMatrix1 &rInputMatrix, TMatrix2 &rInvertedMatrix, double &rInputMatrixDet)
It inverts matrices of order 3.
Definition: math_utils.h:449
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 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 double Norm(const Vector &a)
Calculates the norm of vector "a".
Definition: math_utils.h:703
static Quaternion FromRotationMatrix(const TMatrix3x3 &m)
Definition: quaternion.h:475
void ToRotationMatrix(TMatrix3x3 &R) const
Definition: quaternion.h:213
void ToRotationVector(T &rx, T &ry, T &rz) const
Definition: quaternion.h:262
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
Quaternion conjugate() const
Definition: quaternion.h:195
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
AMatrix::IdentityMatrix< double > IdentityMatrix
Definition: amatrix_interface.h:564
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17