Skip to content
Snippets Groups Projects
Commit c62cced6 authored by mattijs's avatar mattijs
Browse files

ENH: velocityDampingConstraint: damping of excess velocity in steady-state calculations

parent 2ecc5396
No related merge requests found
......@@ -59,11 +59,7 @@ $(generalConstraints)/explicitSetValue/explicitSetValue.C
derivedConstraints=constraints/derived
$(derivedConstraints)/fixedTemperatureConstraint/fixedTemperatureConstraint.C
/* Corrections */
corrections/limitTemperature/limitTemperature.C
$(derivedConstraints)/velocityDampingConstraint/velocityDampingConstraint.C
LIB = $(FOAM_LIBBIN)/libfvOptions
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 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 "velocityDampingConstraint.H"
#include "addToRunTimeSelectionTable.H"
#include "fvMatrix.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(velocityDampingConstraint, 0);
addToRunTimeSelectionTable
(
option,
velocityDampingConstraint,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fv::velocityDampingConstraint::addDamping(fvMatrix<vector>& eqn)
{
// Note: we want to add
// deltaU/deltaT
// where deltaT is a local time scale:
// U/(cbrt of volume)
// Since directly manipulating the diagonal we multiply by volume.
const scalarField& vol = mesh_.V();
const volVectorField& U = eqn.psi();
scalarField& diag = eqn.diag();
label nDamped = 0;
forAll(U, cellI)
{
scalar magU = mag(U[cellI]);
if (magU > UMax_)
{
scalar scale = sqr(Foam::cbrt(vol[cellI]));
diag[cellI] += scale*(magU-UMax_);
nDamped++;
}
}
reduce(nDamped, sumOp<label>());
Info<< type() << " " << name_ << " damped "
<< nDamped << " ("
<< 100*scalar(nDamped)/mesh_.globalData().nTotalCells()
<< "%) of cells" << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::velocityDampingConstraint::velocityDampingConstraint
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
)
:
option(name, modelType, dict, mesh)
{
read(dict);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::velocityDampingConstraint::alwaysApply() const
{
return true;
}
void Foam::fv::velocityDampingConstraint::setValue
(
fvMatrix<vector>& eqn,
const label fieldI
)
{
addDamping(eqn);
}
void Foam::fv::velocityDampingConstraint::writeData(Ostream& os) const
{
os << indent << name_ << endl;
dict_.write(os);
}
bool Foam::fv::velocityDampingConstraint::read(const dictionary& dict)
{
if (option::read(dict))
{
UMax_ = readScalar(coeffs_.lookup("UMax"));
if (coeffs_.found("UNames"))
{
coeffs_.lookup("UNames") >> fieldNames_;
}
else if (coeffs_.found("UName"))
{
word UName(coeffs_.lookup("UName"));
fieldNames_ = wordList(1, UName);
}
else
{
fieldNames_ = wordList(1, "U");
}
applied_.setSize(fieldNames_.size(), false);
return true;
}
else
{
return false;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 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::velocityDampingConstraint
Description
Constraint for velocity to dampen velocity fluctuations in
steady simulations
In case of velocity exceeding limit applies
a source sink to remove the excess velocity by adding a term
that drives the velocity to 0 (note that we cannot use the old
term velocity since it most likely is already excessive). This
additional constraint is scaled with (U-UMax)/dt
where dt is a local time scale (= velocity/cellsize) so it switches off
if the velocity is below UMax.
Constraint described by:
velocityDampingConstraintCoeffs
{
UMax 100;
// Optional: name of velocity field (default: U)
//UName U;
}
SourceFiles
velocityDampingConstraint.C
\*---------------------------------------------------------------------------*/
#ifndef velocityDampingConstraint_H
#define velocityDampingConstraint_H
#include "fvOption.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
/*---------------------------------------------------------------------------*\
Class velocityDampingConstraint Declaration
\*---------------------------------------------------------------------------*/
class velocityDampingConstraint
:
public option
{
protected:
// Protected data
//- Maximum velocity
scalar UMax_;
// Protected Member Functions
void addDamping(fvMatrix<vector>& eqn);
private:
// Private Member Functions
//- Disallow default bitwise copy construct
velocityDampingConstraint(const velocityDampingConstraint&);
//- Disallow default bitwise assignment
void operator=(const velocityDampingConstraint&);
public:
//- Runtime type information
TypeName("velocityDampingConstraint");
// Constructors
//- Construct from components
velocityDampingConstraint
(
const word& name,
const word& modelType,
const dictionary& dict,
const fvMesh& mesh
);
//- Destructor
virtual ~velocityDampingConstraint()
{}
// Member Functions
virtual bool alwaysApply() const;
// Set values directly
//- Constrain vector matrix
virtual void setValue
(
fvMatrix<vector>& eqn,
const label fieldI
);
// I-O
//- Write data
virtual void writeData(Ostream&) const;
//- Read dictionary
virtual bool read(const dictionary& dict);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fv
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
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