From 2c1de380864874257b62a5d845eee0cf79a123af Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Mon, 4 Jul 2011 12:06:12 +0100 Subject: [PATCH] fanPressure BC: Improved handling of reverse-flow Now derived from totalPressure to support all forms of compressibility. --- .../fanPressureFvPatchScalarField.C | 73 ++++--------------- .../fanPressureFvPatchScalarField.H | 20 ++--- .../rotatingTotalPressureFvPatchScalarField.C | 2 +- .../rotatingTotalPressureFvPatchScalarField.H | 2 +- .../totalPressureFvPatchScalarField.C | 20 +++-- .../totalPressureFvPatchScalarField.H | 49 ++++++++++++- 6 files changed, 82 insertions(+), 84 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C index db585345f17..260fb328dcf 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.C @@ -59,10 +59,7 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField const DimensionedField<scalar, volMesh>& iF ) : - fixedValueFvPatchScalarField(p, iF), - phiName_("phi"), - rhoName_("rho"), - p0_(p.size(), 0.0), + totalPressureFvPatchScalarField(p, iF), fanCurve_(), direction_(ffdOut) {} @@ -76,10 +73,7 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField const fvPatchFieldMapper& mapper ) : - fixedValueFvPatchScalarField(ptf, p, iF, mapper), - phiName_(ptf.phiName_), - rhoName_(ptf.rhoName_), - p0_(ptf.p0_, mapper), + totalPressureFvPatchScalarField(ptf, p, iF, mapper), fanCurve_(ptf.fanCurve_), direction_(ptf.direction_) {} @@ -92,10 +86,7 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField const dictionary& dict ) : - fixedValueFvPatchScalarField(p, iF), - phiName_(dict.lookupOrDefault<word>("phi", "phi")), - rhoName_(dict.lookupOrDefault<word>("rho", "rho")), - p0_("p0", dict, p.size()), + totalPressureFvPatchScalarField(p, iF), fanCurve_(dict), direction_(fanFlowDirectionNames_.read(dict.lookup("direction"))) { @@ -109,10 +100,7 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField const fanPressureFvPatchScalarField& pfopsf ) : - fixedValueFvPatchScalarField(pfopsf), - phiName_(pfopsf.phiName_), - rhoName_(pfopsf.rhoName_), - p0_(pfopsf.p0_), + totalPressureFvPatchScalarField(pfopsf), fanCurve_(pfopsf.fanCurve_), direction_(pfopsf.direction_) {} @@ -124,10 +112,7 @@ Foam::fanPressureFvPatchScalarField::fanPressureFvPatchScalarField const DimensionedField<scalar, volMesh>& iF ) : - fixedValueFvPatchScalarField(pfopsf, iF), - phiName_(pfopsf.phiName_), - rhoName_(pfopsf.rhoName_), - p0_(pfopsf.p0_), + totalPressureFvPatchScalarField(pfopsf, iF), fanCurve_(pfopsf.fanCurve_), direction_(pfopsf.direction_) {} @@ -144,7 +129,7 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() // Retrieve flux field const surfaceScalarField& phi = - db().lookupObject<surfaceScalarField>(phiName_); + db().lookupObject<surfaceScalarField>(phiName()); const fvsPatchField<scalar>& phip = patch().patchField<surfaceScalarField, scalar>(phi); @@ -161,7 +146,7 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() else if (phi.dimensions() == dimVelocity*dimArea*dimDensity) { const scalarField& rhop = - patch().lookupPatchField<volScalarField, scalar>(rhoName_); + patch().lookupPatchField<volScalarField, scalar>(rhoName()); aveFlowRate = dir*gSum(phip/rhop)/gSum(patch().magSf()); } else @@ -174,51 +159,23 @@ void Foam::fanPressureFvPatchScalarField::updateCoeffs() << exit(FatalError); } - // Normal flow through fan - if (aveFlowRate >= 0.0) - { - // Pressure drop for this flow rate - const scalar pdFan = fanCurve_(aveFlowRate); - - operator==(p0_ - dir*pdFan); - } - // Reverse flow - else - { - // Assume that fan has stalled if flow reversed - // i.e. apply dp for zero flow rate - const scalar pdFan = fanCurve_(0); - - // Flow speed across patch - scalarField Up = phip/(patch().magSf()); + // Pressure drop for this flow rate + const scalar pdFan = fanCurve_(max(aveFlowRate, 0.0)); - // Pressure drop associated withback flow = dynamic pressure - scalarField pdBackFlow = 0.5*magSqr(Up); - - if (phi.dimensions() == dimVelocity*dimArea*dimDensity) - { - const scalarField& rhop = - patch().lookupPatchField<volScalarField, scalar>(rhoName_); - pdBackFlow /= rhop; - } - - operator==(p0_ - dir*(pdBackFlow + pdFan)); - } - - fixedValueFvPatchScalarField::updateCoeffs(); + totalPressureFvPatchScalarField::updateCoeffs + ( + p0() - dir*pdFan, + patch().lookupPatchField<volVectorField, vector>(UName()) + ); } void Foam::fanPressureFvPatchScalarField::write(Ostream& os) const { - fvPatchScalarField::write(os); - os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl; - os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl; + totalPressureFvPatchScalarField::write(os); fanCurve_.write(os); os.writeKeyword("direction") << fanFlowDirectionNames_[direction_] << token::END_STATEMENT << nl; - p0_.writeEntry("p0", os); - writeEntry("value", os); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H index 7c3d9ff4116..47f5cdd49c9 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/fanPressure/fanPressureFvPatchScalarField.H @@ -25,7 +25,7 @@ Class Foam::fanPressureFvPatchScalarField Description - Assigns pressure inlet or outlet condition for a fan. + Assigns pressure inlet or outlet total pressure condition for a fan. User specifies: - pressure drop vs volumetric flow rate table (fan curve) file name; @@ -56,8 +56,8 @@ Description \endverbatim See Also - Foam::interpolationTable and - Foam::timeVaryingFlowRateInletVelocityFvPatchVectorField + Foam::totalPressureFvPatchScalarField and + Foam::interpolationTable SourceFiles fanPressureFvPatchScalarField.C @@ -67,8 +67,7 @@ SourceFiles #ifndef fanPressureFvPatchScalarField_H #define fanPressureFvPatchScalarField_H -#include "fvPatchFields.H" -#include "fixedValueFvPatchFields.H" +#include "totalPressureFvPatchScalarField.H" #include "interpolationTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -82,19 +81,10 @@ namespace Foam class fanPressureFvPatchScalarField : - public fixedValueFvPatchScalarField + public totalPressureFvPatchScalarField { // Private data - //- Name of the flux transporting the field - word phiName_; - - //- Name of the density field - word rhoName_; - - //- Total pressure - scalarField p0_; - //- Tabulated fan curve interpolationTable<scalar> fanCurve_; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C index 9f3e49576b3..10b284fa64c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.C @@ -112,7 +112,7 @@ void Foam::rotatingTotalPressureFvPatchScalarField::updateCoeffs() + rotationVelocity ); - totalPressureFvPatchScalarField::updateCoeffs(Up); + totalPressureFvPatchScalarField::updateCoeffs(p0(), Up); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.H index 087bf70b4a6..01d9a73ad4f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/rotatingTotalPressure/rotatingTotalPressureFvPatchScalarField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C index 7defeec9315..255a42d8c50 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.C @@ -153,7 +153,11 @@ void Foam::totalPressureFvPatchScalarField::rmap } -void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) +void Foam::totalPressureFvPatchScalarField::updateCoeffs +( + const scalarField& p0p, + const vectorField& Up +) { if (updated()) { @@ -165,7 +169,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) if (psiName_ == "none" && rhoName_ == "none") { - operator==(p0_ - 0.5*(1.0 - pos(phip))*magSqr(Up)); + operator==(p0p - 0.5*(1.0 - pos(phip))*magSqr(Up)); } else if (rhoName_ == "none") { @@ -178,7 +182,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) operator== ( - p0_ + p0p /pow ( (1.0 + 0.5*psip*gM1ByG*(1.0 - pos(phip))*magSqr(Up)), @@ -188,7 +192,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) } else { - operator==(p0_/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up))); + operator==(p0p/(1.0 + 0.5*psip*(1.0 - pos(phip))*magSqr(Up))); } } else if (psiName_ == "none") @@ -196,7 +200,7 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) const fvPatchField<scalar>& rho = patch().lookupPatchField<volScalarField, scalar>(rhoName_); - operator==(p0_ - 0.5*rho*(1.0 - pos(phip))*magSqr(Up)); + operator==(p0p - 0.5*rho*(1.0 - pos(phip))*magSqr(Up)); } else { @@ -220,7 +224,11 @@ void Foam::totalPressureFvPatchScalarField::updateCoeffs(const vectorField& Up) void Foam::totalPressureFvPatchScalarField::updateCoeffs() { - updateCoeffs(patch().lookupPatchField<volVectorField, vector>(UName_)); + updateCoeffs + ( + p0(), + patch().lookupPatchField<volVectorField, vector>(UName()) + ); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.H index 9aa386fe838..1eceb87faae 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/totalPressure/totalPressureFvPatchScalarField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -157,6 +157,45 @@ public: return UName_; } + //- Return the name of the flux field + const word& phiName() const + { + return phiName_; + } + + //- Return reference to the name of the flux field + // to allow adjustment + word& phiName() + { + return phiName_; + } + + //- Return the name of the density field + const word& rhoName() const + { + return rhoName_; + } + + //- Return reference to the name of the density field + // to allow adjustment + word& rhoName() + { + return rhoName_; + } + + //- Return the name of the compressibility field + const word& psiName() const + { + return psiName_; + } + + //- Return reference to the name of the compressibility field + // to allow adjustment + word& psiName() + { + return psiName_; + } + //- Return the heat capacity ratio scalar gamma() const { @@ -201,8 +240,12 @@ public: // Evaluation functions //- Update the coefficients associated with the patch field - // using the given patch velocity field - virtual void updateCoeffs(const vectorField& Up); + // using the given patch total pressure and velocity fields + virtual void updateCoeffs + ( + const scalarField& p0p, + const vectorField& Up + ); //- Update the coefficients associated with the patch field virtual void updateCoeffs(); -- GitLab