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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "SymmetricSquareMatrix.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const SymmetricSquareMatrix<Type>& matrix
34 )
35 {
36  SymmetricSquareMatrix<Type> inv(matrix.n(), matrix.n(), 0.0);
37 
38  for (label i = 0; i < matrix.n(); ++i)
39  {
40  inv[i][i] = 1.0/matrix[i][i];
41 
42  for (label j = 0; j < i; ++j)
43  {
44  scalar sum = 0.0;
45 
46  for (label k = j; k < i; k++)
47  {
48  sum -= matrix[i][k]*inv[k][j];
49  }
50 
51  inv[i][j] = sum/matrix[i][i];
52  }
53  }
54 
55  return inv.T()*inv;
56 }
57 
58 
59 template<class Type>
61 (
62  const SymmetricSquareMatrix<Type>& matrix
63 )
64 {
65  SymmetricSquareMatrix<Type> matrixTmp(matrix);
66 
67  LUDecompose(matrixTmp);
68 
69  return invDecomposed(matrixTmp);
70 }
71 
72 
73 template<class Type>
74 Foam::scalar Foam::detDecomposed(const SymmetricSquareMatrix<Type>& matrix)
75 {
76  scalar diagProduct = 1.0;
77 
78  for (label i = 0; i < matrix.n(); ++i)
79  {
80  diagProduct *= matrix[i][i];
81  }
82 
83  return sqr(diagProduct);
84 }
85 
86 
87 template<class Type>
88 Foam::scalar Foam::det(const SymmetricSquareMatrix<Type>& matrix)
89 {
90  SymmetricSquareMatrix<Type> matrixTmp = matrix;
91 
92  LUDecompose(matrixTmp);
93 
94  return detDecomposed(matrixTmp);
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
SymmetricSquareMatrix.H
Foam::dimensioned::T
dimensioned< Type > T() const
Return transpose.
Foam::detDecomposed
scalar detDecomposed(const SquareMatrix< Type > &, const label sign)
Return the LU decomposed SquareMatrix det.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::invDecomposed
SymmetricSquareMatrix< Type > invDecomposed(const SymmetricSquareMatrix< Type > &)
Return the LU decomposed SymmetricSquareMatrix inverse.
Foam::SymmetricSquareMatrix
A templated 2D square symmetric matrix of objects of <T>, where the n x n matrix dimension is known a...
Definition: SymmetricSquareMatrix.H:51
Foam::LUDecompose
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Definition: scalarMatrices.C:32
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:60