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-------------------------------------------------------------------------------
11License
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
30
31// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32
33template<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
77template<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
90template<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
104template<class Type>
106{
107 SymmetricSquareMatrix<Type> matrixTmp(matrix);
108 LUDecompose(matrixTmp);
109
110 return detDecomposed(matrixTmp);
111}
112
113
114// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
115
116template<class Type>
117template<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// ************************************************************************* //
label k
label n
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:52
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: Matrix.H:81
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
SymmetricSquareMatrix & operator=(const SymmetricSquareMatrix &)=default
Copy assignment.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
dimensionedScalar det(const dimensionedSphericalTensor &dt)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
scalar detDecomposed(const SquareMatrix< Type > &matrix, const label sign)
Return the determinant of the LU decomposed SquareMatrix.
Definition: SquareMatrix.C:107
SymmetricSquareMatrix< Type > invDecomposed(const SymmetricSquareMatrix< Type > &)
Return the LU decomposed SymmetricSquareMatrix inverse.