/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "simpleMatrix.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::simpleMatrix::simpleMatrix(const label mSize)
:
scalarSquareMatrix(mSize),
source_(mSize)
{}
template
Foam::simpleMatrix::simpleMatrix
(
const label mSize,
const scalar coeffVal,
const Type& sourceVal
)
:
scalarSquareMatrix(mSize, coeffVal),
source_(mSize, sourceVal)
{}
template
Foam::simpleMatrix::simpleMatrix
(
const scalarSquareMatrix& matrix,
const Field& source
)
:
scalarSquareMatrix(matrix),
source_(source)
{}
template
Foam::simpleMatrix::simpleMatrix(Istream& is)
:
scalarSquareMatrix(is),
source_(is)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Foam::Field Foam::simpleMatrix::solve() const
{
scalarSquareMatrix tmpMatrix = *this;
Field sourceSol = source_;
Foam::solve(tmpMatrix, sourceSol);
return sourceSol;
}
template
Foam::Field Foam::simpleMatrix::LUsolve() const
{
scalarSquareMatrix luMatrix = *this;
Field sourceSol = source_;
Foam::LUsolve(luMatrix, sourceSol);
return sourceSol;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
void Foam::simpleMatrix::operator=(const simpleMatrix& m)
{
if (this == &m)
{
FatalErrorInFunction
<< "Attempted assignment to self"
<< abort(FatalError);
}
if (m() != m.m())
{
FatalErrorInFunction
<< "Different size matrices"
<< abort(FatalError);
}
if (source_.size() != m.source_.size())
{
FatalErrorInFunction
<< "Different size source vectors"
<< abort(FatalError);
}
scalarSquareMatrix::operator=(m);
source_ = m.source_;
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template
Foam::simpleMatrix Foam::operator+
(
const simpleMatrix& m1,
const simpleMatrix& m2
)
{
return simpleMatrix
(
static_cast(m1)
+ static_cast(m2),
m1.source_ + m2.source_
);
}
template
Foam::simpleMatrix Foam::operator-
(
const simpleMatrix& m1,
const simpleMatrix& m2
)
{
return simpleMatrix
(
static_cast(m1)
- static_cast(m2),
m1.source_ - m2.source_
);
}
template
Foam::simpleMatrix Foam::operator*
(
const scalar s,
const simpleMatrix& m
)
{
return simpleMatrix(s*m.matrix_, s*m.source_);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const simpleMatrix& m
)
{
os << static_cast(m) << nl << m.source_;
return os;
}
// ************************************************************************* //