Skip to content
Snippets Groups Projects
Commit 3154b776 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: preserve origId in foamFormatConvert (fixes# #3051)

- previously read the cloud directly without any of the
  passiveParticle fields (origProcId, origId), which meant they would
  not actually be converted.
parent 60840eb0
Branches
Tags
No related merge requests found
...@@ -73,8 +73,7 @@ Usage ...@@ -73,8 +73,7 @@ Usage
#include "tensorIOField.H" #include "tensorIOField.H"
#include "labelFieldIOField.H" #include "labelFieldIOField.H"
#include "vectorFieldIOField.H" #include "vectorFieldIOField.H"
#include "Cloud.H" #include "passiveParticleCloud.H"
#include "passiveParticle.H"
#include "fieldDictionary.H" #include "fieldDictionary.H"
#include "writeMeshObject.H" #include "writeMeshObject.H"
...@@ -95,7 +94,7 @@ bool writeZones ...@@ -95,7 +94,7 @@ bool writeZones
const word& name, const word& name,
const fileName& meshDir, const fileName& meshDir,
Time& runTime, Time& runTime,
const IOstreamOption::compressionType compression IOstreamOption::compressionType compression
) )
{ {
IOobject io IOobject io
...@@ -123,11 +122,11 @@ bool writeZones ...@@ -123,11 +122,11 @@ bool writeZones
IOPtrList<entry> meshObject(io); IOPtrList<entry> meshObject(io);
forAll(meshObject, i) for (entry& e : meshObject)
{ {
if (meshObject[i].isDict()) if (e.isDict())
{ {
dictionary& d = meshObject[i].dict(); dictionary& d = e.dict();
if (d.found("faceLabels")) if (d.found("faceLabels"))
{ {
...@@ -197,13 +196,13 @@ struct uniqueEqOp ...@@ -197,13 +196,13 @@ struct uniqueEqOp
}; };
template<class T> template<class Type>
bool writeOptionalMeshObject bool writeOptionalMeshObject
( (
const word& name, const word& name,
const fileName& meshDir, const fileName& meshDir,
Time& runTime, Time& runTime,
const bool writeOnProc bool writeOnProc
) )
{ {
IOobject io IOobject io
...@@ -217,22 +216,26 @@ bool writeOptionalMeshObject ...@@ -217,22 +216,26 @@ bool writeOptionalMeshObject
IOobject::NO_REGISTER IOobject::NO_REGISTER
); );
bool writeOk = false; // Check if available and the correct type.
const bool haveFile = io.typeHeaderOk<regIOobject>(false); // Done as typeHeaderOk<regIOobject> + isHeaderClass to ensure
// local-only reading and circumvent is_globalIOobject<Type> check
// in typeHeaderOk<Type>
bool readOnProc =
(
io.typeHeaderOk<regIOobject>(false)
&& io.isHeaderClass<Type>()
);
// Make sure all know if there is a valid class name bool writeOk = false;
wordList classNames(1, io.headerClassName());
Pstream::combineReduce(classNames, uniqueEqOp<word>());
// Check for correct type if (returnReduceOr(readOnProc))
if (classNames[0] == T::typeName)
{ {
Info<< " Reading " << classNames[0] Info<< " Reading " << Type::typeName << " : " << name << endl;
<< " : " << name << endl; Type meshObject(io, readOnProc && writeOnProc);
T meshObject(io, writeOnProc && haveFile);
Info<< " Writing " << name << endl; Info<< " Writing " << name << endl;
writeOk = meshObject.regIOobject::write(writeOnProc && haveFile); writeOk = meshObject.regIOobject::write(readOnProc && writeOnProc);
} }
return writeOk; return writeOk;
...@@ -416,7 +419,6 @@ int main(int argc, char *argv[]) ...@@ -416,7 +419,6 @@ int main(int argc, char *argv[])
} }
// Check for lagrangian // Check for lagrangian
fileNameList lagrangianDirs fileNameList lagrangianDirs
( (
...@@ -451,12 +453,14 @@ int main(int argc, char *argv[]) ...@@ -451,12 +453,14 @@ int main(int argc, char *argv[])
polyMesh::defaultRegion, polyMesh::defaultRegion,
runTime.timeName(), runTime.timeName(),
runTime, runTime,
Foam::IOobject::MUST_READ IOobject::MUST_READ
) )
) )
); );
} }
const auto& mesh = meshPtr();
fileNameList cloudDirs fileNameList cloudDirs
( (
fileHandler().readDir fileHandler().readDir
...@@ -468,11 +472,14 @@ int main(int argc, char *argv[]) ...@@ -468,11 +472,14 @@ int main(int argc, char *argv[])
Pstream::combineReduce(cloudDirs, uniqueEqOp<fileName>()); Pstream::combineReduce(cloudDirs, uniqueEqOp<fileName>());
forAll(cloudDirs, i) for (const auto& cloudDir : cloudDirs)
{ {
fileName dir(cloud::prefix/cloudDirs[i]); fileName dir(cloud::prefix/cloudDir);
// Read with origProcId,origId fields
passiveParticleCloud parcels(mesh, cloudDir, true);
Cloud<passiveParticle> parcels(meshPtr(), cloudDirs[i], false); const bool writeOnProc = parcels.size();
parcels.writeObject parcels.writeObject
( (
...@@ -481,7 +488,7 @@ int main(int argc, char *argv[]) ...@@ -481,7 +488,7 @@ int main(int argc, char *argv[])
runTime.writeFormat(), runTime.writeFormat(),
runTime.writeCompression() runTime.writeCompression()
), ),
parcels.size() writeOnProc
); );
...@@ -496,10 +503,7 @@ int main(int argc, char *argv[]) ...@@ -496,10 +503,7 @@ int main(int argc, char *argv[])
for (const word& name : cloudFields) for (const word& name : cloudFields)
{ {
// Note: try the various field types. Make sure to // These ones already done by cloud itself
// exit once successful conversion to avoid re-read
// converted file.
if if
( (
name == "positions" name == "positions"
...@@ -511,81 +515,32 @@ int main(int argc, char *argv[]) ...@@ -511,81 +515,32 @@ int main(int argc, char *argv[])
continue; continue;
} }
bool writeOk = writeOptionalMeshObject<labelIOField> #undef doLocalCode
( #define doLocalCode(Type) \
name, if \
dir, ( \
runTime, writeOptionalMeshObject<Type> \
parcels.size() > 0 ( \
); name, dir, runTime, writeOnProc \
if (writeOk) continue; ) \
) \
writeOk = writeOptionalMeshObject<scalarIOField> { \
( continue; \
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<vectorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<sphericalTensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<symmTensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<tensorIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<labelFieldIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (writeOk) continue;
writeOk = writeOptionalMeshObject<vectorFieldIOField>
(
name,
dir,
runTime,
parcels.size() > 0
);
if (!writeOk)
{
Info<< " Failed converting " << name << endl;
} }
doLocalCode(labelIOField);
doLocalCode(scalarIOField);
doLocalCode(vectorIOField);
doLocalCode(sphericalTensorIOField);
doLocalCode(symmTensorIOField);
doLocalCode(tensorIOField);
doLocalCode(labelFieldIOField);
doLocalCode(vectorFieldIOField);
#undef doLocalCode
Info<< " Failed converting " << name << endl;
} }
} }
} }
......
...@@ -71,10 +71,9 @@ inline bool writeMeshObject ...@@ -71,10 +71,9 @@ inline bool writeMeshObject
// Switch off type checking (for reading e.g. faceZones as // Switch off type checking (for reading e.g. faceZones as
// generic list of dictionaries). // generic list of dictionaries).
word oldTypeName; const word oldTypeName = Type::typeName;
if (disableHeaderChecking) if (disableHeaderChecking)
{ {
oldTypeName = Type::typeName;
const_cast<word&>(Type::typeName) = word::null; const_cast<word&>(Type::typeName) = word::null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment