ENH: add single-time handling to timeSelector

- the timeSelector is often used to select single or multiple times
  (eg, for post-processing). However, there are a few applications
  where only a *single* time should be selected and set.

  These are now covered by this type of use:

      timeSelector::addOptions_singleTime();  // Single-time options
      ...
      // Allow override of time from specified time options, or no-op
      timeSelector::setTimeIfPresent(runTime, args);

   In some cases, if can be desirable to force starting from the
   initial Time=0 when no time options have been specified:

      // Set time from specified time options, or force start from Time=0
      timeSelector::setTimeIfPresent(runTime, args, true);

   These changes make a number of includes redundant:

     * addTimeOptions.H
     * checkConstantOption.H
     * checkTimeOption.H
     * checkTimeOptions.H
     * checkTimeOptionsNoConstant.H

ENH: add time handling to setFields, setAlphaField (#3143)

    Co-authored-by: Johan Roenby <>

STYLE: replace instant("constant") with instant(0, "constant")

- avoids relying on atof parse behaviour returning zero
This commit is contained in:
Mark Olesen
2024-05-06 16:05:27 +02:00
parent 883196981d
commit dbfd1f90b1
29 changed files with 319 additions and 98 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
Copyright (C) 2023-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,6 +36,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "timeSelector.H"
#include "fvMesh.H"
#include "volFields.H"
#include "pointFields.H"
@ -145,20 +146,22 @@ void ReadAndMapFields
int main(int argc, char *argv[])
{
argList::noFunctionObjects(); // Never use function objects
timeSelector::addOptions_singleTime(); // Single-time options
argList::addNote
(
"Convert polyMesh results to tetDualMesh"
);
#include "addOverwriteOption.H"
#include "addTimeOptions.H"
#include "setRootCase.H"
#include "createTime.H"
// Get times list
instantList Times = runTime.times();
#include "checkTimeOptions.H"
runTime.setTime(Times[startTime], startTime);
// Set time from specified time options, or force start from Time=0
timeSelector::setTimeIfPresent(runTime, args, true);
// Read the mesh
#include "createNamedMesh.H"

View File

@ -353,7 +353,7 @@ int main(int argc, char *argv[])
#include "createTime.H"
runTime.setTime(instant(runTime.constant()), 0);
runTime.setTime(instant(0, runTime.constant()), 0);
#include "createNamedMesh.H"

View File

@ -106,7 +106,7 @@ int main(int argc, char *argv[])
}
runTime.setTime(instant(runTime.constant()), 0);
runTime.setTime(instant(0, runTime.constant()), 0);
#include "createNamedMesh.H"