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
This commit is contained in:
Henry 2015-04-25 15:14:31 +01:00
parent 2edb12fa80
commit f130edc9ac
6 changed files with 40 additions and 38 deletions

View file

@ -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"

View file

@ -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

View file

@ -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();

View file

@ -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<bool> Foam::timeSelector::selected(const instantList& Times) const
{
List<bool> 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<bool> 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::instant> Foam::timeSelector::select
{
List<bool> 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::instant> 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::instant> 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::instant> 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::instant> 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::instant> Foam::timeSelector::selectIfPresent
|| args.optionFound("time")
|| args.optionFound("constant")
|| args.optionFound("noZero")
|| args.optionFound("zeroTime")
|| args.optionFound("withZero")
)
{
return select0(runTime, args);

View file

@ -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,

View file

@ -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",