Commit 02ad76df authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: allow wordHashSet filter for IOobjectList::names

- simplifies usage.
  Support syncPar check on names() to detect inconsistencies.

- simplify readFields, ReadFields and other routines by using these
  new methods.
parent a8ef5610
......@@ -54,7 +54,7 @@ void RotateFields
// Objects of field type
IOobjectList fields(objects.lookupClass(GeometricField::typeName));
forAllIter(IOobjectList, fields, fieldIter)
forAllConstIters(fields, fieldIter)
{
Info<< " Rotating " << fieldIter()->name() << endl;
......
......@@ -193,7 +193,7 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (cellSets.size())
{
os << "cellSets:" << endl;
forAllConstIter(IOobjectList, cellSets, iter)
forAllConstIters(cellSets, iter)
{
cellSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
......@@ -203,7 +203,7 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (faceSets.size())
{
os << "faceSets:" << endl;
forAllConstIter(IOobjectList, faceSets, iter)
forAllConstIters(faceSets, iter)
{
faceSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
......@@ -213,7 +213,7 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (pointSets.size())
{
os << "pointSets:" << endl;
forAllConstIter(IOobjectList, pointSets, iter)
forAllConstIters(pointSets, iter)
{
pointSet set(*iter());
os << '\t' << set.name() << "\tsize:" << set.size() << endl;
......@@ -224,9 +224,8 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (cellZones.size())
{
os << "cellZones:" << endl;
forAll(cellZones, i)
for (const cellZone& zone : cellZones)
{
const cellZone& zone = cellZones[i];
os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
}
}
......@@ -234,9 +233,8 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (faceZones.size())
{
os << "faceZones:" << endl;
forAll(faceZones, i)
for (const faceZone& zone : faceZones)
{
const faceZone& zone = faceZones[i];
os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
}
}
......@@ -244,9 +242,8 @@ void printAllSets(const polyMesh& mesh, Ostream& os)
if (pointZones.size())
{
os << "pointZones:" << endl;
forAll(pointZones, i)
for (const pointZone& zone : pointZones)
{
const pointZone& zone = pointZones[i];
os << '\t' << zone.name() << "\tsize:" << zone.size() << endl;
}
}
......
......@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
//Pout<< "pointSets:" << pointObjects.names() << endl;
forAllConstIter(IOobjectList, pointObjects, iter)
forAllConstIters(pointObjects, iter)
{
// Not in memory. Load it.
pointSet set(*iter());
......@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
//Pout<< "faceSets:" << faceObjects.names() << endl;
forAllConstIter(IOobjectList, faceObjects, iter)
forAllConstIters(faceObjects, iter)
{
// Not in memory. Load it.
faceSet set(*iter());
......@@ -269,7 +269,7 @@ int main(int argc, char *argv[])
//Pout<< "cellSets:" << cellObjects.names() << endl;
forAllConstIter(IOobjectList, cellObjects, iter)
forAllConstIters(cellObjects, iter)
{
if (!slaveCellSets.found(iter.key()))
{
......
......@@ -286,7 +286,7 @@ template<class TopoSet>
void subsetTopoSets
(
const fvMesh& mesh,
const IOobjectList& objectsList,
const IOobjectList& objects,
const labelList& map,
const fvMesh& subMesh,
PtrList<TopoSet>& subSets
......@@ -294,7 +294,7 @@ void subsetTopoSets
{
// Read original sets
PtrList<TopoSet> sets;
ReadFields<TopoSet>(objectsList, sets);
ReadFields<TopoSet>(objects, sets);
subSets.setSize(sets.size());
forAll(sets, i)
......
......@@ -351,7 +351,7 @@ int main(int argc, char *argv[])
// Get list of objects from the database
IOobjectList objects(runTime, runTime.timeName(), regionPrefix);
forAllConstIter(IOobjectList, objects, iter)
forAllConstIters(objects, iter)
{
const word& headerClassName = iter()->headerClassName();
......
......@@ -81,9 +81,10 @@ int main(int argc, char *argv[])
<< endl;
}
const IOobjectList fieldObjs(mesh, runTime.timeName());
const wordList objNames = fieldObjs.names();
const wordList objNames
(
IOobjectList(mesh, runTime.timeName()).sortedNames()
);
PtrList<volScalarField> vsf(objNames.size());
PtrList<volVectorField> vvf(objNames.size());
......
......@@ -173,21 +173,21 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
IOobjectList objects(*this, facesInstance(), "polyMesh/sets");
{
IOobjectList cSets(objects.lookupClass(cellSet::typeName));
forAllConstIter(IOobjectList, cSets, iter)
forAllConstIters(cSets, iter)
{
cellSets.append(new cellSet(*iter()));
}
}
{
IOobjectList fSets(objects.lookupClass(faceSet::typeName));
forAllConstIter(IOobjectList, fSets, iter)
forAllConstIters(fSets, iter)
{
faceSets.append(new faceSet(*iter()));
}
}
{
IOobjectList pSets(objects.lookupClass(pointSet::typeName));
forAllConstIter(IOobjectList, pSets, iter)
forAllConstIters(pSets, iter)
{
pointSets.append(new pointSet(*iter()));
}
......
......@@ -52,7 +52,7 @@ void Foam::lagrangianFieldDecomposer::readFields
);
label lagrangianFieldi = 0;
forAllIter(IOobjectList, lagrangianTypeObjects, iter)
forAllConstIters(lagrangianTypeObjects, iter)
{
lagrangianFields[cloudI].set
(
......@@ -97,7 +97,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
label lagrangianFieldi = 0;
forAllIter(IOobjectList, lagrangianTypeObjectsA, iter)
forAllConstIters(lagrangianTypeObjectsA, iter)
{
lagrangianFields[cloudI].set
(
......@@ -106,7 +106,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields
);
}
forAllIter(IOobjectList, lagrangianTypeObjectsB, iter)
forAllConstIters(lagrangianTypeObjectsB, iter)
{
lagrangianFields[cloudI].set
(
......@@ -129,22 +129,19 @@ Foam::lagrangianFieldDecomposer::decomposeField
Field<Type> procField(field, particleIndices_);
// Create the field for the processor
return tmp<IOField<Type>>
return tmp<IOField<Type>>::New
(
new IOField<Type>
IOobject
(
IOobject
(
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
procField
)
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
procField
);
}
......@@ -161,22 +158,19 @@ Foam::lagrangianFieldDecomposer::decomposeFieldField
Field<Field<Type>> procField(field, particleIndices_);
// Create the field for the processor
return tmp<CompactIOField<Field<Type>, Type>>
return tmp<CompactIOField<Field<Type>, Type>>::New
(
new CompactIOField<Field<Type>, Type>
IOobject
(
IOobject
(
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
procField
)
field.name(),
procMesh_.time().timeName(),
cloud::prefix/cloudName,
procMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
procField
);
}
......
......@@ -39,14 +39,14 @@ void Foam::readFields
{
typedef GeometricField<Type, PatchField, GeoMesh> GeoField;
// Search list of objects for fields of type GeomField
// Search list of objects for fields of type GeoField
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Remove the cellDist field
IOobjectList::iterator celDistIter = fieldObjects.find("cellDist");
if (celDistIter != fieldObjects.end())
auto iter = fieldObjects.find("cellDist");
if (iter.found())
{
fieldObjects.erase(celDistIter);
fieldObjects.erase(iter);
}
// Get sorted set of names (different processors might read objects in
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2016-2017 Wikki Ltd
......@@ -273,23 +273,20 @@ Foam::faFieldReconstructor::reconstructFaAreaField
// Now construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, faPatchField, areaMesh>>
return tmp<GeometricField<Type, faPatchField, areaMesh>>::New
(
new GeometricField<Type, faPatchField, areaMesh>
IOobject
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
}
......@@ -553,23 +550,20 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
// Now construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, faePatchField, edgeMesh>>
return tmp<GeometricField<Type, faePatchField, edgeMesh>>::New
(
new GeometricField<Type, faePatchField, edgeMesh>
IOobject
(
IOobject
(
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject.name(),
mesh_.time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
}
......@@ -581,31 +575,26 @@ void Foam::faFieldReconstructor::reconstructFaAreaFields
const IOobjectList& objects
)
{
const word& fieldClassName =
const word& clsName =
GeometricField<Type, faPatchField, areaMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames = objects.sortedNames(clsName);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
for
(
IOobjectList::const_iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
Info << " " << fieldIter()->name() << endl;
reconstructFaAreaField<Type>(*fieldIter())().write();
}
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
Info<< endl;
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
reconstructFaAreaField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
}
// Reconstruct and write all edge fields
template<class Type>
void Foam::faFieldReconstructor::reconstructFaEdgeFields
......@@ -613,29 +602,24 @@ void Foam::faFieldReconstructor::reconstructFaEdgeFields
const IOobjectList& objects
)
{
const word& fieldClassName =
const word& clsName =
GeometricField<Type, faePatchField, edgeMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames = objects.sortedNames(clsName);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
for
(
IOobjectList::const_iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
reconstructFaEdgeField<Type>(*fieldIter())().write();
}
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
Info<< endl;
reconstructFaEdgeField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
}
......
......@@ -780,18 +780,18 @@ int main(int argc, char *argv[])
);
IOobjectList cSets(objects.lookupClass(cellSet::typeName));
forAllConstIter(IOobjectList, cSets, iter)
forAllConstIters(cSets, iter)
{
cSetNames.insert(iter.key(), cSetNames.size());
}
IOobjectList fSets(objects.lookupClass(faceSet::typeName));
forAllConstIter(IOobjectList, fSets, iter)
forAllConstIters(fSets, iter)
{
fSetNames.insert(iter.key(), fSetNames.size());
}
IOobjectList pSets(objects.lookupClass(pointSet::typeName));
forAllConstIter(IOobjectList, pSets, iter)
forAllConstIters(pSets, iter)
{
pSetNames.insert(iter.key(), pSetNames.size());
}
......@@ -842,7 +842,7 @@ int main(int argc, char *argv[])
objects.lookupClass(cellSet::typeName)
);
forAllConstIter(IOobjectList, cSets, iter)
forAllConstIters(cSets, iter)
{
// Load cellSet
const cellSet procSet(*iter());
......@@ -878,7 +878,7 @@ int main(int argc, char *argv[])
objects.lookupClass(faceSet::typeName)
);
forAllConstIter(IOobjectList, fSets, iter)
forAllConstIters(fSets, iter)
{
// Load faceSet
const faceSet procSet(*iter());
......@@ -912,7 +912,7 @@ int main(int argc, char *argv[])
(
objects.lookupClass(pointSet::typeName)
);
forAllConstIter(IOobjectList, pSets, iter)
forAllConstIters(pSets, iter)
{
// Load pointSet
const pointSet propSet(*iter());
......
......@@ -159,7 +159,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
if (!haveMesh)
{
bool oldParRun = Pstream::parRun();
const bool oldParRun = Pstream::parRun();
Pstream::parRun() = false;
......@@ -383,17 +383,17 @@ Foam::autoPtr<Foam::fvMesh> Foam::loadOrCreateMesh
if (!haveMesh)
{
forAll(pointSetNames, i)
for (const word& setName : pointSetNames)
{
pointSet(mesh, pointSetNames[i], 0).write();
pointSet(mesh, setName, 0).write();
}
forAll(faceSetNames, i)
for (const word& setName : faceSetNames)
{
faceSet(mesh, faceSetNames[i], 0).write();
faceSet(mesh, setName, 0).write();
}
forAll(cellSetNames, i)
for (const word& setName : cellSetNames)
{
cellSet(mesh, cellSetNames[i], 0).write();
cellSet(mesh, setName, 0).write();
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -66,15 +66,12 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField
IOobject::NO_WRITE
);
tmp<DimensionedField<Type, volMesh>> tfield
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
new DimensionedField<Type, volMesh>
(
baseIO,
baseMesh_,
fld.dimensions(),
internalField
)
baseIO,
baseMesh_,
fld.dimensions(),
internalField
);
tfield.ref().oriented() = fld.oriented();
......@@ -213,16 +210,13 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField
IOobject::NO_WRITE
);
tmp<GeometricField<Type, fvPatchField, volMesh>> tfield
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
new GeometricField<Type, fvPatchField, volMesh>
(
baseIO,
baseMesh_,
fld.dimensions(),
internalField,
basePatchFields
)
baseIO,
baseMesh_,
fld.dimensions(),
internalField,
basePatchFields
);