/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 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 "flowRateInletVelocityFvPatchVectorField.H" #include "addToRunTimeSelectionTable.H" #include "volFields.H" #include "one.H" #include "patchPatchDist.H" #include "wallPolyPatch.H" // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // void Foam::flowRateInletVelocityFvPatchVectorField::setWallDist() { if (profile_.valid()) { const labelHashSet otherPatchIDs ( patch().poly().boundaryMesh().findIndices() ); const patchPatchDist pwd(patch().poly(), otherPatchIDs); y_ = pwd.y()/gMax(pwd.y()); } area_ = gSum(patch().magSf()); } Foam::tmp Foam::flowRateInletVelocityFvPatchVectorField::profile() { if (profile_.valid()) { return profile_->value(y_); } else { return tmp(new scalarField(size(), scalar(1))); } } template void Foam::flowRateInletVelocityFvPatchVectorField::updateValues ( const ScaleType& scale, const AlphaType& alpha, const RhoType& rho ) { const scalarField profile(this->profile()); const scalar avgU = scale *flowRate_->value(time().value()) /gSum(alpha*rho*profile*patch().magSf()); operator==(-avgU*profile*patch().nf()); } template void Foam::flowRateInletVelocityFvPatchVectorField::updateValues ( const AlphaType& alpha ) { if (meanVelocity_) { updateValues(area_, alpha, one()); } else if (volumetric_ || rhoName_ == "none") { updateValues(one(), alpha, one()); } else { // Mass flow-rate if (db().foundObject(rhoName_)) { const fvPatchField& rhop = patch().lookupPatchField(rhoName_); updateValues(one(), alpha, rhop); } else { // Use constant density if (rhoInlet_ < 0) { FatalErrorInFunction << "Did not find registered density field " << rhoName_ << " and no constant density 'rhoInlet' specified" << exit(FatalError); } updateValues(one(), alpha, rhoInlet_); } } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::flowRateInletVelocityFvPatchVectorField:: flowRateInletVelocityFvPatchVectorField ( const fvPatch& p, const DimensionedField& iF, const dictionary& dict ) : fixedValueFvPatchField(p, iF, dict, false), flowRate_(), meanVelocity_(), volumetric_(), profile_(), rhoName_("rho"), rhoInlet_ ( dict.lookupOrDefault("rhoInlet", dimensions::density, -vGreat) ), alphaName_(dict.lookupOrDefault("alpha", word::null)), y_(), area_(-vGreat) { if (dict.found("meanVelocity")) { meanVelocity_ = true; volumetric_ = false; flowRate_ = Function1::New ( "meanVelocity", time().userUnits(), dimensions::velocity, dict ); } else if (dict.found("volumetricFlowRate")) { meanVelocity_ = false; volumetric_ = true; flowRate_ = Function1::New ( "volumetricFlowRate", time().userUnits(), dimensions::volumetricFlux, dict ); } else if (dict.found("massFlowRate")) { meanVelocity_ = false; volumetric_ = false; flowRate_ = Function1::New ( "massFlowRate", time().userUnits(), dimensions::massFlux, dict ); rhoName_ = word(dict.lookupOrDefault("rho", "rho")); } else { FatalIOErrorInFunction(dict) << "Please supply 'meanVelocity', 'volumetricFlowRate' or" << " 'massFlowRate' and 'rho'" << exit(FatalIOError); } if (dict.found("profile")) { profile_ = Function1::New("profile", dimless, dimless, dict); } if (!p.time().completeCase() || dict.found("value")) { fvPatchField::operator= ( vectorField("value", iF.dimensions(), dict, p.size()) ); } else { evaluate(Pstream::commsTypes::blocking); } } Foam::flowRateInletVelocityFvPatchVectorField:: flowRateInletVelocityFvPatchVectorField ( const flowRateInletVelocityFvPatchVectorField& ptf, const fvPatch& p, const DimensionedField& iF, const fieldMapper& mapper ) : fixedValueFvPatchField(ptf, p, iF, mapper), flowRate_(ptf.flowRate_, false), meanVelocity_(ptf.meanVelocity_), volumetric_(ptf.volumetric_), profile_(ptf.profile_, false), rhoName_(ptf.rhoName_), rhoInlet_(ptf.rhoInlet_), alphaName_(ptf.alphaName_), y_(), area_(-vGreat) {} Foam::flowRateInletVelocityFvPatchVectorField:: flowRateInletVelocityFvPatchVectorField ( const flowRateInletVelocityFvPatchVectorField& ptf, const DimensionedField& iF ) : fixedValueFvPatchField(ptf, iF), flowRate_(ptf.flowRate_, false), meanVelocity_(ptf.meanVelocity_), volumetric_(ptf.volumetric_), profile_(ptf.profile_, false), rhoName_(ptf.rhoName_), rhoInlet_(ptf.rhoInlet_), alphaName_(ptf.alphaName_), y_(ptf.y_), area_(ptf.area_) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::flowRateInletVelocityFvPatchVectorField::map ( const fvPatchVectorField& ptf, const fieldMapper& mapper ) { fixedValueFvPatchVectorField::map(ptf, mapper); y_.clear(); area_ = -vGreat; } void Foam::flowRateInletVelocityFvPatchVectorField::reset ( const fvPatchVectorField& ptf ) { fixedValueFvPatchVectorField::reset(ptf); y_.clear(); area_ = -vGreat; } void Foam::flowRateInletVelocityFvPatchVectorField::updateCoeffs() { if (updated()) { return; } if (!patch().time().completeCase()) { FatalErrorInFunction << "Cannot evaluate flow rate on a non-parallel processor case" << exit(FatalError); } if (area_ < 0) { setWallDist(); } if (alphaName_ != word::null) { const fvPatchField& alphap = patch().lookupPatchField(alphaName_); updateValues(alphap); } else { updateValues(one()); } fixedValueFvPatchVectorField::updateCoeffs(); } void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const { fvPatchField::write(os); writeEntry(os, time().userUnits(), units::any, flowRate_()); if (profile_.valid()) { writeEntry(os, profile_()); } if (!volumetric_) { writeEntryIfDifferent(os, "rho", "rho", rhoName_); writeEntryIfDifferent(os, "rhoInlet", -vGreat, rhoInlet_); } writeEntryIfDifferent(os, "alpha", word::null, alphaName_); writeEntry(os, "value", *this); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { makePatchTypeField ( fvPatchVectorField, flowRateInletVelocityFvPatchVectorField ); } // ************************************************************************* //