ENH: use objectRegistry/IOobjectList sorted instead of lookupClass

- in most cases a parallel-consistent order is required.
  Even when the order is not important, it will generally require
  fewer allocations to create a UPtrList of entries instead of a
  HashTable or even a wordList.
This commit is contained in:
Mark Olesen
2023-07-17 18:27:55 +02:00
parent d65e2d89b5
commit db16d80840
70 changed files with 1300 additions and 1758 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,50 +90,41 @@ int main(int argc, char *argv[])
<< endl;
}
const wordList objNames
(
IOobjectList(mesh, runTime.timeName()).sortedNames()
const IOobjectList objects(mesh, runTime.timeName());
Info<< "Reading fields:" << endl;
// Read fields
#undef createFields
#define createFields(FieldType, Variable) \
PtrList<FieldType> Variable \
( \
readFields<FieldType>(objects, mesh) \
);
PtrList<volScalarField> vsf(objNames.size());
PtrList<volVectorField> vvf(objNames.size());
PtrList<volSphericalTensorField> vsptf(objNames.size());
PtrList<volSymmTensorField> vsytf(objNames.size());
PtrList<volTensorField> vtf(objNames.size());
createFields(volScalarField, vsf);
createFields(volVectorField, vvf);
createFields(volSphericalTensorField, vsptf);
createFields(volSymmTensorField, vsytf);
createFields(volTensorField, vtf);
PtrList<pointScalarField> psf(objNames.size());
PtrList<pointVectorField> pvf(objNames.size());
PtrList<pointSphericalTensorField> psptf(objNames.size());
PtrList<pointSymmTensorField> psytf(objNames.size());
PtrList<pointTensorField> ptf(objNames.size());
// Point fields
const pointMesh& pMesh = pointMesh::New(mesh);
Info<< "Valid fields:" << endl;
#undef createFields
#define createFields(FieldType, Variable) \
PtrList<FieldType> Variable \
( \
readFields<FieldType>(objects, pMesh) \
);
forAll(objNames, objI)
{
IOobject obj
(
objNames[objI],
runTime.timeName(),
mesh,
IOobject::MUST_READ
);
createFields(pointScalarField, psf);
createFields(pointVectorField, pvf);
createFields(pointSphericalTensorField, psptf);
createFields(pointSymmTensorField, psytf);
createFields(pointTensorField, ptf);
if (obj.typeHeaderOk<volScalarField>(false))
{
addToFieldList(vsf, obj, objI, mesh);
addToFieldList(vvf, obj, objI, mesh);
addToFieldList(vsptf, obj, objI, mesh);
addToFieldList(vsytf, obj, objI, mesh);
addToFieldList(vtf, obj, objI, mesh);
addToFieldList(psf, obj, objI, pointMesh::New(mesh));
addToFieldList(pvf, obj, objI, pointMesh::New(mesh));
addToFieldList(psptf, obj, objI, pointMesh::New(mesh));
addToFieldList(psytf, obj, objI, pointMesh::New(mesh));
addToFieldList(ptf, obj, objI, pointMesh::New(mesh));
}
}
#undef createFields
Info<< endl;
@ -144,6 +136,7 @@ int main(int argc, char *argv[])
forAll(bm, patchi)
{
Info<< bm[patchi].type() << "\t: " << bm[patchi].name() << nl;
outputFieldList(vsf, patchi);
outputFieldList(vvf, patchi);
outputFieldList(vsptf, patchi);
@ -167,6 +160,7 @@ int main(int argc, char *argv[])
DynamicList<HashTable<word>> fieldToTypes(bm.size());
// Per 'group' the patches
DynamicList<DynamicList<label>> groupToPatches(bm.size());
forAll(bm, patchi)
{
HashTable<word> fieldToType;
@ -208,40 +202,39 @@ int main(int argc, char *argv[])
labelHashSet nonGroupPatches;
bm.matchGroups(patchIDs, groups, nonGroupPatches);
const labelList sortedPatches(nonGroupPatches.sortedToc());
forAll(sortedPatches, i)
for (const label patchi : nonGroupPatches.sortedToc())
{
Info<< bm[sortedPatches[i]].type()
<< "\t: " << bm[sortedPatches[i]].name() << nl;
Info<< bm[patchi].type()
<< "\t: " << bm[patchi].name() << nl;
}
if (groups.size())
for (const word& groupName : groups)
{
forAll(groups, i)
{
Info<< "group\t: " << groups[i] << nl;
}
Info<< "group\t: " << groupName << nl;
}
outputFieldList(vsf, patchIDs[0]);
outputFieldList(vvf, patchIDs[0]);
outputFieldList(vsptf, patchIDs[0]);
outputFieldList(vsytf, patchIDs[0]);
outputFieldList(vtf, patchIDs[0]);
outputFieldList(psf, patchIDs[0]);
outputFieldList(pvf, patchIDs[0]);
outputFieldList(psptf, patchIDs[0]);
outputFieldList(psytf, patchIDs[0]);
outputFieldList(ptf, patchIDs[0]);
const label patchi = patchIDs[0];
outputFieldList(vsf, patchi);
outputFieldList(vvf, patchi);
outputFieldList(vsptf, patchi);
outputFieldList(vsytf, patchi);
outputFieldList(vtf, patchi);
outputFieldList(psf, patchi);
outputFieldList(pvf, patchi);
outputFieldList(psptf, patchi);
outputFieldList(psytf, patchi);
outputFieldList(ptf, patchi);
Info<< endl;
}
else
{
// No group.
forAll(patchIDs, i)
for (const label patchi : patchIDs)
{
label patchi = patchIDs[i];
Info<< bm[patchi].type()
<< "\t: " << bm[patchi].name() << nl;
outputFieldList(vsf, patchi);
outputFieldList(vvf, patchi);
outputFieldList(vsptf, patchi);

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,30 +32,49 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::addToFieldList
Foam::PtrList<GeoField> Foam::readFields
(
PtrList<GeoField>& fieldList,
const IOobject& obj,
const label fieldi,
const IOobjectList& objects,
const typename GeoField::Mesh& mesh
)
{
if (obj.isHeaderClass<GeoField>())
const UPtrList<const IOobject> fieldObjects
(
objects.csorted<GeoField>()
);
PtrList<GeoField> fields(fieldObjects.size());
label nFields = 0;
for (const IOobject& io : fieldObjects)
{
fieldList.set
(
fieldi,
new GeoField(obj, mesh)
);
Info<< " " << GeoField::typeName << tab << obj.name() << endl;
if (!nFields)
{
Info<< " " << GeoField::typeName << " (";
}
else
{
Info<< ' ';
}
Info<< io.name();
fields.emplace_set(nFields, io, mesh);
++nFields;
}
if (nFields)
{
Info<< ')' << nl;
}
return fields;
}
template<class GeoField>
void Foam::outputFieldList
(
const PtrList<GeoField>& fieldList,
const UPtrList<GeoField>& fieldList,
const label patchi
)
{
@ -74,7 +94,7 @@ void Foam::outputFieldList
template<class GeoField>
void Foam::collectFieldList
(
const PtrList<GeoField>& fieldList,
const UPtrList<GeoField>& fieldList,
const label patchi,
HashTable<word>& fieldToType
)

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -25,39 +26,39 @@ License
\*---------------------------------------------------------------------------*/
#ifndef patchSummaryTemplates_H
#define patchSummaryTemplates_H
#ifndef Foam_patchSummaryTemplates_H
#define Foam_patchSummaryTemplates_H
#include "fvCFD.H"
#include "volFields.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class GeoField>
void addToFieldList
(
PtrList<GeoField>& fieldList,
const IOobject& obj,
const label fieldi,
const typename GeoField::Mesh& mesh
);
template<class GeoField>
void outputFieldList
(
const PtrList<GeoField>& fieldList,
const label patchi
);
template<class GeoField>
PtrList<GeoField> readFields
(
const IOobjectList& objects,
const typename GeoField::Mesh& mesh
);
template<class GeoField>
void outputFieldList
(
const UPtrList<GeoField>& fieldList,
const label patchi
);
template<class GeoField>
void collectFieldList
(
const UPtrList<GeoField>& fieldList,
const label patchi,
HashTable<word>& fieldToType
);
template<class GeoField>
void collectFieldList
(
const PtrList<GeoField>& fieldList,
const label patchi,
HashTable<word>& fieldToType
);
} // End namespace Foam