OpenFOAM-dev / data /src /finiteVolume /fields /fvPatchFields /derived /flowRateInletVelocity /flowRateInletVelocityFvPatchVectorField.C
Download data/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C from introvoyz042/OpenFOAM-dev: direct link, hf CLI and curl.
- Browser
- Download file 8.87 kB
-
https://huggingface.co/datasets/introvoyz042/OpenFOAM-dev/resolve/main/data/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C
- Command line
-
hf download hf://datasets/introvoyz042/OpenFOAM-dev/data/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C
-
curl -L -o flowRateInletVelocityFvPatchVectorField.C https://huggingface.co/datasets/introvoyz042/OpenFOAM-dev/resolve/main/data/src/finiteVolume/fields/fvPatchFields/derived/flowRateInletVelocity/flowRateInletVelocityFvPatchVectorField.C
8.87 kB
| /*---------------------------------------------------------------------------*\ | |
| ========= | | |
| \\ / 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 <http://www.gnu.org/licenses/>. | |
| \*---------------------------------------------------------------------------*/ | |
| // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // | |
| void Foam::flowRateInletVelocityFvPatchVectorField::setWallDist() | |
| { | |
| if (profile_.valid()) | |
| { | |
| const labelHashSet otherPatchIDs | |
| ( | |
| patch().poly().boundaryMesh().findIndices<wallPolyPatch>() | |
| ); | |
| const patchPatchDist pwd(patch().poly(), otherPatchIDs); | |
| y_ = pwd.y()/gMax(pwd.y()); | |
| } | |
| area_ = gSum(patch().magSf()); | |
| } | |
| Foam::tmp<Foam::scalarField> | |
| Foam::flowRateInletVelocityFvPatchVectorField::profile() | |
| { | |
| if (profile_.valid()) | |
| { | |
| return profile_->value(y_); | |
| } | |
| else | |
| { | |
| return tmp<scalarField>(new scalarField(size(), scalar(1))); | |
| } | |
| } | |
| template<class ScaleType, class AlphaType, class RhoType> | |
| 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<class AlphaType> | |
| 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<volScalarField>(rhoName_)) | |
| { | |
| const fvPatchField<scalar>& rhop = | |
| patch().lookupPatchField<volScalarField, scalar>(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<vector, fvMesh>& iF, | |
| const dictionary& dict | |
| ) | |
| : | |
| fixedValueFvPatchField<vector>(p, iF, dict, false), | |
| flowRate_(), | |
| meanVelocity_(), | |
| volumetric_(), | |
| profile_(), | |
| rhoName_("rho"), | |
| rhoInlet_ | |
| ( | |
| dict.lookupOrDefault<scalar>("rhoInlet", dimensions::density, -vGreat) | |
| ), | |
| alphaName_(dict.lookupOrDefault<word>("alpha", word::null)), | |
| y_(), | |
| area_(-vGreat) | |
| { | |
| if (dict.found("meanVelocity")) | |
| { | |
| meanVelocity_ = true; | |
| volumetric_ = false; | |
| flowRate_ = | |
| Function1<scalar>::New | |
| ( | |
| "meanVelocity", | |
| time().userUnits(), | |
| dimensions::velocity, | |
| dict | |
| ); | |
| } | |
| else if (dict.found("volumetricFlowRate")) | |
| { | |
| meanVelocity_ = false; | |
| volumetric_ = true; | |
| flowRate_ = | |
| Function1<scalar>::New | |
| ( | |
| "volumetricFlowRate", | |
| time().userUnits(), | |
| dimensions::volumetricFlux, | |
| dict | |
| ); | |
| } | |
| else if (dict.found("massFlowRate")) | |
| { | |
| meanVelocity_ = false; | |
| volumetric_ = false; | |
| flowRate_ = | |
| Function1<scalar>::New | |
| ( | |
| "massFlowRate", | |
| time().userUnits(), | |
| dimensions::massFlux, | |
| dict | |
| ); | |
| rhoName_ = word(dict.lookupOrDefault<word>("rho", "rho")); | |
| } | |
| else | |
| { | |
| FatalIOErrorInFunction(dict) | |
| << "Please supply 'meanVelocity', 'volumetricFlowRate' or" | |
| << " 'massFlowRate' and 'rho'" << exit(FatalIOError); | |
| } | |
| if (dict.found("profile")) | |
| { | |
| profile_ = Function1<scalar>::New("profile", dimless, dimless, dict); | |
| } | |
| if (!p.time().completeCase() || dict.found("value")) | |
| { | |
| fvPatchField<vector>::operator= | |
| ( | |
| vectorField("value", iF.dimensions(), dict, p.size()) | |
| ); | |
| } | |
| else | |
| { | |
| evaluate(Pstream::commsTypes::blocking); | |
| } | |
| } | |
| Foam::flowRateInletVelocityFvPatchVectorField:: | |
| flowRateInletVelocityFvPatchVectorField | |
| ( | |
| const flowRateInletVelocityFvPatchVectorField& ptf, | |
| const fvPatch& p, | |
| const DimensionedField<vector, fvMesh>& iF, | |
| const fieldMapper& mapper | |
| ) | |
| : | |
| fixedValueFvPatchField<vector>(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<vector, fvMesh>& iF | |
| ) | |
| : | |
| fixedValueFvPatchField<vector>(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<scalar>& alphap = | |
| patch().lookupPatchField<volScalarField, scalar>(alphaName_); | |
| updateValues(alphap); | |
| } | |
| else | |
| { | |
| updateValues(one()); | |
| } | |
| fixedValueFvPatchVectorField::updateCoeffs(); | |
| } | |
| void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const | |
| { | |
| fvPatchField<vector>::write(os); | |
| writeEntry(os, time().userUnits(), units::any, flowRate_()); | |
| if (profile_.valid()) | |
| { | |
| writeEntry(os, profile_()); | |
| } | |
| if (!volumetric_) | |
| { | |
| writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_); | |
| writeEntryIfDifferent<scalar>(os, "rhoInlet", -vGreat, rhoInlet_); | |
| } | |
| writeEntryIfDifferent<word>(os, "alpha", word::null, alphaName_); | |
| writeEntry(os, "value", *this); | |
| } | |
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | |
| namespace Foam | |
| { | |
| makePatchTypeField | |
| ( | |
| fvPatchVectorField, | |
| flowRateInletVelocityFvPatchVectorField | |
| ); | |
| } | |
| // ************************************************************************* // | |