mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Added conversion of zero-sized zones
This commit is contained in:
@ -31,6 +31,14 @@ Description
|
|||||||
|
|
||||||
Mainly used to convert binary mesh/field files to ASCII.
|
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"
|
#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:
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -76,9 +160,19 @@ int main(int argc, char *argv[])
|
|||||||
writeMeshObject<labelIOList>("neighbour", runTime);
|
writeMeshObject<labelIOList>("neighbour", runTime);
|
||||||
writeMeshObject<faceIOList>("faces", runTime);
|
writeMeshObject<faceIOList>("faces", runTime);
|
||||||
writeMeshObject<pointIOField>("points", runTime);
|
writeMeshObject<pointIOField>("points", runTime);
|
||||||
writeMeshObject<IOPtrList<entry> >("cellZones", runTime);
|
writeMeshObject<labelIOList>("pointProcAddressing", runTime);
|
||||||
writeMeshObject<IOPtrList<entry> >("faceZones", runTime);
|
writeMeshObject<labelIOList>("faceProcAddressing", runTime);
|
||||||
writeMeshObject<IOPtrList<entry> >("pointZones", 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
|
// Get list of objects from the database
|
||||||
IOobjectList objects(runTime, runTime.timeName());
|
IOobjectList objects(runTime, runTime.timeName());
|
||||||
|
|||||||
Reference in New Issue
Block a user