This repository has been archived on 2023-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
foam-extend4.1-coherent-io/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C
2013-08-20 11:42:36 +01:00

275 lines
7.4 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 "totalPressureFvPatchScalarField.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(p, iF),
UName_("U"),
phiName_("phi"),
rhoName_("none"),
psiName_("none"),
gamma_(0.0),
p0_(p.size(), 0.0)
{}
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
fixedValueFvPatchScalarField(p, iF),
UName_(dict.lookupOrDefault<word>("U", "U")),
phiName_(dict.lookupOrDefault<word>("phi", "phi")),
rhoName_(dict.lookupOrDefault<word>("rho", "none")),
psiName_(dict.lookupOrDefault<word>("psi", "none")),
gamma_(readScalar(dict.lookup("gamma"))),
p0_("p0", dict, p.size())
{
if (dict.found("value"))
{
fvPatchField<scalar>::operator=
(
scalarField("value", dict, p.size())
);
}
else
{
fvPatchField<scalar>::operator=(p0_);
}
}
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
(
const totalPressureFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchScalarField(ptf, p, iF, mapper),
UName_(ptf.UName_),
phiName_(ptf.phiName_),
rhoName_(ptf.rhoName_),
psiName_(ptf.psiName_),
gamma_(ptf.gamma_),
p0_(ptf.p0_, mapper)
{}
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
(
const totalPressureFvPatchScalarField& tppsf
)
:
fixedValueFvPatchScalarField(tppsf),
UName_(tppsf.UName_),
phiName_(tppsf.phiName_),
rhoName_(tppsf.rhoName_),
psiName_(tppsf.psiName_),
gamma_(tppsf.gamma_),
p0_(tppsf.p0_)
{}
Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField
(
const totalPressureFvPatchScalarField& tppsf,
const DimensionedField<scalar, volMesh>& iF
)
:
fixedValueFvPatchScalarField(tppsf, iF),
UName_(tppsf.UName_),
phiName_(tppsf.phiName_),
rhoName_(tppsf.rhoName_),
psiName_(tppsf.psiName_),
gamma_(tppsf.gamma_),
p0_(tppsf.p0_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::totalPressureFvPatchScalarField::autoMap
(
const fvPatchFieldMapper& m
)
{
fixedValueFvPatchScalarField::autoMap(m);
p0_.autoMap(m);
}
void Foam::totalPressureFvPatchScalarField::rmap
(
const fvPatchScalarField& ptf,
const labelList& addr
)
{
fixedValueFvPatchScalarField::rmap(ptf, addr);
const totalPressureFvPatchScalarField& tiptf =
refCast<const totalPressureFvPatchScalarField>(ptf);
p0_.rmap(tiptf.p0_, addr);
}
void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up)
{
if (updated())
{
return;
}
if (!this->db().objectRegistry::found(phiName_))
{
// Flux not available, do not update
fixedValueFvPatchScalarField::updateCoeffs();
return;
}
const fvsPatchField<scalar>& phip =
lookupPatchField<surfaceScalarField, scalar>(phiName_);
if (psiName_ == "none" && rhoName_ == "none")
{
operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up));
}
else if (rhoName_ == "none")
{
if (!this->db().objectRegistry::found(psiName_))
{
// psi not available, do not update
fixedValueFvPatchScalarField::updateCoeffs();
return;
}
const fvPatchScalarField& psip =
lookupPatchField<volScalarField, scalar>(psiName_);
if (gamma_ > 1.0)
{
scalar gM1ByG = (gamma_ - 1.0)/gamma_;
operator==
(
p0_
/pow
(
(1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)),
1.0/gM1ByG
)
);
}
else
{
operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up)));
}
}
else if (psiName_ == "none")
{
if (!this->db().objectRegistry::found(rhoName_))
{
// rho not available, do not update
fixedValueFvPatchScalarField::updateCoeffs();
return;
}
const fvPatchScalarField& rho =
lookupPatchField<volScalarField, scalar>(rhoName_);
operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up));
}
else
{
FatalErrorIn
(
"totalPressureFvPatchScalarField::updateCoeffs()"
) << " rho or psi set inconsistently, rho = " << rhoName_
<< ", psi = " << psiName_ << ".\n"
<< " Set either rho or psi or neither depending on the "
"definition of total pressure." << nl
<< " Set the unused variable(s) to 'none'.\n"
<< " on patch " << this->patch().name()
<< " of field " << this->dimensionedInternalField().name()
<< " in file " << this->dimensionedInternalField().objectPath()
<< exit(FatalError);
}
fixedValueFvPatchScalarField::updateCoeffs();
}
void Foam::totalPressureFvPatchScalarField::updateCoeffs()
{
updateCoeffs(lookupPatchField<volVectorField, vector>(UName_));
}
void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const
{
fvPatchScalarField::write(os);
writeEntryIfDifferent<word>(os, "U", "U", UName_);
writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
p0_.writeEntry("p0", os);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
totalPressureFvPatchScalarField
);
}
// ************************************************************************* //