ENH: allow wordHashSet filter for IOobjectList::names

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

- simplify readFields, ReadFields and other routines by using these
  new methods.
This commit is contained in:
Mark Olesen
2018-07-26 14:56:52 +02:00
parent a8ef5610d0
commit 02ad76df4f
51 changed files with 1434 additions and 1397 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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()))
{

View File

@ -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)

View File

@ -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();

View File

@ -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());

View File

@ -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()));
}

View File

@ -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,9 +129,7 @@ Foam::lagrangianFieldDecomposer::decomposeField
Field<Type> procField(field, particleIndices_);
// Create the field for the processor
return tmp<IOField<Type>>
(
new IOField<Type>
return tmp<IOField<Type>>::New
(
IOobject
(
@ -144,7 +142,6 @@ Foam::lagrangianFieldDecomposer::decomposeField
false
),
procField
)
);
}
@ -161,9 +158,7 @@ Foam::lagrangianFieldDecomposer::decomposeFieldField
Field<Field<Type>> procField(field, particleIndices_);
// Create the field for the processor
return tmp<CompactIOField<Field<Type>, Type>>
(
new CompactIOField<Field<Type>, Type>
return tmp<CompactIOField<Field<Type>, Type>>::New
(
IOobject
(
@ -176,7 +171,6 @@ Foam::lagrangianFieldDecomposer::decomposeFieldField
false
),
procField
)
);
}

View File

@ -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

View File

