From 9bbf09573b0b5a4abbe160e237b664d8ebb77597 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 24 Mar 2016 14:48:59 +0000 Subject: [PATCH] SquareMatrix: Add setSize and assignment to identity --- .../RectangularMatrix/RectangularMatrix.H | 2 +- .../matrices/SquareMatrix/SquareMatrix.H | 13 +++++++++++- .../matrices/SquareMatrix/SquareMatrixI.H | 20 +++++++++++++++++++ .../scalarMatrices/scalarMatricesTemplates.C | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H index 7167a23f0c..84a8315113 100644 --- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H +++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H @@ -99,7 +99,7 @@ public: // Member operators - //- Assignment of all entries to zero + //- Assignment of all elements to zero void operator=(const zero); }; diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H index 2af8a5d542..443ac00bd2 100644 --- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H +++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H @@ -106,10 +106,21 @@ public: inline autoPtr> clone() const; + // Member Functions + + // Edit + + //- Resize the matrix preserving the elements + inline void setSize(const label m); + + // Member operators - //- Assignment of all entries to zero + //- Assignment of all elements to zero void operator=(const zero); + + //- Assignment elements to the + void operator=(const Identity); }; diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H index 38dcb15926..7dbc3bde28 100644 --- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H +++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrixI.H @@ -152,6 +152,15 @@ Foam::SquareMatrix::clone() const } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +inline void Foam::SquareMatrix::setSize(const label m) +{ + Matrix, Type>::setSize(m, m); +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template @@ -161,6 +170,17 @@ void Foam::SquareMatrix::operator=(const zero) } +template +void Foam::SquareMatrix::operator=(const Identity) +{ + Matrix, Type>::operator=(Zero); + for (label i=0; in(); i++) + { + this->operator()(i, i) = I; + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam diff --git a/src/OpenFOAM/matrices/scalarMatrices/scalarMatricesTemplates.C b/src/OpenFOAM/matrices/scalarMatrices/scalarMatricesTemplates.C index 915b00d95a..5e9ed25702 100644 --- a/src/OpenFOAM/matrices/scalarMatrices/scalarMatricesTemplates.C +++ b/src/OpenFOAM/matrices/scalarMatrices/scalarMatricesTemplates.C @@ -44,7 +44,7 @@ void Foam::solve label iMax = i; scalar largestCoeff = mag(tmpMatrix[iMax][i]); - // Swap entries around to find a good pivot + // Swap elements around to find a good pivot for (label j=i+1; j largestCoeff)