From d2175f8fe0243cf65ab674c2f39772a7f7dc7943 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Mon, 8 Jan 2018 17:59:55 +0000 Subject: [PATCH 1/4] fvOptions: verticalDamping: Added spatial ramping The onset of vertical damping can now be graduated over a distance. The user specifies an origin and a direction along which the graduation occurs, and a ramping function to specify the form of the graduation. An example specification for the fvOption is: verticalDamping1 { type verticalDamping; selectionMode all; origin (1200 0 0); direction (1 0 0); ramp { type halfCosineRamp; start 0; duration 600; } lambda [0 0 -1 0 0 0 0] 1; // Damping coefficient timeStart 0; duration 1e6; } If the origin, direction or ramp entries are omitted then the fvOption functions as before; applying the damping to the entire volume or the specified cell set. This work was supported by Jan Kaufmann and Jan Oberhagemann at DNV GL. --- .../derived/velocityRamping/velocityRamping.H | 2 +- .../derived/verticalDamping/verticalDamping.C | 37 ++++++++++++++-- .../derived/verticalDamping/verticalDamping.H | 38 ++++++++++++++++- .../multiphase/interFoam/laminar/wave/Allrun | 2 - .../interFoam/laminar/wave/constant/fvOptions | 14 +++++-- .../interFoam/laminar/wave/system/topoSetDict | 42 ------------------- 6 files changed, 83 insertions(+), 52 deletions(-) delete mode 100644 tutorials/multiphase/interFoam/laminar/wave/system/topoSetDict diff --git a/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H index 9d92e09c9..f15d89005 100644 --- a/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H +++ b/src/fvOptions/sources/derived/velocityRamping/velocityRamping.H @@ -40,7 +40,7 @@ Usage velocity (-2.572 0 0); ramp { - type quarterSineRamp; + type halfCosineRamp; start 0; duration 10; } diff --git a/src/fvOptions/sources/derived/verticalDamping/verticalDamping.C b/src/fvOptions/sources/derived/verticalDamping/verticalDamping.C index ab6e1e108..99ab06440 100644 --- a/src/fvOptions/sources/derived/verticalDamping/verticalDamping.C +++ b/src/fvOptions/sources/derived/verticalDamping/verticalDamping.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,6 +28,7 @@ License #include "fvMatrix.H" #include "geometricOneField.H" #include "meshTools.H" +#include "Function1.H" #include "uniformDimensionedFields.H" #include "addToRunTimeSelectionTable.H" @@ -59,6 +60,14 @@ void Foam::fv::verticalDamping::add const DimensionedField& V = mesh_.V(); + // Calculate the scale + const scalarField s + ( + ramp_.valid() + ? ramp_->value((mesh_.cellCentres() - origin_) & direction_) + : tmp(new scalarField(mesh_.nCells(), 1)) + ); + // Check dimensions eqn.dimensions() - V.dimensions()*(lgg.dimensions() & alphaRhoU.dimensions()); @@ -68,7 +77,7 @@ void Foam::fv::verticalDamping::add forAll(cells_, i) { const label c = cells_[i]; - force[i] = V[c]*(lgg.value() & alphaRhoU[c]); + force[i] = V[c]*s[c]*(lgg.value() & alphaRhoU[c]); } meshTools::constrainDirection(mesh_, mesh_.solutionD(), force); forAll(cells_, i) @@ -90,7 +99,10 @@ Foam::fv::verticalDamping::verticalDamping ) : cellSetOption(name, modelType, dict, mesh), - lambda_("lambda", dimless/dimTime, coeffs_.lookup("lambda")) + lambda_("lambda", dimless/dimTime, coeffs_.lookup("lambda")), + ramp_(), + origin_(), + direction_() { read(dict); } @@ -143,6 +155,25 @@ bool Foam::fv::verticalDamping::read(const dictionary& dict) coeffs_.lookup(lambda_.name()) ); + const bool foundRamp = coeffs_.found("ramp"); + const bool foundOrigin = coeffs_.found("origin"); + const bool foundDirection = coeffs_.found("direction"); + if (foundRamp && foundOrigin && foundDirection) + { + ramp_ = Function1::New("ramp", coeffs_); + coeffs_.lookup("origin") >> origin_; + coeffs_.lookup("direction") >> direction_; + direction_ /= mag(direction_); + } + else if (foundRamp || foundOrigin || foundDirection) + { + WarningInFunction + << "The ramping specification is incomplete. \"ramp\", " + << "\"origin\" and \"direction\", must all be specified in " + << "order to ramp the damping. The damping will be applied " + << "uniformly across the cell set." << endl; + } + fieldNames_ = wordList(1, coeffs_.lookupOrDefault("U", "U")); applied_.setSize(1, false); diff --git a/src/fvOptions/sources/derived/verticalDamping/verticalDamping.H b/src/fvOptions/sources/derived/verticalDamping/verticalDamping.H index 1eaef6aa7..d43896470 100644 --- a/src/fvOptions/sources/derived/verticalDamping/verticalDamping.H +++ b/src/fvOptions/sources/derived/verticalDamping/verticalDamping.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -67,6 +67,30 @@ Usage } \endverbatim + Example usage with graduated onset: + \verbatim + verticalDamping1 + { + type verticalDamping; + + selectionMode all; + + origin (1200 0 0); + direction (1 0 0); + ramp + { + type halfCosineRamp; + start 0; + duration 600; + } + + lambda [0 0 -1 0 0 0 0] 1; // Damping coefficient + + timeStart 0; + duration 1e6; + } + \endverbatim + SourceFiles verticalDamping.C @@ -81,6 +105,9 @@ SourceFiles namespace Foam { + +template class Function1; + namespace fv { @@ -99,6 +126,15 @@ private: //- Damping coefficient [1/s] dimensionedScalar lambda_; + //- The ramping function + autoPtr> ramp_; + + //- Origin of the ramping coordinate + vector origin_; + + //- Direction of increasing ramping coordinate + vector direction_; + // Private Member Functions diff --git a/tutorials/multiphase/interFoam/laminar/wave/Allrun b/tutorials/multiphase/interFoam/laminar/wave/Allrun index c3b6a368c..99393456a 100755 --- a/tutorials/multiphase/interFoam/laminar/wave/Allrun +++ b/tutorials/multiphase/interFoam/laminar/wave/Allrun @@ -22,8 +22,6 @@ do runApplication -s $i refineMesh -dict system/refineMeshDictY -overwrite done -runApplication topoSet - runApplication setWaves -alpha alpha.water runApplication decomposePar diff --git a/tutorials/multiphase/interFoam/laminar/wave/constant/fvOptions b/tutorials/multiphase/interFoam/laminar/wave/constant/fvOptions index a2691bbb9..73a539fbf 100644 --- a/tutorials/multiphase/interFoam/laminar/wave/constant/fvOptions +++ b/tutorials/multiphase/interFoam/laminar/wave/constant/fvOptions @@ -19,10 +19,18 @@ option1 { type verticalDamping; - selectionMode cellZone; - cellZone right; + selectionMode all; - lambda 0.1; + origin (1200 0 0); + direction (1 0 0); + ramp + { + type halfCosineRamp; + start 0; + duration 600; + } + + lambda 0.5; timeStart 0; duration 1e6; diff --git a/tutorials/multiphase/interFoam/laminar/wave/system/topoSetDict b/tutorials/multiphase/interFoam/laminar/wave/system/topoSetDict deleted file mode 100644 index d9f4d4ef8..000000000 --- a/tutorials/multiphase/interFoam/laminar/wave/system/topoSetDict +++ /dev/null @@ -1,42 +0,0 @@ -/*--------------------------------*- C++ -*----------------------------------*\ -| ========= | | -| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: dev | -| \\ / A nd | Web: www.OpenFOAM.org | -| \\/ M anipulation | | -\*---------------------------------------------------------------------------*/ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "system"; - object topoSetDict; -} -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -actions -( - { - name right; - type cellSet; - action new; - source boxToCell; - sourceInfo - { - box (1800 -1e6 -1e6) (1e6 1e6 1e6); - } - } - { - name right; - type cellZoneSet; - action new; - source setToCellZone; - sourceInfo - { - set right; - } - } -); - -// ************************************************************************* // From 352c6bf62f6b755905e111f01167e1316f23a320 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 11 Jan 2018 08:52:21 +0000 Subject: [PATCH 2/4] CloudFunctionObjects: ParticleTrap: Corrected example usage Resolves bug report https://bugs.openfoam.org/view.php?id=2805 --- .../CloudFunctionObjects/ParticleTrap/ParticleTrap.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleTrap/ParticleTrap.H b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleTrap/ParticleTrap.H index 496dedb56..84279677e 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleTrap/ParticleTrap.H +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleTrap/ParticleTrap.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -32,7 +32,7 @@ Description particleTrap1 { type particleTrap; - alphaName alpha; // name volume fraction field + alpha alpha; // name of the volume fraction field threshold 0.95; // alpha value below which model is active } \endverbatim From a44e95d119172008536633021e75ee03542057a6 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 11 Jan 2018 09:13:08 +0000 Subject: [PATCH 3/4] ParticleFunctionObjects: Added PatchCollisionDensity object This function object will write a paraview-viewable field showing the area-density of parcel collisions on every patch face. It also outputs the rate of collisions hitting each patch face, calculated over an interval equal to the time elapsed since the last output. It has an optional entry to specify a minimum incident speed below which a collision is not counted. It can be enabled in the cloud properties file as follows: cloudFunctions { patchCollisionDensity1 { type patchCollisionDensity; minSpeed 1e-3; // (optional) } } This work was supported by Anton Kidess, at Hilti --- .../include/makeParcelCloudFunctionObjects.H | 4 +- .../PatchCollisionDensity.C | 168 ++++++++++++++++++ .../PatchCollisionDensity.H | 152 ++++++++++++++++ 3 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.C create mode 100644 src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.H diff --git a/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H b/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H index e270bb22a..0bd12e265 100644 --- a/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H +++ b/src/lagrangian/intermediate/parcels/include/makeParcelCloudFunctionObjects.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,6 +33,7 @@ License #include "ParticleErosion.H" #include "ParticleTracks.H" #include "ParticleTrap.H" +#include "PatchCollisionDensity.H" #include "PatchPostProcessing.H" #include "VoidFraction.H" @@ -47,6 +48,7 @@ License makeCloudFunctionObjectType(ParticleErosion, CloudType); \ makeCloudFunctionObjectType(ParticleTracks, CloudType); \ makeCloudFunctionObjectType(ParticleTrap, CloudType); \ + makeCloudFunctionObjectType(PatchCollisionDensity, CloudType); \ makeCloudFunctionObjectType(PatchPostProcessing, CloudType); \ makeCloudFunctionObjectType(VoidFraction, CloudType); diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.C new file mode 100644 index 000000000..111ffcbed --- /dev/null +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.C @@ -0,0 +1,168 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +\*---------------------------------------------------------------------------*/ + +#include "PatchCollisionDensity.H" +#include "Pstream.H" +#include "stringListOps.H" +#include "ListOps.H" +#include "ListListOps.H" + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +template +void Foam::PatchCollisionDensity::write() +{ + const scalarField z(this->owner().mesh().nCells(), 0); + + volScalarField + ( + IOobject + ( + this->owner().name() + ":collisionDensity", + this->owner().mesh().time().timeName(), + this->owner().mesh() + ), + this->owner().mesh(), + dimless/dimArea, + z, + collisionDensity_ + ) + .write(); + + volScalarField + ( + IOobject + ( + this->owner().name() + ":collisionDensityRate", + this->owner().mesh().time().timeName(), + this->owner().mesh() + ), + this->owner().mesh(), + dimless/dimArea/dimTime, + z, + (collisionDensity_ - collisionDensity0_) + /(this->owner().mesh().time().value() - time0_) + ) + .write(); + + collisionDensity0_ == collisionDensity_; + time0_ = this->owner().mesh().time().value(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::PatchCollisionDensity::PatchCollisionDensity +( + const dictionary& dict, + CloudType& owner, + const word& modelName +) +: + CloudFunctionObject(dict, owner, modelName, typeName), + minSpeed_(dict.lookupOrDefault("minSpeed", -1)), + collisionDensity_ + ( + this->owner().mesh().boundary(), + volScalarField::Internal::null(), + calculatedFvPatchField::typeName + ), + collisionDensity0_ + ( + this->owner().mesh().boundary(), + volScalarField::Internal::null(), + calculatedFvPatchField::typeName + ), + time0_(this->owner().mesh().time().value()) +{ + collisionDensity_ == 0; + collisionDensity0_ == 0; + + IOobject io + ( + this->owner().name() + ":collisionDensity", + this->owner().mesh().time().timeName(), + this->owner().mesh(), + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if (io.typeHeaderOk()) + { + const volScalarField collisionDensity(io, this->owner().mesh()); + collisionDensity_ == collisionDensity.boundaryField(); + collisionDensity0_ == collisionDensity.boundaryField(); + } +} + + +template +Foam::PatchCollisionDensity::PatchCollisionDensity +( + const PatchCollisionDensity& ppm +) +: + CloudFunctionObject(ppm), + minSpeed_(ppm.minSpeed_), + collisionDensity_(ppm.collisionDensity_), + collisionDensity0_(ppm.collisionDensity0_), + time0_(ppm.time0_) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::PatchCollisionDensity::~PatchCollisionDensity() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::PatchCollisionDensity::postPatch +( + const parcelType& p, + const polyPatch& pp, + bool& +) +{ + const label patchi = pp.index(); + const label patchFacei = p.face() - pp.start(); + + vector nw, Up; + this->owner().patchData(p, pp, nw, Up); + + const scalar speed = (p.U() - Up) & nw; + if (speed > minSpeed_) + { + collisionDensity_[patchi][patchFacei] += + 1/this->owner().mesh().magSf().boundaryField()[patchi][patchFacei]; + } +} + + +// ************************************************************************* // diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.H b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.H new file mode 100644 index 000000000..8cb4d76bb --- /dev/null +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchCollisionDensity/PatchCollisionDensity.H @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 . + +Class + Foam::PatchCollisionDensity + +Description + Function object which generates fields of the number and rate of collisions + per unit area on all patches. Can optionally take a minimum speed below + which a collision is not counted. + + Example usage: + \verbatim + patchCollisionDensity1 + { + type patchCollisionDensity; + minSpeed 1e-3; + } + \endverbatim + +SourceFiles + PatchCollisionDensity.C + +\*---------------------------------------------------------------------------*/ + +#ifndef PatchCollisionDensity_H +#define PatchCollisionDensity_H + +#include "CloudFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class PatchCollisionDensity Declaration +\*---------------------------------------------------------------------------*/ + +template +class PatchCollisionDensity +: + public CloudFunctionObject +{ + // Private data + + typedef typename CloudType::particleType parcelType; + + //- The threshold for a collision + const scalar minSpeed_; + + //- The field of the number of collisions per unit area + volScalarField::Boundary collisionDensity_; + + //- The field of the number of collisions per unit area at the last + // output + volScalarField::Boundary collisionDensity0_; + + //- The time at the last output + scalar time0_; + + +protected: + + // Protected Member Functions + + //- Write post-processing info + void write(); + + +public: + + //- Runtime type information + TypeName("patchCollisionDensity"); + + + // Constructors + + //- Construct from dictionary + PatchCollisionDensity + ( + const dictionary& dict, + CloudType& owner, + const word& modelName + ); + + //- Construct copy + PatchCollisionDensity(const PatchCollisionDensity& ppm); + + //- Construct and return a clone + virtual autoPtr> clone() const + { + return autoPtr> + ( + new PatchCollisionDensity(*this) + ); + } + + + //- Destructor + virtual ~PatchCollisionDensity(); + + + // Member Functions + + // Evaluation + + //- Post-patch hook + virtual void postPatch + ( + const parcelType& p, + const polyPatch& pp, + bool& keepParticle + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "PatchCollisionDensity.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From ed877387359b7f3c3db24dc33392bb67b011c6da Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 11 Jan 2018 09:53:19 +0000 Subject: [PATCH 4/4] CrankNicolsonDdtScheme: Syntax fix for Clang 5.0.1 --- .../ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C index 937016332..8066a446d 100644 --- a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C +++ b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C @@ -102,7 +102,7 @@ operator=(const GeoField& gf) template template -CrankNicolsonDdtScheme::DDt0Field& +typename CrankNicolsonDdtScheme::template DDt0Field& CrankNicolsonDdtScheme::ddt0_ ( const word& name,