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

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -24,7 +24,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
checkDecomposePar
Test-checkDecomposePar
Group
grpParallelUtilities
@ -35,8 +35,9 @@ Description
\*---------------------------------------------------------------------------*/
#include "OSspecific.H"
#include "fvCFD.H"
#include "argList.H"
#include "timeSelector.H"
#include "polyMesh.H"
#include "cpuTime.H"
#include "IFstream.H"
#include "regionProperties.H"
@ -44,10 +45,14 @@ Description
#include "decompositionInformation.H"
#include "decompositionModel.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
timeSelector::addOptions_singleTime(); // Single-time options
argList::addNote
(
"Check decomposition from kaffpa (KaHIP) output"
@ -65,9 +70,6 @@ int main(int argc, char *argv[])
argList::addArgument("kaffpa-output-file");
// Include explicit constant options, have zero from time range
timeSelector::addOptions(true, false);
#include "setRootCase.H"
const auto decompFile = args.get<fileName>(1);
@ -75,8 +77,8 @@ int main(int argc, char *argv[])
// Set time from database
#include "createTime.H"
// Allow override of time
instantList times = timeSelector::selectIfPresent(runTime, args);
// Allow override of time from specified time options, or no-op
timeSelector::setTimeIfPresent(runTime, args);
// Allow override of decomposeParDict location
const fileName decompDictFile =
@ -95,7 +97,7 @@ int main(int argc, char *argv[])
Info<< "\n\nDecomposing mesh " << regionName << nl << endl;
Info<< "Create mesh..." << flush;
fvMesh mesh
polyMesh mesh
(
IOobject
(
@ -111,7 +113,7 @@ int main(int argc, char *argv[])
Info<< " nCells = " << mesh.nCells() << endl;
// Expected format is a simple ASCII list
cellToProc.setSize(mesh.nCells());
cellToProc.resize(mesh.nCells());
{
IFstream is(decompFile);