38 bool Foam::ensightFile::allowUndef_ =
false;
63 oss.write(reinterpret_cast<const char*>(&value),
sizeof(Type));
67 oss.width(fieldWidth);
80 for (
const float val :
field)
94 for (
const double val :
field)
108 void Foam::ensightFile::init()
114 std::ios_base::floatfield
125 origFileSize_ = oss.tellp();
132 int64_t begin_footer(-1);
133 List<int64_t> offsets;
150 timeStepOffsets_ = std::move(offsets);
154 oss.seekp(begin_footer);
167 Foam::ensightFile::ensightFile
171 const fileName& pathname,
179 (
append == IOstreamOption::NO_APPEND)
180 ? IOstreamOption::ATOMIC
181 : IOstreamOption::NON_ATOMIC
187 (
append == IOstreamOption::APPEND_APP)
188 ? IOstreamOption::APPEND_ATE
198 Foam::ensightFile::ensightFile
209 ensight::FileName(pathname),
215 Foam::ensightFile::ensightFile
237 (void) writeTimeStepFooter();
257 bool old = allowUndef_;
268 float old = undefValue_;
280 if (len > 80) len = 80;
284 std::copy_n(str, len, buf);
285 std::fill_n(buf + len, (80 - len),
'\0');
287 auto& oss = stdStream();
310 writeString(str, strlen(str));
316 writeString(str.data(), str.size());
322 writeString(str, strlen(str));
329 writeString(str.data(), str.size());
336 writeString(str.data(), str.size());
345 std::streamsize
count 348 stdStream().write(buf,
count);
356 putPrimitive<int32_t>(val, *
this, fieldWidth);
362 putPrimitive<int32_t>(
narrowInt32(val), *
this, fieldWidth);
368 putPrimitive<float>(val, *
this, fieldWidth);
374 putPrimitive<float>(
narrowFloat(val), *
this, fieldWidth);
380 putPrimitive<int32_t>(val, *
this, 10);
388 putPrimitive<int32_t>(
narrowInt32(val), *
this, 10);
396 putPrimitive<float>(val, *
this, 12);
429 writeString(
key +
" undef");
448 writeString(
"C Binary");
472 if (timeStepOffsets_.empty())
480 const int64_t footer_begin(oss.tellp());
483 putPrimitive<int32_t>(int32_t(timeStepOffsets_.size()), *
this, 20);
487 for (int64_t off : timeStepOffsets_)
489 putPrimitive<int64_t>(off, *
this, 20);
494 putPrimitive<int32_t>(0, *
this, 20);
498 putPrimitive<int64_t>(footer_begin, *
this, 20);
504 writeString(
"FILE_INDEX");
509 oss.seekp(footer_begin);
521 writeString(
"BEGIN TIME STEP");
526 const int64_t curr_pos(oss.tellp());
527 timeStepOffsets_.push_back(curr_pos);
532 if (curr_pos >= 0 && curr_pos < origFileSize_)
534 const char fill[] =
"deadbeef";
538 int64_t
pos = curr_pos;
539 pos < origFileSize_ && bool(oss);
561 writeString(
"END TIME STEP");
564 return int64_t(stdStream().tellp());
580 const std::string& description
584 writeString(description);
591 writeString(
"coordinates");
601 writeString(
"particle coordinates");
603 writeInt(nparticles, 8);
610 for (
const label val : list)
620 for (
const label val :
field)
630 for (
const float val :
field)
647 for (
const double val :
field)
A variant of OFstream with specialised handling for Ensight writing of strings, integers and floats (...
void writeBinaryHeader()
Write "C Binary" string for binary files (eg, geometry/measured)
A class for handling keywords in dictionaries.
bool is_appending() const noexcept
True if opened in append mode and file already existed.
int64_t endTimeStep()
Write "END TIME STEP" string and newline (for transient single-file format)
A class for handling file names.
float narrowFloat(const double val)
Type narrowing from double to float.
void syncState()
Set stream state to match that of the std::ostream.
static void putPrimitive(const Type &value, OFstream &os, const int fieldWidth)
Output to file stream as an OSstream, normally using std::ofstream for the actual output...
virtual const fileName & name() const override
Get the name of the output serial stream. (eg, the name of the Fstream file name) ...
int64_t writeTimeStepFooter()
Transient single-file: write the time-step file-offsets as footer information.
static const char *const coordinates
The keyword "coordinates".
int64_t beginTimeStep()
Write "BEGIN TIME STEP" string and newline (for transient single-file format).
void beginPart(const label index)
Begin a part (0-based index internally).
virtual const std::ostream & stdStream() const override
Const access to underlying std::ostream.
dimensionedScalar pos(const dimensionedScalar &ds)
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
int32_t narrowInt32(const int64_t val)
Type narrowing from int64_t to int32_t.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
void writeUndef()
Write undef value.
A class for handling words, derived from Foam::string.
~ensightFile()
Destructor. Commits the time-step footer information (if any)
void writeLabels(const UList< label > &list)
Write a list of integers.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
virtual bool write(const token &tok) override
Write token to stream or otherwise handle it.
static int64_t getTimeStepFooter(IFstream &is, List< int64_t > &offsets)
Extract time step footer information (if any).
Smanip< std::ios_base::fmtflags > setf(std::ios_base::fmtflags flags)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
void beginParticleCoordinates(const label nparticles)
Begin a "particle coordinates" block (measured data)
void beginCoordinates(const label nparticles)
Begin a "coordinates" block. Only used for geometry files.
appendType
File appending (NO_APPEND | APPEND_APP | APPEND_ATE)
void writeString(const char *str, size_t len)
Write character/string content as "%79s" or as binary (max 80 chars)
virtual bool write(const token &) override
Writing token does not make sense.
word format(conversionProperties.get< word >("format"))
void newline()
Add carriage return to ascii stream.
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
void writeList(const UList< label > &field)
Write a list of integers as float values.
void writeInt(const int32_t val, const int fieldWidth)
Write integer value with specified width or as binary.
streamFormat
Data format (ascii | binary)
constexpr floatScalar floatScalarVGREAT
static float undefValue(float value) noexcept
Assign the value to represent undef in the results.
static bool hasUndef(const UList< float > &field)
Check for any NaN in the field.
static bool allowUndef() noexcept
Return setting for whether 'undef' values are allowed in results.
streamFormat format() const noexcept
Get the current stream format.
void writeFloat(const float val, const int fieldWidth)
Write floating-point with specified width or as binary.
IOstream & scientific(IOstream &io)
virtual Ostream & writeKeyword(const keyType &key) override
Write element keyword with trailing newline, optionally with undef and the value for undefined...