35void Foam::vtk::vtmWriter::vtmEntry::clear()
43bool Foam::vtk::vtmWriter::vtmEntry::good() const noexcept
47 type_ == vtmEntry::BEGIN_BLOCK
48 || type_ == vtmEntry::END_BLOCK
49 || (type_ == vtmEntry::DATA && file_.size())
56 if (type_ == vtmEntry::BEGIN_BLOCK)
58 format.openTag(vtk::fileTag::BLOCK);
61 format.xmlAttr(
"name", name_);
67 else if (type_ == vtmEntry::END_BLOCK)
72 else if (type_ == vtmEntry::DATA && file_.size())
74 format.openTag(vtk::fileTag::DATA_SET);
78 format.xmlAttr(
"name", name_);
81 format.xmlAttr(
"file", file_);
93bool Foam::vtk::vtmWriter::pruneEmpty()
95 const label nEntries = entries_.
size();
99 for (label src=0; src < nEntries; ++src)
101 if (entries_[src].good())
105 entries_[dst] = std::move(entries_[src]);
111 const bool changed = (dst != nEntries);
118bool Foam::vtk::vtmWriter::pruneEmptyBlocks()
122 const label nEntries = entries_.size();
126 bool changed =
false;
128 for (label i=0; i < nEntries; ++i)
130 vtmEntry&
e = entries_[i];
132 if (
e.isType(vtmEntry::BEGIN_BLOCK))
134 for (label j=i+1; j < nEntries; ++j)
136 if (entries_[j].
isType(vtmEntry::END_BLOCK))
144 else if (!entries_[j].
isType(vtmEntry::NONE))
171bool Foam::vtk::vtmWriter::collapseBlocks()
173 bool collapsed =
false;
175 const label nEntries = entries_.size();
177 for (label i=0; i < nEntries-2; ++i)
179 vtmEntry&
b = entries_[i];
180 vtmEntry& d = entries_[i+1];
181 vtmEntry&
e = entries_[i+2];
185 b.isType(vtmEntry::BEGIN_BLOCK)
186 &&
e.isType(vtmEntry::END_BLOCK)
187 && d.isType(vtmEntry::DATA)
188 && (d.name_.empty() || d.name_ ==
b.name_)
191 d.name_ = std::move(
b.name_);
213 for (vtmEntry&
e : entries_)
215 if (
e.isType(vtmEntry::BEGIN_BLOCK))
219 else if (
e.isType(vtmEntry::END_BLOCK))
226 entries_.resize(nEntries);
230 else if (
e.isType(vtmEntry::DATA))
245 entries_.append(vtmEntry::endblock());
266 for (
const vtmEntry&
e : entries_)
279 os <<
"{ \"name\" : " <<
e.name_
280 <<
", \"file\" : " <<
e.file_ <<
" }" <<
nl;
283 case vtmEntry::BEGIN_BLOCK:
286 os.beginBlock(
e.name_);
289 case vtmEntry::END_BLOCK:
299 for (label i=0; i < depth; ++i)
306 os <<
"# Had " << depth <<
" unclosed blocks" <<
nl;
310 os <<
"# Had " << (-depth) <<
" too many end blocks" <<
nl;
347 for (
const auto&
e : entries_)
349 if (
e.isType(vtmEntry::DATA) &&
e.name_.size())
363 for (
const auto&
e : entries_)
365 if (
e.isType(vtmEntry::DATA) &&
e.file_.size())
377 timeValue_ = timeValue;
384 timeValue_ = t.
value();
392 blocks_.append(blockName);
394 return blocks_.size();
400 if (!blocks_.empty())
402 const word curr(blocks_.remove());
405 if (!blockName.empty() && blockName != curr)
408 <<
"expecting to end block '" << blockName
409 <<
"' but found '" << curr <<
"' instead"
413 entries_.append(vtmEntry::endblock());
416 return blocks_.size();
496 const word& blockName,
509 for (
const vtmEntry&
e : other.entries_)
533 case vtmEntry::BEGIN_BLOCK:
539 case vtmEntry::END_BLOCK:
556 entries_.append(vtmEntry::endblock());
559 entries_.append(vtmEntry::endblock());
561 if (!hasTime_ && other.hasTime_)
564 timeValue_ = other.timeValue_;
571 const word& blockName,
591 os_.open(file +
"." + ext());
618 for (
const vtmEntry&
e : entries_)
631 case vtmEntry::BEGIN_BLOCK:
636 case vtmEntry::END_BLOCK:
670 .writeTimeValue(timeValue_)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void resize(const label len)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & beginBlock()
Write begin block group without a name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
void size(const label n)
Older name for setAddressableSize.
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
const Type & value() const
Return const reference to value.
A keyword and a list of tokens is an 'entry'.
A class for handling file names.
static std::string path(const std::string &str)
Return directory path name (part before last /)
bool hasExt() const
Various checks for extensions.
word nameLessExt() const
Return basename, without extension.
virtual bool write()
Write the output fields.
Sums a given list of (at least two or more) fields and outputs the result into a new field,...
bool append() const noexcept
True if output format uses an append mode.
Provides a means of accumulating file entries for generating a vtkMultiBlockDataSet (....
vtmWriter()
Default construct, with autoName on.
void repair(bool collapse=false)
Sanity fixes on the data.
void dump(Ostream &os) const
Print debug view of block and dataset contents.
label size() const
The number of data sets.
bool empty() const
If there are no data sets.
void setTime(scalar timeValue)
Define "TimeValue" for FieldData (name as per Catalyst output)
void clear()
Clear all entries and reset output.
A class for handling words, derived from Foam::string.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
@ NONE
No type, or default initialized type.
fileTag
Some common XML tags for vtk files.
@ MULTI_BLOCK
"vtkMultiBlockDataSet"
@ INLINE_ASCII
XML inline ASCII, asciiFormatter.
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Ostream & beginBlock(Ostream &os)
Write begin block group without a name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool isType(const Type &t)
Check is typeid is identical to the TargetType.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
static constexpr const zero Zero
Global zero (0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
constexpr char nl
The newline '\n' character (0x0a)
word format(conversionProperties.get< word >("format"))