Commit 318b71e2 authored by henry's avatar henry
Browse files

Made Matrix generic base-class for SquareMatrix and RectangularMatrix by introducing

the type it will become as a template argument.

Brought everything into line with this change.
parent b722041f
......@@ -34,7 +34,7 @@ Description
#define ODE_H
#include "scalarField.H"
#include "Matrix.H"
#include "scalarMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -80,7 +80,7 @@ public:
const scalar x,
const scalarField& y,
scalarField& dfdx,
Matrix<scalar>& dfdy
scalarSquareMatrix& dfdy
) const = 0;
};
......
......@@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/
#include "KRR4.H"
#include "simpleMatrix.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -36,11 +35,11 @@ namespace Foam
{
addToRunTimeSelectionTable(ODESolver, KRR4, ODE);
const scalar
const scalar
KRR4::safety = 0.9, KRR4::grow = 1.5, KRR4::pgrow = -0.25,
KRR4::shrink = 0.5, KRR4::pshrink = (-1.0/3.0), KRR4::errcon = 0.1296;
const scalar
const scalar
KRR4::gamma = 1.0/2.0,
KRR4::a21 = 2.0, KRR4::a31 = 48.0/25.0, KRR4::a32 = 6.0/25.0,
KRR4::c21 = -8.0, KRR4::c31 = 372.0/25.0, KRR4::c32 = 12.0/5.0,
......@@ -81,8 +80,8 @@ void Foam::KRR4::solve
const ODE& ode,
scalar& x,
scalarField& y,
scalarField& dydx,
const scalar eps,
scalarField& dydx,
const scalar eps,
const scalarField& yScale,
const scalar hTry,
scalar& hDid,
......@@ -109,14 +108,14 @@ void Foam::KRR4::solve
a_[i][i] += 1.0/(gamma*h);
}
simpleMatrix<scalar>::LUDecompose(a_, pivotIndices_);
LUDecompose(a_, pivotIndices_);
for (register label i=0; i<n_; i++)
{
g1_[i] = dydxTemp_[i] + h*c1X*dfdx_[i];
}
simpleMatrix<scalar>::LUBacksubstitute(a_, pivotIndices_, g1_);
LUBacksubstitute(a_, pivotIndices_, g1_);
for (register label i=0; i<n_; i++)
{
......@@ -131,7 +130,7 @@ void Foam::KRR4::solve
g2_[i] = dydx_[i] + h*c2X*dfdx_[i] + c21*g1_[i]/h;
}
simpleMatrix<scalar>::LUBacksubstitute(a_, pivotIndices_, g2_);
LUBacksubstitute(a_, pivotIndices_, g2_);
for (register label i=0; i<n_; i++)
{
......@@ -146,7 +145,7 @@ void Foam::KRR4::solve
g3_[i] = dydx[i] + h*c3X*dfdx_[i] + (c31*g1_[i] + c32*g2_[i])/h;
}
simpleMatrix<scalar>::LUBacksubstitute(a_, pivotIndices_, g3_);
LUBacksubstitute(a_, pivotIndices_, g3_);
for (register label i=0; i<n_; i++)
{
......@@ -154,7 +153,7 @@ void Foam::KRR4::solve
+ (c41*g1_[i] + c42*g2_[i] + c43*g3_[i])/h;
}
simpleMatrix<scalar>::LUBacksubstitute(a_, pivotIndices_, g4_);
LUBacksubstitute(a_, pivotIndices_, g4_);
for (register label i=0; i<n_; i++)
{
......
......@@ -62,15 +62,15 @@ class KRR4
mutable scalarField g4_;
mutable scalarField yErr_;
mutable scalarField dfdx_;
mutable Matrix<scalar> dfdy_;
mutable Matrix<scalar> a_;
mutable scalarSquareMatrix dfdy_;
mutable scalarSquareMatrix a_;
mutable labelList pivotIndices_;
static const int maxtry = 40;
static const scalar safety, grow, pgrow, shrink, pshrink, errcon;
static const scalar
static const scalar
gamma,
a21, a31, a32,
c21, c31, c32, c41, c42, c43,
......
......@@ -60,8 +60,8 @@ class SIBS
static const scalar safe1, safe2, redMax, redMin, scaleMX;
mutable scalarField a_;
mutable Matrix<scalar> alpha_;
mutable Matrix<scalar> d_p_;
mutable scalarSquareMatrix alpha_;
mutable scalarSquareMatrix d_p_;
mutable scalarField x_p_;
mutable scalarField err_;
......@@ -69,7 +69,7 @@ class SIBS
mutable scalarField ySeq_;
mutable scalarField yErr_;
mutable scalarField dfdx_;
mutable Matrix<scalar> dfdy_;
mutable scalarSquareMatrix dfdy_;
mutable label first_, kMax_, kOpt_;
mutable scalar epsOld_, xNew_;
......@@ -82,7 +82,7 @@ void SIMPR
const scalarField& y,
const scalarField& dydx,
const scalarField& dfdx,
const Matrix<scalar>& dfdy,
const scalarSquareMatrix& dfdy,
const scalar deltaX,
const label nSteps,
scalarField& yEnd
......@@ -97,7 +97,7 @@ void polyExtrapolate
scalarField& yz,
scalarField& dy,
scalarField& x_p,
Matrix<scalar>& d_p
scalarSquareMatrix& d_p
) const;
......
......@@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/
#include "SIBS.H"
#include "simpleMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -36,7 +35,7 @@ void Foam::SIBS::SIMPR
const scalarField& y,
const scalarField& dydx,
const scalarField& dfdx,
const Matrix<scalar>& dfdy,
const scalarSquareMatrix& dfdy,
const scalar deltaX,
const label nSteps,
scalarField& yEnd
......@@ -44,7 +43,7 @@ void Foam::SIBS::SIMPR
{
scalar h = deltaX/nSteps;
Matrix<scalar> a(n_, n_);
scalarSquareMatrix a(n_);
for (register label i=0; i<n_; i++)
{
for (register label j=0; j<n_; j++)
......@@ -55,14 +54,14 @@ void Foam::SIBS::SIMPR
}
labelList pivotIndices(n_);
simpleMatrix<scalar>::LUDecompose(a, pivotIndices);
LUDecompose(a, pivotIndices);
for (register label i=0; i<n_; i++)
{
yEnd[i] = h*(dydx[i] + h*dfdx[i]);
}
simpleMatrix<scalar>::LUBacksubstitute(a, pivotIndices, yEnd);
LUBacksubstitute(a, pivotIndices, yEnd);
scalarField del(yEnd);
scalarField ytemp(n_);
......@@ -83,7 +82,7 @@ void Foam::SIBS::SIMPR
yEnd[i] = h*yEnd[i] - del[i];
}
simpleMatrix<scalar>::LUBacksubstitute(a, pivotIndices, yEnd);
LUBacksubstitute(a, pivotIndices, yEnd);
for (register label i=0; i<n_; i++)
{
......@@ -99,7 +98,7 @@ void Foam::SIBS::SIMPR
yEnd[i] = h*yEnd[i] - del[i];
}
simpleMatrix<scalar>::LUBacksubstitute(a, pivotIndices, yEnd);
LUBacksubstitute(a, pivotIndices, yEnd);
for (register label i=0; i<n_; i++)
{
......
......@@ -36,7 +36,7 @@ void Foam::SIBS::polyExtrapolate
scalarField& yz,
scalarField& dy,
scalarField& x,
Matrix<scalar>& d
scalarSquareMatrix& d
) const
{
label n = yz.size();
......
......@@ -177,9 +177,9 @@ dimensionedTypes/dimensionedTensor/dimensionedTensor.C
matrices/solution/solution.C
scalarMatrix = matrices/scalarMatrix
$(scalarMatrix)/scalarMatrix.C
$(scalarMatrix)/SVD/SVD.C
scalarMatrices = matrices/scalarMatrices
$(scalarMatrices)/scalarMatrices.C
$(scalarMatrices)/SVD/SVD.C
LUscalarMatrix = matrices/LUscalarMatrix
$(LUscalarMatrix)/LUscalarMatrix.C
......
......@@ -22,8 +22,6 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "Pstream.H"
......
......@@ -29,7 +29,8 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::DiagonalMatrix<Type>::DiagonalMatrix(const Matrix<Type>& a)
template<class Form>
Foam::DiagonalMatrix<Type>::DiagonalMatrix(const Matrix<Form, Type>& a)
:
List<Type>(min(a.n(), a.m()))
{
......
......@@ -46,7 +46,7 @@ namespace Foam
// * * * * * * * * * * * * Class Forward declaration * * * * * * * * * * * //
template<class Type> class Matrix;
template<class Form, class Type> class Matrix;
/*---------------------------------------------------------------------------*\
Class DiagonalMatrix Declaration
......@@ -62,7 +62,8 @@ public:
// Constructors
//- Construct from diagonal component of a Matrix
DiagonalMatrix<Type>(const Matrix<Type>&);
template<class Form>
DiagonalMatrix<Type>(const Matrix<Form, Type>&);
//- Construct empty from size
DiagonalMatrix<Type>(const label size);
......
......@@ -31,9 +31,9 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::LUscalarMatrix::LUscalarMatrix(const Matrix<scalar>& matrix)
Foam::LUscalarMatrix::LUscalarMatrix(const scalarSquareMatrix& matrix)
:
scalarMatrix(matrix),
scalarSquareMatrix(matrix),
pivotIndices_(n())
{
LUDecompose(*this, pivotIndices_);
......@@ -101,7 +101,7 @@ Foam::LUscalarMatrix::LUscalarMatrix
nCells += lduMatrices[i].size();
}
Matrix<scalar> m(nCells, nCells, 0.0);
scalarSquareMatrix m(nCells, 0.0);
transfer(m);
convert(lduMatrices);
}
......@@ -109,7 +109,7 @@ Foam::LUscalarMatrix::LUscalarMatrix
else
{
label nCells = ldum.lduAddr().size();
Matrix<scalar> m(nCells, nCells, 0.0);
scalarSquareMatrix m(nCells, 0.0);
transfer(m);
convert(ldum, interfaceCoeffs, interfaces);
}
......
......@@ -36,7 +36,7 @@ SourceFiles
#ifndef LUscalarMatrix_H
#define LUscalarMatrix_H
#include "scalarMatrix.H"
#include "scalarMatrices.H"
#include "labelList.H"
#include "FieldField.H"
#include "lduInterfaceFieldPtrsList.H"
......@@ -55,7 +55,7 @@ class procLduMatrix;
class LUscalarMatrix
:
public scalarMatrix
public scalarSquareMatrix
{
// Private data
......@@ -78,7 +78,7 @@ class LUscalarMatrix
void convert(const PtrList<procLduMatrix>& lduMatrices);
//- Print the ratio of the mag-sum of the off-diagonal coefficients
//- Print the ratio of the mag-sum of the off-diagonal coefficients
// to the mag-diagonal
void printDiagonalDominance() const;
......@@ -87,8 +87,8 @@ public:
// Constructors
//- Construct from Matrix<scalar> and perform LU decomposition
LUscalarMatrix(const Matrix<scalar>&);
//- Construct from scalarSquareMatrix and perform LU decomposition
LUscalarMatrix(const scalarSquareMatrix&);
//- Construct from lduMatrix and perform LU decomposition
LUscalarMatrix
......
......@@ -28,8 +28,8 @@ License
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class Type>
void Foam::Matrix<Type>::allocate()
template<class Form, class Type>
void Foam::Matrix<Form, Type>::allocate()
{
if (n_ && m_)
{
......@@ -46,8 +46,8 @@ void Foam::Matrix<Type>::allocate()
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class Type>
Foam::Matrix<Type>::~Matrix()
template<class Form, class Type>
Foam::Matrix<Form, Type>::~Matrix()
{
if (v_)
{
......@@ -59,16 +59,16 @@ Foam::Matrix<Type>::~Matrix()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Foam::Matrix<Type>& Foam::Matrix<Type>::null()
template<class Form, class Type>
const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null()
{
Matrix<Type>* nullPtr = reinterpret_cast<Matrix<Type>*>(NULL);
Matrix<Form, Type>* nullPtr = reinterpret_cast<Matrix<Form, Type>*>(NULL);
return *nullPtr;
}
template<class Type>
Foam::Matrix<Type>::Matrix(const label n, const label m)
template<class Form, class Type>
Foam::Matrix<Form, Type>::Matrix(const label n, const label m)
:
n_(n),
m_(m),
......@@ -76,7 +76,7 @@ Foam::Matrix<Type>::Matrix(const label n, const label m)
{
if (n_ < 0 || m_ < 0)
{
FatalErrorIn("Matrix<Type>::Matrix(const label n, const label m)")
FatalErrorIn("Matrix<Form, Type>::Matrix(const label n, const label m)")
<< "bad n, m " << n_ << ", " << m_
<< abort(FatalError);
}
......@@ -85,8 +85,8 @@ Foam::Matrix<Type>::Matrix(const label n, const label m)
}
template<class Type>
Foam::Matrix<Type>::Matrix(const label n, const label m, const Type& a)
template<class Form, class Type>
Foam::Matrix<Form, Type>::Matrix(const label n, const label m, const Type& a)
:
n_(n),
m_(m),
......@@ -96,7 +96,7 @@ Foam::Matrix<Type>::Matrix(const label n, const label m, const Type& a)
{
FatalErrorIn
(
"Matrix<Type>::Matrix(const label n, const label m, const T&)"
"Matrix<Form, Type>::Matrix(const label n, const label m, const T&)"
) << "bad n, m " << n_ << ", " << m_
<< abort(FatalError);
}
......@@ -117,8 +117,8 @@ Foam::Matrix<Type>::Matrix(const label n, const label m, const Type& a)
}
template<class Type>
Foam::Matrix<Type>::Matrix(const Matrix<Type>& a)
template<class Form, class Type>
Foam::Matrix<Form, Type>::Matrix(const Matrix<Form, Type>& a)
:
n_(a.n_),
m_(a.m_),
......@@ -139,8 +139,8 @@ Foam::Matrix<Type>::Matrix(const Matrix<Type>& a)
}
template<class Type>
void Foam::Matrix<Type>::clear()
template<class Form, class Type>
void Foam::Matrix<Form, Type>::clear()
{
if (v_)
{
......@@ -153,8 +153,8 @@ void Foam::Matrix<Type>::clear()
}
template<class Type>
void Foam::Matrix<Type>::transfer(Matrix<Type>& a)
template<class Form, class Type>
void Foam::Matrix<Form, Type>::transfer(Matrix<Form, Type>& a)
{
clear();
......@@ -169,13 +169,11 @@ void Foam::Matrix<Type>::transfer(Matrix<Type>& a)
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
Foam::Matrix<Type> Foam::Matrix<Type>::T() const
template<class Form, class Type>
Form Foam::Matrix<Form, Type>::T() const
{
const Matrix<Type>& A = *this;
Matrix<Type> At(m(), n());
const Matrix<Form, Type>& A = *this;
Form At(m(), n());
for (register label i=0; i<n(); i++)
{
......@@ -189,8 +187,10 @@ Foam::Matrix<Type> Foam::Matrix<Type>::T() const
}
template<class Type>
void Foam::Matrix<Type>::operator=(const Type& t)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Form, class Type>
void Foam::Matrix<Form, Type>::operator=(const Type& t)
{
if (v_)
{
......@@ -206,12 +206,12 @@ void Foam::Matrix<Type>::operator=(const Type& t)
// Assignment operator. Takes linear time.
template<class Type>
void Foam::Matrix<Type>::operator=(const Matrix<Type>& a)
template<class Form, class Type>
void Foam::Matrix<Form, Type>::operator=(const Matrix<Form, Type>& a)
{
if (this == &a)
{
FatalErrorIn("Matrix<Type>::operator=(const Matrix<Type>&)")
FatalErrorIn("Matrix<Form, Type>::operator=(const Matrix<Form, Type>&)")
<< "attempted assignment to self"
<< abort(FatalError);
}
......@@ -240,8 +240,8 @@ void Foam::Matrix<Type>::operator=(const Matrix<Type>& a)
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type>
const Type& Foam::max(const Matrix<Type>& a)
template<class Form, class Type>
const Type& Foam::max(const Matrix<Form, Type>& a)
{
label nm = a.n_*a.m_;
......@@ -262,7 +262,7 @@ const Type& Foam::max(const Matrix<Type>& a)
}
else
{
FatalErrorIn("max(const Matrix<Type>&)")
FatalErrorIn("max(const Matrix<Form, Type>&)")
<< "matrix is empty"
<< abort(FatalError);
......@@ -272,8 +272,8 @@ const Type& Foam::max(const Matrix<Type>& a)
}
template<class Type>
const Type& Foam::min(const Matrix<Type>& a)
template<class Form, class Type>
const Type& Foam::min(const Matrix<Form, Type>& a)
{
label nm = a.n_*a.m_;
......@@ -294,7 +294,7 @@ const Type& Foam::min(const Matrix<Type>& a)
}
else
{
FatalErrorIn("min(const Matrix<Type>&)")
FatalErrorIn("min(const Matrix<Form, Type>&)")
<< "matrix is empty"
<< abort(FatalError);
......@@ -306,10 +306,10 @@ const Type& Foam::min(const Matrix<Type>& a)
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
template<class Type>
Foam::Matrix<Type> Foam::operator-(const Matrix<Type>& a)
template<class Form, class Type>
Form Foam::operator-(const Matrix<Form, Type>& a)
{
Matrix<Type> na(a.n_, a.m_);
Form na(a.n_, a.m_);
if (a.n_ && a.m_)
{
......@@ -327,14 +327,14 @@ Foam::Matrix<Type> Foam::operator-(const Matrix<Type>& a)
}
template<class Type>
Foam::Matrix<Type> Foam::operator+(const Matrix<Type>& a, const Matrix<Type>& b)
template<class Form, class Type>
Form Foam::operator+(const Matrix<Form, Type>& a, const Matrix<Form, Type>& b)
{
if (a.n_ != b.n_)
{
FatalErrorIn
(
"Matrix<Type>::operator+(const Matrix<Type>&, const Matrix<Type>&)"
"Matrix<Form, Type>::operator+(const Matrix<Form, Type>&, const Matrix<Form, Type>&)"
) << "attempted add matrices with different number of rows: "
<< a.n_ << ", " << b.n_
<< abort(FatalError);
......@@ -344,13 +344,13 @@ Foam::Matrix<Type> Foam::operator+(const Matrix<Type>& a, const Matrix<Type>& b)
{
FatalErrorIn
(
"Matrix<Type>::operator+(const Matrix<Type>&, const Matrix<Type>&)"
"Matrix<Form, Type>::operator+(const Matrix<Form, Type>&, const Matrix<Form, Type>&)"
) << "attempted add matrices with different number of columns: "
<< a.m_ << ", " << b.m_
<< abort(FatalError);
}
Matrix<Type> ab(a.n_, a.m_);
Form ab(a.n_, a.m_);
Type* abv = ab.v_[0];
const Type* av = a.v_[0];
......@@ -366,14 +366,14 @@ Foam::Matrix<Type> Foam::operator+(const Matrix<Type>& a, const Matrix<Type>& b)
}
template<class Type>
Foam::Matrix<Type> Foam::operator-(const Matrix<Type>& a, const Matrix<Type>& b)
template<class Form, class Type>
Form Foam::operator-(const Matrix<Form, Type>& a, const Matrix<Form, Type>& b)
{
if (a.n_ != b.n_)
{
FatalErrorIn
(
"Matrix<Type>::operator-(const Matrix<Type>&, const Matrix<Type>&)"
"Matrix<Form, Type>::operator-(const Matrix<Form, Type>&, const Matrix<Form, Type>&)"
) << "attempted add matrices with different number of rows: "
<< a.n_ << ", " << b.n_
<< abort(FatalError);
......@@ -383,13 +383,13 @@ Foam::Matrix<Type> Foam::operator-(const Matrix<Type>& a, const Matrix<Type>& b)
{
FatalErrorIn
(
"Matrix<Type>::operator-(const Matrix<Type>&, const Matrix<Type>&)"
"Matrix<Form, Type>::operator-(const Matrix<Form, Type>&, const Matrix<Form, Type>&)"
) << "attempted add matrices with different number of columns: "
<< a.m_ << ", " << b.m_
<< abort(FatalError);
}
Matrix<Type> ab(a.n_, a.m_);
Form ab(a.n_, a.m_);
Type* abv = ab.v_[0];
const Type* av = a.v_[0];
......@@ -405,17 +405,17 @@ Foam::Matrix<Type> Foam::operator-(const Matrix<Type>& a, const Matrix<Type>& b)
}