1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "scalarMatrices.H"
30 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
34 scalarRectangularMatrix& ans, // value changed in return
35 const scalarRectangularMatrix& A,
36 const scalarRectangularMatrix& B
44 "scalarRectangularMatrix& answer "
45 "const scalarRectangularMatrix& A, "
46 "const scalarRectangularMatrix& B)"
47 ) << "A and B must have identical inner dimensions but A.m = "
48 << A.m() << " and B.n = " << B.n()
52 ans = scalarRectangularMatrix(A.n(), B.m(), scalar(0));
54 for(register label i = 0; i < A.n(); i++)
56 for(register label j = 0; j < B.m(); j++)
58 for(register label l = 0; l < B.n(); l++)
60 ans[i][j] += A[i][l]*B[l][j];
69 scalarRectangularMatrix& ans, // value changed in return
70 const scalarRectangularMatrix& A,
71 const scalarRectangularMatrix& B,
72 const scalarRectangularMatrix& C
80 "const scalarRectangularMatrix& A, "
81 "const scalarRectangularMatrix& B, "
82 "const scalarRectangularMatrix& C, "
83 "scalarRectangularMatrix& answer)"
84 ) << "A and B must have identical inner dimensions but A.m = "
85 << A.m() << " and B.n = " << B.n()
94 "const scalarRectangularMatrix& A, "
95 "const scalarRectangularMatrix& B, "
96 "const scalarRectangularMatrix& C, "
97 "scalarRectangularMatrix& answer)"
98 ) << "B and C must have identical inner dimensions but B.m = "
99 << B.m() << " and C.n = " << C.n()
100 << abort(FatalError);
103 ans = scalarRectangularMatrix(A.n(), C.m(), scalar(0));
105 for(register label i = 0; i < A.n(); i++)
107 for(register label g = 0; g < C.m(); g++)
109 for(register label l = 0; l < C.n(); l++)
112 for(register label j = 0; j < A.m(); j++)
114 ab += A[i][j]*B[j][l];
116 ans[i][g] += C[l][g] * ab;
125 scalarRectangularMatrix& ans, // value changed in return
126 const scalarRectangularMatrix& A,
127 const DiagonalMatrix<scalar>& B,
128 const scalarRectangularMatrix& C
131 if (A.m() != B.size())
136 "const scalarRectangularMatrix& A, "
137 "const DiagonalMatrix<scalar>& B, "
138 "const scalarRectangularMatrix& C, "
139 "scalarRectangularMatrix& answer)"
140 ) << "A and B must have identical inner dimensions but A.m = "
141 << A.m() << " and B.n = " << B.size()
142 << abort(FatalError);
145 if (B.size() != C.n())
150 "const scalarRectangularMatrix& A, "
151 "const DiagonalMatrix<scalar>& B, "
152 "const scalarRectangularMatrix& C, "
153 "scalarRectangularMatrix& answer)"
154 ) << "B and C must have identical inner dimensions but B.m = "
155 << B.size() << " and C.n = " << C.n()
156 << abort(FatalError);
159 ans = scalarRectangularMatrix(A.n(), C.m(), scalar(0));
161 for(register label i = 0; i < A.n(); i++)
163 for(register label g = 0; g < C.m(); g++)
165 for(register label l = 0; l < C.n(); l++)
167 ans[i][g] += C[l][g] * A[i][l]*B[l];
174 Foam::RectangularMatrix<Foam::scalar> Foam::SVDinv
176 const scalarRectangularMatrix& A,
180 SVD svd(A, minCondition);
181 return svd.VSinvUt();
185 // ************************************************************************* //