ENH: prefer objectRegistry sorted to lookupClass

- lower memory overhead, consistent access pattern
This commit is contained in:
Mark Olesen
2024-04-15 15:32:57 +02:00
parent a803516b16
commit 31aadc5c4d
4 changed files with 32 additions and 27 deletions

View File

@ -5,20 +5,24 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 OpenCFD Ltd.
Copyright (C) 2023-2024 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 "caseInfo.H"
@ -333,16 +337,15 @@ void Foam::functionObjects::caseInfo::writeMeshStats
namespace Foam
{
template<class Type>
template<class GeoFieldType>
void addPatchTypeDetails(const fvMesh& mesh, dictionary& dict)
{
auto objects = mesh.lookupClass<Type>();
for (const auto* objPtr : objects)
for (const GeoFieldType& obj : mesh.csorted<GeoFieldType>())
{
if (objPtr->readOpt() == IOobject::MUST_READ)
if (obj.readOpt() == IOobject::MUST_READ)
{
const auto& bf = objPtr->boundaryField();
dictionary& objDict = dict.subDictOrAdd(objPtr->name());
const auto& bf = obj.boundaryField();
dictionary& objDict = dict.subDictOrAdd(obj.name());
for (const auto& pf : bf)
{
@ -459,14 +462,12 @@ bool Foam::functionObjects::caseInfo::write()
writeFileDicts(dataDicts, dicts);
// Per-region information
const auto meshes = time_.lookupClass<fvMesh>();
dictionary& regionDict = data.subDictOrAdd("regions");
for (const auto& iter : meshes.csorted())
for (const fvMesh& mesh : time_.csorted<fvMesh>())
{
dictionary meshDicts(dicts);
const fvMesh& mesh = *iter.val();
const word& name = mesh.name();
dictionary& out = regionDict.subDictOrAdd(name);
@ -526,4 +527,4 @@ bool Foam::functionObjects::caseInfo::write()
}
// ************************************************************************* //
// ************************************************************************* //