Skip to content
Snippets Groups Projects
Commit 06b16959 authored by mattijs's avatar mattijs
Browse files

Added conversion of zero-sized zones

parent d0b95d69
Branches
Tags
No related merge requests found
......@@ -31,6 +31,14 @@ Description
Mainly used to convert binary mesh/field files to ASCII.
Problem: any zero-size List written binary gets written as '0'. When
reading the file as a dictionary this is interpreted as a label. This
is (usually) not a problem when doing patch fields since these get the
'uniform', 'nonuniform' prefix. However zone contents are labelLists
not labelFields and these go wrong. For now hacked a solution where
we detect the keywords in zones and redo the dictionary entries
to be labelLists.
\*---------------------------------------------------------------------------*/
#include "argList.H"
......@@ -56,6 +64,82 @@ namespace Foam
}
// Hack to do zones which have Lists in them. See above.
bool writeZones(const word& name, Time& runTime)
{
IOobject io
(
name,
runTime.timeName(),
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
bool writeOk = false;
if (io.headerOk())
{
Info<< " Reading " << io.headerClassName()
<< " : " << name << endl;
// Switch off type checking (for reading e.g. faceZones as
// generic list of dictionaries).
const word oldTypeName = IOPtrList<entry>::typeName;
const_cast<word&>(IOPtrList<entry>::typeName) = word::null;
IOPtrList<entry> meshObject(io);
forAll(meshObject, i)
{
if (meshObject[i].isDict())
{
dictionary& d = meshObject[i].dict();
if (d.found("faceLabels"))
{
d.set("faceLabels", labelList(d.lookup("faceLabels")));
}
if (d.found("flipMap"))
{
d.set("flipMap", boolList(d.lookup("flipMap")));
}
if (d.found("cellLabels"))
{
d.set("cellLabels", labelList(d.lookup("cellLabels")));
}
if (d.found("pointLabels"))
{
d.set("pointLabels", labelList(d.lookup("pointLabels")));
}
}
}
const_cast<word&>(IOPtrList<entry>::typeName) = oldTypeName;
// Fake type back to what was in field
const_cast<word&>(meshObject.type()) = io.headerClassName();
Info<< " Writing " << name << endl;
// Force writing as ascii
writeOk = meshObject.regIOobject::writeObject
(
IOstream::ASCII,
IOstream::currentVersion,
runTime.writeCompression()
);
}
return writeOk;
}
// Main program:
int main(int argc, char *argv[])
......@@ -76,9 +160,19 @@ int main(int argc, char *argv[])
writeMeshObject<labelIOList>("neighbour", runTime);
writeMeshObject<faceIOList>("faces", runTime);
writeMeshObject<pointIOField>("points", runTime);
writeMeshObject<IOPtrList<entry> >("cellZones", runTime);
writeMeshObject<IOPtrList<entry> >("faceZones", runTime);
writeMeshObject<IOPtrList<entry> >("pointZones", runTime);
writeMeshObject<labelIOList>("pointProcAddressing", runTime);
writeMeshObject<labelIOList>("faceProcAddressing", runTime);
writeMeshObject<labelIOList>("cellProcAddressing", runTime);
writeMeshObject<labelIOList>("boundaryProcAddressing", runTime);
if (runTime.writeFormat() == IOstream::ASCII)
{
// Only do zones when converting from binary to ascii
// The other way gives problems since working on dictionary level.
writeZones("cellZones", runTime);
writeZones("faceZones", runTime);
writeZones("pointZones", runTime);
}
// Get list of objects from the database
IOobjectList objects(runTime, runTime.timeName());
......
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