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.
This commit is contained in:
Mark Olesen 2022-06-01 11:35:09 +02:00
parent 49d0e82842
commit 8b63b8cdfe
36 changed files with 173 additions and 194 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -12,15 +12,15 @@
if (Y.size())
{
const word inertSpecie(thermo.get<word>("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];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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];

View File

@ -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<AnyType, word, AnyHash>& 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<label>& lookup() const;
@ -143,22 +136,33 @@ public:
//- and rehash the indices
void uniq();
//- Sort the list and rehash the indices
//- Inplace sort list and rehash the indices
inline void sort();
// Search
//- Find index of the value (searches the hash).
// \return position in list or -1 if not found.
inline label find(const word& val) const;
//- True if the value if found in the list (searches the hash).
inline bool found(const word& val) const;
// Member Operators
//- Return name corresponding to specified index.
// Fatal for out of range values.
inline const word& operator[](const label index) const;
//- Return index corresponding to specified name, or -1 on failure
inline label operator[](const word& name) const;
//- Find index of the value (searches the hash) - same as find().
// \return position in list or -1 if not found.
inline label operator[](const word& val) const;
//- Check hashed values for the specified name - same as found.
//- Check hashed values for the specified name - same as found().
// Can be used as a unary predicate.
inline bool operator()(const word& name) const;
inline bool operator()(const word& val) const;
// Assignment
@ -184,10 +188,7 @@ public:
//- Deprecated(2019-01) Is the specified name found in the list?
// \deprecated(2019-01) - use found() method
FOAM_DEPRECATED_FOR(2019-01, "found() method")
bool contains(const word& name) const
{
return this->found(name);
}
bool contains(const word& val) const { return this->found(val); }
};

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -76,17 +76,9 @@ inline Foam::hashedWordList::hashedWordList
const HashTable<AnyType, word, AnyHash>& tbl
)
:
wordList(tbl.size())
wordList(tbl.sortedToc())
{
wordList& list = *this;
label count = 0;
for (auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
{
list[count++] = iter.key();
}
this->sort();
rehash();
}
@ -105,16 +97,27 @@ inline void Foam::hashedWordList::clear()
}
inline void Foam::hashedWordList::append(const word& name, bool unique)
inline void Foam::hashedWordList::append(const word& val)
{
// name is either unique or we don't care about duplicates
if (lookup_.insert(name, size()) || !unique)
if (lookup_.insert(val, size()))
{
wordList::append(name);
wordList::append(val);
}
}
inline Foam::label Foam::hashedWordList::appendUniq(const word& val)
{
if (lookup_.insert(val, size()))
{
wordList::append(val);
return 1; // Increased list length by one
}
return 0; // No change
}
inline const Foam::HashTable<Foam::label>&
Foam::hashedWordList::lookup() const
{
@ -130,17 +133,15 @@ Foam::hashedWordList::lookup() const
}
// TBD (2019-01-07) - overload find() for consistency?
//
// inline Foam::label Foam::hashedWordList::find(const word& name) const
// {
// return lookup().lookup(name, -1); // -1 = not found or not hashed
// }
inline bool Foam::hashedWordList::found(const word& name) const
inline Foam::label Foam::hashedWordList::find(const word& val) const
{
return lookup().found(name);
return lookup().lookup(val, -1); // -1 = not found or not hashed
}
inline bool Foam::hashedWordList::found(const word& val) const
{
return lookup().found(val);
}
@ -201,15 +202,15 @@ inline const Foam::word& Foam::hashedWordList::operator[]
}
inline Foam::label Foam::hashedWordList::operator[](const word& name) const
inline Foam::label Foam::hashedWordList::operator[](const word& val) const
{
return lookup_.lookup(name, -1); // -1 = not found or not hashed
return lookup_.lookup(val, -1); // -1 = not found or not hashed
}
inline bool Foam::hashedWordList::operator()(const word& name) const
inline bool Foam::hashedWordList::operator()(const word& val) const
{
return lookup_.found(name);
return lookup_.found(val);
}

View File

