From c6c4508217dd581e153b027c9d7693dddf016f4f Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Mon, 30 Jan 2012 16:05:15 +0000 Subject: [PATCH] New BC: phaseHydrostaticPressure Applies a constant density hydrostatic pressure to the region of the patch for which the specified phase is non-zero. --- .../multiphase/multiphaseEulerFoam/pEqn.H | 1 - src/finiteVolume/Make/files | 2 +- ...aseHydrostaticPressureFvPatchScalarField.C | 201 ++++++++++++++++ ...aseHydrostaticPressureFvPatchScalarField.H | 223 ++++++++++++++++++ 4 files changed, 425 insertions(+), 2 deletions(-) create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C create mode 100644 src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H b/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H index b93ea3a020b..675a410a167 100644 --- a/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H +++ b/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H @@ -155,7 +155,6 @@ phasei++; } Dp = mag(Dp); - adjustPhi(phi0, U, p); while (pimple.correctNonOrthogonal()) { diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 2d4930f3851..db1aee788a3 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -170,7 +170,7 @@ $(derivedFvPatchFields)/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvP $(derivedFvPatchFields)/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C $(derivedFvPatchFields)/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.C - +$(derivedFvPatchFields)/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C fvsPatchFields = fields/fvsPatchFields $(fvsPatchFields)/fvsPatchField/fvsPatchFields.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C new file mode 100644 index 00000000000..02539fb9fd8 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C @@ -0,0 +1,201 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 3 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, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "phaseHydrostaticPressureFvPatchScalarField.H" +#include "addToRunTimeSelectionTable.H" +#include "fvPatchFieldMapper.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "uniformDimensionedFields.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::phaseHydrostaticPressureFvPatchScalarField:: +phaseHydrostaticPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(p, iF), + phaseName_("alpha"), + rho_(0.0), + pRefValue_(0.0), + pRefPoint_(vector::zero) +{ + this->refValue() = 0.0; + this->refGrad() = 0.0; + this->valueFraction() = 0.0; +} + + +Foam::phaseHydrostaticPressureFvPatchScalarField:: +phaseHydrostaticPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const dictionary& dict +) +: + mixedFvPatchScalarField(p, iF), + phaseName_(dict.lookupOrDefault<word>("phaseName", "alpha")), + rho_(readScalar(dict.lookup("rho"))), + pRefValue_(readScalar(dict.lookup("pRefValue"))), + pRefPoint_(dict.lookup("pRefPoint")) +{ + this->refValue() = pRefValue_; + + if (dict.found("value")) + { + fvPatchScalarField::operator= + ( + scalarField("value", dict, p.size()) + ); + } + else + { + fvPatchScalarField::operator=(this->refValue()); + } + + this->refGrad() = 0.0; + this->valueFraction() = 0.0; +} + + +Foam::phaseHydrostaticPressureFvPatchScalarField:: +phaseHydrostaticPressureFvPatchScalarField +( + const phaseHydrostaticPressureFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField<scalar, volMesh>& iF, + const fvPatchFieldMapper& mapper +) +: + mixedFvPatchScalarField(ptf, p, iF, mapper), + phaseName_(ptf.phaseName_), + rho_(ptf.rho_), + pRefValue_(ptf.pRefValue_), + pRefPoint_(ptf.pRefPoint_) +{} + + +Foam::phaseHydrostaticPressureFvPatchScalarField:: +phaseHydrostaticPressureFvPatchScalarField +( + const phaseHydrostaticPressureFvPatchScalarField& ptf +) +: + mixedFvPatchScalarField(ptf), + phaseName_(ptf.phaseName_) +{} + + +Foam::phaseHydrostaticPressureFvPatchScalarField:: +phaseHydrostaticPressureFvPatchScalarField +( + const phaseHydrostaticPressureFvPatchScalarField& ptf, + const DimensionedField<scalar, volMesh>& iF +) +: + mixedFvPatchScalarField(ptf, iF), + phaseName_(ptf.phaseName_), + rho_(ptf.rho_), + pRefValue_(ptf.pRefValue_), + pRefPoint_(ptf.pRefPoint_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::phaseHydrostaticPressureFvPatchScalarField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + const scalarField& alphap = + patch().lookupPatchField<volScalarField, scalar> + ( + phaseName_ + ); + + const uniformDimensionedVectorField& g = + db().lookupObject<uniformDimensionedVectorField>("g"); + + // scalar rhor = 1000; + // scalarField alphap1 = max(min(alphap, 1.0), 0.0); + // valueFraction() = alphap1/(alphap1 + rhor*(1.0 - alphap1)); + valueFraction() = max(min(alphap, 1.0), 0.0); + + refValue() = + pRefValue_ + + rho_*((g.value() & patch().Cf()) - (g.value() & pRefPoint_)); + + mixedFvPatchScalarField::updateCoeffs(); +} + + +void Foam::phaseHydrostaticPressureFvPatchScalarField::write(Ostream& os) const +{ + fvPatchScalarField::write(os); + if (phaseName_ != "alpha") + { + os.writeKeyword("phaseName") << phaseName_ << token::END_STATEMENT << nl; + } + os.writeKeyword("rho") << rho_ << token::END_STATEMENT << nl; + os.writeKeyword("pRefValue") << pRefValue_ << token::END_STATEMENT << nl; + os.writeKeyword("pRefPoint") << pRefPoint_ << token::END_STATEMENT << nl; + writeEntry("value", os); +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +void Foam::phaseHydrostaticPressureFvPatchScalarField::operator= +( + const fvPatchScalarField& ptf +) +{ + fvPatchScalarField::operator= + ( + valueFraction()*refValue() + + (1 - valueFraction())*ptf + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + phaseHydrostaticPressureFvPatchScalarField + ); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H new file mode 100644 index 00000000000..4c14094f496 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H @@ -0,0 +1,223 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 3 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, see <http://www.gnu.org/licenses/>. + +Class + Foam::phaseHydrostaticPressureFvPatchScalarField + +Description + Phase hydrostatic pressure boundary condition calculated as + + pRefValue + rho*g.(x - pRefPoint) + + where rho is provided and assumed uniform + + applied according to the phase-fraction field provided: + 1 -> fix value to that provided + 0 -> zero-gradient + +SourceFiles + phaseHydrostaticPressureFvPatchScalarField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef phaseHydrostaticPressureFvPatchScalarField_H +#define phaseHydrostaticPressureFvPatchScalarField_H + +#include "mixedFvPatchFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class phaseHydrostaticPressureFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class phaseHydrostaticPressureFvPatchScalarField +: + public mixedFvPatchScalarField +{ + +protected: + + // Protected data + + //- Name of phase-fraction field + word phaseName_; + + //- Constant density in the far-field + scalar rho_; + + //- Reference pressure + scalar pRefValue_; + + //- Reference pressure location + vector pRefPoint_; + + +public: + + //- Runtime type information + TypeName("phaseHydrostaticPressure"); + + + // Constructors + + //- Construct from patch and internal field + phaseHydrostaticPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>& + ); + + //- Construct from patch, internal field and dictionary + phaseHydrostaticPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const dictionary& + ); + + //- Construct by mapping given + // phaseHydrostaticPressureFvPatchScalarField onto a new patch + phaseHydrostaticPressureFvPatchScalarField + ( + const phaseHydrostaticPressureFvPatchScalarField&, + const fvPatch&, + const DimensionedField<scalar, volMesh>&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + phaseHydrostaticPressureFvPatchScalarField + ( + const phaseHydrostaticPressureFvPatchScalarField& + ); + + //- Construct and return a clone + virtual tmp<fvPatchScalarField> clone() const + { + return tmp<fvPatchScalarField > + ( + new phaseHydrostaticPressureFvPatchScalarField(*this) + ); + } + + //- Construct as copy setting internal field reference + phaseHydrostaticPressureFvPatchScalarField + ( + const phaseHydrostaticPressureFvPatchScalarField&, + 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 phaseHydrostaticPressureFvPatchScalarField(*this, iF) + ); + } + + + // Member functions + + // Access + + //- Return the phaseName + const word& phaseName() const + { + return phaseName_; + } + + //- Return reference to the phaseName to allow adjustment + word& phaseName() + { + return phaseName_; + } + + //- Return the constant density in the far-field + scalar rho() const + { + return rho_; + } + + //- Return reference to the constant density in the far-field + // to allow adjustment + scalar& rho() + { + return rho_; + } + + //- Return the reference pressure + scalar pRefValue() const + { + return pRefValue_; + } + + //- Return reference to the reference pressure to allow adjustment + scalar& pRefValue() + { + return pRefValue_; + } + + //- Return the pressure reference location + const vector& pRefPoint() const + { + return pRefPoint_; + } + + //- Return reference to the pressure reference location + // to allow adjustment + vector& pRefPoint() + { + return pRefPoint_; + } + + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + //- Write + virtual void write(Ostream&) const; + + + // Member operators + + virtual void operator=(const fvPatchScalarField& pvf); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // -- GitLab