81 static inline bool lessThan(
const scalar& val,
const scalar&
upper)
101 std::string::npos == dash
102 || std::string::npos !=
outputName.find(
'/', dash)
111 if (std::string::npos ==
dot)
126 const auto dash = file.rfind(sep);
131 std::string::npos == dash
132 || std::string::npos != file.find(
'/', dash)
139 const auto dot = file.find(
'.', dash);
141 if (std::string::npos ==
dot)
143 return file.substr(dash);
146 return file.substr(dash, (
dot-dash));
166 const word ext =
"." + base.
ext();
169 os <<
"{\n \"file-series-version\" : \"1.0\",\n \"files\" : [\n";
173 label nremain = series.
size();
178 for (
const instant& inst : series)
180 os <<
" { \"name\" : \"" 181 << stem << sep << inst.name() << ext
182 <<
"\", \"time\" : " << inst.value() <<
" }";
204 os <<
"{\n \"file-series-version\" : \"1.0\",\n \"files\" : [\n";
208 label nremain = series.
size();
215 os <<
" { \"name\" : \"" 216 << inst.name().name()
217 <<
"\", \"time\" : " << inst.value() <<
" }";
248 print(*osPtr, seriesName, series, sep);
268 print(*osPtr, series);
276 if (inst.
name().empty())
281 const auto iter = existing_.find(inst.
name());
287 if (dst.name() == inst.
name())
290 dst.value() = inst.
value();
296 entries_.append(inst);
297 existing_.insert(inst.
name());
303 bool Foam::vtk::seriesWriter::removeDuplicates()
305 const label nElem = entries_.size();
307 HashTable<label, fileName> filesSeen(2*nElem);
309 bool changed =
false;
311 for (label elemi=0; elemi < nElem; ++elemi)
315 if (inst.name().empty())
321 auto iter = filesSeen.find(inst.name());
326 entries_[*iter].
name().clear();
333 filesSeen.insert(inst.name(), elemi);
342 for (label elemi=0; elemi < nElem; ++elemi)
346 if (!src.name().empty())
350 entries_[dsti] = std::move(src);
356 entries_.resize(dsti);
359 return (nElem != entries_.size());
368 const bool checkFiles,
369 const scalar restartTime
375 if (!seriesFile.
has_ext(
"series"))
377 seriesFile.
ext(
"series");
385 HashSet<fileName> filesOnDisk;
414 unsigned instStatus = 0;
419 IFstream is(seriesFile);
423 parse state = parse::NONE;
424 (state != parse::DONE && state != parse::FAIL)
434 if (tok.isString() && tok.stringToken() ==
"files")
444 state = parse::FILES_ARRAY;
455 case parse::FILES_ARRAY :
457 if (tok.isPunctuation())
459 switch (tok.pToken())
467 state = parse::ENTRY;
491 if (tok.isPunctuation())
493 switch (tok.pToken())
507 &&
lessThan(inst.value(), restartTime)
511 ? filesOnDisk.found(inst.name())
519 state = parse::FILES_ARRAY;
529 else if (tok.isString())
533 const string key(tok.stringToken());
541 inst.name() = tok.stringToken();
549 else if (
"time" ==
key)
553 inst.value() = tok.number();
586 const scalar restartTime
598 fileName seriesFile(seriesName);
600 if (seriesName.
has_ext(
"series"))
605 const word stem = seriesFile.
stem();
606 const word ext = seriesFile.
ext();
609 const auto minLen = stem.
length() + ext.length() + 1;
611 const auto acceptName =
612 [=](
const fileName& file) ->
bool 632 bool warnings =
false;
634 for (
const fileName& file : files)
636 std::ifstream is(
path/file);
647 is.read(&(header.front()), header.size());
648 const std::streamsize gcount = is.gcount();
649 header.erase(gcount <= 0 ? 0 : gcount);
657 auto begAttr = header.find(
"time=");
659 if (string::npos == begAttr)
663 Info<<
"No 'time=' comment attribute found:\n(" <<
nl;
672 const char quote = header[begAttr];
678 (quote ==
'"' || quote ==
'\'')
681 header.find(quote, ++begAttr)
684 header.find_first_of(
"\t\n\v\f\r ", begAttr)
690 string::npos != endAttr && begAttr < endAttr
693 header.substr(begAttr, endAttr-begAttr),
723 const label nElem = entries_.size();
725 for (label elemi=0; elemi < nElem; ++elemi)
733 entries_[dsti] = std::move(src);
734 existing_.insert(entries_[dsti].
name());
740 entries_.resize(dsti);
742 return (nElem != entries_.size());
Begin block [isseparator].
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
const Type & value() const noexcept
Return const reference to value.
static word suffix(const fileName &file, char sep='_')
Extract the time-varying ending of files.
void size(const label n)
Older name for setAddressableSize.
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection)
A class for handling file names.
bool bad() const noexcept
True if stream is corrupted.
static fileName base(const fileName &outputName, char sep='_')
Extract the base name for a file series.
Specialized string sorting.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Begin dimensions [isseparator].
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
constexpr char nl
The newline '\n' character (0x0a)
A token holds an item read from Istream.
Three-way comparison operation of two parameters,.
static bool getValueToken(ISstream &is, token &tok)
No type, or default initialized type.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
string upper(const std::string &s)
Return string copy transformed with std::toupper on each character.
static bool lessThan(const scalar &val, const scalar &upper)
static std::string path(const std::string &str)
Return directory path name (part before last /)
word ext() const
Return file name extension (part after last .)
static std::string stem(const std::string &str)
Return the basename, without extension.
End dimensions [isseparator].
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Various functions to operate on Lists.
scalar value() const noexcept
The value (const access)
bool isDir(const fileName &name, const bool followLink=true)
Does the name exist as a DIRECTORY in the file system?
static bool getToken(ISstream &is, token &tok)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
word outputName("finiteArea-edges.obj")
const T & name() const noexcept
The name/key (const access)
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
List< T > subsetList(const UList< T > &input, const UnaryPredicate &pred, const bool invert=false)
Copy a subset of the input list when predicate is true.
void sort(UList< T > &list)
Sort the list.
bool operator()(const fileNameInstant a, const fileNameInstant b) const
static int compare(const std::string &s1, const std::string &s2)
Natural compare for std::string.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
bool removeNewer(const scalar timeValue)
Remove entries that are greater_equal the time value.
bool remove_ext()
Remove extension, returning true if string changed.
virtual Istream & read(token &t) override
Return next token from stream.
label scan(const fileName &seriesName, const scalar restartTime=ROOTVGREAT)
Clear contents and scan directory for files.
const word & name() const noexcept
Return const reference to name.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name...
bool starts_with(char c) const
True if string starts with given character (cf. C++20)
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
static Ostream & print(Ostream &os, const fileName &seriesName, const UList< instant > &series, const char sep='_')
Print file series (JSON format) for specified time instances.
Generic input stream using a standard (STL) stream.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
static void write(const fileName &base, const UList< instant > &series, const char sep='_')
Write file series (JSON format) to disk, for specified instances.
A tuple of scalar value and key. The value often corresponds to a time value, thus the naming of the ...
messageStream Info
Information stream (stdout output on master, null elsewhere)
void sort()
Sort by time value and by file name.
Instant< fileName > fileNameInstant
A tuple of value and fileName.
bool has_ext() const
Various checks for extensions.
label load(const fileName &seriesName, const bool checkFiles=false, const scalar restartTime=ROOTVGREAT)
Clear contents and reload by parsing the specified file.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
List< fileName > fileNameList
List of fileName.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.