Merge branch 'master' of /home/hunt2/OpenFOAM/OpenFOAM-dev

This commit is contained in:
mattijs
2008-10-01 12:13:55 +01:00
65 changed files with 1478 additions and 624 deletions

View File

@ -151,18 +151,20 @@ public:
const IOobject& fieldIoObject
);
//- Reconstruct and write all volume fields
//- Reconstruct and write all/selected volume fields
template<class Type>
void reconstructFvVolumeFields
(
const IOobjectList& objects
const IOobjectList& objects,
const HashSet<word>& selectedFields
);
//- Reconstruct and write all volume fields
//- Reconstruct and write all/selected volume fields
template<class Type>
void reconstructFvSurfaceFields
(
const IOobjectList& objects
const IOobjectList& objects,
const HashSet<word>& selectedFields
);
};

View File

@ -131,7 +131,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
forAll(cp, faceI)
{
// Subtract one to take into account offsets for
// face direction.
// face direction.
reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
}
@ -151,7 +151,7 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
forAll(cp, faceI)
{
// Subtract one to take into account offsets for
// face direction.
// face direction.
label curF = cp[faceI] - 1;
// Is the face on the boundary?
@ -282,7 +282,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// It is necessary to create a copy of the addressing array to
// take care of the face direction offset trick.
//
//
{
labelList curAddr(faceProcAddressing_[procI]);
@ -342,7 +342,7 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
forAll(cp, faceI)
{
// Subtract one to take into account offsets for
// face direction.
// face direction.
reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
}
@ -452,11 +452,12 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
}
// Reconstruct and write all volume fields
// Reconstruct and write all/selected volume fields
template<class Type>
void Foam::fvFieldReconstructor::reconstructFvVolumeFields
(
const IOobjectList& objects
const IOobjectList& objects,
const HashSet<word>& selectedFields
)
{
const word& fieldClassName =
@ -468,27 +469,29 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeFields
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
for
(
IOobjectList::const_iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllConstIter(IOobjectList, fields, fieldIter)
{
Info<< " " << fieldIter()->name() << endl;
if
(
!selectedFields.size()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvVolumeField<Type>(*fieldIter())().write();
reconstructFvVolumeField<Type>(*fieldIter())().write();
}
}
Info<< endl;
}
}
// Reconstruct and write all surface fields
// Reconstruct and write all/selected surface fields
template<class Type>
void Foam::fvFieldReconstructor::reconstructFvSurfaceFields
(
const IOobjectList& objects
const IOobjectList& objects,
const HashSet<word>& selectedFields
)
{
const word& fieldClassName =
@ -500,18 +503,19 @@ void Foam::fvFieldReconstructor::reconstructFvSurfaceFields
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
for
(
IOobjectList::const_iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllConstIter(IOobjectList, fields, fieldIter)
{
Info<< " " << fieldIter()->name() << endl;
if
(
!selectedFields.size()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvSurfaceField<Type>(*fieldIter())().write();
reconstructFvSurfaceField<Type>(*fieldIter())().write();
}
}
Info<< endl;
}
}

View File

@ -48,9 +48,17 @@ int main(int argc, char *argv[])
argList::noParallel();
timeSelector::addOptions();
# include "addRegionOption.H"
argList::validOptions.insert("fields", "\"(list of fields)\"");
# include "setRootCase.H"
# include "createTime.H"
HashSet<word> selectedFields;
if (args.options().found("fields"))
{
IStringStream(args.options()["fields"])() >> selectedFields;
}
// determine the processor count directly
label nProcs = 0;
while (dir(args.path()/(word("processor") + name(nProcs))))
@ -184,13 +192,37 @@ int main(int argc, char *argv[])
procMeshes.boundaryProcAddressing()
);
fvReconstructor.reconstructFvVolumeFields<scalar>(objects);
fvReconstructor.reconstructFvVolumeFields<vector>(objects);
fvReconstructor.reconstructFvVolumeFields<sphericalTensor>(objects);
fvReconstructor.reconstructFvVolumeFields<symmTensor>(objects);
fvReconstructor.reconstructFvVolumeFields<tensor>(objects);
fvReconstructor.reconstructFvVolumeFields<scalar>
(
objects,
selectedFields
);
fvReconstructor.reconstructFvVolumeFields<vector>
(
objects,
selectedFields
);
fvReconstructor.reconstructFvVolumeFields<sphericalTensor>
(
objects,
selectedFields
);
fvReconstructor.reconstructFvVolumeFields<symmTensor>
(
objects,
selectedFields
);
fvReconstructor.reconstructFvVolumeFields<tensor>
(
objects,
selectedFields
);
fvReconstructor.reconstructFvSurfaceFields<scalar>(objects);
fvReconstructor.reconstructFvSurfaceFields<scalar>
(
objects,
selectedFields
);
}
else
{

View File

@ -139,7 +139,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
IOobject LESPropertiesHeader
(
"RASProperties",
"LESProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,

View File

@ -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;
};

View File

@ -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++)
{

View File

@ -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,

View File

@ -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;

View File

@ -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++)
{

View File

@ -36,7 +36,7 @@ void Foam::SIBS::polyExtrapolate
scalarField& yz,
scalarField& dy,
scalarField& x,
Matrix<scalar>& d
scalarSquareMatrix& d
) const
{
label n = yz.size();

View File

@ -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

View File

@ -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"

View File

@ -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()))
{

View File

@ -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);

View File

@ -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, 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, nCells, 0.0);
transfer(m);
convert(ldum, interfaceCoeffs, interfaces);
}

View File

@ -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

View File

