BUG: Corrections to pressureTools function object

This commit is contained in:
andy
2012-11-22 10:58:29 +00:00
parent f1b15b766b
commit be3793b7bb
2 changed files with 52 additions and 9 deletions

View File

@ -56,7 +56,7 @@ Foam::word Foam::pressureTools::pName() const
} }
Foam::dimensionedScalar Foam::pressureTools::rho Foam::dimensionedScalar Foam::pressureTools::rhoScale
( (
const volScalarField& p const volScalarField& p
) const ) const
@ -72,6 +72,38 @@ Foam::dimensionedScalar Foam::pressureTools::rho
} }
Foam::tmp<Foam::volScalarField> Foam::pressureTools::rho
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return p.mesh().lookupObject<volScalarField>(rhoName_);
}
else
{
return
tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"rho",
p.mesh().time().timeName(),
p.mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
p.mesh(),
dimensionedScalar("zero", dimDensity, rhoRef_)
)
);
}
}
Foam::dimensionedScalar Foam::pressureTools::pRef() const Foam::dimensionedScalar Foam::pressureTools::pRef() const
{ {
dimensionedScalar value("pRef", dimPressure, 0.0); dimensionedScalar value("pRef", dimPressure, 0.0);
@ -81,11 +113,14 @@ Foam::dimensionedScalar Foam::pressureTools::pRef() const
value.value() += pRef_; value.value() += pRef_;
} }
return pRef(); return value;
} }
Foam::tmp<Foam::volScalarField> Foam::pressureTools::pDyn() const Foam::tmp<Foam::volScalarField> Foam::pressureTools::pDyn
(
const volScalarField& p
) const
{ {
const fvMesh& mesh = refCast<const fvMesh>(obr_); const fvMesh& mesh = refCast<const fvMesh>(obr_);
@ -110,7 +145,7 @@ Foam::tmp<Foam::volScalarField> Foam::pressureTools::pDyn() const
{ {
const volVectorField& U = obr_.lookupObject<volVectorField>(UName_); const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
tpDyn() == 0.5*magSqr(U); tpDyn() == rho(p)*0.5*magSqr(U);
} }
return tpDyn; return tpDyn;
@ -126,7 +161,7 @@ Foam::tmp<Foam::volScalarField> Foam::pressureTools::convertToCoeff
if (calcCoeff_) if (calcCoeff_)
{ {
tCoeff() /= pDyn(); tCoeff() /= pDyn(p);
} }
return tCoeff; return tCoeff;
@ -150,6 +185,7 @@ Foam::pressureTools::pressureTools
calcCoeff_(false), calcCoeff_(false),
pName_("p"), pName_("p"),
UName_("U"), UName_("U"),
rhoName_("rho"),
pRef_(0.0), pRef_(0.0),
rhoRef_(1.0) rhoRef_(1.0)
{ {
@ -188,6 +224,7 @@ void Foam::pressureTools::read(const dictionary& dict)
{ {
dict.readIfPresent("pName", pName_); dict.readIfPresent("pName", pName_);
dict.readIfPresent("UName", UName_); dict.readIfPresent("UName", UName_);
dict.readIfPresent("rhoName", rhoName_);
const volScalarField& p = obr_.lookupObject<volScalarField>(pName_); const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
@ -234,7 +271,7 @@ void Foam::pressureTools::write()
obr_, obr_,
IOobject::NO_READ IOobject::NO_READ
), ),
convertToCoeff(rho(p)*(p + pDyn()) + pRef()) convertToCoeff(rhoScale(p)*p + pDyn(p) + pRef())
); );
pResult.write(); pResult.write();

View File

@ -125,6 +125,9 @@ class pressureTools
//- Name of velocity field, default is "U" //- Name of velocity field, default is "U"
word UName_; word UName_;
//- Name of density field, default is "rho"
word rhoName_;
//- Reference pressure level (used for total pressure) //- Reference pressure level (used for total pressure)
scalar pRef_; scalar pRef_;
@ -138,13 +141,16 @@ class pressureTools
word pName() const; word pName() const;
//- Return the density scaling if supplied with kinematic pressure //- Return the density scaling if supplied with kinematic pressure
dimensionedScalar rho(const volScalarField& p) const; dimensionedScalar rhoScale(const volScalarField& p) const;
//- Return the density field
tmp<volScalarField> rho(const volScalarField& p) const;
//- Return the reference pressure //- Return the reference pressure
dimensionedScalar pRef() const; dimensionedScalar pRef() const;
//- Calculate and return the (kinematic) dynamic pressure //- Calculate and return the dynamic pressure
tmp<volScalarField> pDyn() const; tmp<volScalarField> pDyn(const volScalarField& p) const;
//- Convert to coeff data by applying the pDyn scaling //- Convert to coeff data by applying the pDyn scaling
tmp<volScalarField> convertToCoeff(const volScalarField& p) const; tmp<volScalarField> convertToCoeff(const volScalarField& p) const;