@ -80,8 +80,8 @@ diffusionMulticomponent<ReactionThermo, ThermoType>::init()
const List<specieCoeffs>& lhs = reactions_[k].lhs();
const List<specieCoeffs>& rhs = reactions_[k].rhs();
const label fuelIndex = species[fuelNames_[k]];
const label oxidantIndex = species[oxidantNames_[k]];
const label fuelIndex = species.find(fuelNames_[k]);
const label oxidantIndex = species.find(oxidantNames_[k]);
const scalar Wu = specieThermo_[fuelIndex].W();
const scalar Wox = specieThermo_[oxidantIndex].W();
@ -216,7 +216,7 @@ diffusionMulticomponent<ReactionThermo, ThermoType>::correct()
volScalarField& Rijl = RijlPtr[k];
// Obtain individual reaction rates for each reaction
const label fuelIndex = species[fuelNames_[k]];
const label fuelIndex = species.find(fuelNames_[k]);
if (laminarIgn_)
{
@ -247,8 +247,8 @@ diffusionMulticomponent<ReactionThermo, ThermoType>::correct()
for (label k=0; k < nReactions; k++)
{
const label fuelIndex = species[fuelNames_[k]];
const label oxidantIndex = species[oxidantNames_[k]];
const label fuelIndex = species.find(fuelNames_[k]);
const label oxidantIndex = species.find(oxidantNames_[k]);
const volScalarField& Yfuel =
this->thermo().composition().Y(fuelIndex);
@ -381,7 +381,7 @@ Foam::combustionModels::diffusionMulticomponent<ReactionThermo, ThermoType>::R
if (this->active())
{
const label specieI =
this->thermo().composition().species()[Y.member()];
this->thermo().composition().species().find(Y.member());
Su += this->chemistryPtr_->RR(specieI);
}

View File

@ -130,7 +130,7 @@ Foam::combustionModels::laminar<ReactionThermo>::R(volScalarField& Y) const
if (this->active())
{
const label specieI =
this->thermo().composition().species()[Y.member()];
this->thermo().composition().species().find(Y.member());
Su += this->chemistryPtr_->RR(specieI);
}

View File

@ -106,7 +106,7 @@ tmp<fvScalarMatrix> singleStepCombustion<ReactionThermo, ThermoType>::R
) const
{
const label specieI =
this->thermo().composition().species()[Y.member()];
this->thermo().composition().species().find(Y.member());
volScalarField wSpecie
(

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,7 +88,7 @@ Foam::label Foam::triSurfaceLoader::readDir()
names.insert(f.name());
}
}
available_ = names.sortedToc(); // Also hashes the names
available_ = names.sortedToc();
return available_.size();
}
@ -105,7 +105,8 @@ Foam::label Foam::triSurfaceLoader::select(const word& name)
{
if (available_.found(name))
{
selected_ = wordList{name}; // hashedWordList::operator[] is hidden!
selected_.resize(1);
selected_.first() = name;
}
else
{
@ -118,30 +119,25 @@ Foam::label Foam::triSurfaceLoader::select(const word& name)
Foam::label Foam::triSurfaceLoader::select(const wordRe& mat)
{
DynamicList<label> foundIds(available_.size());
if (mat.isPattern())
{
foundIds = findStrings(mat, available_);
sort(foundIds);
labelList foundIds = findStrings(mat, available_);
Foam::sort(foundIds);
selected_ = wordList(available_, foundIds);
}
else if (available_.found(static_cast<const word&>(mat)))
{
selected_.resize(1);
selected_.first() = mat;
}
else
{
const word& plain = mat;
if (available_.found(plain))
{
foundIds.append(available_[plain]);
}
else
{
FatalErrorInFunction
<< "Specified the surfaces " << mat << nl
<< " - but could not find it"
<< exit(FatalError);
}
FatalErrorInFunction
<< "Specified the surfaces " << mat << nl
<< " - but could not find it"
<< exit(FatalError);
}
selected_ = wordList(available_, foundIds);
return selected_.size();
}
@ -158,7 +154,7 @@ Foam::label Foam::triSurfaceLoader::select(const UList<wordRe>& matcher)
DynamicList<label> foundIds(available_.size());
labelHashSet hashedFound(2*available_.size());
DynamicList<word> missing(matcher.size());
DynamicList<word> missing(matcher.size());
wordHashSet hashedMissing(2*matcher.size());
// Exact matches must exist
@ -167,7 +163,7 @@ Foam::label Foam::triSurfaceLoader::select(const UList<wordRe>& matcher)
if (mat.isPattern())
{
labelList indices = findStrings(mat, available_);
sort(indices);
Foam::sort(indices);
for (const label idx : indices)
{
@ -180,9 +176,10 @@ Foam::label Foam::triSurfaceLoader::select(const UList<wordRe>& matcher)
else
{
const word& plain = mat;
if (available_.found(plain))
const label idx = available_.find(plain);
if (idx >= 0)
{
const label idx = available_[plain];
if (hashedFound.insert(idx))
{
foundIds.append(idx);
@ -240,7 +237,7 @@ Foam::autoPtr<Foam::triSurface> Foam::triSurfaceLoader::load
if (surf.patches().size())
{
surf.patches().setSize(1);
surf.patches().resize(1);
}
else
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,20 +39,20 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef triSurfaceLoader_H
#define triSurfaceLoader_H
#ifndef Foam_triSurfaceLoader_H
#define Foam_triSurfaceLoader_H
#include "triSurface.H"
#include "wordRes.H"
#include "Enum.H"
#include "hashedWordList.H"
#include "wordList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class triSurfaceLoader;
class Time;
@ -79,16 +79,16 @@ public:
private:
// Private data
// Private Data
//- The directory to load from (eg, case/constant/triSurface)
fileName directory_;
//- All available files
hashedWordList available_;
wordList available_;
//- Selected files
hashedWordList selected_;
wordList selected_;
// Private Member Functions
@ -119,19 +119,19 @@ public:
// Access
//- The directory being used
inline const fileName& directory() const
const fileName& directory() const noexcept
{
return directory_;
}
//- The list of available files
inline const hashedWordList& available() const
const wordList& available() const noexcept
{
return available_;
}
//- The list of selected files
inline const hashedWordList& selected() const
const wordList& selected() const noexcept
{
return selected_;
}
@ -163,7 +163,6 @@ public:
const enum loadingOption opt = loadingOption::OFFSET_REGION,
const scalar scaleFactor = -1
) const;
};

View File

@ -47,10 +47,7 @@ Foam::InterfaceCompositionModel<Thermo, OtherThermo>::getLocalThermo
return
globalThermo.getLocalThermo
(
globalThermo.species()
[
speciesName
]
globalThermo.species().find(speciesName)
);
}

View File

@ -74,7 +74,7 @@ MultiComponentPhaseModel
species_ = thermoPtr_->composition().species();
inertIndex_ = species_[thermoPtr_().template get<word>("inertSpecie")];
inertIndex_ = species_.find(thermoPtr_().template get<word>("inertSpecie"));
X_.setSize(thermoPtr_->composition().species().size());

View File

@ -84,10 +84,10 @@ Foam::interfaceCompositionModels::Henry<Thermo, OtherThermo>::Yf
const volScalarField& Tf
) const
{
if (this->speciesNames_.found(speciesName))
{
const label index = this->speciesNames_[speciesName];
const label index = this->speciesNames_.find(speciesName);
if (index >= 0)
{
return
k_[index]
*this->otherThermo_.composition().Y(speciesName)

View File

@ -46,10 +46,7 @@ Foam::InterfaceCompositionModel<Thermo, OtherThermo>::getLocalThermo
return
globalThermo.getLocalThermo
(
globalThermo.species()
[
speciesName
]
globalThermo.species().find(speciesName)
);
}
@ -109,7 +106,7 @@ Foam::InterfaceCompositionModel<Thermo, OtherThermo>::dY
Yf(speciesName, Tf)
- thermo_.composition().Y()
[
thermo_.composition().species()[speciesName]
thermo_.composition().species().find(speciesName)
];
}

View File

@ -75,8 +75,8 @@ NonRandomTwoLiquid
species1Name_ = this->speciesNames_[0];
species2Name_ = this->speciesNames_[1];
species1Index_ = this->thermo_.composition().species()[species1Name_];
species2Index_ = this->thermo_.composition().species()[species2Name_];
species1Index_ = this->thermo_.composition().species().find(species1Name_);
species2Index_ = this->thermo_.composition().species().find(species2Name_);
alpha12_.read("alpha", dict.subDict(species1Name_));
alpha21_.read("alpha", dict.subDict(species2Name_));

View File

@ -58,7 +58,7 @@ Foam::interfaceCompositionModels::Saturated<Thermo, OtherThermo>::Saturated
saturatedName_(this->speciesNames_[0]),
saturatedIndex_
(
this->thermo_.composition().species()[saturatedName_]
this->thermo_.composition().species().find(saturatedName_)
),
saturationModel_
(
@ -112,7 +112,7 @@ Foam::interfaceCompositionModels::Saturated<Thermo, OtherThermo>::Yf
{
const label speciesIndex
(
this->thermo_.composition().species()[speciesName]
this->thermo_.composition().species().find(speciesName)
);
return
@ -139,7 +139,7 @@ Foam::interfaceCompositionModels::Saturated<Thermo, OtherThermo>::YfPrime
{
const label speciesIndex
(
this->thermo_.composition().species()[speciesName]
this->thermo_.composition().species().find(speciesName)
);
return

View File

@ -63,14 +63,14 @@ Foam::MultiComponentPhaseModel<BasePhaseModel>::MultiComponentPhaseModel
),
inertIndex_(-1)
{
const word inertSpecie
word inertSpecie;
if
(
this->thermo_->getOrDefault("inertSpecie", word::null)
);
if (inertSpecie != word::null)
this->thermo_->readIfPresent("inertSpecie", inertSpecie)
&& !inertSpecie.empty()
)
{
inertIndex_ = this->thermo_->composition().species()[inertSpecie];
inertIndex_ = this->thermo_->composition().species().find(inertSpecie);
}
PtrList<volScalarField>& Y = this->thermo_->composition().Y();

View File

@ -238,7 +238,7 @@ Foam::radiation::greyMeanAbsorptionEmission::aCont(const label bandI) const
invWt += mixture.Y(s)[celli]/mixture.W(s);
}
label index = mixture.species()[iter.key()];
const label index = mixture.species().find(iter.key());
scalar Xk = mixture.Y(index)[celli]/(mixture.W(index)*invWt);
Xipi = Xk*paToAtm(p[celli]);

View File

@ -73,7 +73,7 @@ greyMeanSolidAbsorptionEmission::X(const word specie) const
}
}
const scalarField& Yj = mixture_.Y(specie);
const label mySpecieI = mixture_.species()[specie];
const label mySpecieI = mixture_.species().find(specie);
forAll(Xj, iCell)
{
Xj[iCell] = Yj[iCell]/mixture_.rho(mySpecieI, p[iCell], T[iCell]);
@ -166,7 +166,7 @@ calc(const label propertyId) const
{
if (mixture_.contains(iter.key()))
{
a += solidData_[iter()][propertyId]*X(iter.key());
a += solidData_[iter.val()][propertyId]*X(iter.key());
}
}

View File

@ -249,7 +249,7 @@ Foam::radiation::wideBandAbsorptionEmission::aCont(const label bandi) const
invWt += mixture.Y(s)[celli]/mixture.W(s);
}
const label index = mixture.species()[iter.key()];
const label index = mixture.species().find(iter.key());
const scalar Xk =
mixture.Y(index)[celli]/(mixture.W(index)*invWt);

View File

@ -133,7 +133,7 @@ Foam::radiation::mixtureFractionSoot<ThermoType>::mixtureFractionSoot
mappingFieldName_ = mixture_.Y(index).name();
}
const label mapFieldIndex = mixture_.species()[mappingFieldName_];
const label mapFieldIndex = mixture_.species().find(mappingFieldName_);
mapFieldMax_ = mixture_.Yprod0()[mapFieldIndex];

View File

@ -99,7 +99,7 @@ inline Foam::volScalarField& Foam::basicMultiComponentMixture::Y
const word& specieName
)
{
return Y_[species_[specieName]];
return Y_[species_.find(specieName)];
}
@ -108,7 +108,7 @@ inline const Foam::volScalarField& Foam::basicMultiComponentMixture::Y
const word& specieName
) const
{
return Y_[species_[specieName]];
return Y_[species_.find(specieName)];
}

