diff --git a/src/fvConstraints/Make/files b/src/fvConstraints/Make/files index 936182a578..15ab3ad94e 100644 --- a/src/fvConstraints/Make/files +++ b/src/fvConstraints/Make/files @@ -2,7 +2,7 @@ fixedValueConstraint/fixedValueConstraint.C fixedTemperatureConstraint/fixedTemperatureConstraint.C limitTemperature/limitTemperature.C limitPressure/limitPressure.C -limitVelocity/limitVelocity.C +limitMag/limitMag.C meanVelocityForce/meanVelocityForce.C meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C diff --git a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H index bec8b2b0db..999b748c47 100644 --- a/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H +++ b/src/fvConstraints/fixedValueConstraint/fixedValueConstraint.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -89,7 +89,11 @@ class fixedValueConstraint //- Set value on a field template - bool constrainType(fvMatrix& eqn, const word& fieldName) const; + inline bool constrainType + ( + fvMatrix& eqn, + const word& fieldName + ) const; public: diff --git a/src/fvConstraints/limitVelocity/limitVelocity.C b/src/fvConstraints/limitMag/limitMag.C similarity index 64% rename from src/fvConstraints/limitVelocity/limitVelocity.C rename to src/fvConstraints/limitMag/limitMag.C index 24049a4ee8..55d8e4727a 100644 --- a/src/fvConstraints/limitVelocity/limitVelocity.C +++ b/src/fvConstraints/limitMag/limitMag.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "limitVelocity.H" +#include "limitMag.H" #include "volFields.H" #include "addToRunTimeSelectionTable.H" @@ -33,11 +33,11 @@ namespace Foam { namespace fv { - defineTypeNameAndDebug(limitVelocity, 0); + defineTypeNameAndDebug(limitMag, 0); addToRunTimeSelectionTable ( fvConstraint, - limitVelocity, + limitMag, dictionary ); } @@ -46,45 +46,22 @@ namespace fv // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::fv::limitVelocity::readCoeffs() +void Foam::fv::limitMag::readCoeffs() { - UName_ = coeffs().lookupOrDefault("U", "U"); + fieldName_ = coeffs().lookup("field"); max_ = coeffs().lookup("max"); } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::fv::limitVelocity::limitVelocity +template +inline bool Foam::fv::limitMag::constrainType ( - const word& name, - const word& modelType, - const dictionary& dict, - const fvMesh& mesh -) -: - fvConstraint(name, modelType, dict, mesh), - set_(coeffs(), mesh), - UName_(word::null), - max_(vGreat) + GeometricField& psi +) const { - readCoeffs(); -} + const scalar maxSqrPsi = sqr(max_); - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -Foam::wordList Foam::fv::limitVelocity::constrainedFields() const -{ - return wordList(1, UName_); -} - - -bool Foam::fv::limitVelocity::constrain(volVectorField& U) const -{ - const scalar maxSqrU = sqr(max_); - - vectorField& Uif = U.primitiveFieldRef(); + Field& psiif = psi.primitiveFieldRef(); const labelList& cells = set_.cells(); @@ -92,32 +69,33 @@ bool Foam::fv::limitVelocity::constrain(volVectorField& U) const { const label celli = cells[i]; - const scalar magSqrUi = magSqr(Uif[celli]); + const scalar magSqrPsii = magSqr(psiif[celli]); - if (magSqrUi > maxSqrU) + if (magSqrPsii > maxSqrPsi) { - Uif[celli] *= sqrt(maxSqrU/magSqrUi); + psiif[celli] *= sqrt(maxSqrPsi/magSqrPsii); } } // handle boundaries in the case of 'all' if (set_.selectionMode() == fvCellSet::selectionModeType::all) { - volVectorField::Boundary& Ubf = U.boundaryFieldRef(); + typename GeometricField::Boundary& psibf = + psi.boundaryFieldRef(); - forAll(Ubf, patchi) + forAll(psibf, patchi) { - fvPatchVectorField& Up = Ubf[patchi]; + fvPatchField& psip = psibf[patchi]; - if (!Up.fixesValue()) + if (!psip.fixesValue()) { - forAll(Up, facei) + forAll(psip, facei) { - const scalar magSqrUi = magSqr(Up[facei]); + const scalar magSqrPsii = magSqr(psip[facei]); - if (magSqrUi > maxSqrU) + if (magSqrPsii > maxSqrPsi) { - Up[facei] *= sqrt(maxSqrU/magSqrUi); + psip[facei] *= sqrt(maxSqrPsi/magSqrPsii); } } } @@ -128,26 +106,60 @@ bool Foam::fv::limitVelocity::constrain(volVectorField& U) const } -void Foam::fv::limitVelocity::updateMesh(const mapPolyMesh& map) +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fv::limitMag::limitMag +( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh +) +: + fvConstraint(name, modelType, dict, mesh), + set_(coeffs(), mesh), + fieldName_(word::null), + max_(vGreat) +{ + readCoeffs(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::wordList Foam::fv::limitMag::constrainedFields() const +{ + return wordList(1, fieldName_); +} + + +FOR_ALL_FIELD_TYPES +( + IMPLEMENT_FV_CONSTRAINT_CONSTRAIN_FIELD, + fv::limitMag +); + + +void Foam::fv::limitMag::updateMesh(const mapPolyMesh& map) { set_.updateMesh(map); } -void Foam::fv::limitVelocity::distribute(const mapDistributePolyMesh& map) +void Foam::fv::limitMag::distribute(const mapDistributePolyMesh& map) { set_.distribute(map); } -bool Foam::fv::limitVelocity::movePoints() +bool Foam::fv::limitMag::movePoints() { set_.movePoints(); return true; } -bool Foam::fv::limitVelocity::read(const dictionary& dict) +bool Foam::fv::limitMag::read(const dictionary& dict) { if (fvConstraint::read(dict)) { diff --git a/src/fvConstraints/limitVelocity/limitVelocity.H b/src/fvConstraints/limitMag/limitMag.H similarity index 78% rename from src/fvConstraints/limitVelocity/limitVelocity.H rename to src/fvConstraints/limitMag/limitMag.H index d3315d3e5b..a6b02840d6 100644 --- a/src/fvConstraints/limitVelocity/limitVelocity.H +++ b/src/fvConstraints/limitMag/limitMag.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,31 +22,33 @@ License along with OpenFOAM. If not, see . Class - Foam::fv::limitVelocity + Foam::fv::limitMag Description - Limits the velocity magnitude to the specified \c max value. + Limits the magnitude of the specified field to the specified \c max value. Usage Example usage: \verbatim limitU { - type limitVelocity; + type limitMag; selectionMode all; + field U; + max 100; } \endverbatim SourceFiles - limitVelocity.C + limitMag.C \*---------------------------------------------------------------------------*/ -#ifndef limitVelocity_H -#define limitVelocity_H +#ifndef limitMag_H +#define limitMag_H #include "fvConstraint.H" #include "fvCellSet.H" @@ -59,10 +61,10 @@ namespace fv { /*---------------------------------------------------------------------------*\ - Class limitVelocity Declaration + Class limitMag Declaration \*---------------------------------------------------------------------------*/ -class limitVelocity +class limitMag : public fvConstraint { @@ -71,8 +73,8 @@ class limitVelocity //- The set of cells the fvConstraint applies to fvCellSet set_; - //- Velocity field name, default = U - word UName_; + //- Field name + word fieldName_; //- Maximum velocity magnitude scalar max_; @@ -83,17 +85,24 @@ class limitVelocity //- Non-virtual read void readCoeffs(); + //- Limit the field + template + inline bool constrainType + ( + GeometricField& psi + ) const; + public: //- Runtime type information - TypeName("limitVelocity"); + TypeName("limitMag"); // Constructors //- Construct from components - limitVelocity + limitMag ( const word& name, const word& modelType, @@ -102,11 +111,11 @@ public: ); //- Disallow default bitwise copy construction - limitVelocity(const limitVelocity&) = delete; + limitMag(const limitMag&) = delete; //- Destructor - virtual ~limitVelocity() + virtual ~limitMag() {} @@ -115,8 +124,8 @@ public: //- Return the list of fields constrained by the fvConstraint virtual wordList constrainedFields() const; - //- Constrain the velocity field - virtual bool constrain(volVectorField& U) const; + //- Add a constraint to an equation + FOR_ALL_FIELD_TYPES(DEFINE_FV_CONSTRAINT_CONSTRAIN_FIELD); //- Update for mesh changes virtual void updateMesh(const mapPolyMesh&); @@ -134,7 +143,7 @@ public: // Member Operators //- Disallow default bitwise assignment - void operator=(const limitVelocity&) = delete; + void operator=(const limitMag&) = delete; };