diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C index c7dbb073e4..861a20dfaf 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.C +++ b/src/OpenFOAM/matrices/Matrix/Matrix.C @@ -421,6 +421,40 @@ Form Foam::operator*(const scalar s, const Matrix& a) } +template +Form Foam::operator*(const Matrix& a, const Matrix& b) +{ + if (a.m() != b.n()) + { + FatalErrorIn + ( + "Matrix::operator*" + "(const Matrix&, const Matrix&)" + ) << "attempted to multiply incompatible matrices:" << nl + << "Matrix A : " << a.n() << " rows, " << a.m() << " columns" << nl + << "Matrix B : " << b.n() << " rows, " << b.m() << " columns" << nl + << "In order to multiply matrices, columns of A must equal " + << "rows of B" + << abort(FatalError); + } + + Form ab(a.n(), b.m(), scalar(0)); + + for (register label i = 0; i < ab.n(); i++) + { + for (register label j = 0; j < ab.m(); j++) + { + for (register label l = 0; l < b.n(); l++) + { + ab[i][j] += a[i][l]*b[l][j]; + } + } + } + + return ab; +} + + // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * // #include "MatrixIO.C" diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H index 89554d4cad..dd55db770c 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.H +++ b/src/OpenFOAM/matrices/Matrix/Matrix.H @@ -215,6 +215,12 @@ template Form operator* const Matrix& ); +template Form operator* +( + const Matrix&, + const Matrix& +); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //