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.
This commit is contained in:
Henry
2015-04-25 11:51:06 +01:00
parent 7ed416b067
commit cb82ae7d96
2 changed files with 21 additions and 19 deletions

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())
@ -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,21 +216,21 @@ 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"))
{
// with -zeroTime enabled, drop 0/ unless specifically requested
// With -zeroTime enabled, drop 0/ unless specifically requested
selectTimes[zeroIdx] = args.optionFound("zeroTime");
}
}
@ -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);

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