Commit 966a941a authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: fix foamListTimes to work with -fileHandler collated

parent 2787a866
......@@ -61,6 +61,7 @@ int main(int argc, char *argv[])
argList::noBanner();
argList::noParallel();
argList::noJobInfo();
argList::noFunctionObjects();
argList::addBoolOption
(
"processor",
......@@ -75,18 +76,16 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
label nProcs = 0;
// Get times list from the master processor and subset based on
// command-line options
// Create the processor databases
PtrList<Time> databases(1);
label nProcs = 0;
instantList timeDirs;
if (args.optionFound("processor"))
{
// Determine the processor count directly
while (isDir(args.path()/(word("processor") + name(nProcs))))
{
++nProcs;
}
// Determine the processor count
nProcs = fileHandler().nProcs(args.path());
if (!nProcs)
{
......@@ -95,78 +94,84 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
// Create the processor databases
databases.setSize(nProcs);
forAll(databases, proci)
{
databases.set
timeDirs = timeSelector::select
(
Time
(
proci,
new Time
(
Time::controlDictName,
args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci))
)
);
}
Time::controlDictName,
args.rootPath(),
args.caseName()/"processor0"
).times(),
args
);
}
else
{
databases.set
timeDirs = timeSelector::select
(
0,
new Time
Time
(
Time::controlDictName,
args.rootPath(),
args.caseName()
)
).times(),
args
);
}
// Use the times list from the master processor
// and select a subset based on the command-line options
instantList timeDirs = timeSelector::select
(
databases[0].times(),
args
);
if (args.optionFound("rm"))
{
if (args.optionFound("processor"))
if (nProcs)
{
for (label proci=0; proci<nProcs; proci++)
// Info<< "Remove " << timeDirs.size()
// << " processor time directories" << nl;
forAllReverse(timeDirs, timei)
{
fileName procPath
fileName path
(
args.path()/(word("processor") + name(proci))
args.path()
/ "processors"
/ timeDirs[timei].name()
);
forAll(timeDirs, timeI)
rmDir(path, true);
for (label proci=0; proci<nProcs; ++proci)
{
rmDir(procPath/timeDirs[timeI].name());
path =
(
args.path()
/ (word("processor") + name(proci))
/ timeDirs[timei].name()
);
rmDir(path, true);
}
}
}
else
{
forAll(timeDirs, timeI)
// Info<< "Remove " << timeDirs.size()
// << " time directories" << nl;
forAllReverse(timeDirs, timei)
{
rmDir(args.path()/timeDirs[timeI].name());
rmDir(args.path()/timeDirs[timei].name(), true);
}
}
}
else
{
forAll(timeDirs, timeI)
forAll(timeDirs, timei)
{
Info<< timeDirs[timeI].name() << endl;
Info<< timeDirs[timei].name() << nl;
}
Info<< flush;
}
return 0;
}
......
......@@ -30,23 +30,27 @@ License
const char* const Foam::instant::typeName = "instant";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::instant::instant()
{}
Foam::instant::instant(const scalar val, const word& tname)
:
value_(val),
name_(tname)
{}
Foam::instant::instant(const scalar val)
:
value_(val),
name_(Time::timeName(val))
{}
Foam::instant::instant(const word& tname)
:
value_(atof(tname.c_str())),
......@@ -56,51 +60,51 @@ Foam::instant::instant(const word& tname)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::instant::equal(const scalar b) const
bool Foam::instant::equal(const scalar val) const
{
return (value_ < b + SMALL && value_ > b - SMALL);
return ((value_ > val - SMALL) && (value_ < val + SMALL));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
bool Foam::operator==(const instant& a, const instant& b)
{
return a.equal(b.value_);
return a.equal(b.value());
}
bool Foam::operator!=(const instant& a, const instant& b)
{
return !operator==(a, b);
return !a.equal(b.value());
}
bool Foam::operator<(const instant& a, const instant& b)
{
return a.value_ < b.value_;
return a.value() < b.value();
}
bool Foam::operator>(const instant& a, const instant& b)
{
return a.value_ > b.value_;
return a.value() > b.value();
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, instant& I)
Foam::Istream& Foam::operator>>(Istream& is, instant& inst)
{
is >> I.value_ >> I.name_;
is >> inst.value_ >> inst.name_;
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const instant& I)
Foam::Ostream& Foam::operator<<(Ostream& os, const instant& inst)
{
os << I.value_ << tab << I.name_;
os << inst.value() << tab << inst.name();
return os;
}
......
......@@ -43,21 +43,11 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
class instant;
// Friend Operators
bool operator==(const instant&, const instant&);
bool operator!=(const instant&, const instant&);
bool operator<(const instant&, const instant&);
bool operator>(const instant&, const instant&);
// IOstream Operators
Istream& operator>>(Istream&, instant&);
Ostream& operator<<(Ostream&, const instant&);
Istream& operator>>(Istream& is, instant& inst);
Ostream& operator<<(Ostream& os, const instant& inst);
/*---------------------------------------------------------------------------*\
......@@ -69,6 +59,7 @@ class instant
// Private data
scalar value_;
word name_;
public:
......@@ -98,60 +89,58 @@ public:
instant();
//- Construct from components
instant(const scalar, const word&);
instant(const scalar val, const word& tname);
//- Construct from time value
explicit instant(const scalar);
explicit instant(const scalar val);
//- Construct from word
explicit instant(const word&);
//- Construct from time name
explicit instant(const word& tname);
// Member Functions
// Access
//- Value (const access)
scalar value() const
{
return value_;
}
//- Value (const access)
scalar value() const
{
return value_;
}
//- Value (non-const access)
scalar& value()
{
return value_;
}
//- Value (non-const access)
scalar& value()
{
return value_;
}
//- Name (const access)
const word& name() const
{
return name_;
}
//- Name (const access)
const word& name() const
{
return name_;
}
//- Name (non-const access)
word& name()
{
return name_;
}
//- Name (non-const access)
word& name()
{
return name_;
}
//- Comparison used for instants to be equal
bool equal(const scalar) const;
//- Compare instant values to be equal (includes SMALL for rounding)
bool equal(const scalar val) const;
// Friend Operators
// IOstream Operators
friend bool operator==(const instant&, const instant&);
friend bool operator!=(const instant&, const instant&);
friend bool operator<(const instant&, const instant&);
friend bool operator>(const instant&, const instant&);
friend Istream& operator>>(Istream& is, instant& inst);
friend Ostream& operator<<(Ostream& os, const instant& inst);
};
// IOstream Operators
// Global Operators
friend Istream& operator>>(Istream&, instant&);
friend Ostream& operator<<(Ostream&, const instant&);
};
bool operator==(const instant& a, const instant& b);
bool operator!=(const instant& a, const instant& b);
bool operator<(const instant& a, const instant& b);
bool operator>(const instant& a, const instant& b);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -51,38 +51,38 @@ bool Foam::timeSelector::selected(const instant& value) const
}
Foam::List<bool> Foam::timeSelector::selected(const instantList& Times) const
Foam::List<bool> Foam::timeSelector::selected(const instantList& times) const
{
List<bool> lst(Times.size(), false);
List<bool> lst(times.size(), false);
// Check ranges, avoid false positive on constant/
forAll(Times, timeI)
forAll(times, timei)
{
if (Times[timeI].name() != "constant" && selected(Times[timeI]))
if (times[timei].name() != "constant" && selected(times[timei]))
{
lst[timeI] = true;
lst[timei] = true;
}
}
// Check specific values
forAll(*this, rangeI)
for (const scalarRange& range : *this)
{
if (operator[](rangeI).isExact())
if (range.isExact())
{
scalar target = operator[](rangeI).value();
const scalar target = range.value();
int nearestIndex = -1;
scalar nearestDiff = Foam::GREAT;
forAll(Times, timeI)
forAll(times, timei)
{
if (Times[timeI].name() == "constant") continue;
if (times[timei].name() == "constant") continue;
scalar diff = fabs(Times[timeI].value() - target);
scalar diff = fabs(times[timei].value() - target);
if (diff < nearestDiff)
{
nearestDiff = diff;
nearestIndex = timeI;
nearestIndex = timei;
}
}
......@@ -97,16 +97,16 @@ Foam::List<bool> Foam::timeSelector::selected(const instantList& Times) const
}
Foam::instantList Foam::timeSelector::select(const instantList& Times)
Foam::instantList Foam::timeSelector::select(const instantList& times)
const
{
return subset(selected(Times), Times);
return subset(selected(times), times);
}
void Foam::timeSelector::inplaceSelect(instantList& Times) const
void Foam::timeSelector::inplaceSelect(instantList& times) const
{
inplaceSubset(selected(Times), Times);
inplaceSubset(selected(times), times);
}
......@@ -163,28 +163,29 @@ void Foam::timeSelector::addOptions
Foam::instantList Foam::timeSelector::select
(
const instantList& timeDirs,
const instantList& times,
const argList& args,
const word& constantName
)
{
if (timeDirs.size())
if (times.size())
{
List<bool> selectTimes(timeDirs.size(), true);
List<bool> selectTimes(times.size(), true);
// Determine locations of constant/ and 0/ directories
label constantIdx = -1;
label zeroIdx = -1;
label latestIdx = -1;
forAll(timeDirs, timeI)
// Determine locations of constant/ and 0/ directories
forAll(times, timei)
{
if (timeDirs[timeI].name() == constantName)
if (times[timei].name() == constantName)
{
constantIdx = timeI;
constantIdx = timei;
}
else if (timeDirs[timeI].value() == 0)
else if (times[timei].value() == 0)
{
zeroIdx = timeI;
zeroIdx = timei;
}
if (constantIdx >= 0 && zeroIdx >= 0)
......@@ -195,11 +196,10 @@ Foam::instantList Foam::timeSelector::select
// 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;
latestIdx = times.size() - 1;
// Avoid false match on constant/
if (latestIdx == constantIdx)
......@@ -214,7 +214,7 @@ Foam::instantList Foam::timeSelector::select
selectTimes = timeSelector
(
args.optionLookup("time")()
).selected(timeDirs);
).selected(times);
}
// Add in latestTime (if selected)
......@@ -244,12 +244,10 @@ Foam::instantList Foam::timeSelector::select
}
}
return subset(selectTimes, timeDirs);
}
else
{
return timeDirs;
return subset(selectTimes, times);
}
return times;
}
......@@ -259,7 +257,7 @@ Foam::instantList Foam::timeSelector::select0
const argList& args
)
{
instantList timeDirs
instantList times
(
timeSelector::select
(
......@@ -269,18 +267,18 @@ Foam::instantList Foam::timeSelector::select0
)
);
if (timeDirs.empty())
if (times.empty())
{
WarningInFunction
<< "No time specified or available, selecting 'constant'"
<< endl;
timeDirs.append(instant(0, runTime.constant()));
times.append(instant(0, runTime.constant()));
}
runTime.setTime(timeDirs[0], 0);
runTime.setTime(times[0], 0);
return timeDirs;
return times;
}
......@@ -301,11 +299,9 @@ Foam::instantList Foam::timeSelector::selectIfPresent
{
return select0(runTime, args);
}
else
{
// No timeSelector option specified. Do not change runTime.
return instantList(1, instant(runTime.value(), runTime.timeName()));
}
// No timeSelector option specified. Do not change runTime.
return instantList(1, instant(runTime.value(), runTime.timeName()));
}
......@@ -316,29 +312,27 @@ Foam::instantList Foam::timeSelector::select
const word& fName
)
{
instantList timeDirs(timeSelector::select0(runTime, args));
instantList times(timeSelector::select0(runTime, args));
if (timeDirs.size() && args.optionFound("newTimes"))
if (times.size() && args.optionFound("newTimes"))
{
List<bool> selectTimes(timeDirs.size(), true);
List<bool> selectTimes(times.size(), true);
forAll(timeDirs, timeI)
forAll(times, timei)
{
selectTimes[timeI] =
selectTimes[timei] =
!fileHandler().exists
(
runTime.path()
/timeDirs[timeI].name()
/fName
/ times[timei].name()
/ fName
);
}
return subset(selectTimes, timeDirs);
}
else
{
return timeDirs;
return subset(selectTimes, times);
}
return times;
}
......
......@@ -99,25 +99,28 @@ public:
timeSelector();
//- Construct from Istream
timeSelector(Istream&);
timeSelector(Istream& is);