From 7142917d06cfe9efee8a9b73745514092faf1e32 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 25 Mar 2023 14:49:58 +0000 Subject: [PATCH] solvers::functions: Added optional subSolverTime controlDict entry Class Foam::solvers::functions Description Solver module to execute the \c functionObjects for a specified solver The solver specified by either the \c subSolver or if not present the \c solver entry in the \c controlDict is instantiated to provide the physical fields needed by the \c functionObjects. The \c functionObjects are then instantiated from the specifications are read from the \c functions entry in the \c controlDict and executed in a time-loop also controlled by entries in \c controlDict and the \c maxDeltaT() returned by the sub-solver. The fields and other objects registered by the sub-solver are set to NO_WRITE as they are not changed by the execution of the functionObjects and should not be written out each write-time. Fields and other objects created and changed by the execution of the functionObjects are written out. When restarting from a time directory which does contain the \c subSolver fields the optional \c controlDict entry \c subSolverTime may be provided to specify which time the \c subSolver should be instantiated for, after which time is reset to \c startTime for the restart. --- .../solvers/modules/functions/functions.C | 21 +++++++++++++++++++ .../solvers/modules/functions/functions.H | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/applications/solvers/modules/functions/functions.C b/applications/solvers/modules/functions/functions.C index 76a1c77573..8fa1244653 100644 --- a/applications/solvers/modules/functions/functions.C +++ b/applications/solvers/modules/functions/functions.C @@ -52,9 +52,30 @@ Foam::solvers::functions::functions(fvMesh& mesh) : runTime.controlDict().lookup("solver") ); + Time& time(const_cast(runTime)); + const TimeState ts(time); + bool startTimeChanged = false; + + if (runTime.controlDict().found("subSolverTime")) + { + const scalar subSolverTime + ( + runTime.controlDict().lookup("subSolverTime") + ); + + time.setTime(subSolverTime, 0); + + startTimeChanged = true; + } + // Instantiate the selected solver solverPtr = (solver::New(solverName, mesh)); + if (startTimeChanged) + { + time.setTime(ts, ts.timeIndex()); + } + // Set all registered objects to NO_WRITE // so only those created by the functionObjects are written for diff --git a/applications/solvers/modules/functions/functions.H b/applications/solvers/modules/functions/functions.H index aff28709d6..2b32a0ceba 100644 --- a/applications/solvers/modules/functions/functions.H +++ b/applications/solvers/modules/functions/functions.H @@ -39,6 +39,11 @@ Description should not be written out each write-time. Fields and other objects created and changed by the execution of the functionObjects are written out. + When restarting from a time directory which does contain the \c subSolver + fields the optional \c controlDict entry \c subSolverTime may be provided to + specify which time the \c subSolver should be instantiated for, after which + time is reset to \c startTime for the restart. + SourceFiles functions.C