diff --git a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C index 23bd20e1bac30b1e9ddee732bc754603b53a1027..aac00fb6fb6a4eaa636ac4c58771cb39e98cbef1 100644 --- a/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C +++ b/applications/utilities/mesh/manipulation/rotateMesh/rotateMesh.C @@ -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; diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index fe8df713060bed7f1996c94914520a6ad05ef7c1..8ee08159bee290130a006bebdc0734b01b21923e 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -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; } } diff --git a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C index a737e50c1fbf4566877f3f39ed884c5926e0beb2..c3f44f961baa802e78c98f726943c6ec289c5d3e 100644 --- a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C +++ b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C @@ -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())) { diff --git a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C index 07fa8786ea81b260c8f56639b81af5a881d8cd4e..ec87e0b02d8f5d8be09898ce60cbd4cc08be8218 100644 --- a/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C +++ b/applications/utilities/mesh/manipulation/subsetMesh/subsetMesh.C @@ -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) diff --git a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C index 7f33b0fbf3a09c1932310e1c2cfd1301652743bb..561a00bde75bf4899147cf53419fcef96cbd727a 100644 --- a/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C +++ b/applications/utilities/miscellaneous/foamFormatConvert/foamFormatConvert.C @@ -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(); diff --git a/applications/utilities/miscellaneous/patchSummary/patchSummary.C b/applications/utilities/miscellaneous/patchSummary/patchSummary.C index d07ef482b9a286294aa110490a682dfddebd9bf6..c843ce59c1a904b3dfcd86341c966299bb867b1c 100644 --- a/applications/utilities/miscellaneous/patchSummary/patchSummary.C +++ b/applications/utilities/miscellaneous/patchSummary/patchSummary.C @@ -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()); diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C index 185a8bbbd5fc7e27fda4279c6cf72e1245f4bd36..3576fd340446029a844f77b366cc022b87c91ada 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecomposition.C @@ -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())); } diff --git a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C index 3528dfd5d3496599532d79a9a6b5255be1d75f53..22b8129d2d65d37d60feef1d627f53233b37cfc5 100644 --- a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C +++ b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C @@ -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 ); } diff --git a/applications/utilities/parallelProcessing/decomposePar/readFields.C b/applications/utilities/parallelProcessing/decomposePar/readFields.C index 046510635728e03386b3c634044f0d308e503290..7d6d3915da5ef8b68902acfefdbcbcc61fa69368 100644 --- a/applications/utilities/parallelProcessing/decomposePar/readFields.C +++ b/applications/utilities/parallelProcessing/decomposePar/readFields.C @@ -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 diff --git a/applications/utilities/parallelProcessing/reconstructPar/faFieldReconstructorReconstructFields.C b/applications/utilities/parallelProcessing/reconstructPar/faFieldReconstructorReconstructFields.C index 0b8f943e29dd7e8345e8e33e1b571d2ab05447a8..053aa3a3294a19dcf89dc5cc743f029751d2d608 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/faFieldReconstructorReconstructFields.C +++ b/applications/utilities/parallelProcessing/reconstructPar/faFieldReconstructorReconstructFields.C @@ -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; } diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 8a6c49fee7b4c2fb687742cd4e4d6d2f9cb7371a..b47fad7758134105add5aa3284183ddfa60b5791 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -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()); diff --git a/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C b/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C index e99ed3e7c3b95a137c41ae61537fe14260f0781a..7103a44f945d8f13647847ec6b5c062c23c2e708 100644 --- a/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C +++ b/applications/utilities/parallelProcessing/redistributePar/loadOrCreateMesh.C @@ -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(); } } diff --git a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C b/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C index 4ea05d956a82de739fef55f1d87c9d830563fc92..b1cc417c2b23f3a9f01789f114b394873e242eb5 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parFvFieldReconstructorReconstructFields.C @@ -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 ); tfield.ref().oriented()= fld.oriented(); @@ -380,16 +374,13 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField IOobject::NO_WRITE ); - tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield + auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New ( - new GeometricField<Type, fvsPatchField, surfaceMesh> - ( - baseIO, - baseMesh_, - fld.dimensions(), - internalField, - basePatchFields - ) + baseIO, + baseMesh_, + fld.dimensions(), + internalField, + basePatchFields ); tfield.ref().oriented() = fld.oriented(); @@ -423,37 +414,37 @@ void Foam::parFvFieldReconstructor::reconstructFvVolumeInternalFields const wordHashSet& selectedFields ) const { - const word& fieldClassName = DimensionedField<Type, volMesh>::typeName; + typedef DimensionedField<Type, volMesh> FieldType; + const word& clsName = FieldType::typeName; + + // Available fields, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - IOobjectList fields = objects.lookupClass(fieldClassName); + if (fieldNames.size()) + { + Info<< " Reconstructing " << clsName << "s\n" << endl; + } - if (fields.size()) + for (const word& fieldName : fieldNames) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " " << fieldName << endl; - forAllConstIter(IOobjectList, fields, fieldIter) + tmp<FieldType> tfld + ( + reconstructFvVolumeInternalField<Type>(*(objects[fieldName])) + ); + if (isWriteProc_) { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; - - tmp<DimensionedField<Type, volMesh>> tfld - ( - reconstructFvVolumeInternalField<Type>(*fieldIter()) - ); - - if (isWriteProc_) - { - tfld().write(); - } - } + tfld().write(); } - Info<< endl; } + + if (fieldNames.size()) Info<< endl; } @@ -464,39 +455,41 @@ void Foam::parFvFieldReconstructor::reconstructFvVolumeFields const wordHashSet& selectedFields ) const { - const word& fieldClassName = - GeometricField<Type, fvPatchField, volMesh>::typeName; + typedef GeometricField<Type, fvPatchField, volMesh> FieldType; + const word& clsName = FieldType::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + // Available fields, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " Reconstructing " << clsName << "s\n" << endl; + } - forAllConstIter(IOobjectList, fields, fieldIter) + for (const word& fieldName : fieldNames) + { + if ("cellDist" == fieldName) { - const word& name = fieldIter()->name(); - - if - ( - (selectedFields.empty() || selectedFields.found(name)) - && name != "cellDist" - ) - { - Info<< " " << name << endl; + continue; + } + Info<< " " << fieldName << endl; - tmp<GeometricField<Type, fvPatchField, volMesh>> tfld - ( - reconstructFvVolumeField<Type>(*fieldIter()) - ); - if (isWriteProc_) - { - tfld().write(); - } - } + tmp<FieldType> tfld + ( + reconstructFvVolumeField<Type>(*(objects[fieldName])) + ); + if (isWriteProc_) + { + tfld().write(); } - Info<< endl; } + + if (fieldNames.size()) Info<< endl; } @@ -507,37 +500,37 @@ void Foam::parFvFieldReconstructor::reconstructFvSurfaceFields const wordHashSet& selectedFields ) const { - const word& fieldClassName = - GeometricField<Type, fvsPatchField, surfaceMesh>::typeName; + typedef GeometricField<Type, fvsPatchField, surfaceMesh> FieldType; + const word& clsName = FieldType::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + // Available fields, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " Reconstructing " << clsName << "s\n" << endl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfld - ( - reconstructFvSurfaceField<Type>(*fieldIter()) - ); - if (isWriteProc_) - { - tfld().write(); - } - } + tmp<FieldType> tfld + ( + reconstructFvSurfaceField<Type>(*(objects[fieldName])) + ); + if (isWriteProc_) + { + tfld().write(); } - Info<< endl; } + + if (fieldNames.size()) Info<< endl; } diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorRedistributeFields.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorRedistributeFields.C index b2650ce1f39cb6cc0927576331c0f6b2502206f4..f1817c30e17f4e76e9cfb0c09a45b47b88a003a6 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorRedistributeFields.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianRedistributorRedistributeFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,25 +40,20 @@ Foam::wordList Foam::parLagrangianRedistributor::filterObjects const wordHashSet& selectedFields ) { - const word fieldClassName(Container::typeName); - // Parallel synchronise - wordList fieldNames(objects.names(fieldClassName)); + wordList fieldNames = + ( + selectedFields.empty() + ? objects.names(Container::typeName) + : objects.names(Container::typeName, selectedFields) + ); + Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>()); Pstream::combineScatter(fieldNames); - if (!selectedFields.empty()) - { - DynamicList<word> selectedNames(fieldNames.size()); - forAll(fieldNames, i) - { - if (selectedFields.found(fieldNames[i])) - { - selectedNames.append(fieldNames[i]); - } - } - fieldNames.transfer(selectedNames); - } + // Ensure order is consistent + Foam::sort(fieldNames); + return fieldNames; } @@ -72,6 +67,8 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields const wordHashSet& selectedFields ) const { + const word fieldClassName(IOField<Type>::typeName); + const wordList objectNames ( filterObjects<IOField<Type>> @@ -83,55 +80,53 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields if (objectNames.size()) { - const word fieldClassName(IOField<Type>::typeName); - Info<< " Redistributing lagrangian " << fieldClassName << "s\n" << endl; + } - forAll(objectNames, i) - { - Info<< " " << objectNames[i] << endl; + for (const word& objectName : objectNames) + { + Info<< " " << objectName << endl; - // Read if present - IOField<Type> field + // Read if present + IOField<Type> field + ( + IOobject + ( + objectName, + srcMesh_.time().timeName(), + cloud::prefix/cloudName, + srcMesh_, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ), + label(0) + ); + + map.distribute(field); + + + if (field.size()) + { + IOField<Type> ( IOobject ( - objectNames[i], - srcMesh_.time().timeName(), + objectName, + tgtMesh_.time().timeName(), cloud::prefix/cloudName, - srcMesh_, - IOobject::READ_IF_PRESENT, + tgtMesh_, + IOobject::NO_READ, IOobject::NO_WRITE, false ), - label(0) - ); - - map.distribute(field); - - - if (field.size()) - { - IOField<Type> - ( - IOobject - ( - objectNames[i], - tgtMesh_.time().timeName(), - cloud::prefix/cloudName, - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - std::move(field) - ).write(); - } + std::move(field) + ).write(); } - - Info<< endl; } + + if (objectNames.size()) Info<< endl; } @@ -144,6 +139,8 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields const wordHashSet& selectedFields ) const { + const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName); + wordList objectNames ( filterObjects<CompactIOField<Field<Type>, Type>> @@ -153,9 +150,9 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields ) ); - // Append IOField names + // Append IOField Field names { - const wordList ioFieldNames + wordList ioFieldNames ( filterObjects<IOField<Field<Type>>> ( @@ -169,52 +166,50 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields if (objectNames.size()) { - const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName); - Info<< " Redistributing lagrangian " << fieldClassName << "s\n" << endl; + } - forAll(objectNames, i) - { - Info<< " " << objectNames[i] << endl; + for (const word& objectName : objectNames) + { + Info<< " " << objectName << endl; - // Read if present - CompactIOField<Field<Type>, Type> field + // Read if present + CompactIOField<Field<Type>, Type> field + ( + IOobject + ( + objectName, + srcMesh_.time().timeName(), + cloud::prefix/cloudName, + srcMesh_, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ), + label(0) + ); + + // Distribute + map.distribute(field); + + // Write + if (field.size()) + { + CompactIOField<Field<Type>, Type> ( IOobject ( - objectNames[i], - srcMesh_.time().timeName(), + objectName, + tgtMesh_.time().timeName(), cloud::prefix/cloudName, - srcMesh_, - IOobject::READ_IF_PRESENT, + tgtMesh_, + IOobject::NO_READ, IOobject::NO_WRITE, false ), - label(0) - ); - - // Distribute - map.distribute(field); - - // Write - if (field.size()) - { - CompactIOField<Field<Type>, Type> - ( - IOobject - ( - objectNames[i], - tgtMesh_.time().timeName(), - cloud::prefix/cloudName, - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - std::move(field) - ).write(); - } + std::move(field) + ).write(); } } } @@ -228,6 +223,8 @@ void Foam::parLagrangianRedistributor::readLagrangianFields const wordHashSet& selectedFields ) { + const word fieldClassName(Container::typeName); + const wordList objectNames ( filterObjects<Container> @@ -239,31 +236,29 @@ void Foam::parLagrangianRedistributor::readLagrangianFields if (objectNames.size()) { - const word fieldClassName(Container::typeName); - Info<< " Reading lagrangian " << fieldClassName << "s\n" << endl; + } - forAll(objectNames, i) - { - Info<< " " << objectNames[i] << endl; + for (const word& objectName : objectNames) + { + Info<< " " << objectName << endl; - // Read if present - Container* fieldPtr = new Container + // Read if present + Container* fieldPtr = new Container + ( + IOobject ( - IOobject - ( - objectNames[i], - cloud.time().timeName(), - cloud, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE - ), - label(0) - ); + objectName, + cloud.time().timeName(), + cloud, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + label(0) + ); - fieldPtr->store(); - } + fieldPtr->store(); } } @@ -275,6 +270,8 @@ void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields passivePositionParticleCloud& cloud ) const { + const word fieldClassName(Container::typeName); + HashTable<Container*> fields ( cloud.lookupClass<Container>() @@ -282,36 +279,34 @@ void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields if (fields.size()) { - const word fieldClassName(Container::typeName); - Info<< " Redistributing lagrangian " << fieldClassName << "s\n" << endl; + } - forAllIter(typename HashTable<Container*>, fields, iter) - { - Container& field = *iter(); + forAllIters(fields, iter) + { + Container& field = *(*iter); - Info<< " " << field.name() << endl; + Info<< " " << field.name() << endl; - map.distribute(field); + map.distribute(field); - if (field.size()) - { - Container + if (field.size()) + { + Container + ( + IOobject ( - IOobject - ( - field.name(), - tgtMesh_.time().timeName(), - cloud::prefix/cloud.name(), - tgtMesh_, - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - std::move(field) - ).write(); - } + field.name(), + tgtMesh_.time().timeName(), + cloud::prefix/cloud.name(), + tgtMesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + std::move(field) + ).write(); } } } diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 07c493473b82b52fc0245f8bcefd8c258ab102b2..671460068e6a318398a3de7b3de47ac9f157b89a 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -636,11 +636,11 @@ void readFields if (haveMesh[Pstream::myProcNo()] && objectNames != masterNames) { FatalErrorInFunction - << "differing fields of type " << GeoField::typeName - << " on processors." << nl - << "Master has:" << masterNames << endl - << Pstream::myProcNo() << " has:" << objectNames - << abort(FatalError); + << "Objects not synchronised across processors." << nl + << "Master has " << flatOutput(masterNames) << nl + << "Processor " << Pstream::myProcNo() + << " has " << flatOutput(objectNames) + << exit(FatalError); } fields.setSize(masterNames.size()); diff --git a/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C b/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C index f079ccc3e92846fbbfcbbdcb148a37a31a075757..448964a78533fcff8cea8f427ee1c462380ac9f7 100644 --- a/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C +++ b/applications/utilities/postProcessing/dataConversion/foamDataToFluent/foamDataToFluent.C @@ -109,51 +109,49 @@ int main(int argc, char *argv[]) IOobjectList objects(mesh, runTime.timeName()); - // Converting volScalarField - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - // Search list of objects for volScalarFields - IOobjectList scalarFields(objects.lookupClass("volScalarField")); - - forAllIter(IOobjectList, scalarFields, iter) + // volScalarField + for + ( + const word& fieldName + : objects.sortedNames(volScalarField::typeName) + ) { - // Read field - volScalarField field(*iter(), mesh); - - // lookup field from dictionary and convert field + // Lookup field from dictionary and convert field label unitNumber; if ( - foamDataToFluentDict.readIfPresent(field.name(), unitNumber) + foamDataToFluentDict.readIfPresent(fieldName, unitNumber) && unitNumber > 0 ) { - Info<< " Converting field " << field.name() << endl; + // Read field + volScalarField field(*(objects[fieldName]), mesh); + + Info<< " Converting field " << fieldName << nl; writeFluentField(field, unitNumber, fluentDataFile); } } - // Converting volVectorField - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - // Search list of objects for volVectorFields - IOobjectList vectorFields(objects.lookupClass("volVectorField")); - - forAllIter(IOobjectList, vectorFields, iter) + // volVectorField + for + ( + const word& fieldName + : objects.sortedNames(volVectorField::typeName) + ) { - // Read field - volVectorField field(*iter(), mesh); - - // lookup field from dictionary and convert field + // Lookup field from dictionary and convert field label unitNumber; if ( - foamDataToFluentDict.readIfPresent(field.name(), unitNumber) + foamDataToFluentDict.readIfPresent(fieldName, unitNumber) && unitNumber > 0 ) { - Info<< " Converting field " << field.name() << endl; + // Read field + volVectorField field(*(objects[fieldName]), mesh); + + Info<< " Converting field " << fieldName << nl; writeFluentField(field, unitNumber, fluentDataFile); } } diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 3e6012716e51ecd73e04f20ceaf613a0755f0f11..7c293bd815a11cf54da9ec40d70571d29f31dc78 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -316,7 +316,7 @@ int main(int argc, char *argv[]) // and doesn't cost much) and simultaneously remove all // "*_0" restart fields - for (auto fieldType : volFieldTypes) + for (const word& fieldType : volFieldTypes) { usableObjects ( @@ -360,7 +360,7 @@ int main(int argc, char *argv[]) // ~~~~~~~~~~~~~~~~~~~~~~ Info<< "Write volume field ("; - for (auto fieldType : volFieldTypes) + for (const word& fieldType : volFieldTypes) { // For convenience, just force each field-type into existence. // This simplifies code logic and doesn't cost much at all. diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H index 1a98fcd52e84d745b670efa557e003e83f0935e7..81559c69f1a2a36ccb452479e3570dfce0c4971d 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H @@ -13,7 +13,7 @@ if (timeDirs.size()) IOobjectList objs(mesh, lastTimeName); - forAllConstIter(IOobjectList, objs, fieldIter) + forAllConstIters(objs, fieldIter) { const IOobject& obj = *fieldIter(); const word& fieldName = obj.name(); diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C b/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C index 78ece90dc04b2551f783515da71d61c65ba436f7..a03b16e674bd610949cd0dd33ccda63e3b2684e6 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/foamToGMV.C @@ -49,13 +49,13 @@ Description int main(int argc, char *argv[]) { const label nTypes = 4; - const word fieldTypes[] = - { + const wordList fieldTypes + ({ "volScalarField", "volVectorField", "surfaceScalarField", cloud::prefix - }; + }); #include "setRootCase.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H index a51474d4bebca85baf1e2e582ba7feeff30f104b..e4db7e1313cd454c5e7291905221be11e977f040 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutput.H @@ -1,16 +1,14 @@ -for (label i=0; i < nTypes; i++) +for (const word& fieldType : fieldTypes) { - wordList fieldNames = objects.names(fieldTypes[i]); + const wordList fieldNames = objects.sortedNames(fieldType); - if (fieldTypes[i] == "volScalarField") + if (fieldType == "volScalarField") { gmvFile << "variable" << nl; } - forAll(fieldNames, j) + for (const word& fieldName : fieldNames) { - const word& fieldName = fieldNames[j]; - IOobject fieldObject ( fieldName, @@ -20,18 +18,18 @@ for (label i=0; i < nTypes; i++) IOobject::NO_WRITE ); - if (fieldTypes[i] == "volScalarField") + if (fieldType == "volScalarField") { volScalarField fld(fieldObject, mesh); gmvFile << fieldName << " 0" << nl; - for (label indx=0;indx<mesh.nCells();indx++) + for (label indx=0; indx<mesh.nCells(); ++indx) { gmvFile << fld[indx] << " "; } gmvFile << nl; } - if (fieldTypes[i] == "volVectorField") + if (fieldType == "volVectorField") { if (fieldName == vComp) { @@ -53,14 +51,14 @@ for (label i=0; i < nTypes; i++) } } - if (fieldTypes[i] == "surfaceScalarField") + if (fieldType == "surfaceScalarField") { // ... } } - if (fieldTypes[i] == cloud::prefix) + if (fieldType == cloud::prefix) { IOobject positionsHeader ( @@ -96,8 +94,8 @@ for (label i=0; i < nTypes; i++) IOobjectList objects(mesh, runTime.timeName(), cloud::prefix); - wordList lagrangianScalarNames = objects.names("scalarField"); - wordList lagrangianVectorNames = objects.names("vectorField"); + wordList lagrangianScalarNames(objects.sortedNames("scalarField")); + wordList lagrangianVectorNames(objects.sortedNames("vectorField")); if (particles.size()) { @@ -106,7 +104,7 @@ for (label i=0; i < nTypes; i++) } } - if (fieldTypes[i] == "volScalarField") + if (fieldType == "volScalarField") { gmvFile << "endvars" << nl; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H index 3d7c4827a026d35d8d4aca8d930b36a8dfb88e81..9ded6f7c7155e86e480e630416b7b4eaa0ea36cf 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H +++ b/applications/utilities/postProcessing/dataConversion/foamToGMV/gmvOutputLagrangian.H @@ -17,10 +17,8 @@ forAllConstIter(Cloud<passiveParticle>, particles, iter) } gmvFile << nl; -forAll(lagrangianScalarNames, i) +for (const word& name : lagrangianScalarNames) { - const word& name = lagrangianScalarNames[i]; - IOField<scalar> fld ( IOobject @@ -48,10 +46,8 @@ forAll(lagrangianScalarNames, i) } -forAll(lagrangianVectorNames, i) +for (const word& name : lagrangianVectorNames) { - const word& name = lagrangianVectorNames[i]; - IOField<vector> fld ( IOobject diff --git a/applications/utilities/postProcessing/dataConversion/foamToTetDualMesh/foamToTetDualMesh.C b/applications/utilities/postProcessing/dataConversion/foamToTetDualMesh/foamToTetDualMesh.C index 0af1e031fea17224fb1605055c2e7da69067e260..295e34c98e480311ee9c26fa989a148a80a09269 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToTetDualMesh/foamToTetDualMesh.C +++ b/applications/utilities/postProcessing/dataConversion/foamToTetDualMesh/foamToTetDualMesh.C @@ -62,7 +62,7 @@ void ReadAndMapFields tetFields.setSize(fieldObjects.size()); label i = 0; - forAllConstIter(IOobjectList, fieldObjects, iter) + forAllConstIters(fieldObjects, iter) { Info<< "Converting " << ReadGeoField::typeName << ' ' << iter.key() << endl; @@ -138,8 +138,6 @@ void ReadAndMapFields } - - int main(int argc, char *argv[]) { #include "addOverwriteOption.H" @@ -152,7 +150,6 @@ int main(int argc, char *argv[]) #include "checkTimeOptions.H" runTime.setTime(Times[startTime], startTime); - // Read the mesh #include "createNamedMesh.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C index a2495f3c577aece2ed603b486e169a92cc0bdbec..d67d0b1602ae3dc5a2e60a22544db1bd19bdf813 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.C @@ -24,7 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "readFields.H" -#include "IOobjectList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -43,37 +42,37 @@ label readFields PtrList<const GeoField>& fields ) { - label nFields = 0; + // Available fields of type GeoField, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(GeoField::typeName) + : objects.sortedNames(GeoField::typeName, selectedFields) + ); - // Available fields of type GeomField - const wordList fieldNames = objects.sortedNames(GeoField::typeName); + // Construct the fields + fields.resize(fieldNames.size()); - fields.setSize(fieldNames.size()); + label nFields = 0; - // Construct the fields for (const word& fieldName : fieldNames) { - if (selectedFields.empty() || selectedFields.found(fieldName)) - { - fields.set + fields.set + ( + nFields++, + proxy.interpolate ( - nFields++, - proxy.interpolate - ( - GeoField(*(objects[fieldName]), mesh) - ).ptr() - ); - } + GeoField(*(objects[fieldName]), mesh) + ).ptr() + ); } - fields.setSize(nFields); - return nFields; } template<class GeoField> -void readFields +label readFields ( const typename GeoField::Mesh& mesh, const IOobjectList& objects, @@ -81,26 +80,29 @@ void readFields PtrList<const GeoField>& fields ) { - // Search list of objects for fields of type GeomField - IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); + // Available fields of type GeoField, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(GeoField::typeName) + : objects.sortedNames(GeoField::typeName, selectedFields) + ); // Construct the fields - fields.setSize(fieldObjects.size()); + fields.resize(fieldNames.size()); + label nFields = 0; - forAllIters(fieldObjects, iter) + for (const word& fieldName : fieldNames) { - if (selectedFields.empty() || selectedFields.found(iter()->name())) - { - fields.set - ( - nFields++, - new GeoField(*iter(), mesh) - ); - } + fields.set + ( + nFields++, + new GeoField(*(objects[fieldName]), mesh) + ); } - fields.setSize(nFields); + return nFields; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H index 6cff9cbae1348ee190da45b3ff05ca4d510532d9..672994d8ccfd961f35414ba54c5ef3bf279c6e7b 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/readFields.H @@ -35,16 +35,16 @@ SourceFiles #define readFields_H #include "fvMeshSubsetProxy.H" +#include "HashSet.H" #include "PtrList.H" #include "IOobjectList.H" -#include "HashSet.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Read the fields, optionally subset, and place on the pointer list +//- Read the fields, optionally subset, and place on the pointer list template<class GeoField> label readFields ( @@ -55,6 +55,18 @@ label readFields PtrList<const GeoField>& fields ); + +//- Read the fields, and place on the pointer list +template<class GeoField> +label readFields +( + const typename GeoField::Mesh& mesh, + const IOobjectList& objects, + const wordHashSet& selectedFields, + PtrList<const GeoField>& fields +); + + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C index a51295b3bf34da446039b83b995d71d740812c56..88ed5f9574eae71258acee24dc8c917af1fdb0d7 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoamFields.C @@ -194,7 +194,6 @@ void Foam::vtkPVFoam::convertAreaFields() // Get objects (fields) for this time - only keep selected fields // the region name is already in the mesh db IOobjectList objects(mesh.mesh(), dbPtr_().timeName()); - objects.filterKeys(selectedFields); if (objects.empty()) diff --git a/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C index 3a1f585c63dc24ae4dcee8d87a4d9dc226dbfd04..78705ec520fe8eebacb4dbd15dbc8948f0b287ad 100644 --- a/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C +++ b/applications/utilities/postProcessing/miscellaneous/temporalInterpolate/temporalInterpolate.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,7 +53,7 @@ class fieldInterpolator Time& runTime_; const fvMesh& mesh_; const IOobjectList& objects_; - const wordHashSet& selectedFields_; + const wordRes& selectedFields_; instant ti_; instant ti1_; const interpolationWeights& interpolator_; @@ -67,7 +67,7 @@ public: Time& runTime, const fvMesh& mesh, const IOobjectList& objects, - const wordHashSet& selectedFields, + const wordRes& selectedFields, const instant& ti, const instant& ti1, const interpolationWeights& interpolator, @@ -94,95 +94,93 @@ public: template<class GeoFieldType> void fieldInterpolator::interpolate() { - const word& fieldClassName = GeoFieldType::typeName; + const word& clsName = GeoFieldType::typeName; - IOobjectList fields = objects_.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields_.empty() + ? objects_.sortedNames(clsName) + : objects_.sortedNames(clsName, selectedFields_) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " " << fieldClassName << "s:"; + Info<< " " << clsName << 's'; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields_.empty() - || selectedFields_.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << '('; + for (const word& fieldName : fieldNames) + { + Info<< ' ' << fieldName << '('; - scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1); + const scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1); - for (int j=0; j<divisions_; j++) - { - instant timej = instant(ti_.value() + (j + 1)*deltaT); + for (int j=0; j<divisions_; j++) + { + instant timej = instant(ti_.value() + (j + 1)*deltaT); - runTime_.setTime(instant(timej.name()), 0); + runTime_.setTime(instant(timej.name()), 0); - Info<< timej.name(); + Info<< timej.name(); - if (j < divisions_-1) - { - Info<< " "; - } + if (j < divisions_-1) + { + Info<< " "; + } - // Calculate times to read and weights - labelList indices; - scalarField weights; - interpolator_.valueWeights - ( - runTime_.value(), - indices, - weights - ); + // Calculate times to read and weights + labelList indices; + scalarField weights; + interpolator_.valueWeights + ( + runTime_.value(), + indices, + weights + ); - const wordList selectedTimeNames - ( - UIndirectList<word>(timeNames_, indices)() - ); + const wordList selectedTimeNames + ( + UIndirectList<word>(timeNames_, indices)() + ); - //Info<< "For time " << runTime_.value() - // << " need times " << selectedTimeNames - // << " need weights " << weights << endl; + //Info<< "For time " << runTime_.value() + // << " need times " << selectedTimeNames + // << " need weights " << weights << endl; - // Read on the objectRegistry all the required fields - ReadFields<GeoFieldType> - ( - fieldIter()->name(), - mesh_, - selectedTimeNames - ); + // Read on the objectRegistry all the required fields + ReadFields<GeoFieldType> + ( + fieldName, + mesh_, + selectedTimeNames + ); - GeoFieldType fieldj + GeoFieldType fieldj + ( + uniformInterpolate<GeoFieldType> + ( + IOobject ( - uniformInterpolate<GeoFieldType> - ( - IOobject - ( - fieldIter()->name(), - runTime_.timeName(), - fieldIter()->db(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - fieldIter()->name(), - selectedTimeNames, - weights - ) - ); - - fieldj.write(); - } - - Info<< ')'; - } + fieldName, + runTime_.timeName(), + objects_[fieldName]->db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + fieldName, + selectedTimeNames, + weights + ) + ); + + fieldj.write(); } - Info<< endl; + Info<< ')'; } + + if (fieldNames.size()) Info<< endl; } @@ -195,9 +193,9 @@ int main(int argc, char *argv[]) argList::addOption ( "fields", - "list", - "specify a list of fields to be interpolated. Eg, '(U T p)' - " - "regular expressions not currently supported" + "wordRes", + "the fields (or field) to be interpolated." + " Eg, '(U T p \"Y.*\")' or a single field 'U'" ); argList::addOption ( @@ -216,24 +214,22 @@ int main(int argc, char *argv[]) #include "createTime.H" runTime.functionObjects().off(); - wordHashSet selectedFields; - args.readIfPresent("fields", selectedFields); + wordRes selectedFields; + args.readListIfPresent<wordRe>("fields", selectedFields); - if (selectedFields.size()) + if (selectedFields.empty()) { - Info<< "Interpolating fields " << selectedFields << nl << endl; + Info<< "Interpolating all fields" << nl << endl; } else { - Info<< "Interpolating all fields" << nl << endl; + Info<< "Interpolating fields " << flatOutput(selectedFields) + << nl << endl; } int divisions = 1; - if (args.found("divisions")) - { - args.lookup("divisions")() >> divisions; - } + args.readIfPresent("divisions", divisions); Info<< "Using " << divisions << " per time interval" << nl << endl; diff --git a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C index 7cff152cd385ea64aaf8a52fd7646e0870f9e272..8cd4737b54421956d30caea485abacd8a56a280e 100644 --- a/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C +++ b/applications/utilities/preProcessing/foamUpgradeCyclics/foamUpgradeCyclics.C @@ -298,10 +298,10 @@ void rewriteField label nChanged = 0; - forAllConstIter(HashTable<word>, thisNames, iter) + forAllConstIters(thisNames, iter) { const word& patchName = iter.key(); - const word& newName = iter(); + const word& newName = iter.object(); Info<< "Looking for entry for patch " << patchName << endl; @@ -376,13 +376,13 @@ void rewriteFields const HashTable<word>& nbrNames ) { - forAll(fieldNames, i) + for (const word& fieldName : fieldNames) { rewriteField ( isTestRun, runTime, - fieldNames[i], + fieldName, thisNames, nbrNames ); diff --git a/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H b/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H index 9fda2c5705b391063eb0f3de0f45c3df746c07e3..df4bab0a404d3f10101df258277874e2c293734a 100644 --- a/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H +++ b/applications/utilities/preProcessing/mapFields/MapConsistentVolFields.H @@ -51,7 +51,7 @@ void MapConsistentVolFields IOobjectList fields = objects.lookupClass(fieldType::typeName); - forAllIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { Info<< " interpolating " << fieldIter()->name() << endl; diff --git a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H index 605f43090ae33a3273201c0bc264b63ff6d219ab..4c86816bc2f772e78ec28f2d8d10d2e58cb7c4db 100644 --- a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H +++ b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H @@ -60,7 +60,7 @@ void MapLagrangianFields { IOobjectList fields = objects.lookupClass(IOField<Type>::typeName); - forAllIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { Info<< " mapping lagrangian field " << fieldIter()->name() << endl; @@ -98,7 +98,7 @@ void MapLagrangianFields IOobjectList fieldFields = objects.lookupClass(IOField<Field<Type>>::typeName); - forAllIter(IOobjectList, fieldFields, fieldIter) + forAllConstIters(fieldFields, fieldIter) { Info<< " mapping lagrangian fieldField " << fieldIter()->name() << endl; @@ -137,7 +137,7 @@ void MapLagrangianFields IOobjectList fieldFields = objects.lookupClass(CompactIOField<Field<Type>, Type>::typeName); - forAllIter(IOobjectList, fieldFields, fieldIter) + forAllConstIters(fieldFields, fieldIter) { Info<< " mapping lagrangian fieldField " << fieldIter()->name() << endl; diff --git a/applications/utilities/preProcessing/mapFields/MapVolFields.H b/applications/utilities/preProcessing/mapFields/MapVolFields.H index 97aff73fff0c728d5414f558f60f82361c14f0ae..f0ed5bb051119499b26cf421a8c3f0d01532999e 100644 --- a/applications/utilities/preProcessing/mapFields/MapVolFields.H +++ b/applications/utilities/preProcessing/mapFields/MapVolFields.H @@ -51,7 +51,7 @@ void MapVolFields IOobjectList fields = objects.lookupClass(fieldType::typeName); - forAllIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { IOobject fieldTargetIOobject ( diff --git a/applications/utilities/preProcessing/mapFields/UnMapped.H b/applications/utilities/preProcessing/mapFields/UnMapped.H index bcbefb2bce04905e95f724c667690c1cfc1d9709..8a4b28d1fb2819ebdbf2ae415109d6976f74e277 100644 --- a/applications/utilities/preProcessing/mapFields/UnMapped.H +++ b/applications/utilities/preProcessing/mapFields/UnMapped.H @@ -39,7 +39,7 @@ void UnMapped(const IOobjectList& objects) { IOobjectList fields = objects.lookupClass(Type::typeName); - forAllConstIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { mvBak(fieldIter()->objectPath(), "unmapped"); } diff --git a/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H b/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H index 19656c12d7828189ad607c81b1798503ac317a97..9e75efae44bec56ef121b27cdc9aa4522479021d 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H +++ b/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H @@ -58,7 +58,7 @@ void MapLagrangianFields { IOobjectList fields = objects.lookupClass(IOField<Type>::typeName); - forAllIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { const word& fieldName = fieldIter()->name(); @@ -97,7 +97,7 @@ void MapLagrangianFields IOobjectList fieldFields = objects.lookupClass(IOField<Field<Type>>::typeName); - forAllIter(IOobjectList, fieldFields, fieldIter) + forAllConstIters(fieldFields, fieldIter) { const word& fieldName = fieldIter()->name(); @@ -149,7 +149,7 @@ void MapLagrangianFields IOobjectList fieldFields = objects.lookupClass(CompactIOField<Field<Type>, Type>::typeName); - forAllIter(IOobjectList, fieldFields, fieldIter) + forAllConstIters(fieldFields, fieldIter) { const word& fieldName = fieldIter()->name(); diff --git a/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H b/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H index 943cbb088cd2820957eb26872117ccd6ad4cf725..f57128bbd921a8a5b9df864cbf6bd97e7b515c13 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H +++ b/applications/utilities/preProcessing/mapFieldsPar/MapVolFields.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -131,52 +131,56 @@ void MapVolFields const fvMesh& meshSource = static_cast<const fvMesh&>(interp.srcRegion()); const fvMesh& meshTarget = static_cast<const fvMesh&>(interp.tgtRegion()); - IOobjectList fields = objects.lookupClass(fieldType::typeName); + // Available fields, sorted order + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(fieldType::typeName) + : objects.sortedNames(fieldType::typeName, selectedFields) + ); - forAllIter(IOobjectList, fields, fieldIter) + for (const word& fieldName : fieldNames) { - const word& fieldName = fieldIter()->name(); + const fieldType fieldSource(*(objects[fieldName]), meshSource); - if (selectedFields.empty() || selectedFields.found(fieldName)) - { - const fieldType fieldSource(*fieldIter(), meshSource); + IOobject targetIO + ( + fieldName, + meshTarget.time().timeName(), + meshTarget, + IOobject::MUST_READ + ); - IOobject targetIO - ( - fieldName, - meshTarget.time().timeName(), - meshTarget, - IOobject::MUST_READ - ); + if (targetIO.typeHeaderOk<fieldType>(true)) + { + Info<< " interpolating onto existing field " + << fieldName << endl; - if (targetIO.typeHeaderOk<fieldType>(true)) - { - Info<< " interpolating onto existing field " - << fieldName << endl; - fieldType fieldTarget(targetIO, meshTarget); + fieldType fieldTarget(targetIO, meshTarget); - interp.mapSrcToTgt(fieldSource, cop, fieldTarget); + interp.mapSrcToTgt(fieldSource, cop, fieldTarget); - evaluateConstraintTypes(fieldTarget); + evaluateConstraintTypes(fieldTarget); - fieldTarget.write(); - } - else - { - Info<< " creating new field " - << fieldName << endl; + fieldTarget.write(); + } + else + { + Info<< " creating new field " + << fieldName << endl; - targetIO.readOpt() = IOobject::NO_READ; + targetIO.readOpt() = IOobject::NO_READ; - tmp<fieldType> - tfieldTarget(interp.mapSrcToTgt(fieldSource, cop)); + tmp<fieldType> tfieldTarget + ( + interp.mapSrcToTgt(fieldSource, cop) + ); - fieldType fieldTarget(targetIO, tfieldTarget); + fieldType fieldTarget(targetIO, tfieldTarget); - evaluateConstraintTypes(fieldTarget); + evaluateConstraintTypes(fieldTarget); - fieldTarget.write(); - } + fieldTarget.write(); } } } diff --git a/applications/utilities/preProcessing/mapFieldsPar/UnMapped.H b/applications/utilities/preProcessing/mapFieldsPar/UnMapped.H index bcbefb2bce04905e95f724c667690c1cfc1d9709..8a4b28d1fb2819ebdbf2ae415109d6976f74e277 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/UnMapped.H +++ b/applications/utilities/preProcessing/mapFieldsPar/UnMapped.H @@ -39,7 +39,7 @@ void UnMapped(const IOobjectList& objects) { IOobjectList fields = objects.lookupClass(Type::typeName); - forAllConstIter(IOobjectList, fields, fieldIter) + forAllConstIters(fields, fieldIter) { mvBak(fieldIter()->objectPath(), "unmapped"); } diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 25ce355abba2d55349a58f33098760ef620c2ff9..b434376143f15511faa0eedfd77a4639787e7e00 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -690,8 +690,6 @@ $(derivedPointPatchFields)/codedFixedValue/codedFixedValuePointPatchFields.C fields/GeometricFields/pointFields/pointFields.C -fields/ReadFields/ReadFields.C - meshes/bandCompression/bandCompression.C meshes/preservePatchTypes/preservePatchTypes.C diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.C b/src/OpenFOAM/db/IOobjectList/IOobjectList.C index e8f77d9d0ee47fc8d4548c09685876abb662f3b3..c8147464dfa8ff01369b98b1154e28257ee8134d 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.C +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.C @@ -29,7 +29,7 @@ License #include "IOList.H" #include "predicates.H" -// * * * * * * * * * * * * * * Static Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // namespace Foam { @@ -45,18 +45,48 @@ namespace Foam forAllConstIters(list, iter) { - if (matcher(iter.key())) + const word& key = iter.key(); + const IOobject* io = iter.object(); + + if (matcher(key)) { if (IOobject::debug) { - InfoInFunction << "Found " << iter.key() << endl; + InfoInFunction << "Found " << key << endl; } - results.set - ( - iter.key(), - new IOobject(*(iter.object())) - ); + results.set(key, new IOobject(*io)); + } + } + + return results; + } + + + // Templated implementation for lookupClass() - file-scope + template<class UnaryMatchPredicate> + static IOobjectList lookupClassImpl + ( + const IOobjectList& list, + const word& clsName, + const UnaryMatchPredicate& matcher + ) + { + IOobjectList results(list.size()); + + forAllConstIters(list, iter) + { + const word& key = iter.key(); + const IOobject* io = iter.object(); + + if (clsName == io->headerClassName() && matcher(key)) + { + if (IOobject::debug) + { + InfoInFunction << "Found " << key << endl; + } + + results.set(key, new IOobject(*io)); } } @@ -77,10 +107,13 @@ namespace Foam // Summary (key,val) = (class-name, object-names) forAllConstIters(list, iter) { - if (matcher(iter.key())) + const word& key = iter.key(); + const IOobject* io = iter.object(); + + if (matcher(key)) { // Create entry (if needed) and insert - summary(iter.object()->headerClassName()).insert(iter.key()); + summary(io->headerClassName()).insert(key); } } @@ -103,13 +136,17 @@ namespace Foam label count = 0; forAllConstIters(list, iter) { - if (iter()->headerClassName() == clsName && matcher(iter.key())) + const word& key = iter.key(); + const IOobject* io = iter.object(); + + if (clsName == io->headerClassName() && matcher(key)) { - objNames[count++] = iter.key(); + objNames[count] = key; + ++count; } } - objNames.setSize(count); + objNames.resize(count); if (doSort) { @@ -118,7 +155,39 @@ namespace Foam return objNames; } -} + + + // With syncPar = true, check that object names are the same on + // all processors. Trigger FatalError if not. + // + // The object names are sorted as a side-effect, since this is + // required for consistent ordering across all processors. + static bool checkNames(wordList& masterNames, const bool syncPar) + { + Foam::sort(masterNames); + + if (syncPar && Pstream::parRun()) + { + const wordList localNames(masterNames); + Pstream::scatter(masterNames); + + if (localNames != masterNames) + { + FatalErrorInFunction + << "Objects not synchronised across processors." << nl + << "Master has " << flatOutput(masterNames) << nl + << "Processor " << Pstream::myProcNo() + << " has " << flatOutput(localNames) + << exit(FatalError); + + return false; + } + } + + return true; + } + +} // End namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -272,28 +341,15 @@ Foam::IOobjectList Foam::IOobjectList::lookup(const wordRes& matcher) const } -Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const +Foam::IOobjectList Foam::IOobjectList::lookup(const wordHashSet& matcher) const { - IOobjectList results(size()); - - forAllConstIters(*this, iter) - { - if (iter()->headerClassName() == clsName) - { - if (IOobject::debug) - { - InfoInFunction << "Found " << iter.key() << endl; - } + return lookupImpl(*this, matcher); +} - results.set - ( - iter.key(), - new IOobject(*(iter.object())) - ); - } - } - return results; +Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const +{ + return lookupClassImpl(*this, clsName, predicates::always()); } @@ -317,6 +373,13 @@ Foam::IOobjectList::classes(const wordRes& matcher) const } +Foam::HashTable<Foam::wordHashSet> +Foam::IOobjectList::classes(const wordHashSet& matcher) const +{ + return classesImpl(*this, matcher); +} + + Foam::wordList Foam::IOobjectList::names() const { return HashPtrTable<IOobject>::toc(); @@ -329,6 +392,15 @@ Foam::wordList Foam::IOobjectList::sortedNames() const } +Foam::wordList Foam::IOobjectList::names(const bool syncPar) const +{ + wordList objNames(HashPtrTable<IOobject>::toc()); + + checkNames(objNames, syncPar); + return objNames; +} + + Foam::wordList Foam::IOobjectList::names ( const word& clsName @@ -338,6 +410,28 @@ Foam::wordList Foam::IOobjectList::names } +Foam::wordList Foam::IOobjectList::sortedNames +( + const word& clsName +) const +{ + return namesImpl(*this, clsName, predicates::always(), true); +} + + +Foam::wordList Foam::IOobjectList::names +( + const word& clsName, + const bool syncPar +) const +{ + wordList objNames(namesImpl(*this, clsName, predicates::always(), false)); + + checkNames(objNames, syncPar); + return objNames; +} + + Foam::wordList Foam::IOobjectList::names ( const word& clsName, @@ -348,6 +442,30 @@ Foam::wordList Foam::IOobjectList::names } +Foam::wordList Foam::IOobjectList::sortedNames +( + const word& clsName, + const wordRe& matcher +) const +{ + return namesImpl(*this, clsName, matcher, true); +} + + +Foam::wordList Foam::IOobjectList::names +( + const word& clsName, + const wordRe& matcher, + const bool syncPar +) const +{ + wordList objNames(namesImpl(*this, clsName, matcher, false)); + + checkNames(objNames, syncPar); + return objNames; +} + + Foam::wordList Foam::IOobjectList::names ( const word& clsName, @@ -360,33 +478,62 @@ Foam::wordList Foam::IOobjectList::names Foam::wordList Foam::IOobjectList::sortedNames ( - const word& clsName + const word& clsName, + const wordRes& matcher ) const { - return namesImpl(*this, clsName, predicates::always(), true); + return namesImpl(*this, clsName, matcher, true); } -Foam::wordList Foam::IOobjectList::sortedNames +Foam::wordList Foam::IOobjectList::names ( const word& clsName, - const wordRe& matcher + const wordRes& matcher, + const bool syncPar ) const { - return namesImpl(*this, clsName, matcher, true); + wordList objNames(namesImpl(*this, clsName, matcher, false)); + + checkNames(objNames, syncPar); + return objNames; +} + + +Foam::wordList Foam::IOobjectList::names +( + const word& clsName, + const wordHashSet& matcher +) const +{ + return namesImpl(*this, clsName, matcher, false); } Foam::wordList Foam::IOobjectList::sortedNames ( const word& clsName, - const wordRes& matcher + const wordHashSet& matcher ) const { return namesImpl(*this, clsName, matcher, true); } +Foam::wordList Foam::IOobjectList::names +( + const word& clsName, + const wordHashSet& matcher, + const bool syncPar +) const +{ + wordList objNames(namesImpl(*this, clsName, matcher, false)); + + checkNames(objNames, syncPar); + return objNames; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // void Foam::IOobjectList::operator=(IOobjectList&& list) diff --git a/src/OpenFOAM/db/IOobjectList/IOobjectList.H b/src/OpenFOAM/db/IOobjectList/IOobjectList.H index 247c6a0633a744cc2fccfea608285b0359dc9ea2..e1922945fcfcca1ec4cb359a0167df2c110c1958 100644 --- a/src/OpenFOAM/db/IOobjectList/IOobjectList.H +++ b/src/OpenFOAM/db/IOobjectList/IOobjectList.H @@ -118,6 +118,9 @@ public: //- The list of all IOobjects with matching names IOobjectList lookup(const wordRes& matcher) const; + //- The list of all IOobjects with matching names + IOobjectList lookup(const wordHashSet& matcher) const; + //- The list of all IOobjects with the given class name IOobjectList lookupClass(const word& clsName) const; @@ -201,6 +204,10 @@ public: // restricted to objects with names that satisfy the input matcher HashTable<wordHashSet> classes(const wordRes& matcher) const; + //- A summary hash of classes used and their associated object names + // restricted to objects with names that satisfy the input matcher + HashTable<wordHashSet> classes(const wordHashSet& matcher) const; + // Summary of names @@ -211,13 +218,61 @@ public: wordList names(const word& clsName) const; //- The names of IOobjects with the given class name that also - // have a name satisfying the input matcher + //- have a name satisfying the input matcher wordList names(const word& clsName, const wordRe& matcher) const; //- The names of IOobjects with the given class name that also - // have a name satisfying the input matcher + //- have a name satisfying the input matcher wordList names(const word& clsName, const wordRes& matcher) const; + //- The names of IOobjects with the given class name that also + //- have a name satisfying the input matcher + wordList names(const word& clsName, const wordHashSet& matcher) const; + + + //- A sorted list of names of the IOobjects. + // With syncPar = true, triggers FatalError if the names are + // not consistent on all processors. + wordList names(const bool syncPar) const; + + //- A sorted list of names of the IOobjects + // With syncPar = true, triggers FatalError if the names are + // not consistent on all processors. + wordList names(const word& clsName, const bool syncPar) const; + + //- The sorted names of IOobjects with the given class name that also + //- have a name satisfying the input matcher + // With syncPar = true, triggers FatalError if the names are + // not consistent on all processors. + wordList names + ( + const word& clsName, + const wordRe& matcher, + const bool syncPar + ) const; + + //- The sorted names of IOobjects with the given class name that also + //- have a name satisfying the input matcher + // With syncPar = true, triggers FatalError if the names are + // not consistent on all processors. + wordList names + ( + const word& clsName, + const wordRes& matcher, + const bool syncPar + ) const; + + //- The sorted names of IOobjects with the given class name that also + //- have a name satisfying the input matcher + // With syncPar = true, triggers FatalError if the names are + // not consistent on all processors. + wordList names + ( + const word& cls, + const wordHashSet& matcher, + const bool syncPar + ) const; + // Summary of names (sorted) @@ -228,13 +283,21 @@ public: wordList sortedNames(const word& clsName) const; //- The sorted names of IOobjects with the given class name that also - // have a name satisfying the input matcher + //- have a name satisfying the input matcher wordList sortedNames(const word& clsName, const wordRe& matcher) const; //- The sorted names of IOobjects with the given class name that also - // have a name satisfying the input matcher + //- have a name satisfying the input matcher wordList sortedNames(const word& clsName, const wordRes& matcher) const; + //- The sorted names of IOobjects with the given class name that also + //- have a name satisfying the input matcher + wordList sortedNames + ( + const word& clsName, + const wordHashSet& matcher + ) const; + // Member Operators diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index c5f19d4c9da3cd17d6e204e613168783af92acbc..003518aa97e35371fba311a817807a67ca2af01f 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -133,6 +133,13 @@ Foam::objectRegistry::classes(const wordRes& matcher) const } +Foam::HashTable<Foam::wordHashSet> +Foam::objectRegistry::classes(const wordHashSet& matcher) const +{ + return classesImpl(*this, matcher); +} + + Foam::wordList Foam::objectRegistry::names() const { return HashTable<regIOobject*>::toc(); diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index eb45cc670c5fef48e1fac7501233dfa7d1dbcdad..c4a021308f7e3799dce28059e8c2a1ece8055e57 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 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. @@ -132,210 +132,223 @@ public: // Member functions - // Access + // Access - //- Return time - const Time& time() const - { - return time_; - } + //- Return time + const Time& time() const + { + return time_; + } - //- Return the parent objectRegistry - const objectRegistry& parent() const - { - return parent_; - } + //- Return the parent objectRegistry + const objectRegistry& parent() const + { + return parent_; + } - //- Local directory path of this objectRegistry relative to the time - virtual const fileName& dbDir() const - { - return dbDir_; - } + //- Local directory path of this objectRegistry relative to the time + virtual const fileName& dbDir() const + { + return dbDir_; + } - // Summary of classes + // Summary of classes - //- A summary hash of classes used and their associated object names. - // Behaviour and usage as per IOobjectList::classes - HashTable<wordHashSet> classes() const; + //- A summary hash of classes used and their associated object names. + // Behaviour and usage as per IOobjectList::classes + HashTable<wordHashSet> classes() const; - //- A summary hash of classes used and their associated object names - // restricted to objects with names that satisfy the input matcher - HashTable<wordHashSet> classes(const wordRe& matcher) const; + //- A summary hash of classes used and their associated object names + //- restricted to objects with names that satisfy the input matcher + HashTable<wordHashSet> classes(const wordRe& matcher) const; - //- A summary hash of classes used and their associated object names - // restricted to objects with names that satisfy the input matcher - HashTable<wordHashSet> classes(const wordRes& matcher) const; - - - // Summary of names - - //- A list of names of the objects - wordList names() const; - - //- The names of objects with the given class name - wordList names(const word& clsName) const; - - //- The names of objects with the given type - template<class Type> - wordList names() const; - - //- The names of objects with the given type that also - // have a name satisfying the input matcher - template<class Type> - wordList names(const wordRe& matcher) const; - - //- The names of objects with the given type that also - // have a name satisfying the input matcher - template<class Type> - wordList names(const wordRes& matcher) const; - - - // Summary of names (sorted) + //- A summary hash of classes used and their associated object names + //- restricted to objects with names that satisfy the input matcher + HashTable<wordHashSet> classes(const wordRes& matcher) const; - //- A sorted list of names of the objects - wordList sortedNames() const; + //- A summary hash of classes used and their associated object names + //- restricted to objects with names that satisfy the input matcher + HashTable<wordHashSet> classes(const wordHashSet& matcher) const; - //- The sorted names of objects with the given class name - wordList sortedNames(const word& clsName) const; - //- The sorted names of objects with the given type - template<class Type> - wordList sortedNames() const; + // Summary of names - //- The sorted names of objects with the given type that also - // have a name satisfying the input matcher - template<class Type> - wordList sortedNames(const wordRe& matcher) const; + //- A list of names of the objects + wordList names() const; - //- The sorted names of objects with the given type that also - // have a name satisfying the input matcher - template<class Type> - wordList sortedNames(const wordRes& matcher) const; + //- The names of objects with the given class name + wordList names(const word& clsName) const; + //- The names of objects with the given type + template<class Type> + wordList names() const; - // Lookup + //- The names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList names(const wordRe& matcher) const; - //- Lookup and return a const sub-objectRegistry. - // Optionally create it if it does not exist. - // If recursive, search parent registries. - const objectRegistry& subRegistry - ( - const word& name, - const bool forceCreate = false, - const bool recursive = false - ) const; + //- The names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList names(const wordRes& matcher) const; + //- The names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList names(const wordHashSet& matcher) const; - //- Lookup and return all objects of the given Type - template<class Type> - HashTable<const Type*> lookupClass(const bool strict = false) const; - //- Lookup and return all objects of the given Type - template<class Type> - HashTable<Type*> lookupClass(const bool strict = false); + // Summary of names (sorted) - //- Is the named Type found? - // If recursive, search parent registries. - template<class Type> - bool foundObject - ( - const word& name, - const bool recursive = false - ) const; + //- A sorted list of names of the objects + wordList sortedNames() const; - //- Lookup and return the object of the given Type. - // If recursive, search parent registries. - template<class Type> - const Type& lookupObject - ( - const word& name, - const bool recursive = false - ) const; + //- The sorted names of objects with the given class name + wordList sortedNames(const word& clsName) const; - //- Lookup and return the object of the given Type. - // If recursive, search parent registries. - template<class Type> - Type& lookupObjectRef - ( - const word& name, - const bool recursive = false - ) const; + //- The sorted names of objects with the given type + template<class Type> + wordList sortedNames() const; - //- Lookup and return pointer to the object of the given Type, - // otherwise nullptr if the object was not found, - // or had the incorrect type. - // If recursive, search parent registries. - template<class Type> - const Type* lookupObjectPtr - ( - const word& name, - const bool recursive = false - ) const; + //- The sorted names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList sortedNames(const wordRe& matcher) const; + //- The sorted names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList sortedNames(const wordRes& matcher) const; - //- Lookup and return non-const pointer to the object - // of the given Type, - // otherwise nullptr if the object was not found, - // or had the incorrect type. - // If recursive, search parent registries. - template<class Type> - Type* lookupObjectRefPtr - ( - const word& name, - const bool recursive = false - ) const; + //- The sorted names of objects with the given type that also + //- have a name satisfying the input matcher + template<class Type> + wordList sortedNames(const wordHashSet& matcher) const; - // Events + // Lookup - //- Return new event number. - label getEvent() const; - - - // Edit - - //- Rename - virtual void rename(const word& newName); - - //- Add an regIOobject to registry - bool checkIn(regIOobject& io) const; - - //- Remove an regIOobject from registry - bool checkOut(regIOobject& io) const; - - - // Reading - - //- Return true if any of the object's files have been modified - virtual bool modified() const; - - //- Read the objects that have been modified - void readModifiedObjects(); - - //- Read object if modified - virtual bool readIfModified(); - - - // Writing - - //- writeData function required by regIOobject but not used - // for this class, write is used instead - virtual bool writeData(Ostream&) const - { - NotImplemented; - - return false; - } - - //- Write the objects - virtual bool writeObject - ( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, - const bool valid - ) const; + //- Lookup and return a const sub-objectRegistry. + // Optionally create it if it does not exist. + // If recursive, search parent registries. + const objectRegistry& subRegistry + ( + const word& name, + const bool forceCreate = false, + const bool recursive = false + ) const; + + + //- Lookup and return all objects of the given Type + template<class Type> + HashTable<const Type*> lookupClass(const bool strict = false) const; + + //- Lookup and return all objects of the given Type + template<class Type> + HashTable<Type*> lookupClass(const bool strict = false); + + //- Is the named Type found? + // If recursive, search parent registries. + template<class Type> + bool foundObject + ( + const word& name, + const bool recursive = false + ) const; + + //- Lookup and return the object of the given Type. + // If recursive, search parent registries. + template<class Type> + const Type& lookupObject + ( + const word& name, + const bool recursive = false + ) const; + + //- Lookup and return the object of the given Type. + // If recursive, search parent registries. + template<class Type> + Type& lookupObjectRef + ( + const word& name, + const bool recursive = false + ) const; + + //- Lookup and return pointer to the object of the given Type, + // otherwise nullptr if the object was not found, + // or had the incorrect type. + // If recursive, search parent registries. + template<class Type> + const Type* lookupObjectPtr + ( + const word& name, + const bool recursive = false + ) const; + + + //- Lookup and return non-const pointer to the object + // of the given Type, + // otherwise nullptr if the object was not found, + // or had the incorrect type. + // If recursive, search parent registries. + template<class Type> + Type* lookupObjectRefPtr + ( + const word& name, + const bool recursive = false + ) const; + + + // Events + + //- Return new event number. + label getEvent() const; + + + // Edit + + //- Rename + virtual void rename(const word& newName); + + //- Add an regIOobject to registry + bool checkIn(regIOobject& io) const; + + //- Remove an regIOobject from registry + bool checkOut(regIOobject& io) const; + + + // Reading + + //- Return true if any of the object's files have been modified + virtual bool modified() const; + + //- Read the objects that have been modified + void readModifiedObjects(); + + //- Read object if modified + virtual bool readIfModified(); + + + // Writing + + //- writeData function required by regIOobject but not used. + // For this class, write is used instead + virtual bool writeData(Ostream&) const + { + NotImplemented; + return false; + } + + //- Write the objects + virtual bool writeObject + ( + IOstream::streamFormat fmt, + IOstream::versionNumber ver, + IOstream::compressionType cmp, + const bool valid + ) const; }; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 040b05f6a3c34ec7ec52ee2e1bd0d1414941d362..551f4055be5e5982bb78933c106edc894157e760 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-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. @@ -69,7 +69,8 @@ Foam::wordList Foam::objectRegistry::namesImpl { if (isA<Type>(*iter()) && matcher(iter()->name())) { - objNames[count++] = iter()->name(); + objNames[count] = iter()->name(); + ++count; } } @@ -101,10 +102,14 @@ Foam::wordList Foam::objectRegistry::names(const wordRe& matcher) const template<class Type> -Foam::wordList Foam::objectRegistry::names -( - const wordRes& matcher -) const +Foam::wordList Foam::objectRegistry::names(const wordRes& matcher) const +{ + return namesImpl<Type>(*this, matcher, false); +} + + +template<class Type> +Foam::wordList Foam::objectRegistry::names(const wordHashSet& matcher) const { return namesImpl<Type>(*this, matcher, false); } @@ -118,10 +123,14 @@ Foam::wordList Foam::objectRegistry::sortedNames() const template<class Type> -Foam::wordList Foam::objectRegistry::sortedNames -( - const wordRe& matcher -) const +Foam::wordList Foam::objectRegistry::sortedNames(const wordRe& matcher) const +{ + return namesImpl<Type>(*this, matcher, true); +} + + +template<class Type> +Foam::wordList Foam::objectRegistry::sortedNames(const wordRes& matcher) const { return namesImpl<Type>(*this, matcher, true); } @@ -130,7 +139,7 @@ Foam::wordList Foam::objectRegistry::sortedNames template<class Type> Foam::wordList Foam::objectRegistry::sortedNames ( - const wordRes& matcher + const wordHashSet& matcher ) const { return namesImpl<Type>(*this, matcher, true); @@ -198,10 +207,8 @@ bool Foam::objectRegistry::foundObject { return true; } - else - { - return false; - } + + return false; } diff --git a/src/OpenFOAM/fields/ReadFields/ReadFields.C b/src/OpenFOAM/fields/ReadFields/ReadFields.C deleted file mode 100644 index df4afd2159d24d37edc080b90b76be14b19ca642..0000000000000000000000000000000000000000 --- a/src/OpenFOAM/fields/ReadFields/ReadFields.C +++ /dev/null @@ -1,87 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. - -\*---------------------------------------------------------------------------*/ - -#include "ReadFields.H" -#include "IOobjectList.H" -#include "objectRegistry.H" - -// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // - -// Read all fields of type. Returns names of fields read. Guarantees all -// processors to read fields in same order. -Foam::wordList Foam::fieldNames -( - const IOobjectList& fieldObjects, - const bool syncPar -) -{ - // Get sorted field names. Sorting needed in parallel since different - // processors (using different file servers) might pick up the files - // in different order. - wordList masterNames(fieldObjects.sortedNames()); - - if (syncPar && Pstream::parRun()) - { - // Check that I have the same fields as the master - const wordList localNames(masterNames); - Pstream::scatter(masterNames); - - wordHashSet localNamesSet(localNames); - - forAll(masterNames, i) - { - const word& masterFld = masterNames[i]; - - wordHashSet::iterator iter = localNamesSet.find(masterFld); - - if (iter == localNamesSet.end()) - { - FatalErrorInFunction - << "Fields not synchronised across processors." << endl - << "Master has fields " << masterNames - << " processor " << Pstream::myProcNo() - << " has fields " << localNames << exit(FatalError); - } - else - { - localNamesSet.erase(iter); - } - } - - if (localNamesSet.size()) - { - FatalErrorInFunction - << "Fields not synchronised across processors." << endl - << "Master has fields " << masterNames - << " processor " << Pstream::myProcNo() - << " has fields " << localNames << exit(FatalError); - } - } - - return masterNames; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/fields/ReadFields/ReadFields.H b/src/OpenFOAM/fields/ReadFields/ReadFields.H index 32dd5af2f7121babe311d843fbbf8706ae52d804..161d90288a00c1f45099c0b492fdff499395c8ec 100644 --- a/src/OpenFOAM/fields/ReadFields/ReadFields.H +++ b/src/OpenFOAM/fields/ReadFields/ReadFields.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,11 +51,9 @@ class regIOobject; class IOobjectList; class objectRegistry; -//- Get sorted names of fields of type. If syncPar and running in parallel -// check for identical names -wordList fieldNames(const IOobjectList& objects, const bool syncPar); - -//- Read Geometric fields +//- Read Geometric fields of templated type. +// \return sorted names of fields read. +// \note All processors guaranteed to read fields in same order. template<class Type, template<class> class PatchField, class GeoMesh> wordList ReadFields ( @@ -66,9 +64,10 @@ wordList ReadFields const bool readOldTime = false ); -//- Read all fields of the specified type. -// Returns names of fields read. -// Guarantees all processors read fields in same order. + +//- Read fields of the templated type. +// \return sorted names of fields read. +// \note All processors guaranteed to read fields in same order. template<class GeoField, class Mesh> wordList ReadFields ( @@ -78,7 +77,9 @@ wordList ReadFields const bool syncPar = true ); -//- Read non-mesh fields, e.g. uniformDimensionedField like 'g' +//- Read non-mesh fields (uniformDimensionedField like 'g'). +// \return sorted names of fields read. +// \note All processors guaranteed to read fields in same order. template<class GeoField> wordList ReadFields ( @@ -87,8 +88,8 @@ wordList ReadFields const bool syncPar = true ); -//- Read all GeometricFields of the specified type. -// The fieldsCache is an objectRegistry of all stored fields +//- Read all GeometricFields of the templated type. +// \param fieldsCache is an objectRegistry of all stored fields template<class GeoField> static void ReadFields ( @@ -98,8 +99,8 @@ static void ReadFields objectRegistry& fieldsCache ); -//- Read all GeometricFields of the specified type. -// The fieldsCache is an objectRegistry of all stored fields +//- Read all GeometricFields of the templated type. +// \param fieldsCache is the objectRegistry name where fields are stored template<class GeoField> static void ReadFields ( @@ -109,9 +110,9 @@ static void ReadFields const word& registryName = "fieldsCache" ); -//- Read the selected GeometricFields of the specified type. +//- Read the selected GeometricFields of the templated type. // The fields are transferred to the objectRegistry and a list of them is -// returned as a stack for later clean-up +// returned as a stack for later cleanup template<class GeoFieldType> void readFields ( @@ -122,9 +123,9 @@ void readFields ); -//- Read the selected UniformDimensionedFields of the specified type. +//- Read the selected UniformDimensionedFields of the templated type. // The fields are transferred to the objectRegistry and a list of them is -// returned as a stack for later clean-up +// returned as a stack for later cleanup template<class GeoFieldType> void readUniformFields ( diff --git a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C index d9c4960d485938f9f6bbd0c21821102c6df7e6d2..7e0db9b6146b3025fbb8766d3083d3882b66df33 100644 --- a/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C +++ b/src/OpenFOAM/fields/ReadFields/ReadFieldsTemplates.C @@ -29,8 +29,6 @@ License // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // -// Read all GeometricFields of type. Returns names of fields read. Guarantees -// all processors to read fields in same order. template<class Type, template<class> class PatchField, class GeoMesh> Foam::wordList Foam::ReadFields ( @@ -43,25 +41,27 @@ Foam::wordList Foam::ReadFields { typedef GeometricField<Type, PatchField, GeoMesh> GeoField; - // Search list of objects for wanted type - IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); + // Names of GeoField objects, sorted order. + const wordList fieldNames(objects.names(GeoField::typeName, syncPar)); - const wordList masterNames(fieldNames(fieldObjects, syncPar)); + // Construct the fields - reading in consistent (master) order. + fields.resize(fieldNames.size()); - fields.setSize(masterNames.size()); + label nFields = 0; - // Make sure to read in masterNames order. - - forAll(masterNames, i) + for (const word& fieldName : fieldNames) { - Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i] - << endl; + if (!nFields) + { + Info<< "Reading " << GeoField::typeName << ':'; + } + Info<< ' ' << fieldName; - const IOobject& io = *fieldObjects[masterNames[i]]; + const IOobject& io = *objects[fieldName]; fields.set ( - i, + nFields++, new GeoField ( IOobject @@ -79,12 +79,13 @@ Foam::wordList Foam::ReadFields ) ); } - return masterNames; + + if (nFields) Info<< endl; + + return fieldNames; } -// Read all fields of type. Returns names of fields read. Guarantees all -// processors to read fields in same order. template<class GeoField, class Mesh> Foam::wordList Foam::ReadFields ( @@ -94,25 +95,27 @@ Foam::wordList Foam::ReadFields const bool syncPar ) { - // Search list of objects for wanted type - IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); + // Names of GeoField objects, sorted order. + const wordList fieldNames(objects.names(GeoField::typeName, syncPar)); - const wordList masterNames(fieldNames(fieldObjects, syncPar)); + // Construct the fields - reading in consistent (master) order. + fields.resize(fieldNames.size()); - fields.setSize(masterNames.size()); + label nFields = 0; - // Make sure to read in masterNames order. - - forAll(masterNames, i) + for (const word& fieldName : fieldNames) { - Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i] - << endl; + if (!nFields) + { + Info<< "Reading " << GeoField::typeName << ':'; + } + Info<< ' ' << fieldName; - const IOobject& io = *fieldObjects[masterNames[i]]; + const IOobject& io = *objects[fieldName]; fields.set ( - i, + nFields++, new GeoField ( IOobject @@ -129,12 +132,13 @@ Foam::wordList Foam::ReadFields ) ); } - return masterNames; + + if (nFields) Info<< endl; + + return fieldNames; } -// Read all (non-mesh) fields of type. Returns names of fields read. Guarantees -// all processors to read fields in same order. template<class GeoField> Foam::wordList Foam::ReadFields ( @@ -143,25 +147,27 @@ Foam::wordList Foam::ReadFields const bool syncPar ) { - // Search list of objects for wanted type - IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); + // Names of GeoField objects, sorted order. + const wordList fieldNames(objects.names(GeoField::typeName, syncPar)); - const wordList masterNames(fieldNames(fieldObjects, syncPar)); + // Construct the fields - reading in consistent (master) order. + fields.resize(fieldNames.size()); - fields.setSize(masterNames.size()); + label nFields = 0; - // Make sure to read in masterNames order. - - forAll(masterNames, i) + for (const word& fieldName : fieldNames) { - Info<< "Reading " << GeoField::typeName << ' ' << masterNames[i] - << endl; + if (!nFields) + { + Info<< "Reading " << GeoField::typeName << ':'; + } + Info<< ' ' << fieldName; - const IOobject& io = *fieldObjects[masterNames[i]]; + const IOobject& io = *objects[fieldName]; fields.set ( - i, + nFields++, new GeoField ( IOobject @@ -177,7 +183,10 @@ Foam::wordList Foam::ReadFields ) ); } - return masterNames; + + if (nFields) Info<< endl; + + return fieldNames; } @@ -190,51 +199,38 @@ void Foam::ReadFields objectRegistry& fieldsCache ) { - // Collect all times that are no longer used + // Unload times that are no longer used { - wordHashSet usedTimes(timeNames); - - DynamicList<word> unusedTimes(fieldsCache.size()); - - forAllIter(objectRegistry, fieldsCache, timeIter) - { - const word& tm = timeIter.key(); - if (!usedTimes.found(tm)) - { - unusedTimes.append(tm); - } - } + wordHashSet unusedTimes(fieldsCache.toc()); + unusedTimes.erase(timeNames); //Info<< "Unloading times " << unusedTimes << endl; - forAll(unusedTimes, i) + for (const word& timeName : unusedTimes) { - objectRegistry& timeCache = const_cast<objectRegistry&> - ( - fieldsCache.lookupObject<objectRegistry>(unusedTimes[i]) - ); + objectRegistry& timeCache = + fieldsCache.lookupObjectRef<objectRegistry>(timeName); + fieldsCache.checkOut(timeCache); } } // Load any new fields - forAll(timeNames, i) + for (const word& timeName : timeNames) { - const word& tm = timeNames[i]; - // Create if not found - if (!fieldsCache.found(tm)) + if (!fieldsCache.found(timeName)) { - //Info<< "Creating registry for time " << tm << endl; + //Info<< "Creating registry for time " << timeName << endl; // Create objectRegistry if not found objectRegistry* timeCachePtr = new objectRegistry ( IOobject ( - tm, - tm, + timeName, + timeName, fieldsCache, IOobject::NO_READ, IOobject::NO_WRITE @@ -245,27 +241,24 @@ void Foam::ReadFields // Obtain cache for current time const objectRegistry& timeCache = - fieldsCache.lookupObject<objectRegistry> - ( - tm - ); + fieldsCache.lookupObject<objectRegistry>(timeName); // Store field if not found if (!timeCache.found(fieldName)) { //Info<< "Loading field " << fieldName - // << " for time " << tm << endl; + // << " for time " << timeName << endl; GeoField loadedFld ( IOobject ( fieldName, - tm, + timeName, mesh.thisDb(), IOobject::MUST_READ, IOobject::NO_WRITE, - false + false // do not register ), mesh ); @@ -276,7 +269,7 @@ void Foam::ReadFields IOobject ( fieldName, - tm, + timeName, timeCache, IOobject::NO_READ, IOobject::NO_WRITE @@ -320,48 +313,48 @@ void Foam::readFields LIFOStack<regIOobject*>& storedObjects ) { - IOobjectList fields(objects.lookupClass(GeoFieldType::typeName)); - if (!fields.size()) return; + // Names of GeoField objects, sorted order. Not synchronised. + const wordList fieldNames + ( + objects.sortedNames + ( + GeoFieldType::typeName, + selectedFields // Only permit these + ) + ); - bool firstField = true; + label nFields = 0; - forAllConstIter(IOobjectList, fields, fieldIter) + for (const word& fieldName : fieldNames) { - const IOobject& io = *fieldIter(); - const word& fieldName = io.name(); + const IOobject& io = *objects[fieldName]; - if (selectedFields.found(fieldName)) + if (!nFields) { - if (firstField) - { - Info<< " " << GeoFieldType::typeName << "s:"; - firstField = false; - } - - Info<< " " << fieldName; + Info<< " " << GeoFieldType::typeName << ':'; + } + Info<< ' ' << fieldName; - GeoFieldType* fieldPtr = new GeoFieldType + GeoFieldType* fieldPtr = new GeoFieldType + ( + IOobject ( - IOobject - ( - fieldName, - io.instance(), - io.local(), - io.db(), - IOobject::MUST_READ, - IOobject::NO_WRITE - ), - mesh - ); - fieldPtr->store(); - storedObjects.push(fieldPtr); - } - } + fieldName, + io.instance(), + io.local(), + io.db(), + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + mesh + ); + fieldPtr->store(); + storedObjects.push(fieldPtr); - if (!firstField) - { - Info<< endl; + ++nFields; } + + if (nFields) Info<< endl; } @@ -374,85 +367,48 @@ void Foam::readUniformFields const bool syncPar ) { - // Search list of objects for wanted type - IOobjectList fields(objects.lookupClass(UniformFieldType::typeName)); - if (!fields.size()) return; + // Names of UniformField objects, sorted order. + const wordList fieldNames + ( + objects.names + ( + UniformFieldType::typeName, + selectedFields, // Only permit these + syncPar + ) + ); - wordList masterNames(fields.names()); + label nFields = 0; - if (syncPar && Pstream::parRun()) + for (const word& fieldName : fieldNames) { - // Check that I have the same fields as the master - const wordList localNames(masterNames); - Pstream::scatter(masterNames); - - wordHashSet localNamesSet(localNames); - - forAll(masterNames, i) - { - const word& masterFld = masterNames[i]; - - wordHashSet::iterator iter = localNamesSet.find(masterFld); - - if (iter == localNamesSet.end()) - { - FatalErrorInFunction - << "Fields not synchronised across processors." << endl - << "Master has fields " << masterNames - << " processor " << Pstream::myProcNo() - << " has fields " << localNames << exit(FatalError); - } - else - { - localNamesSet.erase(iter); - } - } + const IOobject& io = *objects[fieldName]; - if (localNamesSet.size()) + if (!nFields) { - FatalErrorInFunction - << "Fields not synchronised across processors." << endl - << "Master has fields " << masterNames - << " processor " << Pstream::myProcNo() - << " has fields " << localNames << exit(FatalError); + Info<< " " << UniformFieldType::typeName << ':'; } - } + Info<< ' ' << fieldName; - bool firstField = true; - - forAll(masterNames, i) - { - const IOobject& io = *fields[masterNames[i]]; - const word& fieldName = io.name(); - - if (selectedFields.found(fieldName)) - { - if (firstField) - { - Info<< " " << UniformFieldType::typeName << "s:"; - firstField = false; - } - - Info<< " " << fieldName; - - UniformFieldType* fieldPtr = new UniformFieldType + UniformFieldType* fieldPtr = new UniformFieldType + ( + IOobject ( - IOobject - ( - fieldName, - io.instance(), - io.local(), - io.db(), - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ); - fieldPtr->store(); - storedObjects.push(fieldPtr); - } + fieldName, + io.instance(), + io.local(), + io.db(), + IOobject::MUST_READ, + IOobject::NO_WRITE + ) + ); + fieldPtr->store(); + storedObjects.push(fieldPtr); + + ++nFields; } - Info<< endl; + if (nFields) Info<< endl; } diff --git a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/totalFlowRateAdvectiveDiffusive/totalFlowRateAdvectiveDiffusiveFvPatchScalarField.C b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/totalFlowRateAdvectiveDiffusive/totalFlowRateAdvectiveDiffusiveFvPatchScalarField.C index eba0fea41f7c009885881996cdb11e42a901c72c..e63eae2117485997ad509280f4a6cee2a34d476b 100644 --- a/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/totalFlowRateAdvectiveDiffusive/totalFlowRateAdvectiveDiffusiveFvPatchScalarField.C +++ b/src/TurbulenceModels/compressible/turbulentFluidThermoModels/derivedFvPatchFields/totalFlowRateAdvectiveDiffusive/totalFlowRateAdvectiveDiffusiveFvPatchScalarField.C @@ -28,7 +28,6 @@ License #include "fvPatchFieldMapper.H" #include "volFields.H" #include "surfaceFields.H" -#include "IOobjectList.H" #include "turbulentFluidThermoModel.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/dynamicMesh/polyMeshFilter/polyMeshFilterTemplates.C b/src/dynamicMesh/polyMeshFilter/polyMeshFilterTemplates.C index 98078299e05384f6f800d8fc306404525e0722c2..4f377a2e206e80ad8c2e24caa8b5d22e4e2dbe36 100644 --- a/src/dynamicMesh/polyMeshFilter/polyMeshFilterTemplates.C +++ b/src/dynamicMesh/polyMeshFilter/polyMeshFilterTemplates.C @@ -52,7 +52,7 @@ void Foam::polyMeshFilter::updateSets(const mapPolyMesh& map) IOobjectList fileSets(Objects.lookupClass(SetType::typeName)); - forAllConstIter(IOobjectList, fileSets, iter) + forAllConstIters(fileSets, iter) { if (!sets.found(iter.key())) { diff --git a/src/dynamicMesh/setUpdater/setUpdaterTemplates.C b/src/dynamicMesh/setUpdater/setUpdaterTemplates.C index aaf8f190666064a073b4c12212a7c1818bcb10c5..39c443cb04001ef0735ac11e365f320ce8fb3e40 100644 --- a/src/dynamicMesh/setUpdater/setUpdaterTemplates.C +++ b/src/dynamicMesh/setUpdater/setUpdaterTemplates.C @@ -72,7 +72,7 @@ void Foam::setUpdater::updateSets(const mapPolyMesh& morphMap) const IOobjectList fileSets(Objects.lookupClass(Type::typeName)); - forAllConstIter(IOobjectList, fileSets, iter) + forAllConstIters(fileSets, iter) { if (!memSets.found(iter.key())) { diff --git a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorReconstructFields.C b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorReconstructFields.C index af0b1fe55775c345381a4b1653a9625b76490d25..e33420c99ff45133db9ac2e357de7eca11ccfffa 100644 --- a/src/parallel/reconstruct/reconstruct/fvFieldReconstructorReconstructFields.C +++ b/src/parallel/reconstruct/reconstruct/fvFieldReconstructorReconstructFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,15 +56,12 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField ); } - tmp<DimensionedField<Type, volMesh>> tfield + auto tfield = tmp<DimensionedField<Type, volMesh>>::New ( - new DimensionedField<Type, volMesh> - ( - fieldIoObject, - mesh_, - procFields[0].dimensions(), - internalField - ) + fieldIoObject, + mesh_, + procFields[0].dimensions(), + internalField ); tfield.ref().oriented() = procFields[0].oriented(); @@ -106,7 +103,6 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField ); } - return reconstructFvVolumeInternalField ( IOobject @@ -286,16 +282,13 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField // Now construct and write the field // setting the internalField and patchFields - tmp<GeometricField<Type, fvPatchField, volMesh>> tfield + auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New ( - new GeometricField<Type, fvPatchField, volMesh> - ( - fieldIoObject, - mesh_, - procFields[0].dimensions(), - internalField, - patchFields - ) + fieldIoObject, + mesh_, + procFields[0].dimensions(), + internalField, + patchFields ); tfield.ref().oriented() = procFields[0].oriented(); @@ -531,16 +524,13 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField // Now construct and write the field // setting the internalField and patchFields - tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield + auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New ( - new GeometricField<Type, fvsPatchField, surfaceMesh> - ( - fieldIoObject, - mesh_, - procFields[0].dimensions(), - internalField, - patchFields - ) + fieldIoObject, + mesh_, + procFields[0].dimensions(), + internalField, + patchFields ); tfield.ref().oriented() = procFields[0].oriented(); @@ -604,31 +594,30 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields const wordHashSet& selectedFields ) { - const word& fieldClassName = DimensionedField<Type, volMesh>::typeName; + const word& clsName = DimensionedField<Type, volMesh>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " Reconstructing " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - reconstructFvVolumeInternalField<Type>(*fieldIter())().write(); + reconstructFvVolumeInternalField<Type>(*(objects[fieldName]))().write(); - nReconstructed_++; - } - } - Info<< endl; + ++nReconstructed_; } + + if (fieldNames.size()) Info<< endl; } @@ -639,32 +628,31 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeFields const wordHashSet& selectedFields ) { - const word& fieldClassName = + const word& clsName = GeometricField<Type, fvPatchField, volMesh>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " Reconstructing " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - reconstructFvVolumeField<Type>(*fieldIter())().write(); + reconstructFvVolumeField<Type>(*(objects[fieldName]))().write(); - nReconstructed_++; - } - } - Info<< endl; + ++nReconstructed_; } + + if (fieldNames.size()) Info<< endl; } @@ -675,32 +663,31 @@ void Foam::fvFieldReconstructor::reconstructFvSurfaceFields const wordHashSet& selectedFields ) { - const word& fieldClassName = + const word& clsName = GeometricField<Type, fvsPatchField, surfaceMesh>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; + Info<< " Reconstructing " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - reconstructFvSurfaceField<Type>(*fieldIter())().write(); + reconstructFvSurfaceField<Type>(*(objects[fieldName]))().write(); - nReconstructed_++; - } - } - Info<< endl; + ++nReconstructed_; } + + if (fieldNames.size()) Info<< endl; } diff --git a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorReconstructFields.C b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorReconstructFields.C index 9b1448b6f8b9d361d4bc9308cfd4edd885bd71ea..2f2d55191ff56c8ec97d4398667acb6c4c6bd770 100644 --- a/src/parallel/reconstruct/reconstruct/pointFieldReconstructorReconstructFields.C +++ b/src/parallel/reconstruct/reconstruct/pointFieldReconstructorReconstructFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -117,23 +117,20 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject) // Construct and write the field // setting the internalField and patchFields - return tmp<GeometricField<Type, pointPatchField, pointMesh>> + return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New ( - new GeometricField<Type, pointPatchField, pointMesh> + 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 ); } @@ -146,33 +143,29 @@ void Foam::pointFieldReconstructor::reconstructFields const wordHashSet& selectedFields ) { - word fieldClassName + const word& clsName = + GeometricField<Type, pointPatchField, pointMesh>::typeName; + + const wordList fieldNames = ( - GeometricField<Type, pointPatchField, pointMesh>::typeName + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) ); - IOobjectList fields = objects.lookupClass(fieldClassName); - - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing " << fieldClassName << "s\n" << endl; - - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - !selectedFields.size() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; + Info<< " Reconstructing " << clsName << "s\n" << nl; + } - reconstructField<Type>(*fieldIter())().write(); - } - } + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - Info<< endl; + reconstructField<Type>(*(objects[fieldName]))().write(); } + + if (fieldNames.size()) Info<< endl; } diff --git a/src/parallel/reconstruct/reconstruct/reconstructLagrangian.H b/src/parallel/reconstruct/reconstruct/reconstructLagrangian.H index bc8c32d6b51a74bbf83d4af4b49102668de83cfb..5ed7f51fa3d617db2bd9b481b79cc012be435256 100644 --- a/src/parallel/reconstruct/reconstruct/reconstructLagrangian.H +++ b/src/parallel/reconstruct/reconstruct/reconstructLagrangian.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,8 +27,8 @@ InClass Description SourceFiles - reconstructLagrangianPositions.C reconstructLagrangianFields.C + reconstructLagrangianPositions.C \*---------------------------------------------------------------------------*/ diff --git a/src/parallel/reconstruct/reconstruct/reconstructLagrangianFields.C b/src/parallel/reconstruct/reconstruct/reconstructLagrangianFields.C index 62be1dc03cdfd7721b090d28b8142e1de548dcab..3cf6fc70177fcced2d23d6278121b57226d26ac0 100644 --- a/src/parallel/reconstruct/reconstruct/reconstructLagrangianFields.C +++ b/src/parallel/reconstruct/reconstruct/reconstructLagrangianFields.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,47 +39,44 @@ Foam::tmp<Foam::IOField<Type>> Foam::reconstructLagrangianField ) { // Construct empty field on mesh - tmp<IOField<Type>> tfield + auto tfield = tmp<IOField<Type>>::New ( - new IOField<Type> + IOobject ( - IOobject - ( - fieldName, - mesh.time().timeName(), - cloud::prefix/cloudName, - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - Field<Type>(0) - ) + fieldName, + mesh.time().timeName(), + cloud::prefix/cloudName, + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + Field<Type>(0) ); - Field<Type>& field = tfield.ref(); + auto& field = tfield.ref(); - forAll(meshes, i) + for (const fvMesh& localMesh : meshes) { // Check object on local mesh IOobject localIOobject ( fieldName, - meshes[i].time().timeName(), + localMesh.time().timeName(), cloud::prefix/cloudName, - meshes[i], + localMesh, IOobject::MUST_READ, IOobject::NO_WRITE ); if (localIOobject.typeHeaderOk<IOField<Type>>(true)) { - IOField<Type> fieldi(localIOobject); + IOField<Type> localField(localIOobject); - label offset = field.size(); - field.setSize(offset + fieldi.size()); + const label offset = field.size(); + field.setSize(offset + localField.size()); - forAll(fieldi, j) + forAll(localField, j) { - field[offset + j] = fieldi[j]; + field[offset + j] = localField[j]; } } } @@ -99,33 +96,30 @@ Foam::reconstructLagrangianFieldField ) { // Construct empty field on mesh - tmp<CompactIOField<Field<Type>, Type >> tfield + auto tfield = tmp<CompactIOField<Field<Type>, Type>>::New ( - new CompactIOField<Field<Type>, Type> + IOobject ( - IOobject - ( - fieldName, - mesh.time().timeName(), - cloud::prefix/cloudName, - mesh, - IOobject::NO_READ, - IOobject::NO_WRITE - ), - Field<Field<Type>>(0) - ) + fieldName, + mesh.time().timeName(), + cloud::prefix/cloudName, + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + Field<Field<Type>>(0) ); - Field<Field<Type>>& field = tfield.ref(); + auto& field = tfield.ref(); - forAll(meshes, i) + for (const fvMesh& localMesh : meshes) { // Check object on local mesh IOobject localIOobject ( fieldName, - meshes[i].time().timeName(), + localMesh.time().timeName(), cloud::prefix/cloudName, - meshes[i], + localMesh, IOobject::MUST_READ, IOobject::NO_WRITE ); @@ -139,14 +133,14 @@ Foam::reconstructLagrangianFieldField || localIOobject.typeHeaderOk<IOField<Field<Type>>>(false) ) { - CompactIOField<Field<Type>, Type> fieldi(localIOobject); + CompactIOField<Field<Type>, Type> localField(localIOobject); - label offset = field.size(); - field.setSize(offset + fieldi.size()); + const label offset = field.size(); + field.setSize(offset + localField.size()); - forAll(fieldi, j) + forAll(localField, j) { - field[offset + j] = fieldi[j]; + field[offset + j] = localField[j]; } } } @@ -155,7 +149,6 @@ Foam::reconstructLagrangianFieldField } - template<class Type> void Foam::reconstructLagrangianFields ( @@ -166,36 +159,34 @@ void Foam::reconstructLagrangianFields const wordHashSet& selectedFields ) { - const word fieldClassName(IOField<Type>::typeName); + const word& clsName = IOField<Type>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing lagrangian " - << fieldClassName << "s\n" << endl; + Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; - reconstructLagrangianField<Type> - ( - cloudName, - mesh, - meshes, - fieldIter()->name() - )().write(); - } - } + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - Info<< endl; + reconstructLagrangianField<Type> + ( + cloudName, + mesh, + meshes, + fieldName + )().write(); } + + if (fieldNames.size()) Info<< endl; } @@ -210,69 +201,65 @@ void Foam::reconstructLagrangianFieldFields ) { { - const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName); + const word& clsName = CompactIOField<Field<Type>,Type>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing lagrangian " - << fieldClassName << "s\n" << endl; + Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; - reconstructLagrangianFieldField<Type> - ( - cloudName, - mesh, - meshes, - fieldIter()->name() - )().write(); - } - } + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - Info<< endl; + reconstructLagrangianFieldField<Type> + ( + cloudName, + mesh, + meshes, + fieldName + )().write(); } + + if (fieldNames.size()) Info<< endl; } { - const word fieldClassName(IOField<Field<Type>>::typeName); + const word& clsName = IOField<Field<Type>>::typeName; - IOobjectList fields = objects.lookupClass(fieldClassName); + const wordList fieldNames = + ( + selectedFields.empty() + ? objects.sortedNames(clsName) + : objects.sortedNames(clsName, selectedFields) + ); - if (fields.size()) + if (fieldNames.size()) { - Info<< " Reconstructing lagrangian " - << fieldClassName << "s\n" << endl; + Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl; + } - forAllConstIter(IOobjectList, fields, fieldIter) - { - if - ( - selectedFields.empty() - || selectedFields.found(fieldIter()->name()) - ) - { - Info<< " " << fieldIter()->name() << endl; - reconstructLagrangianFieldField<Type> - ( - cloudName, - mesh, - meshes, - fieldIter()->name() - )().write(); - } - } + for (const word& fieldName : fieldNames) + { + Info<< " " << fieldName << endl; - Info<< endl; + reconstructLagrangianFieldField<Type> + ( + cloudName, + mesh, + meshes, + fieldName + )().write(); } + + if (fieldNames.size()) Info<< endl; } } diff --git a/src/parallel/reconstruct/reconstruct/reconstructLagrangianPositions.C b/src/parallel/reconstruct/reconstruct/reconstructLagrangianPositions.C index 1b5d017ef3b63b0b5d7b06022928c5a2b5d254d8..5419f5574b7dca626a48093e06a6138d1407bb53 100644 --- a/src/parallel/reconstruct/reconstruct/reconstructLagrangianPositions.C +++ b/src/parallel/reconstruct/reconstruct/reconstructLagrangianPositions.C @@ -45,12 +45,12 @@ void Foam::reconstructLagrangianPositions IDLList<passiveParticle>() ); - forAll(meshes, i) + forAll(meshes, meshi) { - const labelList& cellMap = cellProcAddressing[i]; - const labelList& faceMap = faceProcAddressing[i]; + const labelList& cellMap = cellProcAddressing[meshi]; + const labelList& faceMap = faceProcAddressing[meshi]; - Cloud<passiveParticle> lpi(meshes[i], cloudName, false); + Cloud<passiveParticle> lpi(meshes[meshi], cloudName, false); forAllConstIter(Cloud<passiveParticle>, lpi, iter) {