1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "scalarMatrix.H"
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 Foam::scalarMatrix::scalarMatrix()
35 Foam::scalarMatrix::scalarMatrix(const label mSize)
37 Matrix<scalar>(mSize, mSize, 0.0)
41 Foam::scalarMatrix::scalarMatrix(const Matrix<scalar>& matrix)
43 Matrix<scalar>(matrix)
47 Foam::scalarMatrix::scalarMatrix(Istream& is)
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 void Foam::scalarMatrix::LUDecompose
57 Matrix<scalar>& matrix,
58 labelList& pivotIndices
64 for (register label i=0; i<n; i++)
66 scalar largestCoeff = 0.0;
68 const scalar* __restrict__ matrixi = matrix[i];
70 for (register label j=0; j<n; j++)
72 if ((temp = mag(matrixi[j])) > largestCoeff)
78 if (largestCoeff == 0.0)
82 "scalarMatrix::LUdecompose"
83 "(Matrix<scalar>& matrix, labelList& rowIndices)"
84 ) << "Singular matrix" << exit(FatalError);
87 vv[i] = 1.0/largestCoeff;
90 for (register label j=0; j<n; j++)
92 scalar* __restrict__ matrixj = matrix[j];
94 for (register label i=0; i<j; i++)
96 scalar* __restrict__ matrixi = matrix[i];
98 scalar sum = matrixi[j];
99 for (register label k=0; k<i; k++)
101 sum -= matrixi[k]*matrix[k][j];
108 scalar largestCoeff = 0.0;
109 for (register label i=j; i<n; i++)
111 scalar* __restrict__ matrixi = matrix[i];
112 scalar sum = matrixi[j];
114 for (register label k=0; k<j; k++)
116 sum -= matrixi[k]*matrix[k][j];
122 if ((temp = vv[i]*mag(sum)) >= largestCoeff)
129 pivotIndices[j] = iMax;
133 scalar* __restrict__ matrixiMax = matrix[iMax];
135 for (register label k=0; k<n; k++)
137 Swap(matrixj[k], matrixiMax[k]);
143 if (matrixj[j] == 0.0)
150 scalar rDiag = 1.0/matrixj[j];
152 for (register label i=j+1; i<n; i++)
154 matrix[i][j] *= rDiag;
161 // ************************************************************************* //