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

@ -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
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;
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;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
tmp<DimensionedField<Type, volMesh>> tfld
(
reconstructFvVolumeInternalField<Type>(*fieldIter())
);
if (isWriteProc_)
{
tfld().write();
}
}
}
Info<< endl;
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();
}
}
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;
forAllConstIter(IOobjectList, fields, fieldIter)
{
const word& name = fieldIter()->name();
if
(
(selectedFields.empty() || selectedFields.found(name))
&& name != "cellDist"
)
{
Info<< " " << name << endl;
tmp<GeometricField<Type, fvPatchField, volMesh>> tfld
(
reconstructFvVolumeField<Type>(*fieldIter())
);
if (isWriteProc_)
{
tfld().write();
}
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for (const word& fieldName : fieldNames)
{
if ("cellDist" == fieldName)
{
continue;
}
Info<< " " << fieldName << endl;
tmp<FieldType> tfld
(
reconstructFvVolumeField<Type>(*(objects[fieldName]))
);
if (isWriteProc_)
{
tfld().write();
}
}
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;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfld
(
reconstructFvSurfaceField<Type>(*fieldIter())
);
if (isWriteProc_)
{
tfld().write();
}
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << endl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
tmp<FieldType> tfld
(
reconstructFvSurfaceField<Type>(*(objects[fieldName]))
);
if (isWriteProc_)
{
tfld().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) 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)
for (const word& objectName : objectNames)
{
Info<< " " << objectName << endl;
// 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())
{
Info<< " " << objectNames[i] << endl;
// Read if present
IOField<Type> field
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)
for (const word& objectName : objectNames)
{
Info<< " " << objectName << endl;
// 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())
{
Info<< " " << objectNames[i] << endl;
// Read if present
CompactIOField<Field<Type>, Type> field
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)
forAllIters(fields, iter)
{
Container& field = *(*iter);
Info<< " " << field.name() << endl;
map.distribute(field);
if (field.size())
{
Container& field = *iter();
Info<< " " << field.name() << endl;
map.distribute(field);
if (field.size())
{
Container
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();
}
}
}

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