From 94061153f1d13a69ce15eb2b9c167544ba2b4d7a Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin <kutalmis.bercin@esi-group.com> Date: Thu, 12 Dec 2019 14:53:17 +0000 Subject: [PATCH] TUT: update velocityDampingConstraint header (#942) STYLE: add getOrDefault(); const specifiers to velocityDampingConstraint TUT: add inactive usage example of velocityDampingConstraint into rhoSimpleFoam/angledDuctExplicitFixedCoeff TUT: add Allclean into rhoSimpleFoam/angledDuctExplicitFixedCoeff, modif the case accordingly --- .../velocityDampingConstraint.C | 8 +-- .../velocityDampingConstraint.H | 58 +++++++++++-------- .../{0 => 0.orig}/T | 0 .../{0 => 0.orig}/U | 0 .../{0 => 0.orig}/alphat | 0 .../{0 => 0.orig}/epsilon | 0 .../{0 => 0.orig}/k | 0 .../{0 => 0.orig}/nut | 0 .../{0 => 0.orig}/p | 0 .../angledDuctExplicitFixedCoeff/Allclean | 8 +++ .../angledDuctExplicitFixedCoeff/Allrun | 2 + .../constant/fvOptions | 8 +++ 12 files changed, 56 insertions(+), 28 deletions(-) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/T (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/U (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/alphat (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/epsilon (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/k (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/nut (100%) rename tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/{0 => 0.orig}/p (100%) create mode 100755 tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allclean diff --git a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C index 9d63bfa7002..a9eeea31b35 100644 --- a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C +++ b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C @@ -55,7 +55,7 @@ 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) + // U/(cbrt of volume) // Since directly manipulating the diagonal we multiply by volume. const scalarField& vol = mesh_.V(); @@ -66,10 +66,10 @@ void Foam::fv::velocityDampingConstraint::addDamping(fvMatrix<vector>& eqn) forAll(U, cellI) { - scalar magU = mag(U[cellI]); + const scalar magU = mag(U[cellI]); if (magU > UMax_) { - scalar scale = sqr(Foam::cbrt(vol[cellI])); + const scalar scale = sqr(Foam::cbrt(vol[cellI])); diag[cellI] += scale*(magU-UMax_); @@ -129,7 +129,7 @@ bool Foam::fv::velocityDampingConstraint::read(const dictionary& dict) if (!coeffs_.readIfPresent("UNames", fieldNames_)) { fieldNames_.resize(1); - fieldNames_.first() = coeffs_.lookupOrDefault<word>("U", "U"); + fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U"); } applied_.setSize(fieldNames_.size(), false); diff --git a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H index 83c65f29d82..cbbe294b861 100644 --- a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H +++ b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H @@ -31,28 +31,38 @@ Group grpFvOptionsConstraints 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) - //U U; - //UNames (U); - } - + Constraint on velocity field to dampen velocity fluctuations. + + This constraint is primarily used to dampen velocity fluctuations in + the start-up phase of simulations. When the local velocity magnitude + exceeds the user-supplied maximum value a sink term is activated in + the affected region to lower the velocity to the limiting value. + +Usage + Example of functionality specification in \c fvOptions: + \verbatim + velocityDamper + { + // Mandatory entries + type velocityDampingConstraint; + UMax 200; + + // Optional entries + selectionMode all; + UNames (U); // names of given velocity fields + U U; // name of given velocity field if + //`UNames` is not present (default: U) + + // Optional fvOptions entries + active true; + } + \endverbatim + +Note + When active, this constraint manipulates the system of equations. + Users should ensure that it is not active when the case is converged + (steady-state) or during the period of interest (transient) to ensure + that its presence does not pollute the results. SourceFiles velocityDampingConstraint.C @@ -82,9 +92,9 @@ class velocityDampingConstraint protected: - // Protected data + // Protected Data - //- Maximum velocity + //- Maximum velocity magnitude scalar UMax_; diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/T b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/T similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/T rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/T diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/U b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/U similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/U rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/U diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/alphat b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/alphat similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/alphat rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/alphat diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/epsilon b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/epsilon similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/epsilon rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/epsilon diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/k b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/k similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/k rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/k diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/nut b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/nut similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/nut rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/nut diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/p b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/p similarity index 100% rename from tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0/p rename to tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/0.orig/p diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allclean b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allclean new file mode 100755 index 00000000000..fb1f3847301 --- /dev/null +++ b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allclean @@ -0,0 +1,8 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions +#------------------------------------------------------------------------------ + +cleanCase0 + +#------------------------------------------------------------------------------ diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allrun b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allrun index 8e142f906ce..236c4d612ac 100755 --- a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allrun +++ b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/Allrun @@ -6,6 +6,8 @@ cd "${0%/*}" || exit # Run from this directory m4 system/blockMeshDict.m4 > system/blockMeshDict runApplication blockMesh +restore0Dir + runApplication $(getApplication) #------------------------------------------------------------------------------ diff --git a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/constant/fvOptions b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/constant/fvOptions index 8c0df22560e..fdea3cedb7e 100644 --- a/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/constant/fvOptions +++ b/tutorials/compressible/rhoSimpleFoam/angledDuctExplicitFixedCoeff/constant/fvOptions @@ -69,4 +69,12 @@ porosityTurbulence } +velocityDamper +{ + type velocityDampingConstraint; + UMax 200; + selectionMode all; + active no; +} + // ************************************************************************* // -- GitLab