ENH: for-range, forAllIters() ... in thermophysicalModels/

- reduced clutter when iterating over containers
This commit is contained in:
Mark Olesen
2019-01-07 09:20:51 +01:00
committed by Andrew Heather
parent 5f42b5df9f
commit 6cbe89720d
8 changed files with 89 additions and 167 deletions

View File

@ -269,7 +269,7 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
) )
); );
typename Thermo::fvMeshDictPhaseConstructorTable::iterator cstrIter = auto cstrIter =
lookupThermo<Thermo, typename Thermo::fvMeshDictPhaseConstructorTable> lookupThermo<Thermo, typename Thermo::fvMeshDictPhaseConstructorTable>
( (
thermoDict, thermoDict,

View File

@ -142,14 +142,13 @@ void Foam::chemistryTabulationMethods::ISAT<CompType, ThermoType>::addToMRU
{ {
if (maxMRUSize_ > 0 && MRURetrieve_) if (maxMRUSize_ > 0 && MRURetrieve_)
{ {
typename SLList<chemPointISAT<CompType, ThermoType>*>::iterator iter = auto iter = MRUList_.begin();
MRUList_.begin();
// First search if the chemPoint is already in the list // First search if the chemPoint is already in the list
bool isInList = false; bool isInList = false;
for ( ; iter != MRUList_.end(); ++iter) for (; iter.good(); ++iter)
{ {
if (iter() == phi0) if (*iter == phi0)
{ {
isInList = true; isInList = true;
break; break;
@ -161,10 +160,7 @@ void Foam::chemistryTabulationMethods::ISAT<CompType, ThermoType>::addToMRU
// If it is in the list, then move it to front // If it is in the list, then move it to front
if (iter != MRUList_.begin()) if (iter != MRUList_.begin())
{ {
// iter hold the position of the element to move
MRUList_.remove(iter); MRUList_.remove(iter);
// Insert the element in front of the list
MRUList_.insert(phi0); MRUList_.insert(phi0);
} }
} }

View File

@ -134,12 +134,6 @@ greyMeanSolidAbsorptionEmission
} }
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::radiation::greyMeanSolidAbsorptionEmission::
~greyMeanSolidAbsorptionEmission()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -167,7 +161,7 @@ calc(const label propertyId) const
scalarField& a = ta.ref().primitiveFieldRef(); scalarField& a = ta.ref().primitiveFieldRef();
forAllConstIter(HashTable<label>, speciesNames_, iter) forAllConstIters(speciesNames_, iter)
{ {
if (mixture_.contains(iter.key())) if (mixture_.contains(iter.key()))
{ {

View File

@ -2,10 +2,8 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd. \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,7 +59,6 @@ class greyMeanSolidAbsorptionEmission
: :
public absorptionEmissionModel public absorptionEmissionModel
{ {
private: private:
// Private data // Private data
@ -115,23 +112,16 @@ public:
//- Destructor //- Destructor
virtual ~greyMeanSolidAbsorptionEmission(); virtual ~greyMeanSolidAbsorptionEmission() = default;
// Member Functions // Member Functions
// Access //- Absorption coefficient for continuous phase
tmp<volScalarField> aCont(const label bandI = 0) const;
// Absorption coefficient //- Emission coefficient for continuous phase
tmp<volScalarField> eCont(const label bandI = 0) const;
//- Absorption coefficient for continuous phase
tmp<volScalarField> aCont(const label bandI = 0) const;
// Emission coefficient
//- Emission coefficient for continuous phase
tmp<volScalarField> eCont(const label bandI = 0) const;
// Member Functions // Member Functions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -425,12 +425,12 @@ bool finishReaction = false;
if (newFormat_) if (newFormat_)
{ {
specieString.replaceAll(" ", "_"); specieString.replaceAll(" ", "_");
size_t strEnd = specieString.find_last_not_of('_'); const auto strEnd = specieString.find_last_not_of('_');
currentSpecieName = specieString.substr(0, strEnd + 1); currentSpecieName = specieString.substr(0, strEnd + 1);
} }
else else
{ {
size_t spacePos = specieString.find(' '); const auto spacePos = specieString.find(' ');
if (spacePos != string::npos) if (spacePos != string::npos)
{ {
currentSpecieName = specieString.substr(0, spacePos); currentSpecieName = specieString.substr(0, spacePos);
@ -459,13 +459,12 @@ bool finishReaction = false;
for (int i=0; i<4; i++) for (int i=0; i<4; i++)
{ {
word elementName = word::validate(thermoFormula.substr(5*i, 2)); word elementName = word::validate(thermoFormula.substr(5*i, 2));
label nAtoms = atoi(thermoFormula.substr(5*i + 2, 3).c_str()); const int nAtoms = atoi(thermoFormula.substr(5*i + 2, 3).c_str());
if (elementName.size() && nAtoms) if (elementName.size() && nAtoms)
{ {
correctElementName(elementName); correctElementName(elementName);
currentSpecieComposition[nSpecieElements].name() = currentSpecieComposition[nSpecieElements].name() = elementName;
elementName;
currentSpecieComposition[nSpecieElements++].nAtoms() = nAtoms; currentSpecieComposition[nSpecieElements++].nAtoms() = nAtoms;
} }
} }
@ -503,38 +502,26 @@ bool finishReaction = false;
<readThermoFormula2>{thermoFormula2} { <readThermoFormula2>{thermoFormula2} {
const string thermoFormula(YYText()); const string thermoFormula(YYText());
word elementName = word::validate(thermoFormula.substr(0, 2)); word elementName = word::validate(thermoFormula.substr(0, 2));
const label nAtoms = atoi(thermoFormula.substr(2, 3).c_str()); const int nAtoms = atoi(thermoFormula.substr(2, 3).c_str());
if if
( (
elementName.size() elementName.size()
&& elementName.find('0') == string::npos && elementName.find('0') == std::string::npos
&& nAtoms && nAtoms
) )
{ {
correctElementName(elementName); correctElementName(elementName);
currentSpecieComposition[nSpecieElements].name() = currentSpecieComposition[nSpecieElements].name() = elementName;
elementName;
currentSpecieComposition[nSpecieElements++].nAtoms() = nAtoms; currentSpecieComposition[nSpecieElements++].nAtoms() = nAtoms;
} }
currentSpecieComposition.setSize(nSpecieElements); currentSpecieComposition.setSize(nSpecieElements);
speciesCompositionTable::iterator specieCompositionIter // Add current specie composition to the hash table
( // - overwrite existing
speciesComposition_.find(currentSpecieName) speciesComposition_.erase(currentSpecieName);
); speciesComposition_.set(currentSpecieName, currentSpecieComposition);
if (specieCompositionIter != speciesComposition_.end())
{
speciesComposition_.erase(specieCompositionIter);
}
speciesComposition_.insert
(
currentSpecieName,
currentSpecieComposition
);
BEGIN(readThermoLineLabel1); BEGIN(readThermoLineLabel1);
} }
@ -589,17 +576,9 @@ bool finishReaction = false;
<readThermoLineLabel4>{thermoLineLabel4} { <readThermoLineLabel4>{thermoLineLabel4} {
HashPtrTable<gasHThermoPhysics>::iterator specieThermoIter speciesThermo_.erase(currentSpecieName);
(
speciesThermo_.find(currentSpecieName)
);
if (specieThermoIter != speciesThermo_.end()) speciesThermo_.set
{
speciesThermo_.erase(specieThermoIter);
}
speciesThermo_.insert
( (
currentSpecieName, currentSpecieName,
autoPtr<gasHThermoPhysics>::New autoPtr<gasHThermoPhysics>::New
@ -673,14 +652,12 @@ bool finishReaction = false;
const word keyword = word::validate(YYText()); const word keyword = word::validate(YYText());
HashTable<int>::iterator reactionKeywordIter const auto reactionKeywordIter =
( reactionKeywordTable_.cfind(keyword);
reactionKeywordTable_.find(keyword)
);
if (reactionKeywordIter != reactionKeywordTable_.end()) if (reactionKeywordIter.found())
{ {
switch(reactionKeywordIter()) switch (reactionKeywordIter.val())
{ {
case duplicateReactionType: case duplicateReactionType:
{ {
@ -785,12 +762,10 @@ bool finishReaction = false;
{ {
currentSpecieName = word::validate(YYText()); currentSpecieName = word::validate(YYText());
HashTable<label>::iterator specieIndexIter const auto specieIndexIter =
( specieIndices_.cfind(currentSpecieName);
specieIndices_.find(currentSpecieName)
);
if (specieIndexIter != specieIndices_.end()) if (specieIndexIter.found())
{ {
if (finishReaction) if (finishReaction)
{ {
@ -815,7 +790,7 @@ bool finishReaction = false;
lrhsPtr = &lhs; lrhsPtr = &lhs;
} }
currentSpecieCoeff.index = specieIndexIter(); currentSpecieCoeff.index = specieIndexIter.val();
lrhsPtr->append(currentSpecieCoeff); lrhsPtr->append(currentSpecieCoeff);
BEGIN(readReactionDelimiter); BEGIN(readReactionDelimiter);
@ -829,16 +804,14 @@ bool finishReaction = false;
<readReactionKeyword>{reactionKeywordSlash} { <readReactionKeyword>{reactionKeywordSlash} {
word keyword = word::validate(YYText()); const word keyword = word::validate(YYText());
HashTable<int>::iterator reactionKeywordIter const auto reactionKeywordIter =
( reactionKeywordTable_.cfind(keyword);
reactionKeywordTable_.find(keyword)
);
if (reactionKeywordIter != reactionKeywordTable_.end()) if (reactionKeywordIter.found())
{ {
switch(reactionKeywordIter()) switch (reactionKeywordIter.val())
{ {
case unimolecularFallOffReactionType: case unimolecularFallOffReactionType:
{ {
@ -1144,14 +1117,12 @@ bool finishReaction = false;
} }
else else
{ {
HashTable<label>::iterator specieIndexIter const auto specieIndexIter =
( specieIndices_.cfind(keyword);
specieIndices_.find(keyword)
);
if (specieIndexIter != specieIndices_.end()) if (specieIndexIter.found())
{ {
currentThirdBodyIndex = specieIndexIter(); currentThirdBodyIndex = specieIndexIter.val();
} }
else else
{ {
@ -1170,12 +1141,10 @@ bool finishReaction = false;
<readSpecieNamePlus>"+" { <readSpecieNamePlus>"+" {
currentSpecieName += "+"; currentSpecieName += "+";
HashTable<label>::iterator specieIndexIter const auto specieIndexIter =
( specieIndices_.cfind(currentSpecieName);
specieIndices_.find(currentSpecieName)
);
if (specieIndexIter != specieIndices_.end()) if (specieIndexIter.found())
{ {
if (finishReaction) if (finishReaction)
{ {
@ -1200,7 +1169,7 @@ bool finishReaction = false;
lrhsPtr = &lhs; lrhsPtr = &lhs;
} }
currentSpecieCoeff.index = specieIndexIter(); currentSpecieCoeff.index = specieIndexIter.val();
lrhsPtr->append(currentSpecieCoeff); lrhsPtr->append(currentSpecieCoeff);
BEGIN(readReactionDelimiter); BEGIN(readReactionDelimiter);
@ -1339,15 +1308,13 @@ bool finishReaction = false;
if (pDependentSpecieName != "M") if (pDependentSpecieName != "M")
{ {
HashTable<label>::iterator specieIndexIter const auto specieIndexIter =
( specieIndices_.cfind(pDependentSpecieName);
specieIndices_.find(pDependentSpecieName)
);
if (specieIndexIter != specieIndices_.end()) if (specieIndexIter.found())
{ {
thirdBodyEfficiencies = 0.0; thirdBodyEfficiencies = 0.0;
thirdBodyEfficiencies[specieIndexIter()] = 1.0; thirdBodyEfficiencies[specieIndexIter.val()] = 1.0;
} }
else else
{ {
@ -1385,14 +1352,11 @@ bool finishReaction = false;
<readReactionOrderSpecie>{specieName} { <readReactionOrderSpecie>{specieName} {
currentSpecieName = word::validate(YYText()); currentSpecieName = word::validate(YYText());
HashTable<label>::iterator specieIndexIter const auto specieIndexIter = specieIndices_.cfind(currentSpecieName);
(
specieIndices_.find(currentSpecieName)
);
if (specieIndexIter != specieIndices_.end()) if (specieIndexIter.found())
{ {
currentSpecieIndex = specieIndexIter(); currentSpecieIndex = specieIndexIter.val();
} }
else else
{ {
@ -1414,11 +1378,11 @@ bool finishReaction = false;
bool found = false; bool found = false;
forAll(lrhs, i) for (gasHReaction::specieCoeffs& coeffs : lrhs)
{ {
if (lrhs[i].index == currentSpecieIndex) if (coeffs.index == currentSpecieIndex)
{ {
lrhs[i].exponent = stringToScalar(YYText()); coeffs.exponent = stringToScalar(YYText());
found = true; found = true;
break; break;
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -73,52 +73,39 @@ void Foam::foamChemistryReader<ThermoType>::readSpeciesComposition()
} }
} }
// Loop through all species in thermoDict to retrieve // Loop through all species in thermoDict to retrieve species composition
// the species composition for (const word& specieName : speciesTable_)
forAll(speciesTable_, si)
{ {
if (thermoDict_.subDict(speciesTable_[si]).isDict("elements")) const dictionary* elemsDict =
{ thermoDict_.subDict(specieName).findDict("elements");
dictionary currentElements
(
thermoDict_.subDict(speciesTable_[si]).subDict("elements")
);
wordList currentElementsName(currentElements.toc()); if (!elemsDict)
List<specieElement> currentComposition(currentElementsName.size());
forAll(currentElementsName, eni)
{
currentComposition[eni].name() = currentElementsName[eni];
currentComposition[eni].nAtoms() =
currentElements.lookupOrDefault
(
currentElementsName[eni],
0
);
}
// Add current specie composition to the hash table
speciesCompositionTable::iterator specieCompositionIter
(
speciesComposition_.find(speciesTable_[si])
);
if (specieCompositionIter != speciesComposition_.end())
{
speciesComposition_.erase(specieCompositionIter);
}
speciesComposition_.insert(speciesTable_[si], currentComposition);
}
else
{ {
FatalIOErrorInFunction(thermoDict_) FatalIOErrorInFunction(thermoDict_)
<< "Specie " << speciesTable_[si] << "Specie " << specieName
<< " does not contain element description." << " does not contain \"elements\" description."
<< exit(FatalIOError); << exit(FatalIOError);
} }
wordList elemNames(elemsDict->toc());
List<specieElement> currentComposition(elemNames.size());
forAll(elemNames, eni)
{
currentComposition[eni].name() = elemNames[eni];
currentComposition[eni].nAtoms() =
elemsDict->lookupOrDefault<label>
(
elemNames[eni],
0
);
}
// Add current specie composition to the hash table
// - overwrite existing
speciesComposition_.erase(specieName);
speciesComposition_.set(specieName, currentComposition);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -72,13 +72,6 @@ Foam::ReactionList<ThermoType>::ReactionList(const ReactionList& reactions)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ThermoType>
Foam::ReactionList<ThermoType>::~ReactionList()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ThermoType> template<class ThermoType>
@ -106,10 +99,8 @@ void Foam::ReactionList<ThermoType>::write(Ostream& os) const
{ {
os.beginBlock("reactions"); os.beginBlock("reactions");
forAllConstIter(typename SLPtrList<Reaction<ThermoType>>, *this, iter) for (const Reaction<ThermoType>& r : *this)
{ {
const Reaction<ThermoType>& r = iter();
os.beginBlock(r.name()); os.beginBlock(r.name());
os.writeEntry("type", r.type()); os.writeEntry("type", r.type());

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -100,7 +100,7 @@ public:
//- Destructor //- Destructor
~ReactionList(); ~ReactionList() = default;
// Public Member Functions // Public Member Functions