ENH: allow "none" as time range specification (issue #1128)

- this corresponds to 'never match', which may be useful in combination
  with -constant selection.

  Eg,

      surfaceMeshTriangulate -constant -time none

  selects only the constant entry and suppresses any automatic time loop

STYLE: adjust help for the standard -times option

- indicate that times can be comma or space separated, since this is
  otherwise not apparent. Don't mention semicolon separators in the help
  since that just adds even more clutter.
This commit is contained in:
Mark Olesen
2018-12-17 01:25:07 +01:00
parent c594d0ae91
commit c4ec41218b
9 changed files with 98 additions and 33 deletions

View File

@ -142,7 +142,7 @@ void Foam::timeSelector::addOptions
( (
"time", "time",
"ranges", "ranges",
"Comma-separated time ranges - eg, ':10,20,40:70,1000:'" "List of ranges. Eg, ':10,20 40:70 1000:', 'none', etc"
); );
} }

View File

@ -32,6 +32,9 @@ Description
Note Note
This class is still subject to larger changes (2018-11) as it matures. This class is still subject to larger changes (2018-11) as it matures.
SeeAlso
Foam::scalarRange, Foam::scalarRanges
SourceFiles SourceFiles
scalarPredicates.C scalarPredicates.C
scalarPredicatesI.H scalarPredicatesI.H
@ -233,7 +236,10 @@ public:
using List<unary>::List; using List<unary>::List;
//- Construct from an initializer list of (opName opValue) tuples //- Construct from an initializer list of (opName opValue) tuples
explicit scalars(std::initializer_list<std::pair<word, scalar>> entries); explicit scalars
(
std::initializer_list<std::pair<word, scalar>> entries
);
//- Copy construct from a list of (opName opValue) tuples //- Copy construct from a list of (opName opValue) tuples
explicit scalars(const UList<Tuple2<word, scalar>>& entries); explicit scalars(const UList<Tuple2<word, scalar>>& entries);

View File

@ -37,6 +37,14 @@ bool Foam::scalarRange::parse(const std::string& str, scalarRange& range)
if (colon == std::string::npos) if (colon == std::string::npos)
{ {
// No colon
if (str == "none")
{
// "none" is an empty (inverse) range
return true;
}
// "VALUE" // "VALUE"
scalar val; scalar val;
if (readScalar(str, val)) if (readScalar(str, val))
@ -119,11 +127,11 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const scalarRange& range)
break; break;
case scalarRange::GE_LE: case scalarRange::GE_LE:
os << range.min_ << ":" << range.max_; os << range.min_ << ':' << range.max_;
break; break;
default: default:
os << "false"; os << "none";
break; break;
} }

View File

@ -30,6 +30,12 @@ Description
The bound can be specified as an "MIN:MAX" range, as a "MIN:" or ":MAX" The bound can be specified as an "MIN:MAX" range, as a "MIN:" or ":MAX"
bound or simply as a single "VALUE". bound or simply as a single "VALUE".
When defined via the parse() method, the special string "none" can be
used to define an empty (inverse) range.
SeeAlso
Foam::predicates::scalars
SourceFiles SourceFiles
scalarRange.C scalarRange.C
@ -103,6 +109,10 @@ public:
//- Construct by parsing string content. //- Construct by parsing string content.
// A colon (:) is used as a range marker or when specifying // A colon (:) is used as a range marker or when specifying
// greater-than or less-than bounds. // greater-than or less-than bounds.
//
// \note The special string "none" can be used define an empty
// (inverse) range
//
// \return True if no parse problems were encountered. // \return True if no parse problems were encountered.
static bool parse(const std::string& str, scalarRange& range); static bool parse(const std::string& str, scalarRange& range);
@ -150,10 +160,13 @@ public:
// For GE, LE bounds it is the min/max value, respectively. // For GE, LE bounds it is the min/max value, respectively.
inline scalar value() const; inline scalar value() const;
//- True if the value matches the condition.
inline bool match(const scalar& value) const;
// Member Operators // Member Operators
//- Unary predicate to test if the value is within the bounds //- Identical to match(), for use as a predicate.
inline bool operator()(const scalar& value) const; inline bool operator()(const scalar& value) const;
inline bool operator==(const scalarRange& rhs) const; inline bool operator==(const scalarRange& rhs) const;

View File

