SquareMatrix.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) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2019 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 "SquareMatrix.H"
30 #include "RectangularMatrix.H"
31 #include "labelList.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 template<class Type>
36 Foam::scalar Foam::detDecomposed
37 (
38  const SquareMatrix<Type>& matrix,
39  const label sign
40 )
41 {
42  Type diagProduct = pTraits<Type>::one;
43 
44  for (label i = 0; i < matrix.m(); ++i)
45  {
46  diagProduct *= matrix(i, i);
47  }
48 
49  return sign*diagProduct;
50 }
51 
52 
53 template<class Type>
54 Foam::scalar Foam::det(const SquareMatrix<Type>& matrix)
55 {
56  SquareMatrix<Type> matrixTmp = matrix;
57 
58  labelList pivotIndices(matrix.m());
59  label sign;
60  LUDecompose(matrixTmp, pivotIndices, sign);
61 
62  return detDecomposed(matrixTmp, sign);
63 }
64 
65 
66 template<class Type>
67 Foam::scalar Foam::det(SquareMatrix<Type>& matrix)
68 {
69  labelList pivotIndices(matrix.m());
70  label sign;
71  LUDecompose(matrix, pivotIndices, sign);
72 
73  return detDecomposed(matrix, sign);
74 }
75 
76 
77 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
78 
79 template<class Type>
80 template<class AnyType>
82 {
83  Matrix<SquareMatrix<Type>, Type>::operator=(Zero);
84 
85  for (label i=0; i < this->n(); ++i)
86  {
87  this->operator()(i, i) = pTraits<Type>::one;
88  }
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::SquareMatrix::operator=
void operator=(const zero)
Assign all elements to zero.
Definition: SquareMatrixI.H:301
Foam::detDecomposed
scalar detDecomposed(const SquareMatrix< Type > &, const label sign)
Return the LU decomposed SquareMatrix det.
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:48
n
label n
Definition: TABSMDCalcMethod2.H:31
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:62
labelList.H
Foam::Identity
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:49
Foam::LUDecompose
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Definition: scalarMatrices.C:34
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:52
Foam::det
dimensionedScalar det(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:62
SquareMatrix.H
RectangularMatrix.H