mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add 'arch' information to output file headers (ASCII)
- this was previously suppressed for ASCII format as being 'clutter', but without it there is no context for interpreting the type of data contained in ASCII files: potentially leading to integer overflows when reading in ParaView etc.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -511,8 +511,8 @@ public:
|
|||||||
// Writing
|
// Writing
|
||||||
|
|
||||||
//- Write the standard OpenFOAM file/dictionary banner
|
//- Write the standard OpenFOAM file/dictionary banner
|
||||||
// Optionally without -*- C++ -*- editor hint (eg, for logs)
|
// Optionally without editor syntax hint (eg, for logs)
|
||||||
static Ostream& writeBanner(Ostream& os, bool noHint=false);
|
static Ostream& writeBanner(Ostream& os, const bool noSyntaxHint=false);
|
||||||
|
|
||||||
//- Write the standard file section divider
|
//- Write the standard file section divider
|
||||||
static Ostream& writeDivider(Ostream& os);
|
static Ostream& writeDivider(Ostream& os);
|
||||||
@ -520,11 +520,18 @@ public:
|
|||||||
//- Write the standard end file divider
|
//- Write the standard end file divider
|
||||||
static Ostream& writeEndDivider(Ostream& os);
|
static Ostream& writeEndDivider(Ostream& os);
|
||||||
|
|
||||||
//- Write header
|
//- Write header with current type().
|
||||||
bool writeHeader(Ostream& os) const;
|
// Optionally without arch information when ASCII
|
||||||
|
bool writeHeader(Ostream& os, const bool noArchAscii=false) const;
|
||||||
|
|
||||||
//- Write header. Allow override of type
|
//- Write header with override of type.
|
||||||
bool writeHeader(Ostream& os, const word& objectType) const;
|
// Optionally without arch information when ASCII
|
||||||
|
bool writeHeader
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const word& objectType,
|
||||||
|
const bool noArchAscii = false
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
// Error Handling
|
// Error Handling
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2016-2017 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -42,7 +42,8 @@ License
|
|||||||
| \\/ M anipulation | |
|
| \\/ M anipulation | |
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
Foam::Ostream& Foam::IOobject::writeBanner(Ostream& os, bool noHint)
|
Foam::Ostream&
|
||||||
|
Foam::IOobject::writeBanner(Ostream& os, const bool noSyntaxHint)
|
||||||
{
|
{
|
||||||
// The version padded with spaces to fit after "Version: "
|
// The version padded with spaces to fit after "Version: "
|
||||||
// - initialized with zero-length string to detect if it has been populated
|
// - initialized with zero-length string to detect if it has been populated
|
||||||
@ -66,7 +67,7 @@ Foam::Ostream& Foam::IOobject::writeBanner(Ostream& os, bool noHint)
|
|||||||
os <<
|
os <<
|
||||||
"/*--------------------------------";
|
"/*--------------------------------";
|
||||||
|
|
||||||
if (noHint)
|
if (noSyntaxHint)
|
||||||
{
|
{
|
||||||
// Without syntax hint
|
// Without syntax hint
|
||||||
os << "---------";
|
os << "---------";
|
||||||
@ -116,7 +117,12 @@ Foam::Ostream& Foam::IOobject::writeEndDivider(Ostream& os)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
|
bool Foam::IOobject::writeHeader
|
||||||
|
(
|
||||||
|
Ostream& os,
|
||||||
|
const word& objectType,
|
||||||
|
const bool noArchAscii
|
||||||
|
) const
|
||||||
{
|
{
|
||||||
if (!os.good())
|
if (!os.good())
|
||||||
{
|
{
|
||||||
@ -127,25 +133,37 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeBanner(os)
|
IOobject::writeBanner(os)
|
||||||
<< "FoamFile\n{\n"
|
<< "FoamFile" << nl
|
||||||
<< " version " << os.version() << ";\n"
|
<< '{' << nl
|
||||||
<< " format " << os.format() << ";\n"
|
<< " version " << os.version() << ';' << nl
|
||||||
<< " class " << type << ";\n";
|
<< " format " << os.format() << ';' << nl;
|
||||||
|
|
||||||
if (os.format() == IOstream::BINARY)
|
if (os.format() == IOstream::BINARY || !noArchAscii)
|
||||||
{
|
{
|
||||||
os << " arch " << foamVersion::buildArch << ";\n";
|
// Arch information (BINARY: always, ASCII: can disable)
|
||||||
|
os << " arch " << foamVersion::buildArch << ';' << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!note().empty())
|
if (!note().empty())
|
||||||
{
|
{
|
||||||
os << " note " << note() << ";\n";
|
os << " note " << note() << ';' << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << " location " << instance()/db().dbDir()/local() << ";\n"
|
os << " class ";
|
||||||
<< " object " << name() << ";\n"
|
if (objectType.empty())
|
||||||
<< "}" << nl;
|
{
|
||||||
|
// Empty type not allowed - use 'dictionary' fallback
|
||||||
|
os << "dictionary";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << objectType;
|
||||||
|
}
|
||||||
|
os << ';' << nl;
|
||||||
|
|
||||||
|
os << " location " << instance()/db().dbDir()/local() << ';' << nl
|
||||||
|
<< " object " << name() << ';' << nl
|
||||||
|
<< '}' << nl;
|
||||||
|
|
||||||
writeDivider(os) << nl;
|
writeDivider(os) << nl;
|
||||||
|
|
||||||
@ -153,9 +171,9 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::IOobject::writeHeader(Ostream& os) const
|
bool Foam::IOobject::writeHeader(Ostream& os, const bool noArchAscii) const
|
||||||
{
|
{
|
||||||
return writeHeader(os, type());
|
return writeHeader(os, type(), noArchAscii);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2018 OpenFOAM Foundation
|
Copyright (C) 2017-2018 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -188,41 +188,47 @@ void Foam::decomposedBlockData::writeHeader
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const IOstream::versionNumber version,
|
const IOstream::versionNumber version,
|
||||||
const IOstream::streamFormat format,
|
const IOstream::streamFormat format,
|
||||||
const word& type,
|
const word& objectType,
|
||||||
const string& note,
|
const string& note,
|
||||||
const fileName& location,
|
const fileName& location,
|
||||||
const word& name
|
const word& objectName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
IOobject::writeBanner(os)
|
IOobject::writeBanner(os)
|
||||||
<< "FoamFile\n{\n"
|
<< "FoamFile" << nl
|
||||||
<< " version " << version << ";\n"
|
<< '{' << nl
|
||||||
<< " format " << format << ";\n"
|
<< " version " << version << ';' << nl
|
||||||
<< " class " << type << ";\n";
|
<< " format " << format << ';' << nl
|
||||||
|
<< " arch " << foamVersion::buildArch << ';' << nl;
|
||||||
// This may be useful to have as well
|
|
||||||
if (os.format() == IOstream::BINARY)
|
|
||||||
{
|
|
||||||
os << " arch " << foamVersion::buildArch << ";\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Pstream::parRun())
|
if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
os << " blocks " << Pstream::nProcs() << ";\n";
|
os << " blocks " << Pstream::nProcs() << ';' << nl;
|
||||||
}
|
}
|
||||||
|
if (!note.empty())
|
||||||
if (note.size())
|
|
||||||
{
|
{
|
||||||
os << " note " << note << ";\n";
|
os << " note " << note << ';' << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.size())
|
os << " class ";
|
||||||
|
if (objectType.empty())
|
||||||
{
|
{
|
||||||
os << " location " << location << ";\n";
|
// Empty type not allowed - use 'dictionary' fallback
|
||||||
|
os << "dictionary";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << objectType;
|
||||||
|
}
|
||||||
|
os << ';' << nl;
|
||||||
|
|
||||||
|
if (!location.empty())
|
||||||
|
{
|
||||||
|
os << " location " << location << ';' << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
os << " object " << name << ";\n"
|
os << " object " << objectName << ';' << nl
|
||||||
<< "}" << nl;
|
<< '}' << nl;
|
||||||
|
|
||||||
IOobject::writeDivider(os) << nl;
|
IOobject::writeDivider(os) << nl;
|
||||||
}
|
}
|
||||||
@ -976,9 +982,8 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const
|
|||||||
// Scatter header information
|
// Scatter header information
|
||||||
|
|
||||||
string versionString(os.version().str());
|
string versionString(os.version().str());
|
||||||
Pstream::scatter(versionString, Pstream::msgType(), comm_);
|
|
||||||
|
|
||||||
label formatValue(os.format());
|
label formatValue(os.format());
|
||||||
|
Pstream::scatter(versionString, Pstream::msgType(), comm_);
|
||||||
Pstream::scatter(formatValue, Pstream::msgType(), comm_);
|
Pstream::scatter(formatValue, Pstream::msgType(), comm_);
|
||||||
|
|
||||||
//word masterName(name());
|
//word masterName(name());
|
||||||
@ -997,8 +1002,8 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const
|
|||||||
writeHeader
|
writeHeader
|
||||||
(
|
(
|
||||||
os,
|
os,
|
||||||
IOstream::versionNumber(versionString),
|
IOstreamOption::versionNumber(versionString),
|
||||||
IOstream::streamFormat(formatValue),
|
IOstreamOption::streamFormat(formatValue),
|
||||||
io.headerClassName(),
|
io.headerClassName(),
|
||||||
io.note(),
|
io.note(),
|
||||||
masterLocation,
|
masterLocation,
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2018 OpenFOAM Foundation
|
Copyright (C) 2017-2018 OpenFOAM Foundation
|
||||||
Copyright (C) 2020 OpenCFD Ltd.
|
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -156,10 +156,10 @@ public:
|
|||||||
Ostream& os,
|
Ostream& os,
|
||||||
const IOstream::versionNumber version,
|
const IOstream::versionNumber version,
|
||||||
const IOstream::streamFormat format,
|
const IOstream::streamFormat format,
|
||||||
const word& type,
|
const word& objectType,
|
||||||
const string& note,
|
const string& note,
|
||||||
const fileName& location,
|
const fileName& location,
|
||||||
const word& name
|
const word& objectName
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Read selected block (non-seeking) + header information
|
//- Read selected block (non-seeking) + header information
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2018 OpenFOAM Foundation
|
Copyright (C) 2017-2018 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -94,16 +94,15 @@ bool Foam::OFstreamCollator::writeFile
|
|||||||
// We don't have IOobject so cannot use IOobject::writeHeader
|
// We don't have IOobject so cannot use IOobject::writeHeader
|
||||||
if (!append)
|
if (!append)
|
||||||
{
|
{
|
||||||
OSstream& os = osPtr();
|
|
||||||
decomposedBlockData::writeHeader
|
decomposedBlockData::writeHeader
|
||||||
(
|
(
|
||||||
os,
|
*osPtr,
|
||||||
ver,
|
ver,
|
||||||
fmt,
|
fmt,
|
||||||
typeName,
|
typeName,
|
||||||
"",
|
"", // note
|
||||||
fName,
|
fName, // location
|
||||||
fName.name()
|
fName.name() // object name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user