@ -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,9 +273,7 @@ Foam::faFieldReconstructor::reconstructFaAreaField
// Now construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, faPatchField, areaMesh>>
(
new GeometricField<Type, faPatchField, areaMesh>
return tmp<GeometricField<Type, faPatchField, areaMesh>>::New
(
IOobject
(
@ -289,7 +287,6 @@ Foam::faFieldReconstructor::reconstructFaAreaField
procFields[0].dimensions(),
internalField,
patchFields
)
);
}
@ -553,9 +550,7 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
// Now construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, faePatchField, edgeMesh>>
(
new GeometricField<Type, faePatchField, edgeMesh>
return tmp<GeometricField<Type, faePatchField, edgeMesh>>::New
(
IOobject
(
@ -569,7 +564,6 @@ Foam::faFieldReconstructor::reconstructFaEdgeField
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;
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for
(
IOobjectList::const_iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
for (const word& fieldName : fieldNames)
{
Info << " " << fieldIter()->name() << endl;
reconstructFaAreaField<Type>(*fieldIter())().write();
Info << " " << fieldName << endl;
reconstructFaAreaField<Type>(*(objects[fieldName]))().write();
}
Info<< endl;
}
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;
reconstructFaEdgeField<Type>(*fieldIter())().write();
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
Info<< endl;
for (const word& fieldName : fieldNames)
{
Info << " " << fieldName << endl;
reconstructFaEdgeField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -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());

View File

@ -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();
}
}

View File

@ -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
(
new DimensionedField<Type, volMesh>
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
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
(
new GeometricField<Type, fvPatchField, volMesh>
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
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
(
new GeometricField<Type, fvsPatchField, surfaceMesh>
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
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;
IOobjectList fields = objects.lookupClass(fieldClassName);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
// Available fields, sorted order
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
tmp<DimensionedField<Type, volMesh>> tfld
(
reconstructFvVolumeInternalField<Type>(*fieldIter())
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
tmp<FieldType> tfld
(
reconstructFvVolumeInternalField<Type>(*(objects[fieldName]))
);
if (isWriteProc_)
{
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);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
const word& name = fieldIter()->name();
if
// Available fields, sorted order
const wordList fieldNames =
(
(selectedFields.empty() || selectedFields.found(name))
&& name != "cellDist"
)
{
Info<< " " << name << endl;
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
tmp<GeometricField<Type, fvPatchField, volMesh>> tfld
if (fieldNames.size())
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for (const word& fieldName : fieldNames)
{
if ("cellDist" == fieldName)
{
continue;
}
Info<< " " << fieldName << endl;
tmp<FieldType> tfld
(
reconstructFvVolumeField<Type>(*fieldIter())
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);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
// Available fields, sorted order
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfld
if (fieldNames.size())
{
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
tmp<FieldType> tfld
(
reconstructFvSurfaceField<Type>(*fieldIter())
reconstructFvSurfaceField<Type>(*(objects[fieldName]))
);
if (isWriteProc_)
{
tfld().write();
}
}
}
Info<< endl;
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -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,21 +80,20 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields
if (objectNames.size())
{
const word fieldClassName(IOField<Type>::typeName);
Info<< " Redistributing lagrangian "
<< fieldClassName << "s\n" << endl;
}
forAll(objectNames, i)
for (const word& objectName : objectNames)
{
Info<< " " << objectNames[i] << endl;
Info<< " " << objectName << endl;
// Read if present
IOField<Type> field
(
IOobject
(
objectNames[i],
objectName,
srcMesh_.time().timeName(),
cloud::prefix/cloudName,
srcMesh_,
@ -117,7 +113,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields
(
IOobject
(
objectNames[i],
objectName,
tgtMesh_.time().timeName(),
cloud::prefix/cloudName,
tgtMesh_,
@ -130,8 +126,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFields
}
}
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,21 +166,20 @@ 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)
for (const word& objectName : objectNames)
{
Info<< " " << objectNames[i] << endl;
Info<< " " << objectName << endl;
// Read if present
CompactIOField<Field<Type>, Type> field
(
IOobject
(
objectNames[i],
objectName,
srcMesh_.time().timeName(),
cloud::prefix/cloudName,
srcMesh_,
@ -204,7 +200,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields
(
IOobject
(
objectNames[i],
objectName,
tgtMesh_.time().timeName(),
cloud::prefix/cloudName,
tgtMesh_,
@ -217,7 +213,6 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields
}
}
}
}
template<class Container>
@ -228,6 +223,8 @@ void Foam::parLagrangianRedistributor::readLagrangianFields
const wordHashSet& selectedFields
)
{
const word fieldClassName(Container::typeName);
const wordList objectNames
(
filterObjects<Container>
@ -239,21 +236,20 @@ void Foam::parLagrangianRedistributor::readLagrangianFields
if (objectNames.size())
{
const word fieldClassName(Container::typeName);
Info<< " Reading lagrangian "
<< fieldClassName << "s\n" << endl;
}
forAll(objectNames, i)
for (const word& objectName : objectNames)
{
Info<< " " << objectNames[i] << endl;
Info<< " " << objectName << endl;
// Read if present
Container* fieldPtr = new Container
(
IOobject
(
objectNames[i],
objectName,
cloud.time().timeName(),
cloud,
IOobject::READ_IF_PRESENT,
@ -265,7 +261,6 @@ void Foam::parLagrangianRedistributor::readLagrangianFields
fieldPtr->store();
}
}
}
template<class Container>
@ -275,6 +270,8 @@ void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields
passivePositionParticleCloud& cloud
) const
{
const word fieldClassName(Container::typeName);
HashTable<Container*> fields
(
cloud.lookupClass<Container>()
@ -282,14 +279,13 @@ 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)
forAllIters(fields, iter)
{
Container& field = *iter();
Container& field = *(*iter);
Info<< " " << field.name() << endl;
@ -314,7 +310,6 @@ void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields
}
}
}
}
// ************************************************************************* //

View File

@ -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());

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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();

View File

@ -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"

View File

@ -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;
}

View File

@ -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

View File

@ -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"

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include "readFields.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -43,17 +42,20 @@ label readFields
PtrList<const GeoField>& fields
)
{
label nFields = 0;
// Available fields of type GeomField
const wordList fieldNames = objects.sortedNames(GeoField::typeName);
fields.setSize(fieldNames.size());
// 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.resize(fieldNames.size());
label nFields = 0;
for (const word& fieldName : fieldNames)
{
if (selectedFields.empty() || selectedFields.found(fieldName))
{
fields.set
(
@ -64,16 +66,13 @@ label readFields
).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)
{
if (selectedFields.empty() || selectedFields.found(iter()->name()))
for (const word& fieldName : fieldNames)
{
fields.set
(
nFields++,
new GeoField(*iter(), mesh)
new GeoField(*(objects[fieldName]), mesh)
);
}
}
fields.setSize(nFields);
return nFields;
}

View File

@ -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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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())

View File

@ -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,25 +94,25 @@ public:
template<class GeoFieldType>
void fieldInterpolator::interpolate()
{
const word& fieldClassName = GeoFieldType::typeName;
const word& clsName = GeoFieldType::typeName;
IOobjectList fields = objects_.lookupClass(fieldClassName);
if (fields.size())
{
Info<< " " << fieldClassName << "s:";
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields_.empty()
|| selectedFields_.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << '(';
? objects_.sortedNames(clsName)
: objects_.sortedNames(clsName, selectedFields_)
);
scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1);
if (fieldNames.size())
{
Info<< " " << clsName << 's';
}
for (const word& fieldName : fieldNames)
{
Info<< ' ' << fieldName << '(';
const scalar deltaT = (ti1_.value() - ti_.value())/(divisions_ + 1);
for (int j=0; j<divisions_; j++)
{
@ -150,7 +150,7 @@ void fieldInterpolator::interpolate()
// Read on the objectRegistry all the required fields
ReadFields<GeoFieldType>
(
fieldIter()->name(),
fieldName,
mesh_,
selectedTimeNames
);
@ -161,14 +161,14 @@ void fieldInterpolator::interpolate()
(
IOobject
(
fieldIter()->name(),
fieldName,
runTime_.timeName(),
fieldIter()->db(),
objects_[fieldName]->db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
fieldIter()->name(),
fieldName,
selectedTimeNames,
weights
)
@ -179,10 +179,8 @@ void fieldInterpolator::interpolate()
Info<< ')';
}
}
Info<< endl;
}
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;

View File

@ -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
);

View File

@ -51,7 +51,7 @@ void MapConsistentVolFields
IOobjectList fields = objects.lookupClass(fieldType::typeName);
forAllIter(IOobjectList, fields, fieldIter)
forAllConstIters(fields, fieldIter)
{
Info<< " interpolating " << fieldIter()->name()
<< endl;

View File

@ -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;

View File

@ -51,7 +51,7 @@ void MapVolFields
IOobjectList fields = objects.lookupClass(fieldType::typeName);
forAllIter(IOobjectList, fields, fieldIter)
forAllConstIters(fields, fieldIter)
{
IOobject fieldTargetIOobject
(

View File

@ -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");
}

View File

@ -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();

View File

@ -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,15 +131,17 @@ 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();
if (selectedFields.empty() || selectedFields.found(fieldName))
{
const fieldType fieldSource(*fieldIter(), meshSource);
const fieldType fieldSource(*(objects[fieldName]), meshSource);
IOobject targetIO
(
@ -153,6 +155,7 @@ void MapVolFields
{
Info<< " interpolating onto existing field "
<< fieldName << endl;
fieldType fieldTarget(targetIO, meshTarget);
interp.mapSrcToTgt(fieldSource, cop, fieldTarget);
@ -168,8 +171,10 @@ void MapVolFields
targetIO.readOpt() = IOobject::NO_READ;
tmp<fieldType>
tfieldTarget(interp.mapSrcToTgt(fieldSource, cop));
tmp<fieldType> tfieldTarget
(
interp.mapSrcToTgt(fieldSource, cop)
);
fieldType fieldTarget(targetIO, tfieldTarget);
@ -179,7 +184,6 @@ void MapVolFields
}
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -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");
}

View File

@ -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

View File

@ -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
results.set(key, new IOobject(*io));
}
}
return results;
}
// Templated implementation for lookupClass() - file-scope
template<class UnaryMatchPredicate>
static IOobjectList lookupClassImpl
(
iter.key(),
new IOobject(*(iter.object()))
);
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::lookup(const wordHashSet& matcher) const
{
return lookupImpl(*this, matcher);
}
Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
{
IOobjectList results(size());
forAllConstIters(*this, iter)
{
if (iter()->headerClassName() == clsName)
{
if (IOobject::debug)
{
InfoInFunction << "Found " << iter.key() << endl;
}
results.set
(
iter.key(),
new IOobject(*(iter.object()))
);
}
}
return results;
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,26 +410,6 @@ Foam::wordList Foam::IOobjectList::names
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRe& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRes& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName
@ -367,6 +419,29 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
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,
const wordRe& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
@ -377,6 +452,30 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
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,
const wordRes& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
@ -387,6 +486,54 @@ Foam::wordList Foam::IOobjectList::sortedNames
}
Foam::wordList Foam::IOobjectList::names
(
const word& clsName,
const wordRes& 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,
const wordHashSet& matcher
) const
{
return namesImpl(*this, clsName, matcher, false);
}
Foam::wordList Foam::IOobjectList::sortedNames
(
const word& clsName,
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)

View File

@ -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

View File

@ -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();

View File

@ -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.
@ -160,13 +160,17 @@ public:
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
//- 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
//- 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
@ -181,15 +185,20 @@ public:
wordList names() const;
//- The names of objects with the given type that also
// have a name satisfying the input matcher
//- 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
//- 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;
// Summary of names (sorted)
@ -204,15 +213,20 @@ public:
wordList sortedNames() const;
//- The sorted names of objects with the given type that also
// have a name satisfying the input matcher
//- 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
//- have a name satisfying the input matcher
template<class Type>
wordList sortedNames(const wordRes& 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 wordHashSet& matcher) const;
// Lookup
@ -319,12 +333,11 @@ public:
// Writing
//- writeData function required by regIOobject but not used
// for this class, write is used instead
//- writeData function required by regIOobject but not used.
// For this class, write is used instead
virtual bool writeData(Ostream&) const
{
NotImplemented;
return false;
}

View File

@ -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,11 +207,9 @@ bool Foam::objectRegistry::foundObject
{
return true;
}
else
{
return false;
}
}
template<class Type>

View File

@ -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;
}
// ************************************************************************* //

View File

@ -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
(

View File

@ -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,25 +313,27 @@ 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<< " " << GeoFieldType::typeName << ':';
}
Info<< " " << fieldName;
Info<< ' ' << fieldName;
GeoFieldType* fieldPtr = new GeoFieldType
(
@ -355,13 +350,11 @@ void Foam::readFields
);
fieldPtr->store();
storedObjects.push(fieldPtr);
}
++nFields;
}
if (!firstField)
{
Info<< endl;
}
if (nFields) Info<< endl;
}
@ -374,66 +367,28 @@ 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);
const IOobject& io = *objects[fieldName];
wordHashSet localNamesSet(localNames);
forAll(masterNames, i)
if (!nFields)
{
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);
Info<< " " << UniformFieldType::typeName << ':';
}
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);
}
}
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;
Info<< ' ' << fieldName;
UniformFieldType* fieldPtr = new UniformFieldType
(
@ -449,10 +404,11 @@ void Foam::readUniformFields
);
fieldPtr->store();
storedObjects.push(fieldPtr);
}
++nFields;
}
Info<< endl;
if (nFields) Info<< endl;
}

View File

@ -28,7 +28,6 @@ License
#include "fvPatchFieldMapper.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "IOobjectList.H"
#include "turbulentFluidThermoModel.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

View File

@ -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()))
{

View File

@ -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()))
{

View File

@ -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
(
new DimensionedField<Type, volMesh>
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
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
(
new GeometricField<Type, fvPatchField, volMesh>
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
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
(
new GeometricField<Type, fvsPatchField, surfaceMesh>
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
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);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
reconstructFvVolumeInternalField<Type>(*fieldIter())().write();
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
nReconstructed_++;
}
}
Info<< endl;
reconstructFvVolumeInternalField<Type>(*(objects[fieldName]))().write();
++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);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
reconstructFvVolumeField<Type>(*fieldIter())().write();
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
nReconstructed_++;
}
}
Info<< endl;
reconstructFvVolumeField<Type>(*(objects[fieldName]))().write();
++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);
if (fields.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
reconstructFvSurfaceField<Type>(*fieldIter())().write();
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
nReconstructed_++;
}
}
Info<< endl;
reconstructFvSurfaceField<Type>(*(objects[fieldName]))().write();
++nReconstructed_;
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -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,9 +117,7 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
// Construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, pointPatchField, pointMesh>>
(
new GeometricField<Type, pointPatchField, pointMesh>
return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
IOobject
(
@ -133,7 +131,6 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
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;
reconstructField<Type>(*fieldIter())().write();
}
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
Info<< endl;
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructField<Type>(*(objects[fieldName]))().write();
}
if (fieldNames.size()) Info<< endl;
}

