Skip to content
Snippets Groups Projects
Commit 7acef189 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide machine/OpenFOAM architecture hint in output files (issue #271)

  FoamFile
  {
      version     2.0;
      format      binary;
      arch        "LSB;label=32;scalar=64";
      class       vectorField;
      object      points;
  }

There is otherwise no simple indication in any of the files as to the
sizes used (Int32 vs Int64, SP vs DP). This makes it difficult for the
end-user and also for any third-party consumers.

--
The architecture information contains three items in the following format:

    (LSB|MSB);label=(32|64);scalar=(32|64)

- The endian value always appears first, without any leading space.
  This make it trivial to check later. Either the first 3 letters (LSB
  vs MSB) or even just the first letter ('L' vs 'M').

- Subsequent key=value pairs for 'label' and 'scalar' are separated
  by semicolons. The ordering of label vs scalar is not specified.

Note that this 'arch' information is purely informational.
It is currently not used by the OpenFOAM input mechanism itself.
parent 9b1fcb0f
Branches
Tags
No related merge requests found
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,11 +29,30 @@ Description
#include "IOobject.H"
#include "objectRegistry.H"
#include "endian.H"
#include "label.H"
#include "scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
{
static std::string archHint;
// Hint about machine endian, OpenFOAM label and scalar sizes
if (archHint.empty())
{
#ifdef WM_LITTLE_ENDIAN
archHint.append("LSB;");
#elif defined (WM_BIG_ENDIAN)
archHint.append("MSB;");
#endif
archHint.append("label=");
archHint.append(std::to_string(8*sizeof(label)));
archHint.append(";scalar=");
archHint.append(std::to_string(8*sizeof(scalar)));
}
if (!os.good())
{
InfoInFunction
......@@ -47,6 +66,7 @@ bool Foam::IOobject::writeHeader(Ostream& os, const word& type) const
<< "FoamFile\n{\n"
<< " version " << os.version() << ";\n"
<< " format " << os.format() << ";\n"
<< " arch " << archHint << ";\n"
<< " class " << type << ";\n";
if (note().size())
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment