From c7e17fa6c2f66cca48ed9d048b6a6005360bd079 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 22 Mar 2016 14:11:41 +0000 Subject: [PATCH] RectangularMatrix: Added construction from and assignment to zero Also added the Field outer-product operator returning a RectangularMatrix --- .../RectangularMatrix/RectangularMatrix.H | 24 ++++++ .../RectangularMatrix/RectangularMatrixI.H | 83 +++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H index fa255b03b4..a947d8105f 100644 --- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H +++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrix.H @@ -39,6 +39,7 @@ SourceFiles #define RectangularMatrix_H #include "Matrix.H" +#include "Identity.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -65,6 +66,17 @@ public: //- Construct given number of rows and columns, inline RectangularMatrix(const label m, const label n); + //- Construct from a block of another matrix + inline RectangularMatrix(const typename RectangularMatrix::Block&); + + //- Construct with given number of rows and columns + // initializing all elements to zero + inline RectangularMatrix(const label m, const label n, const zero); + + //- Construct given number of rows/columns + // Initializing to the identity matrix + inline RectangularMatrix(const label n, const Identity); + //- Construct with given number of rows and columns // and value for all elements. inline RectangularMatrix(const label m, const label n, const Type&); @@ -74,9 +86,21 @@ public: //- Clone inline autoPtr> clone() const; + + + // Member operators + + //- Assignment of all entries to zero + void operator=(const zero); }; +// Global functions and operators + +template +RectangularMatrix outer(const Field& f1, const Field& f2); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H index 55c3f69699..631cc8b93c 100644 --- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H +++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H @@ -31,6 +31,7 @@ inline Foam::RectangularMatrix::RectangularMatrix() Matrix, Type>() {} + template inline Foam::RectangularMatrix::RectangularMatrix ( @@ -41,6 +42,45 @@ inline Foam::RectangularMatrix::RectangularMatrix Matrix, Type>(m, n) {} + +template +inline Foam::RectangularMatrix::RectangularMatrix +( + const typename RectangularMatrix::Block& block +) +: + Matrix, Type>(block) +{} + + +template +inline Foam::RectangularMatrix::RectangularMatrix +( + const label m, + const label n, + const zero +) +: + Matrix, Type>(m, n, Zero) +{} + + +template +inline Foam::RectangularMatrix::RectangularMatrix +( + const label n, + const Identity +) +: + Matrix, Type>(n, n, Zero) +{ + for (label i = 0; i < n; ++i) + { + this->operator()(i, i) = I; + } +} + + template inline Foam::RectangularMatrix::RectangularMatrix ( @@ -52,12 +92,14 @@ inline Foam::RectangularMatrix::RectangularMatrix Matrix, Type>(m, n, t) {} + template inline Foam::RectangularMatrix::RectangularMatrix(Istream& is) : Matrix, Type>(is) {} + template inline Foam::autoPtr> Foam::RectangularMatrix::clone() const @@ -69,4 +111,45 @@ Foam::RectangularMatrix::clone() const } +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +void Foam::RectangularMatrix::operator=(const zero) +{ + Matrix, Type>::operator=(Zero); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // + +template +inline Foam::RectangularMatrix outer +( + const Field& f1, + const Field& f2 +) +{ + RectangularMatrix f1f2T(f1.size(), f2.size()); + + for (label i=0; i