View File

@ -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
\*---------------------------------------------------------------------------*/

View File

@ -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,9 +39,7 @@ Foam::tmp<Foam::IOField<Type>> Foam::reconstructLagrangianField
)
{
// Construct empty field on mesh
tmp<IOField<Type>> tfield
(
new IOField<Type>
auto tfield = tmp<IOField<Type>>::New
(
IOobject
(
@ -53,33 +51,32 @@ Foam::tmp<Foam::IOField<Type>> Foam::reconstructLagrangianField
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,9 +96,7 @@ Foam::reconstructLagrangianFieldField
)
{
// Construct empty field on mesh
tmp<CompactIOField<Field<Type>, Type >> tfield
(
new CompactIOField<Field<Type>, Type>
auto tfield = tmp<CompactIOField<Field<Type>, Type>>::New
(
IOobject
(
@ -113,19 +108,18 @@ Foam::reconstructLagrangianFieldField
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);
if (fields.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
fieldName
)().write();
}
}
Info<< endl;
}
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);
if (fields.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
fieldName
)().write();
}
}
Info<< endl;
}
if (fieldNames.size()) Info<< endl;
}
{
const word fieldClassName(IOField<Field<Type>>::typeName);
const word& clsName = IOField<Field<Type>>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
if (fields.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
const wordList fieldNames =
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fieldNames.size())
{
Info<< " " << fieldIter()->name() << endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
fieldName
)().write();
}
}
Info<< endl;
}
if (fieldNames.size()) Info<< endl;
}
}

View File

@ -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)
{