View File

@ -60,7 +60,7 @@ void Foam::singleStepReactingMixture<ThermoType>::calculateqFuel()
template<class ThermoType>
void Foam::singleStepReactingMixture<ThermoType>::massAndAirStoichRatios()
{
const label O2Index = this->species()["O2"];
const label O2Index = this->species().find("O2");
const scalar Wu = this->speciesData()[fuelIndex_].W();
stoicRatio_ =
@ -136,7 +136,7 @@ void Foam::singleStepReactingMixture<ThermoType>::fresCorrect()
{
const Reaction<ThermoType>& reaction = this->operator[](0);
const label O2Index = this->species()["O2"];
const label O2Index = this->species().find("O2");
const volScalarField& YFuel = this->Y()[fuelIndex_];
const volScalarField& YO2 = this->Y()[O2Index];
@ -204,8 +204,8 @@ Foam::singleStepReactingMixture<ThermoType>::singleStepReactingMixture
specieStoichCoeffs_(this->species_.size(), Zero),
Yprod0_(this->species_.size(), Zero),
fres_(Yprod0_.size()),
inertIndex_(this->species()[thermoDict.get<word>("inertSpecie")]),
fuelIndex_(this->species()[thermoDict.get<word>("fuel")]),
inertIndex_(this->species().find(thermoDict.get<word>("inertSpecie"))),
fuelIndex_(this->species().find(thermoDict.get<word>("fuel"))),
specieProd_(Yprod0_.size(), 1)
{
if (this->size() == 1)

View File

@ -93,7 +93,7 @@ Foam::solidReaction<ReactionThermo>::solidReaction
speciesTable allSpecies(species);
for (const word& gasName : pyrolisisGases_)
{
allSpecies.append(gasName);
allSpecies.appendUniq(gasName);
}
List<specieCoeffs> dummyLhs;
List<specieCoeffs> dummyRhs;

View File

@ -224,7 +224,7 @@ Foam::Reaction<ReactionThermo>::specieCoeffs::specieCoeffs
}
// Lookup specie name: -1 if not found
index = species[specieName];
index = species.find(specieName);
if (failUnknownSpecie && index < 0)
{

View File

@ -53,13 +53,13 @@ inline Foam::LangmuirHinshelwoodReactionRate::LangmuirHinshelwoodReactionRate
inline Foam::LangmuirHinshelwoodReactionRate::LangmuirHinshelwoodReactionRate
(
const speciesTable& st,
const speciesTable& species,
const dictionary& dict
)
:
co_(st["CO"]),
c3h6_(st["C3H6"]),
no_(st["NO"])
co_(species.find("CO")),
c3h6_(species.find("C3H6")),
no_(species.find("NO"))
{
// read (A, Ta) pairs
FixedList<Tuple2<scalar, scalar>, n_> coeffs(dict.lookup("coeffs"));

View File

@ -41,7 +41,7 @@ inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
if (size() != species_.size())
{
FatalErrorInFunction
<< "number of efficiencies = " << size()
<< "Number of efficiencies = " << size()
<< " is not equal to the number of species " << species_.size()
<< exit(FatalError);
}
@ -63,14 +63,24 @@ inline Foam::thirdBodyEfficiencies::thirdBodyEfficiencies
if (coeffs.size() != species_.size())
{
FatalIOErrorInFunction(dict)
<< "number of efficiencies = " << coeffs.size()
<< " is not equat to the number of species " << species_.size()
<< "Number of efficiencies = " << coeffs.size()
<< " is not equal to the number of species " << species_.size()
<< exit(FatalIOError);
}
forAll(coeffs, i)
for (const auto& coeff : coeffs)
{
operator[](species[coeffs[i].first()]) = coeffs[i].second();
const label idx = species.find(coeff.first());
if (idx < 0)
{
FatalIOErrorInFunction(dict)
<< "No such species: " << coeffs.first()
<< ", available: " << flatOutput(species) << endl
<< exit(FatalIOError);
}
operator[](idx) = coeff.second();
}
}
else

View File

@ -34,6 +34,7 @@ Description
#ifndef speciesTable_H
#define speciesTable_H
#include "wordList.H"
#include "hashedWordList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //