mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -142,7 +142,7 @@ void Foam::timeSelector::addOptions
|
||||
(
|
||||
"time",
|
||||
"ranges",
|
||||
"Comma-separated time ranges - eg, ':10,20,40:70,1000:'"
|
||||
"List of ranges. Eg, ':10,20 40:70 1000:', 'none', etc"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,9 @@ Description
|
||||
Note
|
||||
This class is still subject to larger changes (2018-11) as it matures.
|
||||
|
||||
SeeAlso
|
||||
Foam::scalarRange, Foam::scalarRanges
|
||||
|
||||
SourceFiles
|
||||
scalarPredicates.C
|
||||
scalarPredicatesI.H
|
||||
@ -233,7 +236,10 @@ public:
|
||||
using List<unary>::List;
|
||||
|
||||
//- 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
|
||||
explicit scalars(const UList<Tuple2<word, scalar>>& entries);
|
||||
|
||||
@ -37,6 +37,14 @@ bool Foam::scalarRange::parse(const std::string& str, scalarRange& range)
|
||||
|
||||
if (colon == std::string::npos)
|
||||
{
|
||||
// No colon
|
||||
|
||||
if (str == "none")
|
||||
{
|
||||
// "none" is an empty (inverse) range
|
||||
return true;
|
||||
}
|
||||
|
||||
// "VALUE"
|
||||
scalar val;
|
||||
if (readScalar(str, val))
|
||||
@ -119,11 +127,11 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const scalarRange& range)
|
||||
break;
|
||||
|
||||
case scalarRange::GE_LE:
|
||||
os << range.min_ << ":" << range.max_;
|
||||
os << range.min_ << ':' << range.max_;
|
||||
break;
|
||||
|
||||
default:
|
||||
os << "false";
|
||||
os << "none";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,12 @@ Description
|
||||
The bound can be specified as an "MIN:MAX" range, as a "MIN:" or ":MAX"
|
||||
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
|
||||
scalarRange.C
|
||||
|
||||
@ -103,6 +109,10 @@ public:
|
||||
//- Construct by parsing string content.
|
||||
// A colon (:) is used as a range marker or when specifying
|
||||
// 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.
|
||||
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.
|
||||
inline scalar value() const;
|
||||
|
||||
//- True if the value matches the condition.
|
||||
inline bool match(const scalar& value) const;
|
||||
|
||||
|
||||
// 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 scalarRange& rhs) const;
|
||||
|
||||
@ -152,23 +152,29 @@ inline Foam::scalar Foam::scalarRange::value() const
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::scalarRange::operator()(const scalar& value) const
|
||||
inline bool Foam::scalarRange::match(const scalar& value) const
|
||||
{
|
||||
switch (type_)
|
||||
{
|
||||
case EQ: return equal(value, min_);
|
||||
case GE: return value >= min_;
|
||||
case GT: return value > min_;
|
||||
case LE: return value <= max_;
|
||||
case LT: return value < max_;
|
||||
case GE_LE: return value >= min_ && value <= max_;
|
||||
case GE: return (value >= min_);
|
||||
case GT: return (value > min_);
|
||||
case LE: return (value <= max_);
|
||||
case LT: return (value < max_);
|
||||
case GE_LE: return (value >= min_ && value <= max_);
|
||||
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
|
||||
{
|
||||
return (type_ == rhs.type_ && min_ == rhs.min_ && max_ == rhs.max_);
|
||||
|
||||
@ -26,33 +26,39 @@ License
|
||||
#include "scalarRanges.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
Foam::scalarRanges::scalarRanges(const std::string& str)
|
||||
:
|
||||
List<scalarRange>()
|
||||
Foam::scalarRanges Foam::scalarRanges::parse
|
||||
(
|
||||
const std::string& str,
|
||||
bool verbose
|
||||
)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
setSize(nItems);
|
||||
ranges.resize(n);
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -27,6 +27,9 @@ Class
|
||||
Description
|
||||
A collection of scalar bounds to be used as a unary predicate.
|
||||
|
||||
SeeAlso
|
||||
Foam::predicates::scalars
|
||||
|
||||
SourceFiles
|
||||
scalarRanges.C
|
||||
|
||||
@ -55,17 +58,32 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline scalarRanges();
|
||||
//- Inherit constructors from List of scalarRange
|
||||
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.
|
||||
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
|
||||
|
||||
//- 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;
|
||||
|
||||
};
|
||||
|
||||
@ -25,15 +25,15 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * 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)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -20,7 +20,7 @@ runApplication topoSet
|
||||
runApplication createPatch -overwrite
|
||||
|
||||
runApplication surfaceMeshTriangulate \
|
||||
-patches hole ppGeometry.vtp -constant -time ''
|
||||
-patches hole ppGeometry.vtp -constant -time none
|
||||
|
||||
echo "End"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user