mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: impose type-narrowing for Ensight output
This commit is contained in:
@ -225,28 +225,62 @@ Foam::Ostream& Foam::ensightFile::write
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::ensightFile::write(const label value)
|
Foam::Ostream& Foam::ensightFile::write(const int32_t val)
|
||||||
{
|
{
|
||||||
if (format() == IOstream::BINARY)
|
if (format() == IOstream::BINARY)
|
||||||
{
|
{
|
||||||
unsigned int ivalue(value);
|
|
||||||
|
|
||||||
write
|
write
|
||||||
(
|
(
|
||||||
reinterpret_cast<const char *>(&ivalue),
|
reinterpret_cast<const char *>(&val),
|
||||||
sizeof(ivalue)
|
sizeof(int32_t)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stdStream().width(10);
|
stdStream().width(10);
|
||||||
stdStream() << value;
|
stdStream() << val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream& Foam::ensightFile::write(const int64_t val)
|
||||||
|
{
|
||||||
|
int32_t ivalue(narrowInt32(val));
|
||||||
|
|
||||||
|
return write(ivalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream& Foam::ensightFile::write(const floatScalar val)
|
||||||
|
{
|
||||||
|
if (format() == IOstream::BINARY)
|
||||||
|
{
|
||||||
|
write
|
||||||
|
(
|
||||||
|
reinterpret_cast<const char *>(&val),
|
||||||
|
sizeof(floatScalar)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stdStream().width(12);
|
||||||
|
stdStream() << val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Ostream& Foam::ensightFile::write(const doubleScalar val)
|
||||||
|
{
|
||||||
|
float fvalue(narrowFloat(val));
|
||||||
|
|
||||||
|
return write(fvalue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::ensightFile::write
|
Foam::Ostream& Foam::ensightFile::write
|
||||||
(
|
(
|
||||||
const label value,
|
const label value,
|
||||||
@ -255,13 +289,7 @@ Foam::Ostream& Foam::ensightFile::write
|
|||||||
{
|
{
|
||||||
if (format() == IOstream::BINARY)
|
if (format() == IOstream::BINARY)
|
||||||
{
|
{
|
||||||
unsigned int ivalue(value);
|
write(value);
|
||||||
|
|
||||||
write
|
|
||||||
(
|
|
||||||
reinterpret_cast<const char *>(&ivalue),
|
|
||||||
sizeof(ivalue)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -273,36 +301,6 @@ Foam::Ostream& Foam::ensightFile::write
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::ensightFile::write(const scalar value)
|
|
||||||
{
|
|
||||||
float fvalue(value);
|
|
||||||
|
|
||||||
// TBD: limit range?
|
|
||||||
// #if defined(WM_DP)
|
|
||||||
// if (mag(value) < scalar(floatScalarVSMALL))
|
|
||||||
// {
|
|
||||||
// fvalue = 0;
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
if (format() == IOstream::BINARY)
|
|
||||||
{
|
|
||||||
write
|
|
||||||
(
|
|
||||||
reinterpret_cast<const char *>(&fvalue),
|
|
||||||
sizeof(fvalue)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stdStream().width(12);
|
|
||||||
stdStream() << fvalue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::ensightFile::newline()
|
void Foam::ensightFile::newline()
|
||||||
{
|
{
|
||||||
if (format() == IOstream::ASCII)
|
if (format() == IOstream::ASCII)
|
||||||
|
|||||||
@ -172,6 +172,21 @@ public:
|
|||||||
//- Write undef value
|
//- Write undef value
|
||||||
Ostream& writeUndef();
|
Ostream& writeUndef();
|
||||||
|
|
||||||
|
|
||||||
|
//- Writing token does not make sense
|
||||||
|
virtual bool write(const token&)
|
||||||
|
{
|
||||||
|
NotImplemented;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Writing single character does not make sense
|
||||||
|
virtual Ostream& write(const char)
|
||||||
|
{
|
||||||
|
NotImplemented;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
//- Binary write
|
//- Binary write
|
||||||
virtual Ostream& write(const char* buf, std::streamsize count);
|
virtual Ostream& write(const char* buf, std::streamsize count);
|
||||||
|
|
||||||
@ -185,13 +200,19 @@ public:
|
|||||||
virtual Ostream& write(const string& str);
|
virtual Ostream& write(const string& str);
|
||||||
|
|
||||||
//- Write integer as "%10d" or as binary
|
//- Write integer as "%10d" or as binary
|
||||||
Ostream& write(const label value);
|
virtual Ostream& write(const int32_t val);
|
||||||
|
|
||||||
|
//- Write integer as "%10d" or as binary
|
||||||
|
virtual Ostream& write(const int64_t val);
|
||||||
|
|
||||||
//- Write integer with specified width or as binary
|
//- Write integer with specified width or as binary
|
||||||
Ostream& write(const label value, const label fieldWidth);
|
Ostream& write(const label value, const label fieldWidth);
|
||||||
|
|
||||||
//- Write float as "%12.5e" or as binary
|
//- Write floating-point as "%12.5e" or as binary
|
||||||
Ostream& write(const scalar value);
|
virtual Ostream& write(const floatScalar val);
|
||||||
|
|
||||||
|
//- Write floating-point as "%12.5e" or as binary
|
||||||
|
virtual Ostream& write(const doubleScalar val);
|
||||||
|
|
||||||
//- Add carriage return to ascii stream
|
//- Add carriage return to ascii stream
|
||||||
void newline();
|
void newline();
|
||||||
|
|||||||
@ -241,7 +241,7 @@ public:
|
|||||||
//- optionally write all element addresses
|
//- optionally write all element addresses
|
||||||
virtual void writeDict(Ostream& os, const bool full=false) const;
|
virtual void writeDict(Ostream& os, const bool full=false) const;
|
||||||
|
|
||||||
//- Write geometry, using a mesh reference (serial only)
|
//- Write geometry, using a mesh reference
|
||||||
virtual void write
|
virtual void write
|
||||||
(
|
(
|
||||||
ensightGeoFile& os,
|
ensightGeoFile& os,
|
||||||
|
|||||||
@ -117,6 +117,13 @@ public:
|
|||||||
//- Write a field of point values (serial-only)
|
//- Write a field of point values (serial-only)
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void writePointData(ensightFile& os, const Field<Type>& fld) const;
|
void writePointData(ensightFile& os, const Field<Type>& fld) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Housekeeping
|
||||||
|
|
||||||
|
//- Cannot write geometry with a mesh reference
|
||||||
|
virtual void write(ensightGeoFile&, const polyMesh&, bool) const
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user