SymmetricSquareMatrix.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "SymmetricSquareMatrix.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const SymmetricSquareMatrix<Type>& matrix
37 )
38 {
39  const label n = matrix.n();
40 
41  SymmetricSquareMatrix<Type> inv(n, Zero);
42 
43  for (label i = 0; i < n; ++i)
44  {
45  inv(i, i) = 1.0/matrix(i, i);
46 
47  for (label j = 0; j < i; ++j)
48  {
49  Type sum = Zero;
50 
51  for (label k = j; k < i; ++k)
52  {
53  sum -= matrix(i, k)*inv(k, j);
54  }
55 
56  inv(i, j) = sum/matrix(i, i);
57  }
58  }
59 
60  SymmetricSquareMatrix<Type> result(n, Zero);
61 
62  for (label k = 0; k < n; ++k)
63  {
64  for (label i = 0; i <= k; ++i)
65  {
66  for (label j = 0; j <= k; ++j)
67  {
68  result(i, j) += inv(k, i)*inv(k, j);
69  }
70  }
71  }
72 
73  return result;
74 }
75 
76 
77 template<class Type>
79 (
80  const SymmetricSquareMatrix<Type>& matrix
81 )
82 {
83  SymmetricSquareMatrix<Type> matrixTmp(matrix);
84  LUDecompose(matrixTmp);
85 
86  return invDecomposed(matrixTmp);
87 }
88 
89 
90 template<class Type>
92 {
93  Type diagProduct = pTraits<Type>::one;
94 
95  for (label i = 0; i < matrix.m(); ++i)
96  {
97  diagProduct *= matrix(i, i);
98  }
99 
100  return sqr(diagProduct);
101 }
102 
103 
104 template<class Type>
106 {
107  SymmetricSquareMatrix<Type> matrixTmp(matrix);
108  LUDecompose(matrixTmp);
109 
110  return detDecomposed(matrixTmp);
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
115 
116 template<class Type>
117 template<class AnyType>
119 {
120  Matrix<SymmetricSquareMatrix<Type>, Type>::operator=(Zero);
121 
122  for (label i=0; i < this->n(); ++i)
123  {
124  this->operator()(i, i) = pTraits<Type>::one;
125  }
126 }
127 
128 
129 // ************************************************************************* //
Foam::detDecomposed
scalar detDecomposed(const SquareMatrix< Type > &matrix, const label sign)
Return the determinant of the LU decomposed SquareMatrix.
Definition: SquareMatrix.C:107
Foam::SymmetricSquareMatrix::operator=
SymmetricSquareMatrix & operator=(const SymmetricSquareMatrix &)=default
Copy assignment.
SymmetricSquareMatrix.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:53
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Identity
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:49
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::invDecomposed
SymmetricSquareMatrix< Type > invDecomposed(const SymmetricSquareMatrix< Type > &)
Return the LU decomposed SymmetricSquareMatrix inverse.
Foam::SymmetricSquareMatrix
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
Definition: SymmetricSquareMatrix.H:57
Foam::LUDecompose
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Definition: scalarMatrices.C:34
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::Matrix< SymmetricSquareMatrix< Type >, Type >::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62