43 bool 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_);
93 bool 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);
118 bool 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))
171 bool 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();
391 entries_.append(vtmEntry::block(blockName));
392 blocks_.append(blockName);
394 return blocks_.size();
400 if (!blocks_.empty())
403 if (!blockName.empty() && blockName != blocks_.back())
406 <<
"expecting to end block '" << blockName
407 <<
"' but found '" << blocks_.back() <<
"' instead" 412 entries_.push_back(vtmEntry::endblock());
415 return blocks_.size();
456 entries_.append(vtmEntry::entry(
name, file));
475 entries_.append(vtmEntry::entry(
name, file));
495 const word& blockName,
508 for (
const vtmEntry&
e : other.entries_)
532 case vtmEntry::BEGIN_BLOCK:
538 case vtmEntry::END_BLOCK:
555 entries_.append(vtmEntry::endblock());
558 entries_.append(vtmEntry::endblock());
560 if (!hasTime_ && other.hasTime_)
563 timeValue_ = other.timeValue_;
570 const word& blockName,
590 os_.open(file +
"." + ext());
617 for (
const vtmEntry&
e : entries_)
630 case vtmEntry::BEGIN_BLOCK:
635 case vtmEntry::END_BLOCK:
669 .writeTimeValue(timeValue_)
Provides a means of accumulating file entries for generating a vtkMultiBlockDataSet (...
const Type & value() const noexcept
Return const reference to value.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
word stem() const
Return basename, without extension.
label write(const fileName &file)
Open file for writing (creates parent directory) and write the blocks and TimeValue.
constexpr char nl
The newline '\n' character (0x0a)
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
static const fileName null
An empty fileName.
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content...
Ostream & endl(Ostream &os)
Add newline and flush stream.
No type, or default initialized type.
vtmWriter()
Default construct, with autoName on.
static std::string path(const std::string &str)
Return directory path name (part before last /)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
label size() const
The number of data sets.
XML inline ASCII, asciiFormatter.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
bool append(const fileName &file)
Add a file. The name is either empty or created with autoName.
const dimensionedScalar e
Elementary charge.
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.
bool isType(const U &obj)
Check if typeid of the object and Type are identical.
void setTime(scalar timeValue)
Define "TimeValue" for FieldData (name as per Catalyst output)
static const word null
An empty word.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
void repair(bool collapse=false)
Sanity fixes on the data.
label beginBlock(const word &blockName=word::null)
Start a new block, optionally with a name.
OBJstream os(runTime.globalPath()/outputName)
void dump(Ostream &os) const
Print debug view of block and dataset contents.
bool empty() const
If there are no data sets.
word format(conversionProperties.get< word >("format"))
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
#define WarningInFunction
Report a warning using Foam::Warning.
fileTag
Some common XML tags for vtk files.
label endBlock(const word &blockName=word::null)
End the previous block, optionally with name checking.
bool has_ext() const
Various checks for extensions.
Ostream & beginBlock(Ostream &os)
Write begin block group without a name.
void add(const word &blockName, const vtmWriter &other)
Add in content from another vtm and place under the given block name.
static constexpr const zero Zero
Global zero (0)
void clear()
Clear all entries and reset output.