mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: fix foamListTimes to work with -fileHandler collated
This commit is contained in:
@ -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
|
||||
(
|
||||
proci,
|
||||
new Time
|
||||
Time
|
||||
(
|
||||
Time::controlDictName,
|
||||
args.rootPath(),
|
||||
args.caseName()/fileName(word("processor") + name(proci))
|
||||
)
|
||||
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,19 +89,17 @@ 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
|
||||
{
|
||||
@ -135,25 +124,25 @@ public:
|
||||
return name_;
|
||||
}
|
||||
|
||||
//- Comparison used for instants to be equal
|
||||
bool equal(const scalar) 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&);
|
||||
//- Compare instant values to be equal (includes SMALL for rounding)
|
||||
bool equal(const scalar val) const;
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
friend Istream& operator>>(Istream&, instant&);
|
||||
friend Ostream& operator<<(Ostream&, const instant&);
|
||||
friend Istream& operator>>(Istream& is, instant& inst);
|
||||
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
|
||||
|
||||
@ -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,12 +299,10 @@ 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::instantList Foam::timeSelector::select
|
||||
@ -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()
|
||||
/ 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);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- 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
|
||||
// within the ranges
|
||||
List<bool> selected(const instantList&) const;
|
||||
//- within the ranges
|
||||
List<bool> selected(const instantList& times) const;
|
||||
|
||||
//- 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
|
||||
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
|
||||
// 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
|
||||
static instantList select
|
||||
(
|
||||
const instantList&,
|
||||
const instantList& times,
|
||||
const argList& args,
|
||||
const word& constantName = "constant"
|
||||
);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#!/bin/sh
|
||||
cd ${0%/*} || exit 1 # Run from this directory
|
||||
|
||||
# Test if gnuplot exists on the system
|
||||
command -v gnuplot >/dev/null 2>&1 || {
|
||||
@ -6,7 +7,7 @@ command -v gnuplot >/dev/null 2>&1 || {
|
||||
exit 1
|
||||
}
|
||||
|
||||
gnuplot<<EOF
|
||||
gnuplot<<GNUPLOT
|
||||
set term post enhanced color solid linewidth 2.0 20
|
||||
set out "graphs.eps"
|
||||
set encoding utf8
|
||||
@ -15,7 +16,7 @@ gnuplot<<EOF
|
||||
set style line 1 lt 1 linecolor rgb "blue" 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 ylabel "u'"
|
||||
@ -32,6 +33,6 @@ gnuplot<<EOF
|
||||
"../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, \
|
||||
"exptData/T3A.dat" u (\$1/1000*5.4/1.51e-05):2 title "Exp" w p ls 11
|
||||
EOF
|
||||
GNUPLOT
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user