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

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,15 +56,12 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
);
}
tmp<DimensionedField<Type, volMesh>> tfield
auto tfield = tmp<DimensionedField<Type, volMesh>>::New
(
new DimensionedField<Type, volMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField
);
tfield.ref().oriented() = procFields[0].oriented();
@ -106,7 +103,6 @@ Foam::fvFieldReconstructor::reconstructFvVolumeInternalField
);
}
return reconstructFvVolumeInternalField
(
IOobject
@ -286,16 +282,13 @@ Foam::fvFieldReconstructor::reconstructFvVolumeField
// Now construct and write the field
// setting the internalField and patchFields
tmp<GeometricField<Type, fvPatchField, volMesh>> tfield
auto tfield = tmp<GeometricField<Type, fvPatchField, volMesh>>::New
(
new GeometricField<Type, fvPatchField, volMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
tfield.ref().oriented() = procFields[0].oriented();
@ -531,16 +524,13 @@ Foam::fvFieldReconstructor::reconstructFvSurfaceField
// Now construct and write the field
// setting the internalField and patchFields
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tfield
auto tfield = tmp<GeometricField<Type, fvsPatchField, surfaceMesh>>::New
(
new GeometricField<Type, fvsPatchField, surfaceMesh>
(
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject,
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
tfield.ref().oriented() = procFields[0].oriented();
@ -604,31 +594,30 @@ void Foam::fvFieldReconstructor::reconstructFvVolumeInternalFields
const wordHashSet& selectedFields
)
{
const word& fieldClassName = DimensionedField<Type, volMesh>::typeName;
const word& clsName = DimensionedField<Type, volMesh>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructFvVolumeInternalField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << 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);
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;
reconstructFvVolumeField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << 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);
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;
reconstructFvSurfaceField<Type>(*fieldIter())().write();
nReconstructed_++;
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << 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,23 +117,20 @@ Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
// Construct and write the field
// setting the internalField and patchFields
return tmp<GeometricField<Type, pointPatchField, pointMesh>>
return tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
new GeometricField<Type, pointPatchField, pointMesh>
IOobject
(
IOobject
(
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
)
fieldIoObject.name(),
mesh_().time().timeName(),
mesh_(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
procFields[0].dimensions(),
internalField,
patchFields
);
}
@ -146,33 +143,29 @@ void Foam::pointFieldReconstructor::reconstructFields
const wordHashSet& selectedFields
)
{
word fieldClassName
const word& clsName =
GeometricField<Type, pointPatchField, pointMesh>::typeName;
const wordList fieldNames =
(
GeometricField<Type, pointPatchField, pointMesh>::typeName
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
IOobjectList fields = objects.lookupClass(fieldClassName);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing " << fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
!selectedFields.size()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructField<Type>(*fieldIter())().write();
}
}
Info<< endl;
Info<< " Reconstructing " << clsName << "s\n" << nl;
}
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,47 +39,44 @@ Foam::tmp<Foam::IOField<Type>> Foam::reconstructLagrangianField
)
{
// Construct empty field on mesh
tmp<IOField<Type>> tfield
auto tfield = tmp<IOField<Type>>::New
(
new IOField<Type>
IOobject
(
IOobject
(
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Type>(0)
)
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Type>(0)
);
Field<Type>& field = tfield.ref();
auto& field = tfield.ref();
forAll(meshes, i)
for (const fvMesh& localMesh : meshes)
{
// Check object on local mesh
IOobject localIOobject
(
fieldName,
meshes[i].time().timeName(),
localMesh.time().timeName(),
cloud::prefix/cloudName,
meshes[i],
localMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (localIOobject.typeHeaderOk<IOField<Type>>(true))
{
IOField<Type> fieldi(localIOobject);
IOField<Type> localField(localIOobject);
label offset = field.size();
field.setSize(offset + fieldi.size());
const label offset = field.size();
field.setSize(offset + localField.size());
forAll(fieldi, j)
forAll(localField, j)
{
field[offset + j] = fieldi[j];
field[offset + j] = localField[j];
}
}
}
@ -99,33 +96,30 @@ Foam::reconstructLagrangianFieldField
)
{
// Construct empty field on mesh
tmp<CompactIOField<Field<Type>, Type >> tfield
auto tfield = tmp<CompactIOField<Field<Type>, Type>>::New
(
new CompactIOField<Field<Type>, Type>
IOobject
(
IOobject
(
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Field<Type>>(0)
)
fieldName,
mesh.time().timeName(),
cloud::prefix/cloudName,
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
Field<Field<Type>>(0)
);
Field<Field<Type>>& field = tfield.ref();
auto& field = tfield.ref();
forAll(meshes, i)
for (const fvMesh& localMesh : meshes)
{
// Check object on local mesh
IOobject localIOobject
(
fieldName,
meshes[i].time().timeName(),
localMesh.time().timeName(),
cloud::prefix/cloudName,
meshes[i],
localMesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
@ -139,14 +133,14 @@ Foam::reconstructLagrangianFieldField
|| localIOobject.typeHeaderOk<IOField<Field<Type>>>(false)
)
{
CompactIOField<Field<Type>, Type> fieldi(localIOobject);
CompactIOField<Field<Type>, Type> localField(localIOobject);
label offset = field.size();
field.setSize(offset + fieldi.size());
const label offset = field.size();
field.setSize(offset + localField.size());
forAll(fieldi, j)
forAll(localField, j)
{
field[offset + j] = fieldi[j];
field[offset + j] = localField[j];
}
}
}
@ -155,7 +149,6 @@ Foam::reconstructLagrangianFieldField
}
template<class Type>
void Foam::reconstructLagrangianFields
(
@ -166,36 +159,34 @@ void Foam::reconstructLagrangianFields
const wordHashSet& selectedFields
)
{
const word fieldClassName(IOField<Type>::typeName);
const word& clsName = IOField<Type>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
if (fieldNames.size()) Info<< endl;
}
@ -210,69 +201,65 @@ void Foam::reconstructLagrangianFieldFields
)
{
{
const word fieldClassName(CompactIOField<Field<Type>, Type>::typeName);
const word& clsName = CompactIOField<Field<Type>,Type>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
if (fieldNames.size()) Info<< endl;
}
{
const word fieldClassName(IOField<Field<Type>>::typeName);
const word& clsName = IOField<Field<Type>>::typeName;
IOobjectList fields = objects.lookupClass(fieldClassName);
const wordList fieldNames =
(
selectedFields.empty()
? objects.sortedNames(clsName)
: objects.sortedNames(clsName, selectedFields)
);
if (fields.size())
if (fieldNames.size())
{
Info<< " Reconstructing lagrangian "
<< fieldClassName << "s\n" << endl;
forAllConstIter(IOobjectList, fields, fieldIter)
{
if
(
selectedFields.empty()
|| selectedFields.found(fieldIter()->name())
)
{
Info<< " " << fieldIter()->name() << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldIter()->name()
)().write();
}
}
Info<< endl;
Info<< " Reconstructing lagrangian " << clsName << "s\n" << nl;
}
for (const word& fieldName : fieldNames)
{
Info<< " " << fieldName << endl;
reconstructLagrangianFieldField<Type>
(
cloudName,
mesh,
meshes,
fieldName
)().write();
}
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)
{