ENH: fix foamListTimes to work with -fileHandler collated

This commit is contained in:
Mark Olesen
2017-11-26 15:23:02 +01:00
parent 2787a8664d
commit 966a941a64
6 changed files with 168 additions and 172 deletions

View File

@ -61,6 +61,7 @@ int main(int argc, char *argv[])
argList::noBanner(); argList::noBanner();
argList::noParallel(); argList::noParallel();
argList::noJobInfo(); argList::noJobInfo();
argList::noFunctionObjects();
argList::addBoolOption argList::addBoolOption
( (
"processor", "processor",
@ -75,18 +76,16 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
label nProcs = 0; // Get times list from the master processor and subset based on
// command-line options
// Create the processor databases label nProcs = 0;
PtrList<Time> databases(1); instantList timeDirs;
if (args.optionFound("processor")) if (args.optionFound("processor"))
{ {
// Determine the processor count directly // Determine the processor count
while (isDir(args.path()/(word("processor") + name(nProcs)))) nProcs = fileHandler().nProcs(args.path());
{
++nProcs;
}
if (!nProcs) if (!nProcs)
{ {
@ -95,78 +94,84 @@ int main(int argc, char *argv[])
<< exit(FatalError); << exit(FatalError);
} }
// Create the processor databases timeDirs = timeSelector::select
databases.setSize(nProcs);
forAll(databases, proci)
{
databases.set
( (
proci, Time
new Time
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName()/fileName(word("processor") + name(proci)) args.caseName()/"processor0"
) ).times(),
args
); );
} }
}
else else
{ {
databases.set timeDirs = timeSelector::select
( (
0, Time
new Time
( (
Time::controlDictName, Time::controlDictName,
args.rootPath(), args.rootPath(),
args.caseName() 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("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 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 else
{ {
forAll(timeDirs, timeI) forAll(timeDirs, timei)
{ {
Info<< timeDirs[timeI].name() << endl; Info<< timeDirs[timei].name() << nl;
} }
Info<< flush;
} }
return 0; return 0;
} }

View File

@ -30,23 +30,27 @@ License
const char* const Foam::instant::typeName = "instant"; const char* const Foam::instant::typeName = "instant";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::instant::instant() Foam::instant::instant()
{} {}
Foam::instant::instant(const scalar val, const word& tname) Foam::instant::instant(const scalar val, const word& tname)
: :
value_(val), value_(val),
name_(tname) name_(tname)
{} {}
Foam::instant::instant(const scalar val) Foam::instant::instant(const scalar val)
: :
value_(val), value_(val),
name_(Time::timeName(val)) name_(Time::timeName(val))
{} {}
Foam::instant::instant(const word& tname) Foam::instant::instant(const word& tname)
: :
value_(atof(tname.c_str())), value_(atof(tname.c_str())),
@ -56,51 +60,51 @@ Foam::instant::instant(const word& tname)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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) 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) 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) 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) bool Foam::operator>(const instant& a, const instant& b)
{ {
return a.value_ > b.value_; return a.value() > b.value();
} }
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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; 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; return os;
} }

View File

@ -43,21 +43,11 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
class instant; class instant;
// Friend Operators Istream& operator>>(Istream& is, instant& inst);
Ostream& operator<<(Ostream& os, const instant& inst);
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&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -69,6 +59,7 @@ class instant
// Private data // Private data
scalar value_; scalar value_;
word name_; word name_;
public: public:
@ -98,19 +89,17 @@ public:
instant(); instant();
//- Construct from components //- Construct from components
instant(const scalar, const word&); instant(const scalar val, const word& tname);
//- Construct from time value //- Construct from time value
explicit instant(const scalar); explicit instant(const scalar val);
//- Construct from word //- Construct from time name
explicit instant(const word&); explicit instant(const word& tname);
// Member Functions // Member Functions
// Access
//- Value (const access) //- Value (const access)
scalar value() const scalar value() const
{ {
@ -135,25 +124,25 @@ public:
return name_; return name_;
} }
//- Comparison used for instants to be equal //- Compare instant values to be equal (includes SMALL for rounding)
bool equal(const scalar) const; bool equal(const scalar val) const;
// Friend 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&);
// IOstream Operators // IOstream Operators
friend Istream& operator>>(Istream&, instant&); friend Istream& operator>>(Istream& is, instant& inst);
friend Ostream& operator<<(Ostream&, const instant&); friend Ostream& operator<<(Ostream& os, const instant& inst);
}; };
// Global Operators
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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -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/ // 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 // 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; int nearestIndex = -1;
scalar nearestDiff = Foam::GREAT; 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) if (diff < nearestDiff)
{ {
nearestDiff = diff; 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 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 Foam::instantList Foam::timeSelector::select
( (
const instantList& timeDirs, const instantList& times,
const argList& args, const argList& args,
const word& constantName 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 constantIdx = -1;
label zeroIdx = -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) if (constantIdx >= 0 && zeroIdx >= 0)
@ -195,11 +196,10 @@ Foam::instantList Foam::timeSelector::select
// Determine latestTime selection (if any) // Determine latestTime selection (if any)
// This must appear before the -time option processing // This must appear before the -time option processing
label latestIdx = -1;
if (args.optionFound("latestTime")) if (args.optionFound("latestTime"))
{ {
selectTimes = false; selectTimes = false;
latestIdx = timeDirs.size() - 1; latestIdx = times.size() - 1;
// Avoid false match on constant/ // Avoid false match on constant/
if (latestIdx == constantIdx) if (latestIdx == constantIdx)
@ -214,7 +214,7 @@ Foam::instantList Foam::timeSelector::select
selectTimes = timeSelector selectTimes = timeSelector
( (
args.optionLookup("time")() args.optionLookup("time")()
).selected(timeDirs); ).selected(times);
} }
// Add in latestTime (if selected) // Add in latestTime (if selected)
@ -244,12 +244,10 @@ Foam::instantList Foam::timeSelector::select
} }
} }
return subset(selectTimes, timeDirs); return subset(selectTimes, times);
}
else
{
return timeDirs;
} }
return times;
} }
@ -259,7 +257,7 @@ Foam::instantList Foam::timeSelector::select0
const argList& args const argList& args
) )
{ {
instantList timeDirs instantList times
( (
timeSelector::select timeSelector::select
( (
@ -269,18 +267,18 @@ Foam::instantList Foam::timeSelector::select0
) )
); );
if (timeDirs.empty()) if (times.empty())
{ {
WarningInFunction WarningInFunction
<< "No time specified or available, selecting 'constant'" << "No time specified or available, selecting 'constant'"
<< endl; << 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); return select0(runTime, args);
} }
else
{
// No timeSelector option specified. Do not change runTime. // No timeSelector option specified. Do not change runTime.
return instantList(1, instant(runTime.value(), runTime.timeName())); return instantList(1, instant(runTime.value(), runTime.timeName()));
}
} }
@ -316,29 +312,27 @@ Foam::instantList Foam::timeSelector::select
const word& fName 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 !fileHandler().exists
( (
runTime.path() runTime.path()
/timeDirs[timeI].name() / times[timei].name()
/fName / fName
); );
} }
return subset(selectTimes, timeDirs); return subset(selectTimes, times);
}
else
{
return timeDirs;
} }
return times;
} }

View File

@ -99,25 +99,28 @@ public:
timeSelector(); timeSelector();
//- Construct from Istream //- Construct from Istream
timeSelector(Istream&); timeSelector(Istream& is);
// Member Functions // Member Functions
//- Return true if the given instant is within the ranges //- Return true if the given instant is within the ranges
bool selected(const instant&) const; bool selected(const instant& value) const;
//- Return the set of selected instants in the given list that are //- Return the set of selected instants in the given list that are
// within the ranges //- within the ranges
List<bool> selected(const instantList&) const; List<bool> selected(const instantList& times) const;
//- Select a list of Time values that are within the ranges //- Select a list of Time values that are within the ranges
instantList select(const instantList&) const; instantList select(const instantList& times) const;
//- Select a list of Time values that are within the ranges //- Select a list of Time values that are within the ranges
void inplaceSelect(instantList&) const; void inplaceSelect(instantList& times) const;
//- Add the options handled by timeSelector to argList::validOptions
// Static Member Functions
//- Add timeSelector options to argList::validOptions
// //
// \param constant // \param constant
// Add the \b -constant option to include the \c constant/ directory // Add the \b -constant option to include the \c constant/ directory
@ -137,7 +140,7 @@ public:
//- Return the set of times selected based on the argList options //- Return the set of times selected based on the argList options
static instantList select static instantList select
( (
const instantList&, const instantList& times,
const argList& args, const argList& args,
const word& constantName = "constant" const word& constantName = "constant"
); );

View File

@ -1,4 +1,5 @@
#!/bin/sh #!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Test if gnuplot exists on the system # Test if gnuplot exists on the system
command -v gnuplot >/dev/null 2>&1 || { command -v gnuplot >/dev/null 2>&1 || {
@ -6,7 +7,7 @@ command -v gnuplot >/dev/null 2>&1 || {
exit 1 exit 1
} }
gnuplot<<EOF gnuplot<<GNUPLOT
set term post enhanced color solid linewidth 2.0 20 set term post enhanced color solid linewidth 2.0 20
set out "graphs.eps" set out "graphs.eps"
set encoding utf8 set encoding utf8
@ -15,7 +16,7 @@ gnuplot<<EOF
set style line 1 lt 1 linecolor rgb "blue" linewidth 1.5 set style line 1 lt 1 linecolor rgb "blue" linewidth 1.5
set style line 11 lt 2 linecolor rgb "black" linewidth 1.5 set style line 11 lt 2 linecolor rgb "black" linewidth 1.5
time = system("foamListTimes -case .. | tail -1") time = system("foamListTimes -case .. -latestTime")
set xlabel "x" set xlabel "x"
set ylabel "u'" set ylabel "u'"
@ -32,6 +33,6 @@ gnuplot<<EOF
"../postProcessing/wallShearStressGraph/".time."/line_wallShearStress.xy" \ "../postProcessing/wallShearStressGraph/".time."/line_wallShearStress.xy" \
u ((\$1-0.04)*5.4/1.5e-05):(-\$2/0.5/5.4**2) title "kOmegaSSTLM" w l, \ u ((\$1-0.04)*5.4/1.5e-05):(-\$2/0.5/5.4**2) title "kOmegaSSTLM" w l, \
"exptData/T3A.dat" u (\$1/1000*5.4/1.51e-05):2 title "Exp" w p ls 11 "exptData/T3A.dat" u (\$1/1000*5.4/1.51e-05):2 title "Exp" w p ls 11
EOF GNUPLOT
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------