diff --git a/src/fvOptions/Make/files b/src/fvOptions/Make/files index 1692b88e3ea92e8848ec16f092ca3d1a2cd538cb..4591f3f3ae0f62a211f7a6e4c0ce90a4ae9b4474 100644 --- a/src/fvOptions/Make/files +++ b/src/fvOptions/Make/files @@ -56,6 +56,7 @@ constraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C /* Corrections */ corrections/limitTemperature/limitTemperature.C +corrections/limitVelocity/limitVelocity.C LIB = $(FOAM_LIBBIN)/libfvOptions diff --git a/src/fvOptions/corrections/limitVelocity/limitVelocity.C b/src/fvOptions/corrections/limitVelocity/limitVelocity.C new file mode 100644 index 0000000000000000000000000000000000000000..d096c381aa74be6091f9a8886c2b845f5c8bc70c --- /dev/null +++ b/src/fvOptions/corrections/limitVelocity/limitVelocity.C @@ -0,0 +1,127 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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/>. + +\*---------------------------------------------------------------------------*/ + +#include "limitVelocity.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + defineTypeNameAndDebug(limitVelocity, 0); + addToRunTimeSelectionTable + ( + option, + limitVelocity, + dictionary + ); +} +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fv::limitVelocity::limitVelocity +( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh +) +: + cellSetOption(name, modelType, dict, mesh), + UName_(coeffs_.lookupOrDefault<word>("U", "U")), + max_(readScalar(coeffs_.lookup("max"))) +{ + fieldNames_.setSize(1, UName_); + applied_.setSize(1, false); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::fv::limitVelocity::read(const dictionary& dict) +{ + if (cellSetOption::read(dict)) + { + coeffs_.lookup("max") >> max_; + + return true; + } + else + { + return false; + } +} + + +void Foam::fv::limitVelocity::correct(volVectorField& U) +{ + const scalar maxSqrU = sqr(max_); + + vectorField& Uif = U.primitiveFieldRef(); + + forAll(cells_, i) + { + const label celli = cells_[i]; + + const scalar magSqrUi = magSqr(Uif[celli]); + + if (magSqrUi > maxSqrU) + { + Uif[celli] *= maxSqrU/magSqrUi; + } + } + + // handle boundaries in the case of 'all' + if (selectionMode_ == smAll) + { + volVectorField::Boundary& Ubf = U.boundaryFieldRef(); + + forAll(Ubf, patchi) + { + fvPatchVectorField& Up = Ubf[patchi]; + + if (!Up.fixesValue()) + { + forAll(Up, facei) + { + const scalar magSqrUi = magSqr(Up[facei]); + + if (magSqrUi > maxSqrU) + { + Up[facei] *= maxSqrU/magSqrUi; + } + } + } + } + } +} + + +// ************************************************************************* // diff --git a/src/fvOptions/corrections/limitVelocity/limitVelocity.H b/src/fvOptions/corrections/limitVelocity/limitVelocity.H new file mode 100644 index 0000000000000000000000000000000000000000..b1c3f1b0482a9f3b8513faca8ececa9cb523160e --- /dev/null +++ b/src/fvOptions/corrections/limitVelocity/limitVelocity.H @@ -0,0 +1,136 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 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/>. + +Class + Foam::fv::limitVelocity + +Description + Limits the maximum velocity magnitude to the specified \c max value. + +Usage + Example usage: + \verbatim + limitU + { + type limitVelocity; + active yes; + + limitVelocityCoeffs + { + selectionMode all; + max 100; + } + } + \endverbatim + +SourceFiles + limitVelocity.C + +\*---------------------------------------------------------------------------*/ + +#ifndef limitVelocity_H +#define limitVelocity_H + +#include "cellSetOption.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class limitVelocity Declaration +\*---------------------------------------------------------------------------*/ + +class limitVelocity +: + public cellSetOption +{ + +protected: + + // Protected data + + //- Velocity field name, default = U + word UName_; + + //- Maximum velocity magnitude + scalar max_; + + +private: + + // Private Member Functions + + //- Disallow default bitwise copy construct + limitVelocity(const limitVelocity&); + + //- Disallow default bitwise assignment + void operator=(const limitVelocity&); + + +public: + + //- Runtime type information + TypeName("limitVelocity"); + + + // Constructors + + //- Construct from components + limitVelocity + ( + const word& name, + const word& modelType, + const dictionary& dict, + const fvMesh& mesh + ); + + + //- Destructor + virtual ~limitVelocity() + {} + + + // Member Functions + + //- Read dictionary + virtual bool read(const dictionary& dict); + + //- Correct the energy field + virtual void correct(volVectorField& U); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //