From e2e03fd70df823d70cef0c61c13dfa659f52dbc8 Mon Sep 17 00:00:00 2001
From: Andrew Heather <>
Date: Fri, 4 Apr 2025 12:48:38 +0100
Subject: [PATCH] ENH: Added onStart option to timeControl for function object
 control

Triggers function object to execute on the first time step.

Example usage:

    minMax1
    {
        type            fieldMinMax;
        libs            (fieldFunctionObjects);
        writeControl    onStart;
        fields          (".*");
    }

Ref: EP2608
---
 .../db/functionObjects/timeControl/timeControl.C         | 9 ++++++++-
 .../db/functionObjects/timeControl/timeControl.H         | 3 ++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C
index 9550509a6b7..c02461a9ce3 100644
--- a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C
+++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2019 OpenCFD Ltd.
+    Copyright (C) 2016-2019, 2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -47,6 +47,7 @@ Foam::timeControl::controlNames_
     { timeControl::ocAdjustableRunTime, "adjustableRunTime" },
     { timeControl::ocClockTime, "clockTime" },
     { timeControl::ocCpuTime, "cpuTime" },
+    { timeControl::ocOnStart, "onStart" },
     { timeControl::ocOnEnd, "onEnd" },
 });
 
@@ -257,6 +258,12 @@ bool Foam::timeControl::execute()
             break;
         }
 
+        case ocOnStart:
+        {
+            return time_.timeIndex() == 1;
+            break;
+        }
+
         case ocOnEnd:
         {
             scalar endTime = time_.endTime().value() - 0.5*time_.deltaTValue();
diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.H b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.H
index 660176be4ee..3f63e1ecff9 100644
--- a/src/OpenFOAM/db/functionObjects/timeControl/timeControl.H
+++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControl.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019, 2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -74,6 +74,7 @@ public:
         ocAdjustableRunTime,  //!< Currently identical to "runTime"
         ocClockTime,          //!< Use clock time for execution
         ocCpuTime,            //!< Use CPU time for execution
+        ocOnStart,            //!< Execute on first step of run
         ocOnEnd               //!< Execute on end of run
     };
 
-- 
GitLab