From 3416151deed918de563586f3ecdb91d566a30a2f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 14 Jul 2021 11:12:08 +0200 Subject: [PATCH] ENH: improve isolation of basicThermo internals (as private) - getThermoOrDie: returns constructor pointer, or FatalError. Better isolation and avoids additional template/typename previously needed with ambiguous method name (lookupThermo). - makeThermoName: centralize dictionary -> stringified name - splitThermoName: use stringOps functionality --- .../combustionModelTemplates.C | 93 ++++---- .../basic/basicThermo/basicThermo.C | 186 +++++++++++----- .../basic/basicThermo/basicThermo.H | 92 +++++--- .../basic/basicThermo/basicThermoTemplates.C | 199 ++++++------------ .../chemistryReductionMethodNew.C | 73 ++++--- .../chemistryTabulationMethodNew.C | 75 +++---- .../basicChemistryModelTemplates.C | 89 ++++---- .../basicSolidChemistryModel.H | 8 +- .../basicSolidChemistryModelNew.C | 77 +++---- 9 files changed, 468 insertions(+), 424 deletions(-) diff --git a/src/combustionModels/combustionModel/combustionModelTemplates.C b/src/combustionModels/combustionModel/combustionModelTemplates.C index e4576b87aa..fcf4d4a059 100644 --- a/src/combustionModels/combustionModel/combustionModelTemplates.C +++ b/src/combustionModels/combustionModel/combustionModelTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,6 +73,7 @@ Foam::autoPtr Foam::combustionModel::New << "combustion model " << combModelName << "." << endl; } + const word compCombModelName ( combModelName + '<' + CombustionModel::reactionThermo::typeName + '>' @@ -87,20 +88,27 @@ Foam::autoPtr Foam::combustionModel::New const auto& cnstrTable = *(CombustionModel::dictionaryConstructorTablePtr_); - auto compCstrIter = cnstrTable.cfind(compCombModelName); + auto ctorIter = cnstrTable.cfind(thermoCombModelName); - auto thermoCstrIter = cnstrTable.cfind(thermoCombModelName); - - if (!compCstrIter.found() && !thermoCstrIter.found()) + if (!ctorIter.found()) { - wordList thisCmpts; - thisCmpts.append(word::null); - thisCmpts.append(CombustionModel::reactionThermo::typeName); - thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5)); + ctorIter = cnstrTable.cfind(compCombModelName); + } - wordList validNames; + if (!ctorIter.found()) + { + const wordList names(cnstrTable.sortedToc()); - List validCmpts2; + /// DynamicList thisCmpts(6); + /// thisCmpts.append(CombustionModel::reactionThermo::typeName); + /// thisCmpts.append(basicThermo::splitThermoName + /// ( + /// basicThermo::splitThermoName(thermo.thermoName(), 5) + /// ); + /// + /// DynamicList validNames; + + DynamicList validCmpts2; validCmpts2.append ( // Header @@ -112,7 +120,7 @@ Foam::autoPtr Foam::combustionModel::New }) ); - List validCmpts7; + DynamicList validCmpts7; validCmpts7.append ( // Header @@ -129,61 +137,56 @@ Foam::autoPtr Foam::combustionModel::New }) ); - for (const word& validName : cnstrTable.sortedToc()) + for (const word& validName : names) { - wordList cmpts(basicThermo::splitThermoName(validName, 2)); + wordList cmpts(basicThermo::splitThermoName(validName, 0)); if (cmpts.size() == 2) { - validCmpts2.append(cmpts); + validCmpts2.append(std::move(cmpts)); } - else + else if (cmpts.size() == 7) { - cmpts = basicThermo::splitThermoName(validName, 7); - if (cmpts.size() == 7) - { - validCmpts7.append(cmpts); - } - } - - bool isValid = true; - for (label i = 1; i < cmpts.size() && isValid; ++i) - { - isValid = isValid && cmpts[i] == thisCmpts[i]; - } - - if (isValid) - { - validNames.append(cmpts[0]); + /// if (thisCmpts == SubList(cmpts, 6, 1)) + /// { + /// validNames.append(cmpts[0]); + /// } + validCmpts7.append(std::move(cmpts)); } } - FatalErrorInLookup ( combustionModel::typeName, combModelName, cnstrTable - ) - << "All " << validCmpts2[0][0] << '/' << validCmpts2[0][1] - << " combinations are:" << nl << nl; + ); - printTable(validCmpts2, FatalErrorInFunction) - << nl; + if (validCmpts2.size() > 1) + { + FatalError + << "All " << validCmpts2[0][0] << '/' << validCmpts2[0][1] + << " combinations are:" << nl << nl; - FatalErrorInFunction - << "All " << validCmpts7[0][0] << '/' << validCmpts7[0][1] - << "/thermoPhysics combinations are:" << nl << nl; + printTable(validCmpts2, FatalError) << nl; + } - printTable(validCmpts7, FatalErrorInFunction) + if (validCmpts7.size() > 1) + { + FatalError + << "All " << validCmpts7[0][0] << '/' << validCmpts7[0][1] + << "/thermoPhysics combinations are:" << nl << nl; + + printTable(validCmpts7, FatalError) << nl; + } + + FatalError << exit(FatalError); } return autoPtr ( - thermoCstrIter.found() - ? thermoCstrIter()(combModelName, thermo, turb, combustionProperties) - : compCstrIter()(combModelName, thermo, turb, combustionProperties) + ctorIter()(combModelName, thermo, turb, combustionProperties) ); } diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C index b25fd1d891..b2204d0d42 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C @@ -27,6 +27,8 @@ License \*---------------------------------------------------------------------------*/ #include "basicThermo.H" +#include "stringOps.H" +#include "wordIOList.H" #include "zeroGradientFvPatchFields.H" #include "fixedEnergyFvPatchScalarField.H" #include "gradientEnergyFvPatchScalarField.H" @@ -47,6 +49,115 @@ namespace Foam const Foam::word Foam::basicThermo::dictName("thermophysicalProperties"); +const Foam::wordList Foam::basicThermo::componentHeader4 +({ + "type", + "mixture", + "properties", + "energy" +}); + +const Foam::wordList Foam::basicThermo::componentHeader7 +({ + "type", + "mixture", + "transport", + "thermo", + "equationOfState", + "specie", + "energy" +}); + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +Foam::Ostream& Foam::basicThermo::printThermoNames +( + Ostream& os, + const wordList& cmptNames, + const wordList& thermoNames +) +{ + const int nCmpt = cmptNames.size(); + + // Build a table of constituent parts by split name into constituent parts + // - remove incompatible entries from the list + // - note: row-0 contains the names of constituent parts (ie, the header) + + DynamicList outputTbl; + outputTbl.resize(thermoNames.size()+1); + + label rowi = 0; + + // Header + outputTbl[rowi] = cmptNames; + if (!outputTbl[rowi].empty()) + { + ++rowi; + } + + for (const word& thermoName : thermoNames) + { + outputTbl[rowi] = basicThermo::splitThermoName(thermoName, nCmpt); + if (!outputTbl[rowi].empty()) + { + ++rowi; + } + } + + if (rowi > 1) + { + outputTbl.resize(rowi); + Foam::printTable(outputTbl, os); + } + + return os; +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::word Foam::basicThermo::makeThermoName +( + const dictionary& thermoTypeDict, + const wordList*& cmptHeaderPtr +) +{ + if (thermoTypeDict.found("properties")) + { + if (cmptHeaderPtr) + { + cmptHeaderPtr = &(componentHeader4); + } + + return word + ( + thermoTypeDict.get("type") + '<' + + thermoTypeDict.get("mixture") + '<' + + thermoTypeDict.get("properties") + ',' + + thermoTypeDict.get("energy") + ">>" + ); + } + else + { + if (cmptHeaderPtr) + { + cmptHeaderPtr = &(componentHeader7); + } + + return word + ( + thermoTypeDict.get("type") + '<' + + thermoTypeDict.get("mixture") + '<' + + thermoTypeDict.get("transport") + '<' + + thermoTypeDict.get("thermo") + '<' + + thermoTypeDict.get("equationOfState") + '<' + + thermoTypeDict.get("specie") + ">>," + + thermoTypeDict.get("energy") + ">>>" + ); + } +} + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -60,14 +171,17 @@ Foam::wordList Foam::basicThermo::heBoundaryBaseTypes() { if (isA(tbf[patchi])) { - const fixedJumpFvPatchScalarField& pf = - dynamic_cast(tbf[patchi]); + const auto& pf = + dynamic_cast + ( + tbf[patchi] + ); hbt[patchi] = pf.interfaceFieldType(); } else if (isA(tbf[patchi])) { - const fixedJumpAMIFvPatchScalarField& pf = + const auto& pf = dynamic_cast ( tbf[patchi] @@ -345,13 +459,14 @@ const Foam::basicThermo& Foam::basicThermo::lookupThermo forAllConstIters(thermos, iter) { + thermo = iter.val(); if ( - &(iter()->he().internalField()) + &(thermo->he().internalField()) == &(pf.internalField()) ) { - return *iter(); + return *thermo; } } @@ -455,60 +570,29 @@ void Foam::basicThermo::validate Foam::wordList Foam::basicThermo::splitThermoName ( - const word& thermoName, - const int nCmpt + const std::string& thermoName, + const int nExpectedCmpts ) { - wordList cmpts(nCmpt); + // Split on ",<>" but include space for good measure. + // Splits things like + // "hePsiThermo>,enthalpy>>>" - string::size_type beg=0, end=0, endb=0, endc=0; - int i = 0; + const auto parsed = stringOps::splitAny(thermoName, " ,<>"); + const int nParsed(parsed.size()); - while - ( - (endb = thermoName.find('<', beg)) != string::npos - || (endc = thermoName.find(',', beg)) != string::npos - ) + wordList cmpts; + + if (!nExpectedCmpts || nParsed == nExpectedCmpts) { - if (endb == string::npos) - { - end = endc; - } - else if ((endc = thermoName.find(',', beg)) != string::npos) - { - end = std::min(endb, endc); - } - else - { - end = endb; - } + cmpts.resize(nParsed); - if (beg < end) + auto iter = cmpts.begin(); + for (const auto& sub : parsed) { - cmpts[i] = thermoName.substr(beg, end-beg); - cmpts[i++].replaceAll(">",""); - - // If the number of number of components in the name - // is greater than nCmpt return an empty list - if (i == nCmpt) - { - return wordList::null(); - } + *iter = word(sub.str()); + ++iter; } - beg = end + 1; - } - - // If the number of number of components in the name is not equal to nCmpt - // return an empty list - if (i + 1 != nCmpt) - { - return wordList::null(); - } - - if (beg < thermoName.size()) - { - cmpts[i] = thermoName.substr(beg, string::npos); - cmpts[i].replaceAll(">",""); } return cmpts; diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H index dcd7dce5df..f4ffb6491f 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H @@ -65,6 +65,55 @@ class basicThermo : public IOdictionary { + // Private Data + + //- Components names/order + static const wordList componentHeader4; + + //- Components names/order + static const wordList componentHeader7; + + + // Private Member Functions + + //- Construct name of thermo package from dictionary components + static word makeThermoName + ( + const dictionary& dict, + const wordList*& cmptHeaderPtr + ); + + //- Look up field from registry or construct and store + static volScalarField& lookupOrConstruct + ( + const fvMesh& mesh, + const word& fieldName, + bool& isOwner //!< Stored to registry by this instance + ); + + //- Generic lookup for thermodynamics package thermoTypeName + // \return constructor pointer, or FatalError + template + static typename ThermoConstructTable::mapped_type + getThermoOrDie + ( + const dictionary& thermoTypeDict, + ThermoConstructTable& thermoTable, + const word& thermoTypeName, + const wordList& cmptNames + ); + + //- Generic lookup for each of the related thermodynamics packages + // \return constructor pointer, or FatalError + template + static typename ThermoConstructTable::mapped_type + getThermoOrDie + ( + const dictionary& thermoDict, + ThermoConstructTable& thermoTable + ); + + protected: // Protected Data @@ -96,14 +145,6 @@ protected: // Protected Member Functions - //- Look up field from registry or construct and store - static volScalarField& lookupOrConstruct - ( - const fvMesh& mesh, - const word& fieldName, - bool& isOwner //!< Stored to registry by this instance - ); - //- Return the enthalpy/internal energy field boundary types //- by interrogating the temperature field boundary types wordList heBoundaryTypes(); @@ -173,24 +214,6 @@ public: // Selectors - //- Generic lookup for thermodynamics package thermoTypeName - template - static typename Table::iterator lookupThermo - ( - const dictionary& thermoTypeDict, - Table* tablePtr, - std::initializer_list cmptNames, - const word& thermoTypeName - ); - - //- Generic lookup for each of the related thermodynamics packages - template - static typename Table::iterator lookupThermo - ( - const dictionary& thermoDict, - Table* tablePtr - ); - //- Generic New for each of the related thermodynamics packages template static autoPtr New @@ -249,6 +272,14 @@ public: static const basicThermo& lookupThermo(const fvPatchScalarField& pf); + //- Print (filtered) table of thermo names, splits on \c " ,<>" + static Ostream& printThermoNames + ( + Ostream& os, + const wordList& cmptNames, + const wordList& thermoNames + ); + //- Check that the thermodynamics package is consistent // with energy forms supported by the application void validate @@ -287,11 +318,14 @@ public: const word& ) const; - //- Split name of thermo package into a list of the components names + //- Split thermo package name into a list of components names + // Splits on \c " ,<>" + // \return empty list if the split name does not have the + // expected number of components (non-zero). static wordList splitThermoName ( - const word& thermoName, - const int nCmpt + const std::string& thermoName, + const int nExpectedCmpts ); //- Update properties diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C index 38351182af..084e626996 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,140 +28,78 @@ License #include "basicThermo.H" -// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -typename Table::iterator Foam::basicThermo::lookupThermo +template +typename ThermoConstructTable::mapped_type +Foam::basicThermo::getThermoOrDie ( const dictionary& thermoTypeDict, - Table* tablePtr, - std::initializer_list cmptNames, - const word& thermoTypeName + ThermoConstructTable& thermoTable, + const word& thermoTypeName, + const wordList& cmptNames ) { // Lookup the thermo package - // Table iterator, not const_iterator - auto cstrIter = tablePtr->find(thermoTypeName); + auto ctorIter = thermoTable.cfind(thermoTypeName); // Print error message if package not found in the table - if (!cstrIter.found()) + if (!ctorIter.found()) { - const int nCmpt = cmptNames.size(); - - // Build a table of the thermo packages constituent parts - // Note: row-0 contains the names of constituent parts - List validCmpts(tablePtr->size()+1); - - // Header (row 0) - validCmpts[0].resize(nCmpt); - std::copy(cmptNames.begin(), cmptNames.end(), validCmpts[0].begin()); - - // Split the thermo package names into their constituent parts - // Removing incompatible entries from the list - label rowi = 1; - for (const word& validName : tablePtr->sortedToc()) - { - validCmpts[rowi] = Thermo::splitThermoName(validName, nCmpt); - - if (validCmpts[rowi].size()) - { - ++rowi; - } - } - validCmpts.resize(rowi); - - FatalIOErrorInLookup ( thermoTypeDict, Thermo::typeName, word::null, // Suppress long name? Just output dictionary (above) - *tablePtr + thermoTable ); - // Table of available packages (as constituent parts) - printTable(validCmpts, FatalIOError) - << exit(FatalIOError); + basicThermo::printThermoNames + ( + FatalIOError, + cmptNames, + thermoTable.sortedToc() + ) << exit(FatalIOError); + + // return nullptr; } - return cstrIter; + return ctorIter.val(); } -template -typename Table::iterator Foam::basicThermo::lookupThermo +template +typename ThermoConstructTable::mapped_type +Foam::basicThermo::getThermoOrDie ( const dictionary& thermoDict, - Table* tablePtr + ThermoConstructTable& thermoTable ) { - if (thermoDict.isDict("thermoType")) + const dictionary* dictptr = thermoDict.findDict("thermoType"); + + if (dictptr) { - const dictionary& thermoTypeDict = thermoDict.subDict("thermoType"); + const auto& thermoTypeDict = *dictptr; + + const wordList* cmptHeaderPtr = &(wordList::null()); + + // Thermo package name, constructed from components + const word thermoTypeName + ( + basicThermo::makeThermoName(thermoTypeDict, cmptHeaderPtr) + ); Info<< "Selecting thermodynamics package " << thermoTypeDict << endl; - if (thermoTypeDict.found("properties")) - { - std::initializer_list cmptNames - { - "type", - "mixture", - "properties", - "energy" - }; - - // Construct the name of the thermo package from the components - const word thermoTypeName - ( - thermoTypeDict.get("type") + '<' - + thermoTypeDict.get("mixture") + '<' - + thermoTypeDict.get("properties") + ',' - + thermoTypeDict.get("energy") + ">>" - ); - - return lookupThermo - ( - thermoTypeDict, - tablePtr, - cmptNames, - thermoTypeName - ); - } - else - { - std::initializer_list cmptNames - { - "type", - "mixture", - "transport", - "thermo", - "equationOfState", - "specie", - "energy" - }; - - // Construct the name of the thermo package from the components - const word thermoTypeName - ( - thermoTypeDict.get("type") + '<' - + thermoTypeDict.get("mixture") + '<' - + thermoTypeDict.get("transport") + '<' - + thermoTypeDict.get("thermo") + '<' - + thermoTypeDict.get("equationOfState") + '<' - + thermoTypeDict.get("specie") + ">>," - + thermoTypeDict.get("energy") + ">>>" - ); - - return lookupThermo - ( - thermoTypeDict, - tablePtr, - cmptNames, - thermoTypeName - ); - } + return getThermoOrDie + ( + thermoTypeDict, + thermoTable, + thermoTypeName, + *cmptHeaderPtr + ); } else { @@ -169,25 +107,26 @@ typename Table::iterator Foam::basicThermo::lookupThermo Info<< "Selecting thermodynamics package " << thermoTypeName << endl; - // Table iterator, not const_iterator - auto cstrIter = tablePtr->find(thermoTypeName); + auto ctorIter = thermoTable.cfind(thermoTypeName); - if (!cstrIter.found()) + if (!ctorIter.found()) { FatalIOErrorInLookup ( thermoDict, Thermo::typeName, thermoTypeName, - *tablePtr + thermoTable ) << exit(FatalIOError); } - return cstrIter; + return ctorIter.val(); } } +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // + template Foam::autoPtr Foam::basicThermo::New ( @@ -208,14 +147,13 @@ Foam::autoPtr Foam::basicThermo::New ) ); - auto cstrIter = - lookupThermo - ( - thermoDict, - Thermo::fvMeshConstructorTablePtr_ - ); + auto* ctorPtr = getThermoOrDie + ( + thermoDict, + *(Thermo::fvMeshConstructorTablePtr_) + ); - return autoPtr(cstrIter()(mesh, phaseName)); + return autoPtr(ctorPtr(mesh, phaseName)); } @@ -227,14 +165,13 @@ Foam::autoPtr Foam::basicThermo::New const word& phaseName ) { - auto cstrIter = - lookupThermo - ( - dict, - Thermo::dictionaryConstructorTablePtr_ - ); + auto* ctorPtr = getThermoOrDie + ( + dict, + *(Thermo::dictionaryConstructorTablePtr_) + ); - return autoPtr(cstrIter()(mesh, dict, phaseName)); + return autoPtr(ctorPtr(mesh, dict, phaseName)); } @@ -259,16 +196,14 @@ Foam::autoPtr Foam::basicThermo::New ) ); - auto cstrIter = - lookupThermo - ( - thermoDict, - Thermo::fvMeshDictPhaseConstructorTablePtr_ - ); + auto* ctorPtr = getThermoOrDie + ( + thermoDict, + *(Thermo::fvMeshDictPhaseConstructorTablePtr_) + ); - return autoPtr(cstrIter()(mesh, phaseName, dictName)); + return autoPtr(ctorPtr(mesh, phaseName, dictName)); } - // ************************************************************************* // diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReductionMethod/chemistryReductionMethodNew.C b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReductionMethod/chemistryReductionMethodNew.C index a42f3a37f5..e2fe639651 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReductionMethod/chemistryReductionMethodNew.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/reduction/chemistryReductionMethod/chemistryReductionMethodNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,23 +51,26 @@ Foam::chemistryReductionMethod::New + '<' + CompType::typeName + ',' + ThermoType::typeName() + '>' ); - auto cstrIter = dictionaryConstructorTablePtr_->cfind(methodTypeName); + const auto& cnstrTable = *(dictionaryConstructorTablePtr_); + + auto cstrIter = cnstrTable.cfind(methodTypeName); if (!cstrIter.found()) { + const wordList names(cnstrTable.sortedToc()); + constexpr const int nCmpt = 7; - wordList thisCmpts; - thisCmpts.append(word::null); - thisCmpts.append(CompType::typeName); - thisCmpts.append - ( - basicThermo::splitThermoName(ThermoType::typeName(), 5) - ); + /// DynamicList thisCmpts(6); + /// thisCmpts.append(CompType::typeName); + /// thisCmpts.append + /// ( + /// basicThermo::splitThermoName(ThermoType::typeName(), 5) + /// ); + /// + /// DynamicList validNames; - wordList validNames; - - List validCmpts; + DynamicList validCmpts; validCmpts.append ( // Header @@ -83,42 +86,38 @@ Foam::chemistryReductionMethod::New }) ); - for - ( - const word& validName - : dictionaryConstructorTablePtr_->sortedToc() - ) + for (const word& validName : names) { - validCmpts.append - ( - basicThermo::splitThermoName(validName, nCmpt) - ); - const wordList& cmpts = validCmpts.last(); + wordList cmpts(basicThermo::splitThermoName(validName, nCmpt)); - bool isValid = true; - for (label i = 1; i < cmpts.size() && isValid; ++i) + if (!cmpts.empty()) { - isValid = isValid && cmpts[i] == thisCmpts[i]; - } - - if (isValid) - { - validNames.append(cmpts[0]); + /// if (thisCmpts == SubList(cmpts, 6, 1)) + /// { + /// validNames.append(cmpts[0]); + /// } + validCmpts.append(std::move(cmpts)); } } - FatalErrorInLookup ( typeName_(), methodName, - *dictionaryConstructorTablePtr_ - ) - << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] - << "/thermoPhysics combinations:" << nl << nl; + cnstrTable + ); - // Table of available packages (as constituent parts) - printTable(validCmpts, FatalErrorInFunction) + if (validCmpts.size() > 1) + { + FatalError + << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] + << "/thermoPhysics combinations:" << nl << nl; + + // Table of available packages (as constituent parts) + printTable(validCmpts, FatalError) << nl; + } + + FatalError << exit(FatalError); } diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/chemistryTabulationMethod/chemistryTabulationMethodNew.C b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/chemistryTabulationMethod/chemistryTabulationMethodNew.C index 09ac87d906..78217af122 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/chemistryTabulationMethod/chemistryTabulationMethodNew.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/tabulation/chemistryTabulationMethod/chemistryTabulationMethodNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +39,7 @@ Foam::chemistryTabulationMethod::New TDACChemistryModel& chemistry ) { - const dictionary& tabulationDict(dict.subDict("tabulation")); + const dictionary& tabulationDict = dict.subDict("tabulation"); const word methodName(tabulationDict.get("method")); @@ -50,21 +50,26 @@ Foam::chemistryTabulationMethod::New + '<' + CompType::typeName + ',' + ThermoType::typeName() + '>' ); - auto cstrIter = dictionaryConstructorTablePtr_->cfind(methodTypeName); + const auto& cnstrTable = *(dictionaryConstructorTablePtr_); + + auto cstrIter = cnstrTable.cfind(methodTypeName); if (!cstrIter.found()) { - wordList thisCmpts; - thisCmpts.append(word::null); - thisCmpts.append(CompType::typeName); - thisCmpts.append - ( - basicThermo::splitThermoName(ThermoType::typeName(), 5) - ); + const wordList names(cnstrTable.sortedToc()); - wordList validNames; + constexpr const int nCmpt = 7; - List validCmpts; + /// DynamicList thisCmpts(6); + /// thisCmpts.append(CompType::typeName); + /// thisCmpts.append + /// ( + /// basicThermo::splitThermoName(ThermoType::typeName(), 5) + /// ); + /// + /// DynamicList validNames; + + DynamicList validCmpts; validCmpts.append ( wordList @@ -79,27 +84,17 @@ Foam::chemistryTabulationMethod::New }) ); - for - ( - const word& validName - : dictionaryConstructorTablePtr_->sortedToc() - ) + for (const word& validName : names) { - validCmpts.append - ( - basicThermo::splitThermoName(validName, 7) - ); - const wordList& cmpts = validCmpts.last(); + wordList cmpts(basicThermo::splitThermoName(validName, nCmpt)); - bool isValid = true; - for (label i = 1; i < cmpts.size() && isValid; ++i) + if (!cmpts.empty()) { - isValid = isValid && cmpts[i] == thisCmpts[i]; - } - - if (isValid) - { - validNames.append(cmpts[0]); + /// if (thisCmpts == SubList(cmpts, 6, 1)) + /// { + /// validNames.append(cmpts[0]); + /// } + validCmpts.append(std::move(cmpts)); } } @@ -108,13 +103,20 @@ Foam::chemistryTabulationMethod::New ( typeName_(), methodName, - *dictionaryConstructorTablePtr_ - ) - << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] - << "/thermoPhysics combinations:" << nl << nl; + cnstrTable + ); - // Table of available packages (as constituent parts) - printTable(validCmpts, FatalErrorInFunction) + if (validCmpts.size() > 1) + { + FatalError + << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] + << "/thermoPhysics combinations:" << nl << nl; + + // Table of available packages (as constituent parts) + printTable(validCmpts, FatalError) << nl; + } + + FatalError << exit(FatalError); } @@ -122,7 +124,6 @@ Foam::chemistryTabulationMethod::New ( cstrIter()(dict, chemistry) ); - } diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C index b6293541dd..1dff300bf7 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelTemplates.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -87,13 +87,14 @@ Foam::autoPtr Foam::basicChemistryModel::New ) ); - dictionary chemistryTypeDictNew; - chemistryTypeDictNew.add("solver", solverName); - chemistryTypeDictNew.add("method", methodName); + { + dictionary chemistryTypeDictNew; - Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl; + chemistryTypeDictNew.add("solver", solverName); + chemistryTypeDictNew.add("method", methodName); - const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_); + Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl; + } const word chemSolverCompThermoName ( @@ -102,30 +103,32 @@ Foam::autoPtr Foam::basicChemistryModel::New + thermo.thermoName() + ">>" ); - auto cstrIter = cnstrTable.cfind(chemSolverCompThermoName); - if (!cstrIter.found()) + const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_); + + auto ctorIter = cnstrTable.cfind(chemSolverCompThermoName); + + if (!ctorIter.found()) { + const wordList names(cnstrTable.sortedToc()); + constexpr const int nCmpt = 8; - wordList thisCmpts; - thisCmpts.append(word::null); - thisCmpts.append(word::null); + DynamicList thisCmpts(6); thisCmpts.append(ChemistryModel::reactionThermo::typeName); thisCmpts.append ( basicThermo::splitThermoName(thermo.thermoName(), 5) ); - List validNames; - + DynamicList validNames; validNames.append ( // Header wordList({"solver", "method"}) ); - List validCmpts; + DynamicList validCmpts(names.size() + 1); validCmpts.append ( // Header @@ -142,48 +145,50 @@ Foam::autoPtr Foam::basicChemistryModel::New }) ); - for (const word& validName : cnstrTable.sortedToc()) + for (const word& validName : names) { - validCmpts.append - ( - basicThermo::splitThermoName(validName, nCmpt) - ); + wordList cmpts(basicThermo::splitThermoName(validName, nCmpt)); - const wordList& cmpts = validCmpts.last(); - - bool isValid = true; - for (label i = 2; i < cmpts.size() && isValid; ++i) + if (!cmpts.empty()) { - isValid = isValid && cmpts[i] == thisCmpts[i]; - } - - if (isValid) - { - validNames.append(SubList(cmpts, 2)); + if (thisCmpts == SubList(cmpts, 6, 2)) + { + validNames.append(SubList(cmpts, 2)); + } + validCmpts.append(std::move(cmpts)); } } - FatalErrorInFunction << "Unknown " << typeName_() << " type " << solverName << nl << nl; - FatalErrorInFunction - << "All " << validNames[0][0] << '/' << validNames[0][1] - << "combinations for this thermodynamic model:" << nl << nl; + if (validNames.size() > 1) + { + FatalError + << "All " << validNames[0][0] << '/' << validNames[0][1] + << " combinations for this thermodynamic model:" + << nl << nl; - // Table of available packages (as constituent parts) - printTable(validNames, FatalErrorInFunction) - << nl - << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/' - << validCmpts[0][2] << "/thermoPhysics combinations are:" - << nl << nl; + // Table of available packages (as constituent parts) + printTable(validNames, FatalError) << nl; + } - // Table of available packages (as constituent parts) - printTable(validCmpts, FatalErrorInFunction) + if (validCmpts.size() > 1) + { + FatalError + << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/' + << validCmpts[0][2] << "/thermoPhysics combinations:" + << nl << nl; + + // Table of available packages (as constituent parts) + printTable(validCmpts, FatalError) << nl; + } + + FatalError << exit(FatalError); } - return autoPtr(cstrIter()(thermo)); + return autoPtr(ctorIter()(thermo)); } // ************************************************************************* // diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H index 5f54dfbfcc..f704e843a4 100644 --- a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.H @@ -32,7 +32,7 @@ Description SourceFiles basicSolidChemistryModelI.H basicSolidChemistryModel.C - newChemistrySolidModel.C + basicSolidChemistryModelNew.C \*---------------------------------------------------------------------------*/ @@ -50,11 +50,11 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward Declarations class fvMesh; /*---------------------------------------------------------------------------*\ - class basicSolidChemistryModel Declaration + Class basicSolidChemistryModel Declaration \*---------------------------------------------------------------------------*/ class basicSolidChemistryModel @@ -72,7 +72,7 @@ class basicSolidChemistryModel protected: - // Protected data + // Protected Data //- Solid thermo solidReactionThermo& solidThermo_; diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C index 7170f2cb76..83e272847a 100644 --- a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModelNew.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2017 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,23 +51,6 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo) Info<< "Selecting chemistry type " << chemistryTypeDict << endl; - std::initializer_list cmptNames - { - "chemistrySolver", - "chemistryThermo", - "baseChemistry", - "transport", - "thermo", - "equationOfState", - "specie", - "energy", - "transport", - "thermo", - "equationOfState", - "specie", - "energy" - }; - const IOdictionary thermoDict ( IOobject @@ -112,48 +95,48 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo) Info<< "chemistryTypeName " << chemistryTypeName << endl; - auto cstrIter = thermoConstructorTablePtr_->cfind(chemistryTypeName); + const auto& cnstrTable = *(thermoConstructorTablePtr_); - if (!cstrIter.found()) + auto ctorIter = cnstrTable.cfind(chemistryTypeName); + + if (!ctorIter.found()) { - const int nCmpt = cmptNames.size(); - - // Build a table of the thermo packages constituent parts - // Note: row-0 contains the names of constituent parts - List validCmpts(thermoConstructorTablePtr_->size()+1); - - // Header (row 0) - validCmpts[0].resize(nCmpt); - std::copy(cmptNames.begin(), cmptNames.end(), validCmpts[0].begin()); - - label rowi = 1; - for (const word& validName : thermoConstructorTablePtr_->sortedToc()) - { - validCmpts[rowi] = basicThermo::splitThermoName(validName, nCmpt); - - if (validCmpts[rowi].size()) - { - ++rowi; - } - } - validCmpts.resize(rowi); - - FatalIOErrorInLookup ( chemistryTypeDict, typeName, word::null, // Suppress long name? Just output dictionary (above) - *thermoConstructorTablePtr_ + cnstrTable ); // Table of available packages (as constituent parts) - printTable(validCmpts, FatalIOError) + basicThermo::printThermoNames + ( + FatalIOError, + wordList + ({ + "chemistrySolver", + "chemistryThermo", + "baseChemistry", + "transport", + "thermo", // solid + "equationOfState", + "specie", + "energy", + "transport", + "thermo", // gas + "equationOfState", + "specie", + "energy" + }), + cnstrTable.sortedToc() + ); + + FatalIOError << exit(FatalIOError); } - return - autoPtr(cstrIter()(thermo)); + return autoPtr(ctorIter()(thermo)); }