@ -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)
}
template<class Type>
Foam::Matrix<Type> Foam::operator*(const scalar s, const Matrix<Type>& a)
template<class Form, class Type>
Form Foam::operator*(const scalar s, const Matrix<Form, Type>& a)
{
Matrix<Type> sa(a.n_, a.m_);
Form sa(a.n_, a.m_);
if (a.n_ && a.m_)
{
Type* sav = sa.v_[0];
const Type* av = a.v_[0];
label nm = a.n_*a.m_;;
label nm = a.n_*a.m_;
for (register label i=0; i<nm; i++)
{
sav[i] = s*av[i];

View File

@ -51,37 +51,26 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class Type> class Matrix;
template<class Form, class Type> class Matrix;
template<class Type> const Type& max(const Matrix<Type>&);
template<class Type> const Type& min(const Matrix<Type>&);
template<class Type> Matrix<Type> operator-(const Matrix<Type>&);
template<class Type> Matrix<Type> operator+
template<class Form, class Type> Istream& operator>>
(
const Matrix<Type>&,
const Matrix<Type>&
);
template<class Type> Matrix<Type> operator-
(
const Matrix<Type>&,
const Matrix<Type>&
);
template<class Type> Matrix<Type> operator*
(
const scalar,
const Matrix<Type>&
Istream&,
Matrix<Form, Type>&
);
template<class Type> Istream& operator>>(Istream&, Matrix<Type>&);
template<class Type> Ostream& operator<<(Ostream&, const Matrix<Type>&);
template<class Form, class Type> Ostream& operator<<
(
Ostream&,
const Matrix<Form, Type>&
);
/*---------------------------------------------------------------------------*\
Class Matrix Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
template<class Form, class Type>
class Matrix
{
// Private data
@ -112,13 +101,13 @@ public:
Matrix(const label n, const label m, const Type&);
//- Copy constructor.
Matrix(const Matrix<Type>&);
Matrix(const Matrix<Form, Type>&);
//- Construct from Istream.
Matrix(Istream&);
//- Clone
inline autoPtr<Matrix<Type> > clone() const;
inline autoPtr<Matrix<Form, Type> > clone() const;
// Destructor
@ -129,7 +118,7 @@ public:
// Member functions
//- Return a null Matrix
static const Matrix<Type>& null();
static const Matrix<Form, Type>& null();
// Access
@ -160,7 +149,11 @@ public:
//- Transfer the contents of the argument Matrix into this Matrix
// and annull the argument Matrix.
void transfer(Matrix<Type>&);
void transfer(Matrix<Form, Type>&);
//- Return the transpose of the matrix
Form T() const;
// Member operators
@ -171,52 +164,49 @@ public:
//- Return subscript-checked element of constant Matrix.
inline const Type* operator[](const label) const;
//- Return the transpose of the matrix
Matrix<Type> T() const;
//- Assignment operator. Takes linear time.
void operator=(const Matrix<Type>&);
void operator=(const Matrix<Form, Type>&);
//- Assignment of all entries to the given value
void operator=(const Type&);
// Friend functions
friend const Type& max<Type>(const Matrix<Type>&);
friend const Type& min<Type>(const Matrix<Type>&);
// Friend operators
friend Matrix<Type> operator-<Type>(const Matrix<Type>&);
friend Matrix<Type> operator+<Type>
(
const Matrix<Type>&,
const Matrix<Type>&
);
friend Matrix<Type> operator-<Type>
(
const Matrix<Type>&,
const Matrix<Type>&
);
friend Matrix<Type> operator*<Type>
(
const scalar,
const Matrix<Type>&
);
// IOstream operators
//- Read Matrix from Istream, discarding contents of existing Matrix.
friend Istream& operator>> <Type>(Istream&, Matrix<Type>&);
friend Istream& operator>> <Form, Type>(Istream&, Matrix<Form, Type>&);
// Write Matrix to Ostream.
friend Ostream& operator<< <Type>(Ostream&, const Matrix<Type>&);
friend Ostream& operator<< <Form, Type>(Ostream&, const Matrix<Form, Type>&);
};
// Global functions and operators
template<class Form, class Type> const Type& max(const Matrix<Form, Type>&);
template<class Form, class Type> const Type& min(const Matrix<Form, Type>&);
template<class Form, class Type> Form operator-(const Matrix<Form, Type>&);
template<class Form, class Type> Form operator+
(
const Matrix<Form, Type>&,
const Matrix<Form, Type>&
);
template<class Form, class Type> Form operator-
(
const Matrix<Form, Type>&,
const Matrix<Form, Type>&
);
template<class Form, class Type> Form operator*
(
const scalar,
const Matrix<Form, Type>&
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -26,8 +26,8 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
inline Foam::Matrix<Type>::Matrix()
template<class Form, class Type>
inline Foam::Matrix<Form, Type>::Matrix()
:
n_(0),
m_(0),
@ -35,67 +35,67 @@ inline Foam::Matrix<Type>::Matrix()
{}
template<class Type>
inline Foam::autoPtr<Foam::Matrix<Type> > Foam::Matrix<Type>::clone() const
template<class Form, class Type>
inline Foam::autoPtr<Foam::Matrix<Form, Type> > Foam::Matrix<Form, Type>::clone() const
{
return autoPtr<Matrix<Type> >(new Matrix<Type>(*this));
return autoPtr<Matrix<Form, Type> >(new Matrix<Form, Type>(*this));
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Return the number of rows
template<class Type>
inline Foam::label Foam::Matrix<Type>::n() const
template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::n() const
{
return n_;
}
template<class Type>
inline Foam::label Foam::Matrix<Type>::m() const
template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::m() const
{
return m_;
}
template<class Type>
inline Foam::label Foam::Matrix<Type>::size() const
template<class Form, class Type>
inline Foam::label Foam::Matrix<Form, Type>::size() const
{
return n_*m_;
}
template<class Type>
inline void Foam::Matrix<Type>::checki(const label i) const
template<class Form, class Type>
inline void Foam::Matrix<Form, Type>::checki(const label i) const
{
if (!n_)
{
FatalErrorIn("Matrix<Type>::checki(const label)")
FatalErrorIn("Matrix<Form, Type>::checki(const label)")
<< "attempt to access element from zero sized row"
<< abort(FatalError);
}
else if (i<0 || i>=n_)
{
FatalErrorIn("Matrix<Type>::checki(const label)")
FatalErrorIn("Matrix<Form, Type>::checki(const label)")
<< "index " << i << " out of range 0 ... " << n_-1
<< abort(FatalError);
}
}
template<class Type>
inline void Foam::Matrix<Type>::checkj(const label j) const
template<class Form, class Type>
inline void Foam::Matrix<Form, Type>::checkj(const label j) const
{
if (!m_)
{
FatalErrorIn("Matrix<Type>::checkj(const label)")
FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
<< "attempt to access element from zero sized column"
<< abort(FatalError);
}
else if (j<0 || j>=m_)
{
FatalErrorIn("Matrix<Type>::checkj(const label)")
FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
<< "index " << j << " out of range 0 ... " << m_-1
<< abort(FatalError);
}
@ -104,8 +104,8 @@ inline void Foam::Matrix<Type>::checkj(const label j) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
inline Type* Foam::Matrix<Type>::operator[](const label i)
template<class Form, class Type>
inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
{
# ifdef FULLDEBUG
checki(i);
@ -114,8 +114,8 @@ inline Type* Foam::Matrix<Type>::operator[](const label i)
}
template<class Type>
inline const Type* Foam::Matrix<Type>::operator[](const label i) const
template<class Form, class Type>
inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
{
# ifdef FULLDEBUG
checki(i);

View File

@ -32,8 +32,8 @@ License
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class Type>
Foam::Matrix<Type>::Matrix(Istream& is)
template<class Form, class Type>
Foam::Matrix<Form, Type>::Matrix(Istream& is)
:
n_(0),
m_(0),
@ -43,17 +43,17 @@ Foam::Matrix<Type>::Matrix(Istream& is)
}
template<class Type>
Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
template<class Form, class Type>
Foam::Istream& Foam::operator>>(Istream& is, Matrix<Form, Type>& M)
{
// Anull matrix
M.clear();
is.fatalCheck("operator>>(Istream&, Matrix<Type>&)");
is.fatalCheck("operator>>(Istream&, Matrix<Form, Type>&)");
token firstToken(is);
is.fatalCheck("operator>>(Istream&, Matrix<Type>&) : reading first token");
is.fatalCheck("operator>>(Istream&, Matrix<Form, Type>&) : reading first token");
if (firstToken.isLabel())
{
@ -88,7 +88,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
is.fatalCheck
(
"operator>>(Istream&, Matrix<Type>&) : "
"operator>>(Istream&, Matrix<Form, Type>&) : "
"reading entry"
);
}
@ -103,7 +103,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
is.fatalCheck
(
"operator>>(Istream&, Matrix<Type>&) : "
"operator>>(Istream&, Matrix<Form, Type>&) : "
"reading the single entry"
);
@ -128,7 +128,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
is.fatalCheck
(
"operator>>(Istream&, Matrix<Type>&) : "
"operator>>(Istream&, Matrix<Form, Type>&) : "
"reading the binary block"
);
}
@ -136,7 +136,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
}
else
{
FatalIOErrorIn("operator>>(Istream&, Matrix<Type>&)", is)
FatalIOErrorIn("operator>>(Istream&, Matrix<Form, Type>&)", is)
<< "incorrect first token, expected <int>, found "
<< firstToken.info()
<< exit(FatalIOError);
@ -146,8 +146,8 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Type>& M)
}
template<class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Type>& M)
template<class Form, class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M)
{
label nm = M.n_*M.m_;

View File

@ -0,0 +1,92 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::RectangularMatrix
Description
A templated 2D rectangular matrix of objects of \<T\>, where the n x n matrix
dimension is known and used for subscript bounds checking, etc.
SourceFiles
RectangularMatrixI.H
RectangularMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef RectangularMatrix_H
#define RectangularMatrix_H
#include "Matrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class Matrix Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class RectangularMatrix
:
public Matrix<RectangularMatrix<Type>, Type>
{
public:
// Constructors
//- Null constructor.
inline RectangularMatrix();
//- Construct given number of rows and columns,
inline RectangularMatrix(const label m, const label n);
//- Construct with given number of rows and columns
// and value for all elements.
inline RectangularMatrix(const label m, const label n, const Type&);
//- Construct from Istream.
inline RectangularMatrix(Istream&);
//- Clone
inline autoPtr<RectangularMatrix<Type> > clone() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "RectangularMatrixI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
inline Foam::RectangularMatrix<Type>::RectangularMatrix()
:
Matrix<RectangularMatrix<Type>, Type>()
{}
template<class Type>
inline Foam::RectangularMatrix<Type>::RectangularMatrix
(
const label m,
const label n
)
:
Matrix<RectangularMatrix<Type>, Type>(m, n)
{}
template<class Type>
inline Foam::RectangularMatrix<Type>::RectangularMatrix
(
const label m,
const label n,
const Type& t
)
:
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
{
return autoPtr<RectangularMatrix<Type> >(new RectangularMatrix<Type>(*this));
}
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::SquareMatrix
Description
A templated 2D square matrix of objects of \<T\>, where the n x n matrix
dimension is known and used for subscript bounds checking, etc.
SourceFiles
SquareMatrixI.H
SquareMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef SquareMatrix_H
#define SquareMatrix_H
#include "Matrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class Matrix Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class SquareMatrix
:
public Matrix<SquareMatrix<Type>, Type>
{
public:
// Constructors
//- Null constructor.
inline SquareMatrix();
//- Construct given number of rows/columns.
inline SquareMatrix(const label n);
//- Construct given number of rows and columns,
// It checks that m == n.
inline SquareMatrix(const label m, const label n);
//- Construct with given number of rows and rows
// and value for all elements.
// It checks that m == n.
inline SquareMatrix(const label m, const label n, const Type&);
//- Construct from Istream.
inline SquareMatrix(Istream&);
//- Clone
inline autoPtr<SquareMatrix<Type> > clone() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "SquareMatrixI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
inline Foam::SquareMatrix<Type>::SquareMatrix()
:
Matrix<SquareMatrix<Type>, Type>()
{}
template<class Type>
inline Foam::SquareMatrix<Type>::SquareMatrix(const label n)
:
Matrix<SquareMatrix<Type>, Type>(n, n)
{}
template<class Type>
inline Foam::SquareMatrix<Type>::SquareMatrix(const label m, const label n)
:
Matrix<SquareMatrix<Type>, Type>(m, n)
{
if (m != n)
{
FatalErrorIn
(
"SquareMatrix<Type>::SquareMatrix(const label m, const label n)"
) << "m != n for constructing a square matrix" << exit(FatalError);
}
}
template<class Type>
inline Foam::SquareMatrix<Type>::SquareMatrix
(
const label m,
const label n,
const Type& t
)
:
Matrix<SquareMatrix<Type>, Type>(m, n, t)
{
if (m != n)
{
FatalErrorIn
(
"SquareMatrix<Type>::SquareMatrix"
"(const label m, const label n, const Type&)"
) << "m != n for constructing a square matrix" << exit(FatalError);
}
}
template<class Type>
inline Foam::SquareMatrix<Type>::SquareMatrix(Istream& is)
:
Matrix<SquareMatrix<Type>, Type>(is)
{}
template<class Type>
inline Foam::autoPtr<Foam::SquareMatrix<Type> >
Foam::SquareMatrix<Type>::clone() const
{
return autoPtr<SquareMatrix<Type> >(new SquareMatrix<Type>(*this));
}
// ************************************************************************* //

View File

@ -26,12 +26,12 @@ License
#include "SVD.H"
#include "scalarList.H"
#include "scalarMatrix.H"
#include "scalarMatrices.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * //
Foam::SVD::SVD(const Matrix<scalar>& A, const scalar minCondition)
Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
:
U_(A),
V_(A.m(), A.m()),
@ -294,8 +294,11 @@ Foam::SVD::SVD(const Matrix<scalar>& A, const scalar minCondition)
}
if (its == 34)
{
WarningIn("SVD::SVD(Matrix<scalar>& A)")
<< "no convergence in 35 SVD iterations"
WarningIn
(
"SVD::SVD"
"(scalarRectangularMatrix& A, const scalar minCondition)"
) << "no convergence in 35 SVD iterations"
<< endl;
}
@ -375,7 +378,7 @@ Foam::SVD::SVD(const Matrix<scalar>& A, const scalar minCondition)
multiply(VSinvUt_, V_, inv(S_), U_.T());
// test SVD
/*Matrix<scalar> SVDA(A.n(), A.m());
/*scalarRectangularMatrix SVDA(A.n(), A.m());
multiply(SVDA, U_, S_, transpose(V_));
scalar maxDiff = 0;
scalar diff = 0;

View File

@ -23,12 +23,13 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
SVD
Foam::SVD
Description
Singular value decomposition of a rectangular matrix.
SourceFiles
SVDI.H
SVD.C
\*---------------------------------------------------------------------------*/
@ -36,8 +37,7 @@ SourceFiles
#ifndef SVD_H
#define SVD_H
#include "DiagonalMatrix.H"
#include "Matrix.H"
#include "scalarMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -56,16 +56,16 @@ class SVD
// Private data
//- Rectangular matrix with the same dimensions as the input
Matrix<scalar> U_;
scalarRectangularMatrix U_;
//- square matrix V
Matrix<scalar> V_;
scalarRectangularMatrix V_;
//- The singular values
DiagonalMatrix<scalar> S_;
//- The matrix product V S^(-1) U^T
Matrix<scalar> VSinvUt_;
scalarRectangularMatrix VSinvUt_;
//- The number of zero singular values
label nZeros_;
@ -88,22 +88,22 @@ public:
// Constructors
//- Construct from a rectangular Matrix
SVD(const Matrix<scalar>& A, const scalar minCondition = 0);
SVD(const scalarRectangularMatrix& A, const scalar minCondition = 0);
// Access functions
//- Return U
inline const Matrix<scalar>& U() const;
inline const scalarRectangularMatrix& U() const;
//- Return the square matrix V
inline const Matrix<scalar>& V() const;
inline const scalarRectangularMatrix& V() const;
//- Return the singular values
inline const DiagonalMatrix<scalar>& S() const;
inline const scalarDiagonalMatrix& S() const;
//- Return VSinvUt (the pseudo inverse)
inline const Matrix<scalar>& VSinvUt() const;
inline const scalarRectangularMatrix& VSinvUt() const;
//- Return the number of zero singular values
inline label nZeros() const;

View File

@ -35,22 +35,22 @@ inline const T Foam::SVD::sign(const T& a, const T& b)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::Matrix<Foam::scalar>& Foam::SVD::U() const
inline const Foam::scalarRectangularMatrix& Foam::SVD::U() const
{
return U_;
}
inline const Foam::Matrix<Foam::scalar>& Foam::SVD::V() const
inline const Foam::scalarRectangularMatrix& Foam::SVD::V() const
{
return V_;
}
inline const Foam::DiagonalMatrix<Foam::scalar>& Foam::SVD::S() const
inline const Foam::scalarDiagonalMatrix& Foam::SVD::S() const
{
return S_;
}
inline const Foam::Matrix<Foam::scalar>& Foam::SVD::VSinvUt() const
inline const Foam::scalarRectangularMatrix& Foam::SVD::VSinvUt() const
{
return VSinvUt_;
}

View File

@ -24,39 +24,14 @@ License
\*---------------------------------------------------------------------------*/
#include "scalarMatrix.H"
#include "scalarMatrices.H"
#include "SVD.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::scalarMatrix::scalarMatrix()
{}
Foam::scalarMatrix::scalarMatrix(const label mSize)
:
Matrix<scalar>(mSize, mSize, 0.0)
{}
Foam::scalarMatrix::scalarMatrix(const Matrix<scalar>& matrix)
:
Matrix<scalar>(matrix)
{}
Foam::scalarMatrix::scalarMatrix(Istream& is)
:
Matrix<scalar>(is)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::scalarMatrix::LUDecompose
void Foam::LUDecompose
(
Matrix<scalar>& matrix,
scalarSquareMatrix& matrix,
labelList& pivotIndices
)
{
@ -81,8 +56,8 @@ void Foam::scalarMatrix::LUDecompose
{
FatalErrorIn
(
"scalarMatrix::LUdecompose"
"(Matrix<scalar>& matrix, labelList& rowIndices)"
"LUdecompose"
"(scalarSquareMatrix& matrix, labelList& rowIndices)"
) << "Singular matrix" << exit(FatalError);
}
@ -164,9 +139,9 @@ void Foam::scalarMatrix::LUDecompose
void Foam::multiply
(
Matrix<scalar>& ans, // value changed in return
const Matrix<scalar>& A,
const Matrix<scalar>& B
scalarRectangularMatrix& ans, // value changed in return
const scalarRectangularMatrix& A,
const scalarRectangularMatrix& B
)
{
if (A.m() != B.n())
@ -174,15 +149,15 @@ void Foam::multiply
FatalErrorIn
(
"multiply("
"Matrix<scalar>& answer "
"const Matrix<scalar>& A, "
"const Matrix<scalar>& B)"
"scalarRectangularMatrix& answer "
"const scalarRectangularMatrix& A, "
"const scalarRectangularMatrix& B)"
) << "A and B must have identical inner dimensions but A.m = "
<< A.m() << " and B.n = " << B.n()
<< abort(FatalError);
}
ans = Matrix<scalar>(A.n(), B.m(), scalar(0));
ans = scalarRectangularMatrix(A.n(), B.m(), scalar(0));
for(register label i = 0; i < A.n(); i++)
{
@ -199,10 +174,10 @@ void Foam::multiply
void Foam::multiply
(
Matrix<scalar>& ans, // value changed in return
const Matrix<scalar>& A,
const Matrix<scalar>& B,
const Matrix<scalar>& C
scalarRectangularMatrix& ans, // value changed in return
const scalarRectangularMatrix& A,
const scalarRectangularMatrix& B,
const scalarRectangularMatrix& C
)
{
if (A.m() != B.n())
@ -210,10 +185,10 @@ void Foam::multiply
FatalErrorIn
(
"multiply("
"const Matrix<scalar>& A, "
"const Matrix<scalar>& B, "
"const Matrix<scalar>& C, "
"Matrix<scalar>& answer)"
"const scalarRectangularMatrix& A, "
"const scalarRectangularMatrix& B, "
"const scalarRectangularMatrix& C, "
"scalarRectangularMatrix& answer)"
) << "A and B must have identical inner dimensions but A.m = "
<< A.m() << " and B.n = " << B.n()
<< abort(FatalError);
@ -224,16 +199,16 @@ void Foam::multiply
FatalErrorIn
(
"multiply("
"const Matrix<scalar>& A, "
"const Matrix<scalar>& B, "
"const Matrix<scalar>& C, "
"Matrix<scalar>& answer)"
"const scalarRectangularMatrix& A, "
"const scalarRectangularMatrix& B, "
"const scalarRectangularMatrix& C, "
"scalarRectangularMatrix& answer)"
) << "B and C must have identical inner dimensions but B.m = "
<< B.m() << " and C.n = " << C.n()
<< abort(FatalError);
}
ans = Matrix<scalar>(A.n(), C.m(), scalar(0));
ans = scalarRectangularMatrix(A.n(), C.m(), scalar(0));
for(register label i = 0; i < A.n(); i++)
{
@ -255,10 +230,10 @@ void Foam::multiply
void Foam::multiply
(
Matrix<scalar>& ans, // value changed in return
const Matrix<scalar>& A,
scalarRectangularMatrix& ans, // value changed in return
const scalarRectangularMatrix& A,
const DiagonalMatrix<scalar>& B,
const Matrix<scalar>& C
const scalarRectangularMatrix& C
)
{
if (A.m() != B.size())
@ -266,10 +241,10 @@ void Foam::multiply
FatalErrorIn
(
"multiply("
"const Matrix<scalar>& A, "
"const scalarRectangularMatrix& A, "
"const DiagonalMatrix<scalar>& B, "
"const Matrix<scalar>& C, "
"Matrix<scalar>& answer)"
"const scalarRectangularMatrix& C, "
"scalarRectangularMatrix& answer)"
) << "A and B must have identical inner dimensions but A.m = "
<< A.m() << " and B.n = " << B.size()
<< abort(FatalError);
@ -280,16 +255,16 @@ void Foam::multiply
FatalErrorIn
(
"multiply("
"const Matrix<scalar>& A, "
"const scalarRectangularMatrix& A, "
"const DiagonalMatrix<scalar>& B, "
"const Matrix<scalar>& C, "
"Matrix<scalar>& answer)"
"const scalarRectangularMatrix& C, "
"scalarRectangularMatrix& answer)"
) << "B and C must have identical inner dimensions but B.m = "
<< B.size() << " and C.n = " << C.n()
<< abort(FatalError);
}
ans = Matrix<scalar>(A.n(), C.m(), scalar(0));
ans = scalarRectangularMatrix(A.n(), C.m(), scalar(0));
for(register label i = 0; i < A.n(); i++)
{
@ -304,9 +279,9 @@ void Foam::multiply
}
Foam::Matrix<Foam::scalar> Foam::SVDinv
Foam::RectangularMatrix<Foam::scalar> Foam::SVDinv
(
const Matrix<scalar>& A,
const scalarRectangularMatrix& A,
scalar minCondition
)
{

View File

@ -0,0 +1,137 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
scalarMatrices
Description
Scalar matrices
SourceFiles
scalarMatrices.C
scalarMatricesTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef scalarMatrices_H
#define scalarMatrices_H
#include "RectangularMatrix.H"
#include "SquareMatrix.H"
#include "DiagonalMatrix.H"
#include "scalarField.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef RectangularMatrix<scalar> scalarRectangularMatrix;
typedef SquareMatrix<scalar> scalarSquareMatrix;
typedef DiagonalMatrix<scalar> scalarDiagonalMatrix;
//- Solve the matrix using Gaussian elimination with pivoting,
// returning the solution in the source
template<class Type>
void solve(scalarSquareMatrix& matrix, Field<Type>& source);
//- Solve the matrix using Gaussian elimination with pivoting
// and return the solution
template<class Type>
void solve
(
Field<Type>& psi,
const scalarSquareMatrix& matrix,
const Field<Type>& source
);
//- LU decompose the matrix with pivoting
void LUDecompose
(
scalarSquareMatrix& matrix,
labelList& pivotIndices
);
//- LU back-substitution with given source, returning the solution
// in the source
template<class Type>
void LUBacksubstitute
(
const scalarSquareMatrix& luMmatrix,
const labelList& pivotIndices,
Field<Type>& source
);
//- Solve the matrix using LU decomposition with pivoting
// returning the LU form of the matrix and the solution in the source
template<class Type>
void LUsolve(scalarSquareMatrix& matrix, Field<Type>& source);
void multiply
(
scalarRectangularMatrix& answer, // value changed in return
const scalarRectangularMatrix& A,
const scalarRectangularMatrix& B
);
void multiply
(
scalarRectangularMatrix& answer, // value changed in return
const scalarRectangularMatrix& A,
const scalarRectangularMatrix& B,
const scalarRectangularMatrix& C
);
void multiply
(
scalarRectangularMatrix& answer, // value changed in return
const scalarRectangularMatrix& A,
const DiagonalMatrix<scalar>& B,
const scalarRectangularMatrix& C
);
//- Return the inverse of matrix A using SVD
scalarRectangularMatrix SVDinv
(
const scalarRectangularMatrix& A,
scalar minCondition = 0
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "scalarMatricesTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -24,15 +24,15 @@ License
\*---------------------------------------------------------------------------*/
#include "scalarMatrix.H"
#include "scalarMatrices.H"
#include "Swap.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::scalarMatrix::solve
void Foam::solve
(
Matrix<scalar>& tmpMatrix,
scalarSquareMatrix& tmpMatrix,
Field<Type>& sourceSol
)
{
@ -68,7 +68,7 @@ void Foam::scalarMatrix::solve
// Check that the system of equations isn't singular
if (mag(tmpMatrix[i][i]) < 1e-20)
{
FatalErrorIn("scalarMatrix::solve()")
FatalErrorIn("solve(scalarSquareMatrix&, Field<Type>& sourceSol)")
<< "Singular Matrix"
<< exit(FatalError);
}
@ -102,18 +102,23 @@ void Foam::scalarMatrix::solve
template<class Type>
void Foam::scalarMatrix::solve(Field<Type>& psi, const Field<Type>& source) const
void Foam::solve
(
Field<Type>& psi,
const scalarSquareMatrix& matrix,
const Field<Type>& source
)
{
Matrix<scalar> tmpMatrix = *this;
scalarSquareMatrix tmpMatrix = matrix;
psi = source;
solve(tmpMatrix, psi);
}
template<class Type>
void Foam::scalarMatrix::LUBacksubstitute
void Foam::LUBacksubstitute
(
const Matrix<scalar>& luMatrix,
const scalarSquareMatrix& luMatrix,
const labelList& pivotIndices,
Field<Type>& sourceSol
)
@ -160,9 +165,9 @@ void Foam::scalarMatrix::LUBacksubstitute
template<class Type>
void Foam::scalarMatrix::LUsolve
void Foam::LUsolve
(
Matrix<scalar>& matrix,
scalarSquareMatrix& matrix,
Field<Type>& sourceSol
)
{

View File

@ -1,155 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::scalarMatrix
Description
Foam::scalarMatrix
SourceFiles
scalarMatrix.C
\*---------------------------------------------------------------------------*/
#ifndef scalarMatrix_H
#define scalarMatrix_H
#include "Matrix.H"
#include "DiagonalMatrix.H"
#include "scalarField.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class scalarMatrix Declaration
\*---------------------------------------------------------------------------*/
class scalarMatrix
:
public Matrix<scalar>
{
public:
// Constructors
//- Construct null
scalarMatrix();
//- Construct given size
scalarMatrix(const label);
//- Construct from Matrix<scalar>
scalarMatrix(const Matrix<scalar>&);
//- Construct from Istream
scalarMatrix(Istream&);
// Member Functions
//- Solve the matrix using Gaussian elimination with pivoting,
// returning the solution in the source
template<class Type>
static void solve(Matrix<scalar>& matrix, Field<Type>& source);
//- Solve the matrix using Gaussian elimination with pivoting
// and return the solution
template<class Type>
void solve(Field<Type>& psi, const Field<Type>& source) const;
//- LU decompose the matrix with pivoting
static void LUDecompose
(
Matrix<scalar>& matrix,
labelList& pivotIndices
);
//- LU back-substitution with given source, returning the solution
// in the source
template<class Type>
static void LUBacksubstitute
(
const Matrix<scalar>& luMmatrix,
const labelList& pivotIndices,
Field<Type>& source
);
//- Solve the matrix using LU decomposition with pivoting
// returning the LU form of the matrix and the solution in the source
template<class Type>
static void LUsolve(Matrix<scalar>& matrix, Field<Type>& source);
};
// Global functions
void multiply
(
Matrix<scalar>& answer, // value changed in return
const Matrix<scalar>& A,
const Matrix<scalar>& B
);
void multiply
(
Matrix<scalar>& answer, // value changed in return
const Matrix<scalar>& A,
const Matrix<scalar>& B,
const Matrix<scalar>& C
);
void multiply
(
Matrix<scalar>& answer, // value changed in return
const Matrix<scalar>& A,
const DiagonalMatrix<scalar>& B,
const Matrix<scalar>& C
);
//- Return the inverse of matrix A using SVD
Matrix<scalar> SVDinv(const Matrix<scalar>& A, scalar minCondition = 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "scalarMatrixTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -31,7 +31,7 @@ License
template<class Type>
Foam::simpleMatrix<Type>::simpleMatrix(const label mSize)
:
scalarMatrix(mSize),
scalarSquareMatrix(mSize),
source_(mSize, pTraits<Type>::zero)
{}
@ -39,11 +39,11 @@ Foam::simpleMatrix<Type>::simpleMatrix(const label mSize)
template<class Type>
Foam::simpleMatrix<Type>::simpleMatrix
(
const scalarMatrix& matrix,
const scalarSquareMatrix& matrix,
const Field<Type>& source
)
:
scalarMatrix(matrix),
scalarSquareMatrix(matrix),
source_(source)
{}
@ -51,7 +51,7 @@ Foam::simpleMatrix<Type>::simpleMatrix
template<class Type>
Foam::simpleMatrix<Type>::simpleMatrix(Istream& is)
:
scalarMatrix(is),
scalarSquareMatrix(is),
source_(is)
{}
@ -61,10 +61,10 @@ Foam::simpleMatrix<Type>::simpleMatrix(Istream& is)
template<class Type>
Foam::Field<Type> Foam::simpleMatrix<Type>::solve() const
{
scalarMatrix tmpMatrix = *this;
scalarSquareMatrix tmpMatrix = *this;
Field<Type> sourceSol = source_;
scalarMatrix::solve(tmpMatrix, sourceSol);
Foam::solve(tmpMatrix, sourceSol);
return sourceSol;
}
@ -73,10 +73,10 @@ Foam::Field<Type> Foam::simpleMatrix<Type>::solve() const
template<class Type>
Foam::Field<Type> Foam::simpleMatrix<Type>::LUsolve() const
{
scalarMatrix luMatrix = *this;
scalarSquareMatrix luMatrix = *this;
Field<Type> sourceSol = source_;
scalarMatrix::LUsolve(luMatrix, sourceSol);
Foam::LUsolve(luMatrix, sourceSol);
return sourceSol;
}
@ -108,7 +108,7 @@ void Foam::simpleMatrix<Type>::operator=(const simpleMatrix<Type>& m)
<< abort(FatalError);
}
scalarMatrix::operator=(m);
scalarSquareMatrix::operator=(m);
source_ = m.source_;
}
@ -124,8 +124,8 @@ Foam::simpleMatrix<Type> Foam::operator+
{
return simpleMatrix<Type>
(
static_cast<const scalarMatrix&>(m1)
+ static_cast<const scalarMatrix&>(m2),
static_cast<const scalarSquareMatrix&>(m1)
+ static_cast<const scalarSquareMatrix&>(m2),
m1.source_ + m2.source_
);
}
@ -140,8 +140,8 @@ Foam::simpleMatrix<Type> Foam::operator-
{
return simpleMatrix<Type>
(
static_cast<const scalarMatrix&>(m1)
- static_cast<const scalarMatrix&>(m2),
static_cast<const scalarSquareMatrix&>(m1)
- static_cast<const scalarSquareMatrix&>(m2),
m1.source_ - m2.source_
);
}
@ -159,7 +159,7 @@ Foam::simpleMatrix<Type> Foam::operator*(const scalar s, const simpleMatrix<Type
template<class Type>
Foam::Ostream& Foam::operator<<(Ostream& os, const simpleMatrix<Type>& m)
{
os << static_cast<const scalarMatrix&>(m) << nl << m.source_;
os << static_cast<const scalarSquareMatrix&>(m) << nl << m.source_;
return os;
}

View File

@ -36,7 +36,7 @@ SourceFiles
#ifndef simpleMatrix_H
#define simpleMatrix_H
#include "scalarMatrix.H"
#include "scalarMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,27 +48,6 @@ namespace Foam
template<class Type>
class simpleMatrix;
template<class Type>
simpleMatrix<Type> operator+
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
template<class Type>
simpleMatrix<Type> operator-
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
template<class Type>
simpleMatrix<Type> operator*
(
const scalar,
const simpleMatrix<Type>&
);
template<class Type>
Ostream& operator<<
(
@ -84,7 +63,7 @@ Ostream& operator<<
template<class Type>
class simpleMatrix
:
public scalarMatrix
public scalarSquareMatrix
{
// Private data
@ -99,7 +78,7 @@ public:
simpleMatrix(const label);
//- Construct from components
simpleMatrix(const scalarMatrix&, const Field<Type>&);
simpleMatrix(const scalarSquareMatrix&, const Field<Type>&);
//- Construct from Istream
simpleMatrix(Istream&);
@ -137,27 +116,6 @@ public:
void operator=(const simpleMatrix<Type>&);
// Friend Operators
friend simpleMatrix<Type> operator+ <Type>
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
friend simpleMatrix<Type> operator- <Type>
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
friend simpleMatrix<Type> operator* <Type>
(
const scalar,
const simpleMatrix<Type>&
);
// Ostream Operator
friend Ostream& operator<< <Type>
@ -168,6 +126,30 @@ public:
};
// Global operators
template<class Type>
simpleMatrix<Type> operator+
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
template<class Type>
simpleMatrix<Type> operator-
(
const simpleMatrix<Type>&,
const simpleMatrix<Type>&
);
template<class Type>
simpleMatrix<Type> operator*
(
const scalar,
const simpleMatrix<Type>&
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -49,11 +49,11 @@ Foam::quadraticFitData::quadraticFitData
:
MeshObject<fvMesh, quadraticFitData>(mesh),
centralWeight_(cWeight),
#ifdef SPHERICAL_GEOMETRY
# ifdef SPHERICAL_GEOMETRY
dim_(2),
#else
# else
dim_(mesh.nGeometricD()),
#endif
# endif
minSize_
(
dim_ == 1 ? 3 :
@ -204,7 +204,7 @@ Foam::label Foam::quadraticFitData::calcFit
scalar scale = 0;
// calculate the matrix of the polynomial components
Matrix<scalar> B(C.size(), minSize_, scalar(0));
scalarRectangularMatrix B(C.size(), minSize_, scalar(0));
for(label ip = 0; ip < C.size(); ip++)
{
@ -212,11 +212,11 @@ Foam::label Foam::quadraticFitData::calcFit
scalar px = (p - p0)&idir;
scalar py = (p - p0)&jdir;
#ifndef SPHERICAL_GEOMETRY
# ifndef SPHERICAL_GEOMETRY
scalar pz = (p - p0)&kdir;
#else
# else
scalar pz = mag(p) - mag(p0);
#endif
# endif
if (ip == 0)
{

View File

@ -114,7 +114,7 @@ Foam::scalarField Foam::chemistryModel::omega
forAll(reactions_, i)
{
const reaction& R = reactions_[i];
scalar omegai = omega
(
R, c, T, p, pf, cf, lRef, pr, cr, rRef
@ -164,13 +164,13 @@ Foam::scalar Foam::chemistryModel::omega
pf = 1.0;
pr = 1.0;
label Nl = R.lhs().size();
label Nr = R.rhs().size();
label slRef = 0;
lRef = R.lhs()[slRef].index;
pf = kf;
for(label s=1; s<Nl; s++)
{
@ -212,7 +212,7 @@ Foam::scalar Foam::chemistryModel::omega
label srRef = 0;
rRef = R.rhs()[srRef].index;
// find the matrix element and element position for the rhs
pr = kr;
for(label s=1; s<Nr; s++)
@ -250,7 +250,7 @@ Foam::scalar Foam::chemistryModel::omega
{
pr *= pow(cr, exp-1.0);
}
}
return pf*cf - pr*cr;
@ -313,12 +313,12 @@ void Foam::chemistryModel::jacobian
const scalar t,
const scalarField& c,
scalarField& dcdt,
Matrix<scalar>& dfdc
scalarSquareMatrix& dfdc
) const
{
scalar T = c[Ns_];
scalar p = c[Ns_ + 1];
scalarField c2(Ns(), 0.0);
for(label i=0; i<Ns(); i++)
{
@ -470,23 +470,23 @@ Foam::tmp<Foam::volScalarField> Foam::chemistryModel::tc() const
scalar pi = thermo_.p()[celli];
scalarField c(Ns_);
scalar cSum = 0.0;
for(label i=0; i<Ns_; i++)
{
scalar Yi = Y_[i][celli];
c[i] = rhoi*Yi/specieThermo_[i].W();
cSum += c[i];
}
forAll(reactions_, i)
{
const reaction& R = reactions_[i];
omega
(
R, c, Ti, pi, pf, cf, lRef, pr, cr, rRef
);
forAll(R.rhs(), s)
{
scalar sr = R.rhs()[s].stoichCoeff;
@ -544,22 +544,22 @@ void Foam::chemistryModel::calculate()
{
RR_[i][celli] = 0.0;
}
scalar rhoi = rho_[celli];
scalar Ti = thermo_.T()[celli];
scalar pi = thermo_.p()[celli];
scalarField c(Ns_);
scalarField dcdt(nEqns(), 0.0);
for(label i=0; i<Ns_; i++)
{
scalar Yi = Y_[i][celli];
c[i] = rhoi*Yi/specieThermo_[i].W();
}
dcdt = omega(c, Ti, pi);
for(label i=0; i<Ns_; i++)
{
RR_[i][celli] = dcdt[i]*specieThermo_[i].W();
@ -624,7 +624,7 @@ Foam::scalar Foam::chemistryModel::solve(const scalar t0, const scalar deltaT)
for(label i=0; i<Ns_; i++)
{
mixture += (c[i]/cTot)*specieThermo_[i];
}
}
Ti = mixture.TH(hi, Ti);
timeLeft -= dt;
@ -639,7 +639,7 @@ Foam::scalar Foam::chemistryModel::solve(const scalar t0, const scalar deltaT)
for(label i=0; i<Ns_; i++)
{
WTot += c[i]*specieThermo_[i].W();
}
}
WTot /= cTot;
for(label i=0; i<Ns_; i++)

View File

@ -39,7 +39,6 @@ SourceFiles
#include "hCombustionThermo.H"
#include "reactingMixture.H"
#include "Matrix.H"
#include "ODE.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -251,7 +250,7 @@ public:
const scalar t,
const scalarField& c,
scalarField& dcdt,
Matrix<scalar>& dfdc
scalarSquareMatrix& dfdc
) const;
//- Calculates the reaction rates

View File

@ -204,11 +204,20 @@ LRR::LRR
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
mut_ = Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
{
FatalErrorIn
@ -221,6 +230,12 @@ LRR::LRR
<< exit(FatalError);
}
mut_ == Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -310,8 +325,13 @@ void LRR::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -399,9 +419,13 @@ void LRR::correct()
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/epsilon_;
mut_ == rho_*Cmu_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
// Correct wall shear stresses

View File

@ -97,6 +97,7 @@ class LRR
volScalarField k_;
volScalarField epsilon_;
volScalarField mut_;
volScalarField alphat_;
public:
@ -152,7 +153,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -226,11 +226,20 @@ LaunderGibsonRSTM::LaunderGibsonRSTM
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
mut_ = Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
{
FatalErrorIn
@ -243,6 +252,12 @@ LaunderGibsonRSTM::LaunderGibsonRSTM
<< exit(FatalError);
}
mut_ == Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -335,8 +350,13 @@ void LaunderGibsonRSTM::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -438,9 +458,12 @@ void LaunderGibsonRSTM::correct()
// Re-calculate turbulent viscosity
mut_ = Cmu_*rho_*sqr(k_)/epsilon_;
mut_ == Cmu_*rho_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
// Correct wall shear stresses

View File

@ -104,6 +104,7 @@ class LaunderGibsonRSTM
volScalarField k_;
volScalarField epsilon_;
volScalarField mut_;
volScalarField alphat_;
public:
@ -161,7 +162,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -14,6 +14,9 @@ kOmegaSST/kOmegaSST.C
/* Wall functions */
wallFunctions = derivedFvPatchFields/wallFunctions
alphatWallFunctions = $(wallFunctions)/alphatWallFunctions
$(alphatWallFunctions)/alphatWallFunction/alphatWallFunctionFvPatchScalarField.C
mutWallFunctions = $(wallFunctions)/mutWallFunctions
$(mutWallFunctions)/mutWallFunction/mutWallFunctionFvPatchScalarField.C
$(mutWallFunctions)/mutRoughWallFunction/mutRoughWallFunctionFvPatchScalarField.C

View File

@ -47,7 +47,8 @@ void RASModel::printCoeffs()
{
if (printCoeffs_)
{
Info<< type() << "Coeffs" << coeffDict_ << endl;
Info<< type() << "Coeffs" << coeffDict_ << nl
<< "wallFunctionCoeffs" << wallFunctionDict_ << endl;
}
}
@ -115,6 +116,15 @@ RASModel::RASModel
0.09
)
),
Prt_
(
dimensioned<scalar>::lookupOrAddToDict
(
"Prt",
wallFunctionDict_,
0.85
)
),
yPlusLam_(yPlusLam(kappa_.value(), E_.value())),
@ -148,11 +158,9 @@ tmp<scalarField> RASModel::yPlus(const label patchNo) const
tmp<scalarField> tYp(new scalarField(curPatch.size()));
scalarField& Yp = tYp();
if (typeid(curPatch) == typeid(wallFvPatch))
if (isType<wallFvPatch>(curPatch))
{
scalar Cmu(readScalar(coeffDict_.lookup("Cmu")));
Yp = pow(Cmu, 0.25)
Yp = pow(Cmu_.value(), 0.25)
*y_[patchNo]
*sqrt(k()().boundaryField()[patchNo].patchInternalField())
/(
@ -165,8 +173,8 @@ tmp<scalarField> RASModel::yPlus(const label patchNo) const
WarningIn
(
"tmp<scalarField> RASModel::yPlus(const label patchNo) const"
) << "Patch " << patchNo << " is not a wall. Returning blank field"
<< endl;
) << "Patch " << patchNo << " is not a wall. Returning null field"
<< nl << endl;
Yp.setSize(0);
}
@ -191,8 +199,11 @@ bool RASModel::read()
lookup("turbulence") >> turbulence_;
coeffDict_ = subDict(type() + "Coeffs");
kappa_.readIfPresent(subDict("wallFunctionCoeffs"));
E_.readIfPresent(subDict("wallFunctionCoeffs"));
wallFunctionDict_ = subDict("wallFunctionCoeffs");
kappa_.readIfPresent(wallFunctionDict_);
E_.readIfPresent(wallFunctionDict_);
Cmu_.readIfPresent(wallFunctionDict_);
Prt_.readIfPresent(wallFunctionDict_);
yPlusLam_ = yPlusLam(kappa_.value(), E_.value());

View File

@ -95,6 +95,7 @@ protected:
dimensionedScalar kappa_;
dimensionedScalar E_;
dimensionedScalar Cmu_;
dimensionedScalar Prt_;
scalar yPlusLam_;
@ -244,6 +245,12 @@ public:
return Cmu_;
}
//- Return turbulent Prandtl number for use in wall-functions
dimensionedScalar Prt() const
{
return Prt_;
}
//- Return the near wall distances
const nearWallDist& y() const
{

View File

@ -174,11 +174,26 @@ RNGkEpsilon::RNGkEpsilon
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
mut_ = Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -263,8 +278,13 @@ void RNGkEpsilon::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -330,8 +350,12 @@ void RNGkEpsilon::correct()
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/epsilon_;
mut_ == rho_*Cmu_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
}

View File

@ -87,6 +87,7 @@ class RNGkEpsilon
volScalarField k_;
volScalarField epsilon_;
volScalarField mut_;
volScalarField alphat_;
public:
@ -142,7 +143,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -27,6 +27,7 @@ License
#include "backwardsCompatibilityWallFunctions.H"
#include "calculatedFvPatchField.H"
#include "alphatWallFunctionFvPatchScalarField.H"
#include "mutWallFunctionFvPatchScalarField.H"
#include "epsilonWallFunctionFvPatchScalarField.H"
#include "kQRWallFunctionFvPatchField.H"
@ -41,6 +42,76 @@ namespace compressible
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
tmp<volScalarField> autoCreateAlphat
(
const word& fieldName,
const fvMesh& mesh
)
{
IOobject alphatHeader
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (alphatHeader.headerOk())
{
return tmp<volScalarField>(new volScalarField(alphatHeader, mesh));
}
else
{
Info<< "--> Upgrading " << fieldName << " to employ run-time "
<< "selectable wall functions" << endl;
const fvBoundaryMesh& bm = mesh.boundary();
wordList alphatBoundaryTypes(bm.size());
forAll(bm, patchI)
{
if (isType<wallFvPatch>(bm[patchI]))
{
alphatBoundaryTypes[patchI] =
RASModels::alphatWallFunctionFvPatchScalarField::typeName;
}
else
{
alphatBoundaryTypes[patchI] =
calculatedFvPatchField<scalar>::typeName;
}
}
tmp<volScalarField> alphat
(
new volScalarField
(
IOobject
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
dimensionedScalar("zero", dimDensity*dimArea/dimTime, 0.0),
alphatBoundaryTypes
)
);
Info<< " Writing updated " << fieldName << endl;
alphat().write();
return alphat;
}
}
tmp<volScalarField> autoCreateMut
(
const word& fieldName,

View File

@ -53,6 +53,13 @@ namespace compressible
const fvMesh& mesh
);
//- alphat
tmp<volScalarField> autoCreateAlphat
(
const word& fieldName,
const fvMesh& mesh
);
//- epsilon
tmp<volScalarField> autoCreateEpsilon
(

View File

@ -0,0 +1,132 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "alphatWallFunctionFvPatchScalarField.H"
#include "RASModel.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
namespace RASModels
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
alphatWallFunctionFvPatchScalarField::
alphatWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(p, iF)
{}
alphatWallFunctionFvPatchScalarField::
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchScalarField(ptf, p, iF, mapper)
{}
alphatWallFunctionFvPatchScalarField::
alphatWallFunctionFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchScalarField(p, iF, dict)
{}
alphatWallFunctionFvPatchScalarField::
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField& awfpsf
)
:
fixedValueFvPatchScalarField(awfpsf)
{}
alphatWallFunctionFvPatchScalarField::
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField& awfpsf,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(awfpsf, iF)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void alphatWallFunctionFvPatchScalarField::updateCoeffs()
{
const RASModel& ras = db().lookupObject<RASModel>("RASProperties");
const scalar Prt = ras.Prt().value();
const scalarField& mutw =
patch().lookupPatchField<volScalarField, scalar>("mut");
operator==(mutw/Prt);
}
void alphatWallFunctionFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeField(fvPatchScalarField, alphatWallFunctionFvPatchScalarField);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace RASModels
} // End namespace compressible
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,155 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::compressible::RASModels::alphatWallFunctionFvPatchScalarField
Description
Boundary condition for turbulent thermal diffusivity when using wall
functions
- replicates OpenFOAM v1.5 (and earlier) behaviour
SourceFiles
alphatWallFunctionFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#ifndef alphatWallFunctionFvPatchScalarField_H
#define alphatWallFunctionFvPatchScalarField_H
#include "fixedValueFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace compressible
{
namespace RASModels
{
/*---------------------------------------------------------------------------*\
Class alphatWallFunctionFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class alphatWallFunctionFvPatchScalarField
:
public fixedValueFvPatchScalarField
{
public:
//- Runtime type information
TypeName("alphatWallFunction");
// Constructors
//- Construct from patch and internal field
alphatWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
alphatWallFunctionFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// alphatWallFunctionFvPatchScalarField
// onto a new patch
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchScalarField> clone() const
{
return tmp<fvPatchScalarField>
(
new alphatWallFunctionFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
alphatWallFunctionFvPatchScalarField
(
const alphatWallFunctionFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchScalarField> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchScalarField>
(
new alphatWallFunctionFvPatchScalarField(*this, iF)
);
}
// Member functions
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
// I-O
//- Write
void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace RASModels
} // End namespace compressible
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -155,11 +155,26 @@ kEpsilon::kEpsilon
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
mut_ = Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == Cmu_*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -243,8 +258,13 @@ void kEpsilon::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == rho_*Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -303,8 +323,12 @@ void kEpsilon::correct()
// Re-calculate viscosity
mut_ = rho_*Cmu_*sqr(k_)/epsilon_;
mut_ == rho_*Cmu_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
}

View File

@ -74,7 +74,6 @@ class kEpsilon
// Model coefficients
// dimensionedScalar Cmu;
dimensionedScalar Cmu_;
dimensionedScalar C1_;
dimensionedScalar C2_;
@ -88,6 +87,7 @@ class kEpsilon
volScalarField k_;
volScalarField epsilon_;
volScalarField mut_;
volScalarField alphat_;
public:
@ -144,7 +144,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -258,11 +258,26 @@ kOmegaSST::kOmegaSST
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
mut_ = a1_*rho_*k_/max(a1_*omega_, F2()*sqrt(magSqr(symm(fvc::grad(U_)))));
mut_ == a1_*rho_*k_/max(a1_*omega_, F2()*sqrt(magSqr(symm(fvc::grad(U_)))));
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -351,11 +366,15 @@ void kOmegaSST::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ =
mut_ ==
a1_*rho_*k_
/max(a1_*omega_, F2()*sqrt(magSqr(symm(fvc::grad(U_)))));
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -430,8 +449,12 @@ void kOmegaSST::correct()
// Re-calculate viscosity
mut_ = a1_*rho_*k_/max(a1_*omega_, F2()*sqrt(S2));
mut_ == a1_*rho_*k_/max(a1_*omega_, F2()*sqrt(S2));
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
}

View File

@ -134,6 +134,7 @@ class kOmegaSST
volScalarField k_;
volScalarField omega_;
volScalarField mut_;
volScalarField alphat_;
// Private member functions
@ -238,7 +239,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -187,14 +187,29 @@ realizableKE::realizableKE
IOobject::AUTO_WRITE
),
autoCreateMut("mut", mesh_)
),
alphat_
(
IOobject
(
"alphat",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
autoCreateAlphat("alphat", mesh_)
)
{
bound(k_, k0_);
bound(epsilon_, epsilon0_);
mut_ = rCmu(fvc::grad(U_))*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_ == rCmu(fvc::grad(U_))*rho_*sqr(k_)/(epsilon_ + epsilonSmall_);
mut_.correctBoundaryConditions();
alphat_ == mut_/Prt_;
alphat_.correctBoundaryConditions();
printCoeffs();
}
@ -276,8 +291,13 @@ void realizableKE::correct()
if (!turbulence_)
{
// Re-calculate viscosity
mut_ = rCmu(fvc::grad(U_))*rho_*sqr(k_)/epsilon_;
mut_ == rCmu(fvc::grad(U_))*rho_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
return;
}
@ -342,8 +362,12 @@ void realizableKE::correct()
bound(k_, k0_);
// Re-calculate viscosity
mut_ = rCmu(gradU, S2, magS)*rho_*sqr(k_)/epsilon_;
mut_ == rCmu(gradU, S2, magS)*rho_*sqr(k_)/epsilon_;
mut_.correctBoundaryConditions();
// Re-calculate thermal diffusivity
alphat_ = mut_/Prt_;
alphat_.correctBoundaryConditions();
}

View File

@ -91,6 +91,7 @@ class realizableKE
volScalarField k_;
volScalarField epsilon_;
volScalarField mut_;
volScalarField alphat_;
tmp<volScalarField> rCmu
(
@ -157,7 +158,7 @@ public:
{
return tmp<volScalarField>
(
new volScalarField("alphaEff", alphah_*mut_ + alpha())
new volScalarField("alphaEff", alphah_*alphat_ + alpha())
);
}

View File

@ -187,7 +187,7 @@ LRR::LRR
autoCreateNut("nut", mesh_)
)
{
nut_ = Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_ == Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_.correctBoundaryConditions();
if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
@ -381,7 +381,7 @@ void LRR::correct()
// Re-calculate viscosity
nut_ = Cmu_*sqr(k_)/epsilon_;
nut_ == Cmu_*sqr(k_)/epsilon_;
nut_.correctBoundaryConditions();

View File

@ -216,7 +216,7 @@ LaunderGibsonRSTM::LaunderGibsonRSTM
autoCreateNut("nut", mesh_)
)
{
nut_ = Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_ == Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_.correctBoundaryConditions();
if (couplingFactor_.value() < 0.0 || couplingFactor_.value() > 1.0)
@ -422,7 +422,7 @@ void LaunderGibsonRSTM::correct()
// Re-calculate turbulent viscosity
nut_ = Cmu_*sqr(k_)/epsilon_;
nut_ == Cmu_*sqr(k_)/epsilon_;
nut_.correctBoundaryConditions();

View File

@ -228,7 +228,7 @@ LienCubicKE::LienCubicKE
)
)
{
nut_ = Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_) + C5viscosity_;
nut_ == Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_) + C5viscosity_;
nut_.correctBoundaryConditions();
printCoeffs();
@ -385,7 +385,7 @@ void LienCubicKE::correct()
- 2.0*pow(Cmu_, 3.0)*pow(k_, 4.0)/pow(epsilon_, 3.0)
*(magSqr(gradU_ + gradU_.T()) - magSqr(gradU_ - gradU_.T()));
nut_ = Cmu_*sqr(k_)/epsilon_ + C5viscosity_;
nut_ == Cmu_*sqr(k_)/epsilon_ + C5viscosity_;
nut_.correctBoundaryConditions();
nonlinearStress_ = symm

View File

@ -45,7 +45,8 @@ void RASModel::printCoeffs()
{
if (printCoeffs_)
{
Info<< type() << "Coeffs" << coeffDict_ << endl;;
Info<< type() << "Coeffs" << coeffDict_ << nl
<< "wallFunctionCoeffs" << wallFunctionDict_ << endl;
}
}
@ -148,9 +149,10 @@ tmp<scalarField> RASModel::yPlus(const label patchNo) const
tmp<scalarField> tYp(new scalarField(curPatch.size()));
scalarField& Yp = tYp();
if (typeid(curPatch) == typeid(wallFvPatch))
if (isType<wallFvPatch>(curPatch))
{
Yp = pow(Cmu_.value(), 0.25)*y_[patchNo]
Yp = pow(Cmu_.value(), 0.25)
*y_[patchNo]
*sqrt(k()().boundaryField()[patchNo].patchInternalField())
/nu().boundaryField()[patchNo];
}
@ -158,9 +160,8 @@ tmp<scalarField> RASModel::yPlus(const label patchNo) const
{
WarningIn
(
"tmp<scalarField> RASModel::yPlus(const label patchNo)"
) << "const : " << nl
<< "Patch " << patchNo << " is not a wall. Returning zero field"
"tmp<scalarField> RASModel::yPlus(const label patchNo) const"
) << "Patch " << patchNo << " is not a wall. Returning null field"
<< nl << endl;
Yp.setSize(0);
@ -185,8 +186,8 @@ bool RASModel::read()
{
lookup("turbulence") >> turbulence_;
coeffDict_ = subDict(type() + "Coeffs");
wallFunctionDict_ = subDict("wallFunctionCoeffs");
wallFunctionDict_ = subDict("wallFunctionCoeffs");
kappa_.readIfPresent(wallFunctionDict_);
E_.readIfPresent(wallFunctionDict_);
Cmu_.readIfPresent(wallFunctionDict_);

View File

@ -156,7 +156,7 @@ RNGkEpsilon::RNGkEpsilon
autoCreateNut("nut", mesh_)
)
{
nut_ = Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_ == Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_.correctBoundaryConditions();
printCoeffs();
@ -297,7 +297,7 @@ void RNGkEpsilon::correct()
// Re-calculate viscosity
nut_ = Cmu_*sqr(k_)/epsilon_;
nut_ == Cmu_*sqr(k_)/epsilon_;
nut_.correctBoundaryConditions();
}

View File

@ -160,7 +160,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs()
scalar yPlus = Cmu25*y[faceI]*sqrt(k[faceCellI])/nuw[faceI];
omega[faceCellI] = sqrt(k[faceCellI])/(Cmu25*kappa*y[faceCellI]);
omega[faceCellI] = sqrt(k[faceCellI])/(Cmu25*kappa*y[faceI]);
if (yPlus > yPlusLam)
{
@ -168,7 +168,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs()
(nutw[faceI] + nuw[faceI])
*magGradUw[faceI]
*Cmu25*sqrt(k[faceCellI])
/(kappa*y[faceCellI]);
/(kappa*y[faceI]);
}
else
{

View File

@ -130,7 +130,7 @@ kEpsilon::kEpsilon
autoCreateNut("nut", mesh_)
)
{
nut_ = Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_ == Cmu_*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_.correctBoundaryConditions();
printCoeffs();
@ -267,7 +267,7 @@ void kEpsilon::correct()
// Re-calculate viscosity
nut_ = Cmu_*sqr(k_)/epsilon_;
nut_ == Cmu_*sqr(k_)/epsilon_;
nut_.correctBoundaryConditions();
}

View File

@ -141,7 +141,7 @@ kOmega::kOmega
autoCreateNut("nut", mesh_)
)
{
nut_ = k_/(omega_ + omegaSmall_);
nut_ == k_/(omega_ + omegaSmall_);
nut_.correctBoundaryConditions();
printCoeffs();
@ -273,7 +273,7 @@ void kOmega::correct()
// Re-calculate viscosity
nut_ = k_/omega_;
nut_ == k_/omega_;
nut_.correctBoundaryConditions();
}

View File

@ -250,7 +250,7 @@ kOmegaSST::kOmegaSST
autoCreateNut("nut", mesh_)
)
{
nut_ =
nut_ ==
a1_*k_
/max
(
@ -411,7 +411,7 @@ void kOmegaSST::correct()
// Re-calculate viscosity
nut_ = a1_*k_/max(a1_*omega_, F2()*sqrt(S2));
nut_ == a1_*k_/max(a1_*omega_, F2()*sqrt(S2));
nut_.correctBoundaryConditions();
}

View File

@ -182,7 +182,7 @@ realizableKE::realizableKE
bound(k_, k0_);
bound(epsilon_, epsilon0_);
nut_ = rCmu(fvc::grad(U_))*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_ == rCmu(fvc::grad(U_))*sqr(k_)/(epsilon_ + epsilonSmall_);
nut_.correctBoundaryConditions();
printCoeffs();
@ -326,7 +326,7 @@ void realizableKE::correct()
// Re-calculate viscosity
nut_ = rCmu(gradU, S2, magS)*sqr(k_)/epsilon_;
nut_ == rCmu(gradU, S2, magS)*sqr(k_)/epsilon_;
nut_.correctBoundaryConditions();
}