@ -152,23 +152,29 @@ inline Foam::scalar Foam::scalarRange::value() const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // inline bool Foam::scalarRange::match(const scalar& value) const
inline bool Foam::scalarRange::operator()(const scalar& value) const
{ {
switch (type_) switch (type_)
{ {
case EQ: return equal(value, min_); case EQ: return equal(value, min_);
case GE: return value >= min_; case GE: return (value >= min_);
case GT: return value > min_; case GT: return (value > min_);
case LE: return value <= max_; case LE: return (value <= max_);
case LT: return value < max_; case LT: return (value < max_);
case GE_LE: return value >= min_ && value <= max_; case GE_LE: return (value >= min_ && value <= max_);
default: return false; default: return false;
} }
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::scalarRange::operator()(const scalar& value) const
{
return match(value);
}
inline bool Foam::scalarRange::operator==(const scalarRange& rhs) const inline bool Foam::scalarRange::operator==(const scalarRange& rhs) const
{ {
return (type_ == rhs.type_ && min_ == rhs.min_ && max_ == rhs.max_); return (type_ == rhs.type_ && min_ == rhs.min_ && max_ == rhs.max_);

View File

@ -26,33 +26,39 @@ License
#include "scalarRanges.H" #include "scalarRanges.H"
#include "stringOps.H" #include "stringOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::scalarRanges::scalarRanges(const std::string& str) Foam::scalarRanges Foam::scalarRanges::parse
: (
List<scalarRange>() const std::string& str,
bool verbose
)
{ {
const SubStrings<std::string> items = stringOps::splitAny(str, " ,;"); const SubStrings<std::string> items = stringOps::splitAny(str, " ,;");
setSize(items.size()); scalarRanges ranges(items.size());
label nItems = 0; label n = 0;
for (const auto& item : items) for (const auto& item : items)
{ {
const std::string s = item.str(); const std::string s = item.str();
if (scalarRange::parse(s, operator[](nItems))) scalarRange& range = ranges[n];
if (scalarRange::parse(s, range))
{ {
++nItems; ++n;
} }
else else if (verbose)
{ {
Info<< "Bad scalar-range while parsing: " << s << endl; Info<< "Bad scalar-range while parsing: " << s << endl;
} }
} }
setSize(nItems); ranges.resize(n);
return ranges;
} }

View File

@ -27,6 +27,9 @@ Class
Description Description
A collection of scalar bounds to be used as a unary predicate. A collection of scalar bounds to be used as a unary predicate.
SeeAlso
Foam::predicates::scalars
SourceFiles SourceFiles
scalarRanges.C scalarRanges.C
@ -55,17 +58,32 @@ public:
// Constructors // Constructors
//- Construct null //- Inherit constructors from List of scalarRange
inline scalarRanges(); using List<scalarRange>::List;
//- Construct by parsing a string for scalar ranges //- Construct by parsing string for scalar ranges
// The individual items are space, comma or semicolon delimited. // The individual items are space, comma or semicolon delimited.
scalarRanges(const std::string& str); // Optionally report when any range failed to parse
inline scalarRanges(const std::string& str, bool verbose = true);
// Static Constructors
//- Construct by parsing string for scalar ranges
// The individual items are space, comma or semicolon delimited.
static scalarRanges parse(const std::string& str, bool verbose = true);
// Member Functions
//- Match any condition in the list.
// \return True if the value matches any condition in the list.
inline bool match(const scalar& value) const;
// Member Operators // Member Operators
//- Unary predicate to test if the value is within any of the ranges //- Identical to match(), for use as a predicate.
inline bool operator()(const scalar& value) const; inline bool operator()(const scalar& value) const;
}; };

View File

@ -25,15 +25,15 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::scalarRanges::scalarRanges() inline Foam::scalarRanges::scalarRanges(const std::string& str, bool verbose)
: :
List<scalarRange>() List<scalarRange>(scalarRanges::parse(str, verbose))
{} {}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool Foam::scalarRanges::operator()(const scalar& value) const inline bool Foam::scalarRanges::match(const scalar& value) const
{ {
for (const scalarRange& range : *this) for (const scalarRange& range : *this)
{ {
@ -47,4 +47,12 @@ inline bool Foam::scalarRanges::operator()(const scalar& value) const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline bool Foam::scalarRanges::operator()(const scalar& value) const
{
return match(value);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -20,7 +20,7 @@ runApplication topoSet
runApplication createPatch -overwrite runApplication createPatch -overwrite
runApplication surfaceMeshTriangulate \ runApplication surfaceMeshTriangulate \
-patches hole ppGeometry.vtp -constant -time '' -patches hole ppGeometry.vtp -constant -time none
echo "End" echo "End"