From b0719c3531ca795c693171e4287539560e162f93 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 30 Jun 2015 22:39:59 +0100 Subject: [PATCH] patchMeanVelocityForce: Variant of patchMeanVelocityForce in which the velocity is averaged over a patch rather than a cellSet This is useful to drive mean flow in a duct with a non-uniform cross-section. --- src/fvOptions/Make/files | 1 + .../meanVelocityForce/meanVelocityForce.C | 37 +++-- .../meanVelocityForce/meanVelocityForce.H | 15 ++- .../patchMeanVelocityForce.C | 86 ++++++++++++ .../patchMeanVelocityForce.H | 127 ++++++++++++++++++ 5 files changed, 254 insertions(+), 12 deletions(-) create mode 100644 src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C create mode 100644 src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.H diff --git a/src/fvOptions/Make/files b/src/fvOptions/Make/files index 52ce4a5428..ff2f45032b 100644 --- a/src/fvOptions/Make/files +++ b/src/fvOptions/Make/files @@ -22,6 +22,7 @@ $(derivedSources)/effectivenessHeatExchangerSource/effectivenessHeatExchangerSou $(derivedSources)/explicitPorositySource/explicitPorositySource.C $(derivedSources)/meanVelocityForce/meanVelocityForce.C $(derivedSources)/meanVelocityForce/meanVelocityForceIO.C +$(derivedSources)/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C $(derivedSources)/radialActuationDiskSource/radialActuationDiskSource.C $(derivedSources)/rotorDiskSource/rotorDiskSource.C $(derivedSources)/rotorDiskSource/bladeModel/bladeModel.C diff --git a/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.C b/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.C index 393acaadf1..4b717229ce 100644 --- a/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.C +++ b/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.C @@ -132,33 +132,50 @@ Foam::fv::meanVelocityForce::meanVelocityForce // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::fv::meanVelocityForce::correct(volVectorField& U) +Foam::scalar Foam::fv::meanVelocityForce::magUbarAve +( + const volVectorField& U +) const { - const scalarField& rAU = rAPtr_().internalField(); - - // Integrate flow variables over cell set scalar magUbarAve = 0.0; - scalar rAUave = 0.0; + const scalarField& cv = mesh_.V(); forAll(cells_, i) { label cellI = cells_[i]; scalar volCell = cv[cellI]; magUbarAve += (flowDir_ & U[cellI])*volCell; + } + + reduce(magUbarAve, sumOp()); + + magUbarAve /= V_; + + return magUbarAve; +} + + +void Foam::fv::meanVelocityForce::correct(volVectorField& U) +{ + const scalarField& rAU = rAPtr_().internalField(); + + // Integrate flow variables over cell set + scalar rAUave = 0.0; + const scalarField& cv = mesh_.V(); + forAll(cells_, i) + { + label cellI = cells_[i]; + scalar volCell = cv[cellI]; rAUave += rAU[cellI]*volCell; } // Collect across all processors - reduce(magUbarAve, sumOp()); reduce(rAUave, sumOp()); // Volume averages - magUbarAve /= V_; rAUave /= V_; - // magUbarAve = - // gSum((flowDir_ & U.boundaryField()[0])*mesh_.boundary()[0].magSf()) - // /gSum(mesh_.boundary()[0].magSf()); + scalar magUbarAve = this->magUbarAve(U); // Calculate the pressure gradient increment needed to adjust the average // flow-rate to the desired value diff --git a/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.H b/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.H index e34904f88e..a9cbfa725a 100644 --- a/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.H +++ b/src/fvOptions/sources/derived/meanVelocityForce/meanVelocityForce.H @@ -72,7 +72,9 @@ class meanVelocityForce : public cellSetOption { - // Private data +protected: + + // Protected data //- Average velocity vector Ubar_; @@ -93,7 +95,11 @@ class meanVelocityForce autoPtr rAPtr_; - // Private Member Functions + // Protected Member Functions + + //- Calculate and return the magnitude of the mean velocity + // averaged over the selected cellSet + virtual scalar magUbarAve(const volVectorField& U) const; //- Write the pressure gradient to file (for restarts etc) void writeProps(const scalar gradP) const; @@ -101,6 +107,11 @@ class meanVelocityForce //- Correct driving force for a constant mass flow rate void update(fvMatrix& eqn); + +private: + + // Private Member Functions + //- Disallow default bitwise copy construct meanVelocityForce(const meanVelocityForce&); diff --git a/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C b/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C new file mode 100644 index 0000000000..8fdf8a9881 --- /dev/null +++ b/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 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 . + +\*---------------------------------------------------------------------------*/ + +#include "patchMeanVelocityForce.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + defineTypeNameAndDebug(patchMeanVelocityForce, 0); + + addToRunTimeSelectionTable + ( + option, + patchMeanVelocityForce, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fv::patchMeanVelocityForce::patchMeanVelocityForce +( + const word& sourceName, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh +) +: + meanVelocityForce(sourceName, modelType, dict, mesh), + patch_(coeffs_.lookup("patch")), + patchi_(mesh.boundaryMesh().findPatchID(patch_)) +{ + if (patchi_ < 0) + { + FatalErrorIn("fv::patchMeanVelocityForce::patchMeanVelocityForce") + << "Cannot find patch " << patch_ + << exit(FatalError); + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::scalar Foam::fv::patchMeanVelocityForce::magUbarAve +( + const volVectorField& U +) const +{ + return + gSum + ( + (flowDir_ & U.boundaryField()[patchi_]) + *mesh_.boundary()[patchi_].magSf() + )/gSum(mesh_.boundary()[patchi_].magSf()); +} + + +// ************************************************************************* // diff --git a/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.H b/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.H new file mode 100644 index 0000000000..b261b4d9f9 --- /dev/null +++ b/src/fvOptions/sources/derived/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.H @@ -0,0 +1,127 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 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 . + +Class + Foam::fv::patchMeanVelocityForce + +Description + Calculates and applies the force necessary to maintain the specified mean + velocity averaged over the specified patch. + + Note: Currently only handles kinematic pressure (incompressible solvers). + + \heading Source usage + Example usage: + \verbatim + patchMeanVelocityForceCoeffs + { + fieldNames (U); // Name of velocity field + patch inlet; // Name of the patch + Ubar (10.0 0 0); // Desired mean velocity + relaxation 0.2; // Optional relaxation factor + } + \endverbatim + +SourceFiles + patchMeanVelocityForce.C + +\*---------------------------------------------------------------------------*/ + +#ifndef patchMeanVelocityForce_H +#define patchMeanVelocityForce_H + +#include "meanVelocityForce.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class patchMeanVelocityForce Declaration +\*---------------------------------------------------------------------------*/ + +class patchMeanVelocityForce +: + public meanVelocityForce +{ +protected: + + // Protected data + + //- Patch name + word patch_; + + //- Patch index + label patchi_; + + + // Protected Member Functions + + //- Calculate and return the magnitude of the mean velocity + // averaged over the specified patch + virtual scalar magUbarAve(const volVectorField& U) const; + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + patchMeanVelocityForce(const patchMeanVelocityForce&); + + //- Disallow default bitwise assignment + void operator=(const patchMeanVelocityForce&); + + +public: + + //- Runtime type information + TypeName("patchMeanVelocityForce"); + + + // Constructors + + //- Construct from explicit source name and mesh + patchMeanVelocityForce + ( + const word& sourceName, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //