Commit 22b2e397 authored by Henry Weller's avatar Henry Weller
Browse files

RectangularMatrix: Added construction from and assignment to zero

Also added the Field outer-product operator returning a RectangularMatrix
parent c33961f3
......@@ -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
......
......@@ -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
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment