From 8b63b8cdfecba42762ece9421a81852400e864fe Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 1 Jun 2022 11:35:09 +0200 Subject: [PATCH] ENH: add hashedWordList find, appendUniq methods - aligns calling signatures with wordList, for possible future replacement - drop construct from const char** (can use initializer_list instead) ENH: replace hashedWordList with plain wordList in triSurfaceLoader - additional hashing optimisation (and overhead) is not worth it for the comparatively small lists of surfaces used. --- .../combustion/fireFoam/createFieldRefs.H | 2 +- .../combustion/reactingFoam/createFieldRefs.H | 2 +- .../rhoReactingBuoyantFoam/createFieldRefs.H | 2 +- .../rhoReactingFoam/createFieldRefs.H | 2 +- .../fluid/setRegionFluidFields.H | 6 +- .../coalChemistryFoam/createFieldRefs.H | 2 +- .../reactingParcelFoam/createFieldRefs.H | 2 +- .../createFieldRefs.H | 2 +- .../simpleCoalParcelFoam/createFieldRefs.H | 2 +- .../lagrangian/sprayFoam/createFieldRefs.H | 2 +- .../primitives/strings/lists/hashedWordList.C | 44 ++++---------- .../primitives/strings/lists/hashedWordList.H | 57 +++++++++--------- .../strings/lists/hashedWordListI.H | 59 ++++++++++--------- .../diffusionMulticomponent.C | 12 ++-- src/combustionModels/laminar/laminar.C | 2 +- .../singleStepCombustion.C | 2 +- .../triSurfaceLoader/triSurfaceLoader.C | 47 +++++++-------- .../triSurfaceLoader/triSurfaceLoader.H | 23 ++++---- .../InterfaceCompositionModel.C | 5 +- .../MultiComponentPhaseModel.C | 2 +- .../interfaceCompositionModels/Henry/Henry.C | 6 +- .../InterfaceCompositionModel.C | 7 +-- .../NonRandomTwoLiquid/NonRandomTwoLiquid.C | 4 +- .../Saturated/Saturated.C | 6 +- .../MultiComponentPhaseModel.C | 12 ++-- .../greyMeanAbsorptionEmission.C | 2 +- .../greyMeanSolidAbsorptionEmission.C | 4 +- .../wideBandAbsorptionEmission.C | 2 +- .../mixtureFractionSoot/mixtureFractionSoot.C | 2 +- .../basicMultiComponentMixtureI.H | 4 +- .../singleStepReactingMixture.C | 8 +-- .../Reactions/solidReaction/solidReaction.C | 2 +- .../reaction/Reactions/Reaction/Reaction.C | 2 +- .../LangmuirHinshelwoodReactionRateI.H | 8 +-- .../thirdBodyEfficienciesI.H | 20 +++++-- .../specie/speciesTable/speciesTable.H | 1 + 36 files changed, 173 insertions(+), 194 deletions(-) diff --git a/applications/solvers/combustion/fireFoam/createFieldRefs.H b/applications/solvers/combustion/fireFoam/createFieldRefs.H index a911c586d9..d5b7f4a483 100644 --- a/applications/solvers/combustion/fireFoam/createFieldRefs.H +++ b/applications/solvers/combustion/fireFoam/createFieldRefs.H @@ -1,4 +1,4 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); regionModels::surfaceFilmModel& surfaceFilm = tsurfaceFilm(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/combustion/reactingFoam/createFieldRefs.H b/applications/solvers/combustion/reactingFoam/createFieldRefs.H index fdc479bc23..da9419e207 100644 --- a/applications/solvers/combustion/reactingFoam/createFieldRefs.H +++ b/applications/solvers/combustion/reactingFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/createFieldRefs.H b/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/createFieldRefs.H index fdc479bc23..da9419e207 100644 --- a/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/createFieldRefs.H +++ b/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFieldRefs.H b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFieldRefs.H index fdc479bc23..da9419e207 100644 --- a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFieldRefs.H +++ b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/setRegionFluidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/setRegionFluidFields.H index 4b1ade67e8..a35a63d52b 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/setRegionFluidFields.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/setRegionFluidFields.H @@ -12,15 +12,15 @@ if (Y.size()) { const word inertSpecie(thermo.get("inertSpecie")); - if (!composition.species().found(inertSpecie)) + inertIndex = composition.species().find(inertSpecie); + if (inertIndex < 0) { FatalIOErrorIn(args.executable().c_str(), thermo) << "Inert specie " << inertSpecie << " not found in available species " - << composition.species() + << flatOutput(composition.species()) << exit(FatalIOError); } - inertIndex = composition.species()[inertSpecie]; } volScalarField& rho = rhoFluid[i]; diff --git a/applications/solvers/lagrangian/coalChemistryFoam/createFieldRefs.H b/applications/solvers/lagrangian/coalChemistryFoam/createFieldRefs.H index 453ae090bb..02ec6a1801 100644 --- a/applications/solvers/lagrangian/coalChemistryFoam/createFieldRefs.H +++ b/applications/solvers/lagrangian/coalChemistryFoam/createFieldRefs.H @@ -1,4 +1,4 @@ const volScalarField& T = thermo.T(); const volScalarField& psi = thermo.psi(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/lagrangian/reactingParcelFoam/createFieldRefs.H b/applications/solvers/lagrangian/reactingParcelFoam/createFieldRefs.H index bbbc50c122..0179150443 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/createFieldRefs.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/createFieldRefs.H @@ -1,4 +1,4 @@ -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); const volScalarField& T = thermo.T(); const volScalarField& psi = thermo.psi(); diff --git a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/createFieldRefs.H b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/createFieldRefs.H index fdc479bc23..da9419e207 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/createFieldRefs.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/lagrangian/simpleCoalParcelFoam/createFieldRefs.H b/applications/solvers/lagrangian/simpleCoalParcelFoam/createFieldRefs.H index fdc479bc23..da9419e207 100644 --- a/applications/solvers/lagrangian/simpleCoalParcelFoam/createFieldRefs.H +++ b/applications/solvers/lagrangian/simpleCoalParcelFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& psi = thermo.psi(); const volScalarField& T = thermo.T(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/applications/solvers/lagrangian/sprayFoam/createFieldRefs.H b/applications/solvers/lagrangian/sprayFoam/createFieldRefs.H index e7f76d8456..73cb3d28b7 100644 --- a/applications/solvers/lagrangian/sprayFoam/createFieldRefs.H +++ b/applications/solvers/lagrangian/sprayFoam/createFieldRefs.H @@ -1,3 +1,3 @@ const volScalarField& T = thermo.T(); const volScalarField& psi = thermo.psi(); -const label inertIndex(composition.species()[inertSpecie]); +const label inertIndex(composition.species().find(inertSpecie)); diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordList.C b/src/OpenFOAM/primitives/strings/lists/hashedWordList.C index ae611720d3..f8737e5857 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordList.C +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordList.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,44 +26,18 @@ License \*---------------------------------------------------------------------------*/ #include "hashedWordList.H" -#include "CStringList.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::hashedWordList::hashedWordList -( - const label len, - const char** array, - bool unique -) -: - wordList(len) -{ - for (label i=0; i < len; ++i) - { - wordList::operator[](i) = array[i]; - } - - rehash(unique); -} - - -Foam::hashedWordList::hashedWordList(const char** array, bool unique) -: - hashedWordList(CStringList::count(array), array, unique) -{} - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::hashedWordList::rehash() const { - lookup_.clear(); - const wordUList& list = *this; const label len = list.size(); - for (label i=0; i < len; ++i) + lookup_.clear(); + lookup_.resize(2*len); + + for (label i = 0; i < len; ++i) { lookup_.insert(list[i], i); } @@ -72,13 +46,15 @@ void Foam::hashedWordList::rehash() const void Foam::hashedWordList::uniq() { - lookup_.clear(); - wordList& list = *this; const label len = list.size(); + lookup_.clear(); + lookup_.resize(2*len); + label count = 0; - for (label i=0; i < len; ++i) + + for (label i = 0; i < len; ++i) { word& item = list[i]; diff --git a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H index 933966c47f..bf0553a9a3 100644 --- a/src/OpenFOAM/primitives/strings/lists/hashedWordList.H +++ b/src/OpenFOAM/primitives/strings/lists/hashedWordList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,8 +37,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef hashedWordList_H -#define hashedWordList_H +#ifndef Foam_hashedWordList_H +#define Foam_hashedWordList_H #include "wordList.H" #include "HashTable.H" @@ -68,10 +68,10 @@ public: //- Default construct an empty list hashedWordList() = default; - //- Copy construct. + //- Copy construct inline hashedWordList(const hashedWordList& list); - //- Move construct. + //- Move construct inline hashedWordList(hashedWordList&& list); //- Copy construct from list of words @@ -95,16 +95,8 @@ public: const HashTable& tbl ); - //- Construct from number and list of words, - // optionally eliminating duplicates - hashedWordList(const label len, const char** array, bool unique=false); - - //- Construct from a nullptr-terminated list of words, - //- optionally eliminating duplicates - hashedWordList(const char** array, bool unique=false); - //- Construct from Istream - inline hashedWordList(Istream& is); + inline explicit hashedWordList(Istream& is); // Member Functions @@ -112,12 +104,13 @@ public: //- Clear the list, i.e. set size to zero. inline void clear(); - //- Append an element at the end of the list, - //- optionally avoid append if it would be a duplicate entry - inline void append(const word& name, bool unique=false); + //- Append an element if not already in the list. + FOAM_DEPRECATED_FOR(2022-05, "appendUniq method") + inline void append(const word& val); - //- Search hashed values for the specified name - inline bool found(const word& name) const; + //- Append an element if not already in the list. + // \return the change in list length + inline label appendUniq(const word& val); //- Return the hash of words/indices for inspection inline const HashTable