From f130edc9ac19cc179a2b0bd2458402b30ac4b453 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 25 Apr 2015 15:14:31 +0100 Subject: [PATCH] timeSelector: Change select0 to return 'constant' if no times are specified or available This allows checkMesh and other mesh manipulation utilities to operate on the mesh without any time directories being present. Also renamed option zeroTime -> withZero for consistency with the noZero option --- .../reconstructPar/reconstructPar.C | 2 +- .../reconstructParMesh/reconstructParMesh.C | 2 +- .../foamToEnsightParts/foamToEnsightParts.C | 4 +- src/OpenFOAM/db/Time/timeSelector.C | 49 ++++++++++--------- src/OpenFOAM/db/Time/timeSelector.H | 17 ++++--- src/postProcessing/postCalc/postCalc.C | 4 +- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 31df7a79..db2df9ee 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) ); // Enable -constant ... if someone really wants it - // Enable -zeroTime to prevent accidentally trashing the initial fields + // Enable -withZero to prevent accidentally trashing the initial fields timeSelector::addOptions(true, true); argList::noParallel(); #include "addRegionOption.H" diff --git a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C index 7f8f3d67..cfa77f70 100644 --- a/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C +++ b/applications/utilities/parallelProcessing/reconstructParMesh/reconstructParMesh.C @@ -432,7 +432,7 @@ int main(int argc, char *argv[]) ); // Enable -constant ... if someone really wants it - // Enable -zeroTime to prevent accidentally trashing the initial fields + // Enable -withZero to prevent accidentally trashing the initial fields timeSelector::addOptions(true, true); argList::noParallel(); argList::addOption diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C index c58a008c..8e948b16 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -79,7 +79,7 @@ using namespace Foam; int main(int argc, char *argv[]) { // enable -constant - // probably don't need -zeroTime though, since the fields are vetted + // probably don't need -withZero though, since the fields are vetted // afterwards anyhow timeSelector::addOptions(true, false); argList::noParallel(); diff --git a/src/OpenFOAM/db/Time/timeSelector.C b/src/OpenFOAM/db/Time/timeSelector.C index 7a8bcc5e..61f3d9a6 100644 --- a/src/OpenFOAM/db/Time/timeSelector.C +++ b/src/OpenFOAM/db/Time/timeSelector.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,7 +55,7 @@ Foam::List Foam::timeSelector::selected(const instantList& Times) const { List lst(Times.size(), false); - // check ranges, avoid false positive on constant/ + // Check ranges, avoid false positive on constant/ forAll(Times, timeI) { if (Times[timeI].name() != "constant" && selected(Times[timeI])) @@ -64,7 +64,7 @@ Foam::List Foam::timeSelector::selected(const instantList& Times) const } } - // check specific values + // Check specific values forAll(*this, rangeI) { if (operator[](rangeI).isExact()) @@ -113,7 +113,7 @@ void Foam::timeSelector::inplaceSelect(instantList& Times) const void Foam::timeSelector::addOptions ( const bool constant, - const bool zeroTime + const bool withZero ) { if (constant) @@ -124,11 +124,11 @@ void Foam::timeSelector::addOptions "include the 'constant/' dir in the times list" ); } - if (zeroTime) + if (withZero) { argList::addBoolOption ( - "zeroTime", + "withZero", "include the '0/' dir in the times list" ); } @@ -136,7 +136,7 @@ void Foam::timeSelector::addOptions ( "noZero", "exclude the '0/' dir from the times list, " - "has precedence over the -zeroTime option" + "has precedence over the -withZero option" ); argList::addBoolOption ( @@ -163,7 +163,7 @@ Foam::List Foam::timeSelector::select { List selectTimes(timeDirs.size(), true); - // determine locations of constant/ and 0/ directories + // Determine locations of constant/ and 0/ directories label constantIdx = -1; label zeroIdx = -1; @@ -184,15 +184,15 @@ Foam::List Foam::timeSelector::select } } - // determine latestTime selection (if any) - // this must appear before the -time option processing + // Determine latestTime selection (if any) + // This must appear before the -time option processing label latestIdx = -1; if (args.optionFound("latestTime")) { selectTimes = false; latestIdx = timeDirs.size() - 1; - // avoid false match on constant/ + // Avoid false match on constant/ if (latestIdx == constantIdx) { latestIdx = -1; @@ -201,15 +201,14 @@ Foam::List Foam::timeSelector::select if (args.optionFound("time")) { - // can match 0/, but can never match constant/ + // Can match 0/, but can never match constant/ selectTimes = timeSelector ( args.optionLookup("time")() ).selected(timeDirs); } - - // add in latestTime (if selected) + // Add in latestTime (if selected) if (latestIdx >= 0) { selectTimes[latestIdx] = true; @@ -217,22 +216,22 @@ Foam::List Foam::timeSelector::select if (constantIdx >= 0) { - // only add constant/ if specifically requested + // Only add constant/ if specifically requested selectTimes[constantIdx] = args.optionFound("constant"); } - // special treatment for 0/ + // Special treatment for 0/ if (zeroIdx >= 0) { if (args.optionFound("noZero")) { - // exclude 0/ if specifically requested + // Exclude 0/ if specifically requested selectTimes[zeroIdx] = false; } - else if (argList::validOptions.found("zeroTime")) + else if (argList::validOptions.found("withZero")) { - // with -zeroTime enabled, drop 0/ unless specifically requested - selectTimes[zeroIdx] = args.optionFound("zeroTime"); + // With -withZero enabled, drop 0/ unless specifically requested + selectTimes[zeroIdx] = args.optionFound("withZero"); } } @@ -260,9 +259,11 @@ Foam::List Foam::timeSelector::select0 if (timeDirs.empty()) { - FatalErrorIn(args.executable()) - << "No times selected" - << exit(FatalError); + WarningIn(args.executable()) + << "No time specified or available, selecting 'constant'" + << endl; + + timeDirs.append(instant(0, runTime.constant())); } runTime.setTime(timeDirs[0], 0); @@ -283,7 +284,7 @@ Foam::List Foam::timeSelector::selectIfPresent || args.optionFound("time") || args.optionFound("constant") || args.optionFound("noZero") - || args.optionFound("zeroTime") + || args.optionFound("withZero") ) { return select0(runTime, args); diff --git a/src/OpenFOAM/db/Time/timeSelector.H b/src/OpenFOAM/db/Time/timeSelector.H index ce22d83f..590da7a1 100644 --- a/src/OpenFOAM/db/Time/timeSelector.H +++ b/src/OpenFOAM/db/Time/timeSelector.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,7 +59,7 @@ Description \endverbatim The first argument avoids adding the \b -constant option. The second - argument adds an additional \b -zeroTime option and also prevents the + argument adds an additional \b -withZero option and also prevents the \c 0/ directory from being included in the default time range and in the \b -latestTime selection. @@ -122,16 +122,16 @@ public: // \param constant // Add the \b -constant option to include the \c constant/ directory // - // \param zeroTime - // Enable the \b -zeroTime option and alter the normal time selection + // \param withZero + // Enable the \b -withZero option and alter the normal time selection // behaviour (and \b -latestTime behaviour) to exclude the \c 0/ // directory. The \c 0/ directory will only be included when - // \b -zeroTime is specified. - // The \b -noZero option has precedence over the @b -zeroTime option. + // \b -withZero is specified. + // The \b -noZero option has precedence over the @b -withZero option. static void addOptions ( const bool constant=true, - const bool zeroTime=false + const bool withZero=false ); //- Return the set of times selected based on the argList options @@ -143,7 +143,8 @@ public: ); //- Return the set of times selected based on the argList options - // also set the runTime to the first instance + // also set the runTime to the first instance or the + // \c constant/ directory if no instances are specified or available static instantList select0 ( Time& runTime, diff --git a/src/postProcessing/postCalc/postCalc.C b/src/postProcessing/postCalc/postCalc.C index 9eec208a..d0d32d62 100644 --- a/src/postProcessing/postCalc/postCalc.C +++ b/src/postProcessing/postCalc/postCalc.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -57,7 +57,7 @@ namespace Foam int main(int argc, char *argv[]) { Foam::timeSelector::addOptions(); -# include "addRegionOption.H" + #include "addRegionOption.H" Foam::argList::addBoolOption ( "noWrite",