From be6fd90b927e4432b7c77492a48635f9ee60b9a5 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 3 Jun 2008 15:33:56 +0100 Subject: [PATCH] * src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/: Added new BC (untested). --- src/finiteVolume/Make/files | 1 + ...ngUniformTotalPressureFvPatchScalarField.C | 301 ++++++++++++++++++ ...ngUniformTotalPressureFvPatchScalarField.H | 228 +++++++++++++ 3 files changed, 530 insertions(+) create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.H diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index d2d506ed53..c899636dce 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -99,6 +99,7 @@ $(derivedFvPatchFields)/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueF $(derivedFvPatchFields)/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchFields.C $(derivedFvPatchFields)/totalPressure/totalPressureFvPatchScalarField.C +$(derivedFvPatchFields)/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C $(derivedFvPatchFields)/totalTemperature/totalTemperatureFvPatchScalarField.C $(derivedFvPatchFields)/turbulentInlet/turbulentInletFvPatchFields.C $(derivedFvPatchFields)/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C new file mode 100644 index 0000000000..326b19ed53 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C @@ -0,0 +1,301 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 "timeVaryingUniformTotalPressureFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "IFstream.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +timeVaryingUniformTotalPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchScalarField(p, iF), + UName_("undefined"), + phiName_("undefined"), + rhoName_("undefined"), + psiName_("undefined"), + gamma_(0.0), + p0_(0.0) + +{} + + +Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +timeVaryingUniformTotalPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchScalarField(p, iF), + UName_(dict.lookup("U")), + phiName_(dict.lookup("phi")), + rhoName_(dict.lookup("rho")), + psiName_(dict.lookup("psi")), + gamma_(readScalar(dict.lookup("gamma"))), + p0_(readScalar(dict.lookup("p0"))), + totalPressureDataFileName_(dict.lookup("totalPressureDataFileName")), + totalPressureTimeSeries_(word(dict.lookup("timeBounding"))) +{ + if (dict.found("value")) + { + fvPatchField::operator= + ( + scalarField("value", dict, p.size()) + ); + } + else + { + fvPatchField::operator=(p0_); + } +} + + +Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +timeVaryingUniformTotalPressureFvPatchScalarField +( + const timeVaryingUniformTotalPressureFvPatchScalarField& 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_), + totalPressureDataFileName_(ptf.totalPressureDataFileName_), + totalPressureTimeSeries_(ptf.timeBounding()) +{} + + +Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +timeVaryingUniformTotalPressureFvPatchScalarField +( + const timeVaryingUniformTotalPressureFvPatchScalarField& tppsf +) +: + fixedValueFvPatchScalarField(tppsf), + UName_(tppsf.UName_), + phiName_(tppsf.phiName_), + rhoName_(tppsf.rhoName_), + psiName_(tppsf.psiName_), + gamma_(tppsf.gamma_), + p0_(tppsf.p0_), + totalPressureDataFileName_(tppsf.totalPressureDataFileName_), + totalPressureTimeSeries_(tppsf.timeBounding()) +{} + + +Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +timeVaryingUniformTotalPressureFvPatchScalarField +( + const timeVaryingUniformTotalPressureFvPatchScalarField& 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_), + totalPressureDataFileName_(tppsf.totalPressureDataFileName_), + totalPressureTimeSeries_(tppsf.timeBounding()) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::timeVaryingUniformTotalPressureFvPatchScalarField:: +currentValue() +{ + if (totalPressureTimeSeries_.size() == 0) + { + fileName fName(totalPressureDataFileName_); + fName.expand(); + + if (fName.size() == 0) + { + FatalErrorIn + ( + "timeVaryingUniformFixedValueFvPatchField::currentValue()" + ) << "timeDataFile not specified for Patch " + << patch().name() + << exit(FatalError); + } + else + { + // relative path + if (fName[0] != '/') + { + fName = db().path()/fName; + } + + // just in case we change the interface to timeSeries + word boundType = timeBounding(); + + IFstream(fName)() >> totalPressureTimeSeries_; + totalPressureTimeSeries_.bounding(boundType); + + // be a bit paranoid and check that the list is okay + totalPressureTimeSeries_.check(); + } + + if (totalPressureTimeSeries_.size() == 0) + { + FatalErrorIn + ( + "timeVaryingUniformFixedValueFvPatchField" + "::currentValue()" + ) << "empty time series for Patch " + << this->patch().name() + << exit(FatalError); + } + } + + return totalPressureTimeSeries_(this->db().time().timeOutputValue()); +} + + +void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs +( + const vectorField& Up +) +{ + if (updated()) + { + return; + } + + p0_ = currentValue(); + + 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 + ( + "timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs()" + ) << " rho or psi set inconsitently, rho = " << rhoName_ + << ", psi = " << psiName_ << '.' << nl + << " Set either rho or psi or neither depending on the " + "definition of total pressure." << nl + << " Set the unused variables to 'none'." + << "\n on patch " << this->patch().name() + << " of field " << this->dimensionedInternalField().name() + << " in file " << this->dimensionedInternalField().objectPath() + << exit(FatalError); + } + + fixedValueFvPatchScalarField::updateCoeffs(); +} + + +void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::updateCoeffs() +{ + updateCoeffs(patch().lookupPatchField(UName_)); +} + + +void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::write(Ostream& os) const +{ + fvPatchScalarField::write(os); + os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl; + os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; + os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; + os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl; + os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl; + os.writeKeyword("p0") << p0_ << token::END_STATEMENT << endl; + os.writeKeyword("totalPressureDataFileName") + << totalPressureDataFileName_ << token::END_STATEMENT << nl; + os.writeKeyword("timeBounding") + << timeBounding() << token::END_STATEMENT << nl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + timeVaryingUniformTotalPressureFvPatchScalarField + ); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.H new file mode 100644 index 0000000000..8436623183 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.H @@ -0,0 +1,228 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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::timeVaryingUniformTotalPressureFvPatchScalarField + +Description + See timeVaryingUniformFixedValueFvPatchField.H + and totalPressureFvPatchScalarField.H + +SourceFiles + timeVaryingUniformTotalPressureFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef timeVaryingUniformTotalPressureFvPatchScalarField_H +#define timeVaryingUniformTotalPressureFvPatchScalarField_H + +#include "fixedValueFvPatchFields.H" +#include "timeSeries.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class timeVaryingTotalPressureFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class timeVaryingUniformTotalPressureFvPatchScalarField +: + public fixedValueFvPatchScalarField +{ + // Private data + + //- Name of the velocity field + word UName_; + + //- Name of the flux transporting the field + word phiName_; + + //- Name of the density field used to normalise the mass flux + // if neccessary + word rhoName_; + + //- Name of the compressibility field used to calculate the wave speed + word psiName_; + + //- Heat capacity ratio + scalar gamma_; + + //- Total pressure + scalar p0_; + + fileName totalPressureDataFileName_; + timeSeries totalPressureTimeSeries_; + + //- Interpolate the value at the current time + scalar currentValue(); + + +public: + + //- Runtime type information + TypeName("timeVaryingTotalPressure"); + + + // Constructors + + //- Construct from patch and internal field + timeVaryingUniformTotalPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + timeVaryingUniformTotalPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given patch field onto a new patch + timeVaryingUniformTotalPressureFvPatchScalarField + ( + const timeVaryingUniformTotalPressureFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + timeVaryingUniformTotalPressureFvPatchScalarField + ( + const timeVaryingUniformTotalPressureFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new timeVaryingUniformTotalPressureFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + timeVaryingUniformTotalPressureFvPatchScalarField + ( + const timeVaryingUniformTotalPressureFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + new timeVaryingUniformTotalPressureFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Return the name of the velocity field + const word& UName() const + { + return UName_; + } + + //- Return reference to the name of the velocity field + // to allow adjustment + word& UName() + { + return UName_; + } + + //- Return the heat capacity ratio + scalar gamma() const + { + return gamma_; + } + + //- Return reference to the heat capacity ratio to allow adjustment + scalar& gamma() + { + return gamma_; + } + + //- Return the total pressure + scalar p0() const + { + return p0_; + } + + //- Return reference to the total pressure to allow adjustment + scalar p0() + { + return p0_; + } + + //- Return the out-of-bounds treatment as a word + word timeBounding() const + { + return totalPressureTimeSeries_.bounding(); + } + + //- Return the time series used + const timeSeries& totalPressureTimeSeries() const + { + return totalPressureTimeSeries_; + } + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + // using the given patch velocity field + virtual void updateCoeffs(const vectorField& Up); + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //