/*---------------------------------------------------------------------------*\ ========= | \\ / 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& 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& iF, const dictionary& dict ) : fixedValueFvPatchScalarField(p, iF), UName_(dict.lookupOrDefault("U", "U")), phiName_(dict.lookupOrDefault("phi", "phi")), rhoName_(dict.lookupOrDefault("rho", "none")), psiName_(dict.lookupOrDefault("psi", "none")), gamma_(readScalar(dict.lookup("gamma"))), p0_("p0", dict, p.size()) { if (dict.found("value")) { fvPatchField::operator= ( scalarField("value", dict, p.size()) ); } else { fvPatchField::operator=(p0_); } } Foam::totalPressureFvPatchScalarField::totalPressureFvPatchScalarField ( const totalPressureFvPatchScalarField& ptf, const fvPatch& p, const DimensionedField& 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& 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(ptf); p0_.rmap(tiptf.p0_, addr); } void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) { if (updated()) { return; } const fvsPatchField& phip = patch().lookupPatchField(phiName_); if (psiName_ == "none" && rhoName_ == "none") { operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up)); } else if (rhoName_ == "none") { const fvPatchField& psip = patch().lookupPatchField(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") { const fvPatchField& rho = patch().lookupPatchField(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(patch().lookupPatchField(UName_)); } void Foam::totalPressureFvPatchScalarField::write(Ostream& os) const { fvPatchScalarField::write(os); writeEntryIfDifferent(os, "U", "U", UName_); writeEntryIfDifferent(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 ); } // ************************************************************************* //