Go to the documentation of this file.
43 bool Foam::vtk::vtmWriter::vtmEntry::good()
const
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 label nblock = blocks_.size();
404 const word curr(blocks_.remove());
407 if (!blockName.empty() && blockName != curr)
410 <<
"expecting to end block '" << blockName
411 <<
"' but found '" << curr <<
"' instead"
415 entries_.append(vtmEntry::endblock());
418 return blocks_.size();
459 entries_.append(vtmEntry::entry(
name, file));
478 entries_.append(vtmEntry::entry(
name, file));
498 const word& blockName,
511 for (
const vtmEntry&
e : other.entries_)
535 case vtmEntry::BEGIN_BLOCK:
541 case vtmEntry::END_BLOCK:
558 entries_.append(vtmEntry::endblock());
561 entries_.append(vtmEntry::endblock());
563 if (!hasTime_ && other.hasTime_)
566 timeValue_ = other.timeValue_;
573 const word& blockName,
593 os_.open(file +
"." + ext());
620 for (
const vtmEntry&
e : entries_)
633 case vtmEntry::BEGIN_BLOCK:
638 case vtmEntry::END_BLOCK:
672 .writeTimeValue(timeValue_)
void resize(const label len)
void setTime(scalar timeValue)
Define "TimeValue" for FieldData (name as per Catalyst output)
void add(const word &blockName, const vtmWriter &other)
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
label beginBlock(const word &blockName=word::null)
Start a new block, optionally with a name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
No type, or default initialized type.
A class for handling words, derived from Foam::string.
A class for handling file names.
static std::string path(const std::string &str)
Return directory path name (part before last /)
static constexpr const zero Zero
Global zero (0)
const Foam::Enum< fileTag > fileExtension
File extension (without ".") for some vtk XML file content types.
XML inline ASCII, asciiFormatter.
label endBlock(const word &blockName=word::null)
End the previous block, optionally with name checking.
word nameLessExt() const
Return basename, without extension.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Type & value() const
Return const reference to value.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
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.
word format(conversionProperties.get< word >("format"))
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
bool hasExt() const
Various checks for extensions.
label write(const fileName &file)
void clear()
Clear all entries and reset output.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
OBJstream os(runTime.globalPath()/outputName)
Ostream & beginBlock(Ostream &os)
Write begin block group without a name.
vtmWriter()
Construct null, with autoName on.
fileTag
Some common XML tags for vtk files.
bool append(const fileName &file)
Add a file. The name is either empty or created with autoName.
static const fileName null
An empty fileName.
bool isType(const Type &t)
Check is typeid is identical to the TargetType.
Provides a means of accumulating file entries for generating a vtkMultiBlockDataSet (....
const dimensionedScalar e
Elementary charge.
static const word null
An empty word.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
autoPtr< vtk::formatter > newFormatter(std::ostream &os, unsigned prec=IOstream::defaultPrecision())
Return a default asciiFormatter.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void repair(bool collapse=false)
Sanity fixes on the data.
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
#define WarningInFunction
Report a warning using Foam::Warning.