From fa57b4e45e7af69e9050d71bc2b8a76b40d0cba0 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Wed, 11 Dec 2019 20:12:49 +0000 Subject: [PATCH 1/2] ENH: adjust dynamicFvMesh to support controllable mesh motion updates --- .../dynamicFvMesh/dynamicFvMesh.C | 68 ++++++++++++++++--- .../dynamicFvMesh/dynamicFvMesh.H | 29 +++++++- .../dynamicFvMesh/dynamicFvMeshNew.C | 1 - 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C index d19c8691af..b0cbbbc3a9 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,12 +37,36 @@ namespace Foam } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::dynamicFvMesh::readDict() +{ + IOdictionary dict + ( + IOobject + ( + "dynamicMeshDict", + thisDb().time().constant(), + thisDb(), + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE, + false // Do not register + ) + ); + + timeControl_.read(dict); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::dynamicFvMesh::dynamicFvMesh(const IOobject& io) : - fvMesh(io) -{} + fvMesh(io), + timeControl_(io.time(), "update") +{ + readDict(); +} Foam::dynamicFvMesh::dynamicFvMesh @@ -52,8 +76,11 @@ Foam::dynamicFvMesh::dynamicFvMesh const bool syncPar ) : - fvMesh(io, Zero, syncPar) -{} + fvMesh(io, Zero, syncPar), + timeControl_(io.time(), "update") +{ + readDict(); +} Foam::dynamicFvMesh::dynamicFvMesh @@ -74,8 +101,11 @@ Foam::dynamicFvMesh::dynamicFvMesh std::move(allOwner), std::move(allNeighbour), syncPar - ) -{} + ), + timeControl_(io.time(), "update") +{ + readDict(); +} Foam::dynamicFvMesh::dynamicFvMesh @@ -94,8 +124,28 @@ Foam::dynamicFvMesh::dynamicFvMesh std::move(faces), std::move(cells), syncPar - ) -{} + ), + timeControl_(io.time(), "update") +{ + readDict(); +} + + +bool Foam::dynamicFvMesh::controlledUpdate() +{ + if (timeControl_.execute()) + { + if (!timeControl_.always()) + { + // Feedback that update has been triggered + Info<< "Mesh update triggered based on " << timeControl_.name() << nl; + } + + return this->update(); + } + + return false; +} // ************************************************************************* // diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H index 666fe89471..8a0a7e3563 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,16 @@ Class Description Abstract base class for geometry and/or topology changing fvMesh. + Supports optional update controls that may be used by custom solvers: + \table + Property | Description | Required | Default + updateControl | See time controls below | no | timeStep + updateInterval | Steps/time between update phases | no | 1 + \endtable + +See also + Foam::timeControl + SourceFiles dynamicFvMesh.C dynamicFvMeshNew.C @@ -40,6 +50,7 @@ SourceFiles #define dynamicFvMesh_H #include "fvMesh.H" +#include "timeControl.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,15 +58,24 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class dynamicFvMesh Declaration + Class dynamicFvMesh Declaration \*---------------------------------------------------------------------------*/ class dynamicFvMesh : public fvMesh { + // Private Data + + //- Optional update control + timeControl timeControl_; + + // Private Member Functions + //- Read the updateControl/updateInterval from dynamicMeshDict + void readDict(); + //- No copy construct dynamicFvMesh(const dynamicFvMesh&) = delete; @@ -83,7 +103,7 @@ public: // Constructors - //- Construct from objectRegistry, and read/write options + //- Construct from an IOobject explicit dynamicFvMesh(const IOobject& io); //- Construct from components without boundary. @@ -144,6 +164,9 @@ public: return true; } + //- Update the mesh if controller permits + virtual bool controlledUpdate(); + //- Update the mesh for both mesh motion and topology change virtual bool update() = 0; }; diff --git a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C index ae5a9afb9f..8b85cbb172 100644 --- a/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C +++ b/src/dynamicFvMesh/dynamicFvMesh/dynamicFvMeshNew.C @@ -88,7 +88,6 @@ Foam::autoPtr Foam::dynamicFvMesh::New(const IOobject& io) return autoPtr(cstrIter()(io)); } - return autoPtr(new staticFvMesh(io)); } From 87bba9ae14894aa286fbc13031e240064886a181 Mon Sep 17 00:00:00 2001 From: Andrew Heather <> Date: Wed, 11 Dec 2019 20:25:18 +0000 Subject: [PATCH 2/2] ENH: add selectable update control/interval to pimpleFoam, rhoPimpleFoam - Allows user-defined control of when the mesh motion occurs, which can be especially useful in situations where the mesh motion is much slower than any of the fluid physics. For example, in constant/dynamicMeshDict: updateControl runTime; updateInterval 0.5; to have mesh motion triggered every 1/2 second. Note that the _exact_ time that the mesh motion actually occurs may be slightly differently since the "runTime" triggering is fuzzy in nature. It will trigger when the threshold has been crossed, which will depend on the current time-step size. --- .../solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C | 7 ++++++- .../solvers/incompressible/pimpleFoam/pimpleFoam.C | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C index d6b0163349..69eb579d70 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +37,10 @@ Description Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and pseudo-transient simulations. +Note + The motion frequency of this solver can be influenced by the presence + of "updateControl" and "updateInterval" in the dynamicMeshDict. + \*---------------------------------------------------------------------------*/ #include "fvCFD.H" @@ -131,7 +136,7 @@ int main(int argc, char *argv[]) } // Do any mesh changes - mesh.update(); + mesh.controlledUpdate(); if (mesh.changing()) { diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C index 9c9fb3bb2b..282c75e954 100644 --- a/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C +++ b/applications/solvers/incompressible/pimpleFoam/pimpleFoam.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -67,6 +68,10 @@ Description \ | As required by user selection \endplaintable +Note + The motion frequency of this solver can be influenced by the presence + of "updateControl" and "updateInterval" in the dynamicMeshDict. + \*---------------------------------------------------------------------------*/ #include "fvCFD.H" @@ -121,7 +126,8 @@ int main(int argc, char *argv[]) { if (pimple.firstIter() || moveMeshOuterCorrectors) { - mesh.update(); + // Do any mesh changes + mesh.controlledUpdate(); if (mesh.changing()) {