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

ENH: simplify foamToEnsight using new IOobjectList methods

BUG: foamToEnsight fails with missing field at time 0 (fixes #473)
parent 9761e9d8
Branches
Tags
No related merge requests found
...@@ -23,7 +23,7 @@ if (!fieldsToUse.found(fieldName)) ...@@ -23,7 +23,7 @@ if (!fieldsToUse.found(fieldName))
).typeHeaderOk<volScalarField>(false, false) ).typeHeaderOk<volScalarField>(false, false)
); );
if (variableGood) if (!variableGood)
{ {
break; break;
} }
......
...@@ -35,36 +35,25 @@ if (timeDirs.size() && !noLagrangian) ...@@ -35,36 +35,25 @@ if (timeDirs.size() && !noLagrangian)
cloudPrefix/cloudName cloudPrefix/cloudName
); );
// clouds always require "positions" // Clouds always have "positions"
if (cloudObjs.found("positions")) if (cloudObjs.found("positions"))
{ {
HashTable<HashTable<word>>::iterator cloudIter = // Save the cloud fields on a per cloud basis
cloudFields.find(cloudName); auto fieldsPerCloud = cloudFields(cloudName);
if (cloudIter == cloudFields.end()) forAllConstIters(cloudObjs, fieldIter)
{ {
// A newly discovered cloud const IOobject* obj = fieldIter();
cloudFields.insert(cloudName, HashTable<word>());
cloudIter = cloudFields.find(cloudName);
}
forAllConstIter(IOobjectList, cloudObjs, fieldIter) // Field name/type
{ fieldsPerCloud.insert(obj->name(), obj->headerClassName());
const IOobject& obj = *fieldIter();
// Add field and field type
cloudIter().insert
(
obj.name(),
obj.headerClassName()
);
} }
} }
} }
} }
// prune out "positions" again since it gets treated specially // Prune out "positions" again since it gets treated specially
forAllIter(HashTable<HashTable<word>>, cloudFields, cloudIter) forAllIters(cloudFields, cloudIter)
{ {
cloudIter().erase("positions"); cloudIter().erase("positions");
} }
...@@ -76,18 +65,13 @@ if (timeDirs.size() && !noLagrangian) ...@@ -76,18 +65,13 @@ if (timeDirs.size() && !noLagrangian)
} }
// sorted list of cloud names // Sorted list of cloud names
const wordList cloudNames(cloudFields.sortedToc()); const wordList cloudNames(cloudFields.sortedToc());
if (cloudNames.size()) if (cloudNames.size())
{ {
// complete the echo information // Complete the echo information - as flatOutput
Info<< "("; cloudNames.writeList(Info) << endl;
forAll(cloudNames, cloudNo)
{
Info<< ' ' << cloudNames[cloudNo];
}
Info<< " ) " << endl;
} }
// ************************************************************************* // // ************************************************************************* //
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -78,6 +78,7 @@ Note ...@@ -78,6 +78,7 @@ Note
#include "fvc.H" #include "fvc.H"
#include "volFields.H" #include "volFields.H"
#include "hashedWordList.H"
#include "labelIOField.H" #include "labelIOField.H"
#include "scalarIOField.H" #include "scalarIOField.H"
...@@ -190,7 +191,7 @@ int main(int argc, char *argv[]) ...@@ -190,7 +191,7 @@ int main(int argc, char *argv[])
); );
// The volume field types that we handle // The volume field types that we handle
const wordList volFieldTypes const hashedWordList volFieldTypes
{ {
volScalarField::typeName, volScalarField::typeName,
volVectorField::typeName, volVectorField::typeName,
...@@ -207,7 +208,7 @@ int main(int argc, char *argv[]) ...@@ -207,7 +208,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
// default to binary output, unless otherwise specified // Default to binary output, unless otherwise specified
const IOstream::streamFormat format = const IOstream::streamFormat format =
( (
args.optionFound("ascii") args.optionFound("ascii")
...@@ -234,7 +235,7 @@ int main(int argc, char *argv[]) ...@@ -234,7 +235,7 @@ int main(int argc, char *argv[])
} }
// //
// general (case) output options // General (case) output options
// //
ensightCase::options caseOpts(format); ensightCase::options caseOpts(format);
...@@ -257,7 +258,7 @@ int main(int argc, char *argv[]) ...@@ -257,7 +258,7 @@ int main(int argc, char *argv[])
// //
// output configuration (geometry related) // Output configuration (geometry related)
// //
ensightMesh::options writeOpts(format); ensightMesh::options writeOpts(format);
writeOpts.noPatches(args.optionFound("noPatches")); writeOpts.noPatches(args.optionFound("noPatches"));
...@@ -313,12 +314,6 @@ int main(int argc, char *argv[]) ...@@ -313,12 +314,6 @@ int main(int argc, char *argv[])
ensCase.printInfo(Info) << endl; ensCase.printInfo(Info) << endl;
} }
// Set Time to the last time before looking for lagrangian objects
runTime.setTime(timeDirs.last(), timeDirs.size()-1);
IOobjectList objects(mesh, runTime.timeName());
#include "checkMeshMoving.H" #include "checkMeshMoving.H"
#include "findCloudFields.H" #include "findCloudFields.H"
...@@ -331,6 +326,40 @@ int main(int argc, char *argv[]) ...@@ -331,6 +326,40 @@ int main(int argc, char *argv[])
<< timer.cpuTimeIncrement() << " s, " << timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << nl << endl; << mem.update().size() << " kB" << nl << endl;
// Get the list of supported classes/fields
HashTable<wordHashSet> usableObjects;
{
// Initially all possible objects that are available at the final time
IOobjectList objects(mesh, timeDirs.last().name());
// Categorize by classes, pre-filter on name (if requested)
usableObjects =
(
fieldPatterns.empty()
? objects.classes()
: objects.classes(fieldPatterns)
);
// Limit to types that we explicitly handle
usableObjects.filterKeys(volFieldTypes);
// Force each field-type into existence (simplifies code logic
// and doesn't cost much) and simultaneously remove all
// "*_0" restart fields
for (auto fieldType : volFieldTypes)
{
usableObjects
(
fieldType
).filterKeys
(
[](const word& k){ return k.endsWith("_0"); },
true // prune
);
}
}
// ignore special fields (_0 fields), // ignore special fields (_0 fields),
// ignore fields we don't handle, // ignore fields we don't handle,
// ignore fields that are not available for all time-steps // ignore fields that are not available for all time-steps
...@@ -362,25 +391,22 @@ int main(int argc, char *argv[]) ...@@ -362,25 +391,22 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~
Info<< "Write volume field ("; Info<< "Write volume field (";
forAll(volFieldTypes, typei) for (auto fieldType : volFieldTypes)
{ {
const word& fieldType = volFieldTypes[typei]; // For convenience, just force each field-type into existence.
wordList fieldNames = objects.names(fieldType); // This simplifies code logic and doesn't cost much at all.
wordHashSet& fieldNames = usableObjects(fieldType);
// Filter on name as required forAllIters(fieldNames, fieldIter)
if (!fieldPatterns.empty())
{ {
inplaceSubsetStrings(fieldPatterns, fieldNames); const word& fieldName = fieldIter.key();
}
forAll(fieldNames, fieldi)
{
const word& fieldName = fieldNames[fieldi];
#include "checkData.H" #include "checkData.H"
// Partially complete field?
if (!fieldsToUse[fieldName]) if (!fieldsToUse[fieldName])
{ {
fieldNames.erase(fieldIter);
continue; continue;
} }
...@@ -597,7 +623,8 @@ int main(int argc, char *argv[]) ...@@ -597,7 +623,8 @@ int main(int argc, char *argv[])
} }
else else
{ {
// Do not currently handle this type - blacklist for the future. // Do not currently handle this type
// - blacklist for the future.
fieldsToUse.set(fieldName, false); fieldsToUse.set(fieldName, false);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment