From c7e17fa6c2f66cca48ed9d048b6a6005360bd079 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> 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 fa255b03b42..a947d8105f2 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<Type>); + //- 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<RectangularMatrix<Type>> clone() const; + + + // Member operators + + //- Assignment of all entries to zero + void operator=(const zero); }; +// Global functions and operators + +template<class Type> +RectangularMatrix<Type> outer(const Field<Type>& f1, const Field<Type>& f2); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H index 55c3f69699f..631cc8b93c9 100644 --- a/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H +++ b/src/OpenFOAM/matrices/RectangularMatrix/RectangularMatrixI.H @@ -31,6 +31,7 @@ inline Foam::RectangularMatrix<Type>::RectangularMatrix() Matrix<RectangularMatrix<Type>, Type>() {} + template<class Type> inline Foam::RectangularMatrix<Type>::RectangularMatrix ( @@ -41,6 +42,45 @@ inline Foam::RectangularMatrix<Type>::RectangularMatrix Matrix<RectangularMatrix<Type>, Type>(m, n) {} + +template<class Type> +inline Foam::RectangularMatrix<Type>::RectangularMatrix +( + const typename RectangularMatrix::Block& block +) +: + Matrix<RectangularMatrix<Type>, Type>(block) +{} + + +template<class Type> +inline Foam::RectangularMatrix<Type>::RectangularMatrix +( + const label m, + const label n, + const zero +) +: + Matrix<RectangularMatrix<Type>, Type>(m, n, Zero) +{} + + +template<class Type> +inline Foam::RectangularMatrix<Type>::RectangularMatrix +( + const label n, + const Identity<Type> +) +: + Matrix<RectangularMatrix<Type>, Type>(n, n, Zero) +{ + for (label i = 0; i < n; ++i) + { + this->operator()(i, i) = I; + } +} + + template<class Type> inline Foam::RectangularMatrix<Type>::RectangularMatrix ( @@ -52,12 +92,14 @@ inline Foam::RectangularMatrix<Type>::RectangularMatrix Matrix<RectangularMatrix<Type>, Type>(m, n, t) {} + template<class Type> inline Foam::RectangularMatrix<Type>::RectangularMatrix(Istream& is) : Matrix<RectangularMatrix<Type>, Type>(is) {} + template<class Type> inline Foam::autoPtr<Foam::RectangularMatrix<Type>> Foam::RectangularMatrix<Type>::clone() const @@ -69,4 +111,45 @@ Foam::RectangularMatrix<Type>::clone() const } +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template<class Type> +void Foam::RectangularMatrix<Type>::operator=(const zero) +{ + Matrix<RectangularMatrix<Type>, Type>::operator=(Zero); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // + +template<class Type> +inline Foam::RectangularMatrix<Type> outer +( + const Field<Type>& f1, + const Field<Type>& f2 +) +{ + RectangularMatrix<Type> f1f2T(f1.size(), f2.size()); + + for (label i=0; i<f1f2T.m(); ++i) + { + for (label j=0; j<f1f2T.n(); ++j) + { + f1f2T(i, j) = f1[i]*f2[j]; + } + } + + return f1f2T; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + // ************************************************************************* // -- GitLab