From 2caad45a9b5ec6db05687aefcafe275877edc776 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 22 Jan 2021 19:18:51 +0000 Subject: [PATCH] functionObjects/setTimeStep: Compatibility with 'adjustableRunTime' setTimeStep is now compatible with a 'writeControl adjustableRunTime;' setting in the systemControlDict. If 'adjustableRunTime' is selected then the time-step values set by this function object will not be exactly as specified, but write intervals will be matched exactly. All function object time adjustment is now done during the execute methods, so the specific setTimeStep hooks have been removed. --- src/OpenFOAM/db/Time/Time.C | 4 +- .../functionObject/functionObject.C | 8 +--- .../functionObject/functionObject.H | 5 --- .../functionObjectList/functionObjectList.C | 39 +------------------ .../functionObjectList/functionObjectList.H | 5 +-- .../setTimeStep/setTimeStepFunctionObject.C | 4 +- .../setTimeStep/setTimeStepFunctionObject.H | 17 +++++--- 7 files changed, 17 insertions(+), 65 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 52290cc590..527581461b 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -970,8 +970,6 @@ void Foam::Time::setDeltaT(const scalar deltaT) { setDeltaTNoAdjust(deltaT); - functionObjects_.setTimeStep(); - if (writeControl_ == writeControl::adjustableRunTime) { adjustDeltaT(); diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index dc620ad927..8878dc618e 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -150,12 +150,6 @@ bool Foam::functionObject::end() } -bool Foam::functionObject::setTimeStep() -{ - return false; -} - - Foam::scalar Foam::functionObject::timeToNextWrite() { return vGreat; diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index fe2607544f..dc0498facc 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H @@ -230,11 +230,6 @@ public: //- Called when Time::run() determines that the time-loop exits. virtual bool end(); - //- Called by Time::setDeltaT(). Allows the functionObject to override - // the time-step value. - // Returns whether or not the value was overridden. - virtual bool setTimeStep(); - //- Called by Time::adjustTimeStep(). Allows the functionObject to // insert a write time earlier than that already in use by the run // time. Returns the write time, or vGreat. diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 89f1ae1c93..8254750912 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -628,43 +628,6 @@ bool Foam::functionObjectList::end() } -bool Foam::functionObjectList::setTimeStep() -{ - bool set = true; - - if (execution_) - { - if (!updated_) - { - read(); - } - - wordList names; - - forAll(*this, oi) - { - if (operator[](oi).setTimeStep()) - { - names.append(operator[](oi).name()); - set = true; - } - } - - if (names.size() > 1) - { - WarningInFunction << "Multiple function objects (" << names[0]; - for (label i = 1; i < names.size(); ++ i) - { - WarningInFunction << ", " << names[i]; - } - WarningInFunction << ") are setting the time step." << endl; - } - } - - return set; -} - - Foam::scalar Foam::functionObjectList::timeToNextWrite() { scalar result = vGreat; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index bed96380c8..2d77fe41f2 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -272,9 +272,6 @@ public: //- Called when Time::run() determines that the time-loop exits bool end(); - //- Override the time-step value - bool setTimeStep(); - //- Return the time to the next write scalar timeToNextWrite(); diff --git a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C index d363fe4876..d93ccaac8a 100644 --- a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C +++ b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -86,7 +86,7 @@ bool Foam::functionObjects::setTimeStepFunctionObject::execute() if (!adjustTimeStep) { - const_cast(time_).setDeltaTNoAdjust + const_cast(time_).setDeltaT ( timeStepPtr_().value(time_.timeOutputValue()) ); diff --git a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H index bbda0f5a00..77d72d5c35 100644 --- a/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H +++ b/src/functionObjects/utilities/setTimeStep/setTimeStepFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2013-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,12 +25,17 @@ Class Foam::functionObjects::setTimeStepFunctionObject Description - Updates the writeInterval as a Function1 of time. + Updates the time step as a Function1 of time. - Can only be used with solvers with adjustTimeStep control - (e.g. pimpleFoam). Makes no attempt to cooperate with other timeStep - 'controllers' (maxCo, other functionObjects). Supports 'enabled' flag but - none of the other ones 'startTime', 'endTime', 'writeControl' etc. + Makes no attempt to cooperate with other timeStep controllers (i.e., solver + courant number control or other functionObjects). In general any value set + here will be overwritten by solver time-step adjustment if enabled, so for + this to work 'adjustTime' should be switched off. This is compatible with + 'adjustableWriteTime', in which case the time-step values set will not be + exactly as specified, but write intervals will be matched exactly. + + This function supports the 'enabled' flag but none of the other run + controls; 'startTime', 'endTime', 'writeControl', etc... SourceFiles setTimeStepFunctionObject.C