From 9fc02015687a0f52d71f6c8ba61d97473cd7551c Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 7 Feb 2016 22:55:52 +0000 Subject: [PATCH] flowRateInletVelocity: Added option to extrapolate the velocity profile to the inlet e.g. inlet { type flowRateInletVelocity; massFlowRate 0.2; extrapolateProfile yes; rho rho; rhoInlet 1.0; value uniform (0 0 0); } --- .../flowRateInletVelocityFvPatchVectorField.C | 75 ++++++++++++++----- .../flowRateInletVelocityFvPatchVectorField.H | 25 +++++-- 2 files changed, 77 insertions(+), 23 deletions(-) diff --git a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C index 7dc2d9497b..bd09517b1e 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,6 +28,7 @@ License #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" #include "surfaceFields.H" +#include "one.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -42,7 +43,8 @@ flowRateInletVelocityFvPatchVectorField flowRate_(), volumetric_(false), rhoName_("rho"), - rhoInlet_(0.0) + rhoInlet_(0.0), + extrapolateProfile_(false) {} @@ -59,7 +61,8 @@ flowRateInletVelocityFvPatchVectorField flowRate_(ptf.flowRate_, false), volumetric_(ptf.volumetric_), rhoName_(ptf.rhoName_), - rhoInlet_(ptf.rhoInlet_) + rhoInlet_(ptf.rhoInlet_), + extrapolateProfile_(ptf.extrapolateProfile_) {} @@ -72,7 +75,11 @@ flowRateInletVelocityFvPatchVectorField ) : fixedValueFvPatchField(p, iF), - rhoInlet_(dict.lookupOrDefault("rhoInlet", -VGREAT)) + rhoInlet_(dict.lookupOrDefault("rhoInlet", -VGREAT)), + extrapolateProfile_ + ( + dict.lookupOrDefault("extrapolateProfile", false) + ) { if (dict.found("volumetricFlowRate")) { @@ -120,7 +127,8 @@ flowRateInletVelocityFvPatchVectorField flowRate_(ptf.flowRate_, false), volumetric_(ptf.volumetric_), rhoName_(ptf.rhoName_), - rhoInlet_(ptf.rhoInlet_) + rhoInlet_(ptf.rhoInlet_), + extrapolateProfile_(ptf.extrapolateProfile_) {} @@ -135,12 +143,50 @@ flowRateInletVelocityFvPatchVectorField flowRate_(ptf.flowRate_, false), volumetric_(ptf.volumetric_), rhoName_(ptf.rhoName_), - rhoInlet_(ptf.rhoInlet_) + rhoInlet_(ptf.rhoInlet_), + extrapolateProfile_(ptf.extrapolateProfile_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +void Foam::flowRateInletVelocityFvPatchVectorField::updateValues +( + const RhoType& rho +) +{ + const scalar t = db().time().timeOutputValue(); + + tmp n = patch().nf(); + + if (extrapolateProfile_) + { + vectorField newValues(this->patchInternalField()); + + scalar flowRate = flowRate_->value(t); + scalar estimatedFlowRate = -gSum(rho*(this->patch().Sf() & newValues)); + + if (estimatedFlowRate/flowRate > 0.5) + { + newValues *= (mag(flowRate)/mag(estimatedFlowRate)); + } + else + { + newValues -= + ((flowRate - estimatedFlowRate)/gSum(rho*patch().magSf()))*n; + } + + this->operator==(newValues); + } + else + { + const scalar avgU = -flowRate_->value(t)/gSum(rho*patch().magSf()); + operator==(n*avgU); + } +} + + void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() { if (updated()) @@ -148,27 +194,19 @@ void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() return; } - const scalar t = db().time().timeOutputValue(); - - // a simpler way of doing this would be nice - const scalar avgU = -flowRate_->value(t)/gSum(patch().magSf()); - - tmp n = patch().nf(); - if (volumetric_ || rhoName_ == "none") { - // volumetric flow-rate or density not given - operator==(n*avgU); + updateValues(one()); } else { - // mass flow-rate + // Mass flow-rate if (db().foundObject(rhoName_)) { const fvPatchField& rhop = patch().lookupPatchField(rhoName_); - operator==(n*avgU/rhop); + updateValues(rhop); } else { @@ -180,7 +218,8 @@ void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() << " and no constant density 'rhoInlet' specified" << exit(FatalError); } - operator==(n*avgU/rhoInlet_); + + updateValues(rhoInlet_); } } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H index 1fbd21c75b..cd46853c3b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.H @@ -49,15 +49,17 @@ Description massFlowRate | mass flow rate [kg/s] | no | volumetricFlowRate | volumetric flow rate [m3/s]| no | rhoInlet | inlet density | no | + extrapolateProfile | Extrapolate velocity profile | no | false \endtable Example of the boundary condition specification for a volumetric flow rate: \verbatim myPatch { - type flowRateInletVelocity; + type flowRateInletVelocity; volumetricFlowRate 0.2; - value uniform (0 0 0); // placeholder + extrapolateProfile yes; + value uniform (0 0 0); } \endverbatim @@ -67,8 +69,10 @@ Description { type flowRateInletVelocity; massFlowRate 0.2; + extrapolateProfile yes; rho rho; rhoInlet 1.0; + value uniform (0 0 0); } \endverbatim @@ -78,9 +82,9 @@ Description Note - \c rhoInlet is required for the case of a mass flow rate, where the density field is not available at start-up - - the value is positive into the domain (as an inlet) - - may not work correctly for transonic inlets - - strange behaviour with potentialFoam since the U equation is not solved + - The value is positive into the domain (as an inlet) + - May not work correctly for transonic inlets + - Strange behaviour with potentialFoam since the U equation is not solved SeeAlso Foam::DataEntry @@ -101,6 +105,7 @@ SourceFiles namespace Foam { + /*---------------------------------------------------------------------------*\ Class flowRateInletVelocityFvPatchVectorField Declaration \*---------------------------------------------------------------------------*/ @@ -123,6 +128,16 @@ class flowRateInletVelocityFvPatchVectorField //- Rho initialisation value (for start; if value not supplied) scalar rhoInlet_; + //- Set true to extrapolate the velocity profile from the interior + Switch extrapolateProfile_; + + + // Private member functions + + //- Update the patch values given the appropriate density type and value + template + void updateValues(const RhoType& rho); + public: