Commit 20f9d827 authored by Henry Weller's avatar Henry Weller
Browse files

fvOptions::limitVelocity: New fvOption to limit the maximum velocity magnitude

e.g. to avoid excessive unphysical velocities generated during slamming events in
incompressible VoF simulations

Usage
    Example usage:
    limitU
    {
        type            limitVelocity;
        active          yes;

        limitVelocityCoeffs
        {
            selectionMode   all;
            max             100;
        }
    }
parent 8e3c88ed
......@@ -56,6 +56,7 @@ constraints/fixedTemperatureConstraint/fixedTemperatureConstraint.C
/* Corrections */
corrections/limitTemperature/limitTemperature.C
corrections/limitVelocity/limitVelocity.C
LIB = $(FOAM_LIBBIN)/libfvOptions
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
}
}
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment