diff --git a/etc/codeTemplates/dynamicCode/basicChemistryModel b/etc/codeTemplates/dynamicCode/basicChemistryModel new file mode 100644 index 0000000000..a2b7146d35 --- /dev/null +++ b/etc/codeTemplates/dynamicCode/basicChemistryModel @@ -0,0 +1,54 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: dev + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object basicChemistryModel; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver +( + EulerImplicit + ode + noChemistrySolver +); + +solverRenamed +( + none noChemistrySolver +); + +method +( + Standard + TDAC +); + +methodRenamed +( + standard Standard +); + +codeOptions +#{ +EXE_INC = \ + -I$(LIB_SRC)/transportModels/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \ + -I$(LIB_SRC)/ODE/lnInclude \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude +#}; + + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/basicChemistryModel.C b/etc/codeTemplates/dynamicCode/basicChemistryModel.C new file mode 100644 index 0000000000..971b50f3ac --- /dev/null +++ b/etc/codeTemplates/dynamicCode/basicChemistryModel.C @@ -0,0 +1,235 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) YEAR OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "makeChemistrySolver.H" +#include "${method}ChemistryModel.H" +#include "${solver}.H" + +#include "typedefThermo.H" + +#include "${specie}.H" + +#include "thermo.H" + +// EoS +#include "${equationOfState}.H" + +// Thermo +#include "${thermo}Thermo.H" +#include "${energy}.H" + +// Transport +#include "${transport}Transport.H" + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +extern "C" +{ + // dynamicCode: + // SHA1 = ${SHA1sum} + // + // Unique function name that can be checked if the correct library version + // has been loaded + void ${typeName}_${SHA1sum}(bool load) + { + if (load) + { + // code that can be explicitly executed after loading + } + else + { + // code that can be explicitly executed before unloading + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#define ThermoPhysics \ + ${transport}Transport${energy}${thermo}Thermo${equationOfState}${specie} + +namespace Foam +{ + typedefThermo + ( + ${transport}Transport, + ${energy}, + ${thermo}Thermo, + ${equationOfState}, + ${specie} + ); + + defineChemistrySolver(${method}ChemistryModel, ThermoPhysics); + makeChemistrySolver(${solver}, ${method}ChemistryModel, ThermoPhysics); +} + + +#if ${method} == TDAC + +#include "makeChemistryReductionMethod.H" +#include "makeChemistryTabulationMethod.H" + +namespace Foam +{ + defineChemistrySolver(StandardChemistryModel, ThermoPhysics); + defineChemistryReductionMethod(nullArg, ThermoPhysics); + defineChemistryTabulationMethod(nullArg, ThermoPhysics); +} + +#include "noChemistryReduction.H" +#include "DAC.H" +#include "DRG.H" +#include "DRGEP.H" +#include "EFA.H" +#include "PFA.H" + +namespace Foam +{ + makeChemistryReductionMethod(none, ThermoPhysics); + makeChemistryReductionMethod(DAC, ThermoPhysics); + makeChemistryReductionMethod(DRG, ThermoPhysics); + makeChemistryReductionMethod(DRGEP, ThermoPhysics); + makeChemistryReductionMethod(EFA, ThermoPhysics); + makeChemistryReductionMethod(PFA, ThermoPhysics); +} + +#include "noChemistryTabulation.H" +#include "ISAT.H" +namespace Foam +{ + makeChemistryTabulationMethod(none, ThermoPhysics); + makeChemistryTabulationMethod(ISAT, ThermoPhysics); +} + +#endif + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "makeReaction.H" + +#include "ArrheniusReactionRate.H" +#include "LandauTellerReactionRate.H" +#include "thirdBodyArrheniusReactionRate.H" + +#include "JanevReactionRate.H" +#include "powerSeriesReactionRate.H" + +#include "ChemicallyActivatedReactionRate.H" +#include "FallOffReactionRate.H" + +#include "LindemannFallOffFunction.H" +#include "SRIFallOffFunction.H" +#include "TroeFallOffFunction.H" + +#include "LangmuirHinshelwoodReactionRate.H" + +#include "MichaelisMentenReactionRate.H" + +namespace Foam +{ + defineReaction(nullArg, ThermoPhysics); + + makeIRNReactions(ArrheniusReactionRate, ThermoPhysics); + makeIRNReactions(LandauTellerReactionRate, ThermoPhysics); + makeIRNReactions(thirdBodyArrheniusReactionRate, ThermoPhysics); + makeIRReactions(JanevReactionRate, ThermoPhysics); + makeIRReactions(powerSeriesReactionRate, ThermoPhysics); + + makeIRRPressureDependentReactions + ( + FallOffReactionRate, + ArrheniusReactionRate, + LindemannFallOffFunction, + ThermoPhysics + ); + + makeIRRPressureDependentReactions + ( + FallOffReactionRate, + ArrheniusReactionRate, + TroeFallOffFunction, + ThermoPhysics + ); + + makeIRRPressureDependentReactions + ( + FallOffReactionRate, + ArrheniusReactionRate, + SRIFallOffFunction, + ThermoPhysics + ); + + makeIRRPressureDependentReactions + ( + ChemicallyActivatedReactionRate, + ArrheniusReactionRate, + LindemannFallOffFunction, + ThermoPhysics + ); + + makeIRRPressureDependentReactions + ( + ChemicallyActivatedReactionRate, + ArrheniusReactionRate, + TroeFallOffFunction, + ThermoPhysics + ); + + makeIRRPressureDependentReactions + ( + ChemicallyActivatedReactionRate, + ArrheniusReactionRate, + SRIFallOffFunction, + ThermoPhysics + ); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "LangmuirHinshelwoodReactionRate.H" + +namespace Foam +{ + makeIRReactions(LangmuirHinshelwoodReactionRate, ThermoPhysics); +} + + +#include "fluxLimitedLangmuirHinshelwoodReactionRate.H" + +namespace Foam +{ + makeGeneralReaction + ( + IrreversibleReaction, + fluxLimitedLangmuirHinshelwoodReactionRate, + ThermoPhysics + ); +} + + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidReactionThermo b/etc/codeTemplates/dynamicCode/fluidReactionThermo index 8c8875327d..8d0c2e1c61 100644 --- a/etc/codeTemplates/dynamicCode/fluidReactionThermo +++ b/etc/codeTemplates/dynamicCode/fluidReactionThermo @@ -10,7 +10,7 @@ FoamFile version 2.0; format ascii; class dictionary; - object fluidThermo; + object fluidReactionThermo; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -20,7 +20,7 @@ type heRhoThermo ); -baseType +typeBase ( hePsiThermo psiReactionThermo heRhoThermo rhoReactionThermo @@ -42,7 +42,7 @@ mixture coefficientWilkeMultiComponentMixture ); -renameMixture +mixtureRenamed ( pureMixture singleComponentMixture multiComponentMixture coefficientMultiComponentMixture @@ -90,6 +90,11 @@ equationOfState rPolynomial ); +specie +( + specie +); + codeOptions #{ EXE_INC = \ @@ -100,14 +105,5 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude #}; -codeLibs -#{ -LIB_LIBS = \ - -ltransportModels \ - -lspecie \ - -lfluidThermophysicalModels \ - -lfiniteVolume -#}; - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidReactionThermo.C b/etc/codeTemplates/dynamicCode/fluidReactionThermo.C index 04218c2876..a3f5156f6d 100644 --- a/etc/codeTemplates/dynamicCode/fluidReactionThermo.C +++ b/etc/codeTemplates/dynamicCode/fluidReactionThermo.C @@ -26,7 +26,7 @@ License #include "forThermo.H" #include "makeReactionThermo.H" -#include "specie.H" +#include "${specie}.H" #include "thermo.H" @@ -41,9 +41,8 @@ License #include "${transport}Transport.H" // psi/rho -#include "${baseType}.H" +#include "${typeBase}.H" #include "${type}.H" -#include "psiReactionThermo.H" // Mixture #include "${mixture}.H" @@ -82,12 +81,13 @@ namespace Foam ${energy}, ${thermo}Thermo, ${equationOfState}, - specie, + ${specie}, makeReactionThermo, - ${baseType}, + ${typeBase}, ${type}, ${mixture} ); } + // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidThermo b/etc/codeTemplates/dynamicCode/fluidThermo index dfda52b907..15c9c5a4e1 100644 --- a/etc/codeTemplates/dynamicCode/fluidThermo +++ b/etc/codeTemplates/dynamicCode/fluidThermo @@ -20,7 +20,7 @@ type heRhoThermo ); -baseType +typeBase ( hePsiThermo psiThermo heRhoThermo rhoThermo @@ -81,6 +81,11 @@ equationOfState rPolynomial ); +specie +( + specie +); + codeOptions #{ EXE_INC = \ @@ -91,15 +96,5 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude #}; -codeLibs -#{ -LIB_LIBS = \ - -ltransportModels \ - -lspecie \ - -lthermophysicalProperties \ - -lfluidThermophysicalModels \ - -lfiniteVolume -#}; - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidThermo.C b/etc/codeTemplates/dynamicCode/fluidThermo.C index 4c835e49f3..be8850ffa4 100644 --- a/etc/codeTemplates/dynamicCode/fluidThermo.C +++ b/etc/codeTemplates/dynamicCode/fluidThermo.C @@ -26,7 +26,7 @@ License #include "forThermo.H" #include "makeThermo.H" -#include "specie.H" +#include "${specie}.H" #include "thermo.H" @@ -41,7 +41,7 @@ License #include "${transport}Transport.H" // psi/rho -#include "${baseType}.H" +#include "${typeBase}.H" #include "${type}.H" // Mixture @@ -81,9 +81,9 @@ namespace Foam ${energy}, ${thermo}Thermo, ${equationOfState}, - specie, + ${specie}, makeThermo, - ${baseType}, + ${typeBase}, ${type}, ${mixture} ); diff --git a/etc/codeTemplates/dynamicCode/psiThermo b/etc/codeTemplates/dynamicCode/psiThermo index 229dcea2f6..0d11871fd9 100644 --- a/etc/codeTemplates/dynamicCode/psiThermo +++ b/etc/codeTemplates/dynamicCode/psiThermo @@ -19,7 +19,7 @@ type hePsiThermo ); -baseType +typeBase ( hePsiThermo psiThermo ); @@ -66,6 +66,11 @@ equationOfState perfectGas ); +specie +( + specie +); + codeOptions #{ EXE_INC = \ @@ -76,15 +81,5 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude #}; -codeLibs -#{ -LIB_LIBS = \ - -ltransportModels \ - -lspecie \ - -lthermophysicalProperties \ - -lfluidThermophysicalModels \ - -lfiniteVolume -#}; - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/psiuReactionThermo b/etc/codeTemplates/dynamicCode/psiuReactionThermo index cdd3c47225..cd39756562 100644 --- a/etc/codeTemplates/dynamicCode/psiuReactionThermo +++ b/etc/codeTemplates/dynamicCode/psiuReactionThermo @@ -19,7 +19,7 @@ type heheuPsiThermo ); -baseType +typeBase ( heheuPsiThermo psiuReactionThermo ); @@ -65,6 +65,11 @@ equationOfState perfectGas ); +specie +( + specie +); + codeOptions #{ EXE_INC = \ @@ -75,13 +80,5 @@ EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude #}; -codeLibs -#{ -LIB_LIBS = \ - -lfluidThermophysicalModels \ - -lspecie \ - -lfiniteVolume -#}; - // ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/psiuReactionThermo.C b/etc/codeTemplates/dynamicCode/psiuReactionThermo.C index 947e99f18c..7133ae4fec 100644 --- a/etc/codeTemplates/dynamicCode/psiuReactionThermo.C +++ b/etc/codeTemplates/dynamicCode/psiuReactionThermo.C @@ -26,7 +26,7 @@ License #include "forThermo.H" #include "makeReactionThermo.H" -#include "specie.H" +#include "${specie}.H" #include "thermo.H" @@ -41,7 +41,7 @@ License #include "${transport}Transport.H" // psi/rho -#include "${baseType}.H" +#include "${typeBase}.H" #include "${type}.H" // Mixture @@ -81,7 +81,7 @@ namespace Foam ${energy}, ${thermo}Thermo, ${equationOfState}, - specie, + ${specie}, makePsiuReactionThermo, ${mixture} ); diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 32d22c51c9..029215e1e3 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -268,6 +268,7 @@ $(dll)/dlLibraryTable/dlLibraryTable.C $(dll)/dynamicCode/dynamicCode.C $(dll)/dynamicCode/dynamicCodeContext.C $(dll)/codedBase/codedBase.C +$(dll)/compileTemplate/compileTemplate.C db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObjectList/functionObjectList.C diff --git a/src/thermophysicalModels/basic/basicThermo/compileThermo.C b/src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.C similarity index 55% rename from src/thermophysicalModels/basic/basicThermo/compileThermo.C rename to src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.C index a1b178d7e1..f673e8f813 100644 --- a/src/thermophysicalModels/basic/basicThermo/compileThermo.C +++ b/src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.C @@ -23,8 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "basicThermo.H" -#include "compileThermo.H" +#include "compileTemplate.H" #include "dynamicCodeContext.H" #include "Time.H" #include "IFstream.H" @@ -33,40 +32,40 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // template<> -const Foam::wordList Foam::CodedBase::codeKeys_ = +const Foam::wordList Foam::CodedBase::codeKeys_ = {}; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -Foam::dictionary Foam::compileThermo::optionsDict +Foam::dictionary Foam::compileTemplate::optionsDict ( - const word& thermoTypeName, - const word& instantiatedThermoName + const word& templateName, + const word& instantiatedName ) const { - IFstream optionsFile(dynamicCode::resolveTemplate(thermoTypeName)); + IFstream optionsFile(dynamicCode::resolveTemplate(templateName)); if (!optionsFile.good()) { FatalErrorInFunction - << "Failed to open dictionary file " << thermoTypeName + << "Failed to open dictionary file " << templateName << exit(FatalError); } dictionary dict(optionsFile); - fileName thermoTypeFileName(instantiatedThermoName); - thermoTypeFileName.replaceAll(',', '_'); - thermoTypeFileName.replaceAll('<', '_'); - thermoTypeFileName.replaceAll('>', '_'); + fileName templateFileName(instantiatedName); + templateFileName.replaceAll(',', '_'); + templateFileName.replaceAll('<', '_'); + templateFileName.replaceAll('>', '_'); - dict.add("name", thermoTypeFileName); + dict.add("name", templateFileName); return dict; } -void Foam::compileThermo::setFilterVariable +void Foam::compileTemplate::setFilterVariable ( dynamicCode& dynCode, const dynamicCodeContext& context, @@ -74,45 +73,32 @@ void Foam::compileThermo::setFilterVariable const word& type ) const { - const HashSet types(context.dict().lookup(name)); - if (!types.found(type)) + if (context.dict().found(name)) { - FatalIOErrorInFunction(thermoTypeDict_) - << "Unknown " << name << " type " << type << nl - << "Supported " << name << " types: " << types - << exit(FatalIOError); + const HashSet types(context.dict().lookup(name)); + if (!types.found(type)) + { + FatalIOErrorInFunction(context.dict()) + << "Unknown " << name << " type " << type << nl + << "Supported " << name << " types: " << types + << exit(FatalIOError); + } } dynCode.setFilterVariable(name, type); } -void Foam::compileThermo::setFilterVariable +void Foam::compileTemplate::setFilterVariable ( dynamicCode& dynCode, const dynamicCodeContext& context, - const word& name + const Pair& substitution ) const { - setFilterVariable - ( - dynCode, - context, - name, - thermoTypeDict_.lookup(name) - ); -} - - -void Foam::compileThermo::setFilterRenamedVariable -( - dynamicCode& dynCode, - const dynamicCodeContext& context, - const word& name, - const word& typeRenameMapName -) const -{ - word type(thermoTypeDict_.lookup(name)); + const word& name(substitution.first()); + word type(substitution.second()); + const word typeRenameMapName(name + "Renamed"); if (context.dict().found(typeRenameMapName)) { @@ -128,10 +114,17 @@ void Foam::compileThermo::setFilterRenamedVariable } setFilterVariable(dynCode, context, name, type); + + const word typeBase(name + "Base"); + if (context.dict().found(typeBase)) + { + const HashTable typeToBaseMap(context.dict().lookup(typeBase)); + dynCode.setFilterVariable(typeBase, typeToBaseMap[type]); + } } -void Foam::compileThermo::prepare +void Foam::compileTemplate::prepare ( dynamicCode& dynCode, const dynamicCodeContext& context @@ -139,20 +132,13 @@ void Foam::compileThermo::prepare { dynCode.setFilterVariable("typeName", codeName()); - const word type(thermoTypeDict_.lookup("type")); - dynCode.setFilterVariable("type", type); - - const HashTable typeToBaseMap(context.dict().lookup("baseType")); - dynCode.setFilterVariable("baseType", typeToBaseMap[type]); - - setFilterRenamedVariable(dynCode, context, "mixture", "renameMixture"); - setFilterVariable(dynCode, context, "transport"); - setFilterVariable(dynCode, context, "thermo"); - setFilterVariable(dynCode, context, "equationOfState"); - setFilterVariable(dynCode, context, "energy"); + forAll(substitutions_, i) + { + setFilterVariable(dynCode, context, substitutions_[i]); + } // Compile filtered C template - dynCode.addCompileFile(thermoTypeName_ + ".C"); + dynCode.addCompileFile(templateName_ + ".C"); // Define Make/options dynCode.setMakeOptions(context.options() + "\n\n" + context.libs()); @@ -169,19 +155,19 @@ void Foam::compileThermo::prepare // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::compileThermo::compileThermo +Foam::compileTemplate::compileTemplate ( - const word& thermoTypeName, - const word& instantiatedThermoName, - const dictionary& thermoTypeDict + const word& templateName, + const word& instantiatedName, + const List>& substitutions ) : - CodedBase + CodedBase ( - optionsDict(thermoTypeName, instantiatedThermoName) + optionsDict(templateName, instantiatedName) ), - thermoTypeName_(thermoTypeName), - thermoTypeDict_(thermoTypeDict) + templateName_(templateName), + substitutions_(substitutions) { this->updateLibrary(); } diff --git a/src/thermophysicalModels/basic/basicThermo/compileThermo.H b/src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.H similarity index 76% rename from src/thermophysicalModels/basic/basicThermo/compileThermo.H rename to src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.H index 7eee5259f7..b9b1203ffc 100644 --- a/src/thermophysicalModels/basic/basicThermo/compileThermo.H +++ b/src/OpenFOAM/db/dynamicLibrary/compileTemplate/compileTemplate.H @@ -23,8 +23,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef compileThermo_H -#define compileThermo_H +#ifndef compileTemplate_H +#define compileTemplate_H #include "CodedBase.H" #include "dynamicCode.H" @@ -35,28 +35,28 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class compileThermo Declaration + Class compileTemplate Declaration \*---------------------------------------------------------------------------*/ -class compileThermo +class compileTemplate : - public CodedBase + public CodedBase { // Private Member Data //- Name of the class Thermo basicThermo is instantiated on - const word thermoTypeName_; + const word templateName_; - //- Reference to the dictionary containing the thermo components - const dictionary& thermoTypeDict_; + //- List of template argument substitutions + const List> substitutions_; // Private Member Functions dictionary optionsDict ( - const word& thermoTypeName, - const word& instantiatedThermoName + const word& templateName, + const word& instantiatedName ) const; void setFilterVariable @@ -71,15 +71,7 @@ class compileThermo ( dynamicCode& dynCode, const dynamicCodeContext& context, - const word& name - ) const; - - void setFilterRenamedVariable - ( - dynamicCode& dynCode, - const dynamicCodeContext& context, - const word& name, - const word& typeRenameMapName + const Pair& substitution ) const; //- Adapt the context for the current object @@ -95,11 +87,11 @@ public: // Constructors //- Construct from name and dictionary - compileThermo + compileTemplate ( - const word& thermoTypeName, - const word& instantiatedThermoName, - const dictionary& thermoTypeDict + const word& templateName, + const word& instantiatedName, + const List>& substitutions ); }; diff --git a/src/thermophysicalModels/basic/Make/files b/src/thermophysicalModels/basic/Make/files index f3720d753b..92dff66672 100644 --- a/src/thermophysicalModels/basic/Make/files +++ b/src/thermophysicalModels/basic/Make/files @@ -1,5 +1,4 @@ basicThermo/basicThermo.C -basicThermo/compileThermo.C fluidThermo/fluidThermo.C diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C index eaaa095bc8..f0b5bfffd1 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -179,6 +179,24 @@ Foam::wordList Foam::basicThermo::splitThermoName } +Foam::List> Foam::basicThermo::thermoNameComponents +( + const word& thermoName +) +{ + const wordList components(splitThermoName(thermoName, 5)); + + return List> + { + {"transport", components[0]}, + {"thermo", components[1]}, + {"equationOfState", components[2]}, + {"specie", components[3]}, + {"energy", components[4]} + }; +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // Foam::wordList Foam::basicThermo::heBoundaryBaseTypes() diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H index b3154cdd84..951308d5ff 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H @@ -169,6 +169,12 @@ public: const int nCmpt ); + //- Split name of thermo package into a list of named components names + static List> thermoNameComponents + ( + const word& thermoName + ); + // Selectors diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C index 79b561473d..bf161313e5 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C @@ -25,7 +25,7 @@ License #include "basicThermo.H" #include "wordIOList.H" -#include "compileThermo.H" +#include "compileTemplate.H" // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -50,11 +50,23 @@ typename Table::iterator Foam::basicThermo::lookupCstrIter && !dynamicCode::resolveTemplate(Thermo::typeName).empty() ) { - compileThermo thermo + compileTemplate thermo ( Thermo::typeName, thermoTypeName, - thermoTypeDict + List> + { + {"type", thermoTypeDict.lookup("type")}, + {"mixture", thermoTypeDict.lookup("mixture")}, + {"transport", thermoTypeDict.lookup("transport")}, + {"thermo", thermoTypeDict.lookup("thermo")}, + { + "equationOfState", + thermoTypeDict.lookup("equationOfState") + }, + {"specie", thermoTypeDict.lookup("specie")}, + {"energy", thermoTypeDict.lookup("energy")} + } ); cstrIter = tablePtr->find(thermoTypeName); diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelNew.C b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelNew.C index 97a5ed4cc3..500b988ec8 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelNew.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/basicChemistryModel/basicChemistryModelNew.C @@ -25,6 +25,7 @@ License #include "basicChemistryModel.H" #include "basicThermo.H" +#include "compileTemplate.H" // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // @@ -94,63 +95,105 @@ Foam::autoPtr Foam::basicChemistryModel::New if (cstrIter == thermoConstructorTablePtr_->end()) { - FatalErrorInFunction - << "Unknown " << typeName_() << " type " << chemistryTypeDictNew - << endl; - - const wordList names(thermoConstructorTablePtr_->sortedToc()); - - wordList thisCmpts; - thisCmpts.append(word::null); - thisCmpts.append(word::null); - thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5)); - - List validNames; - validNames.append(wordList(2, word::null)); - validNames[0][0] = "solver"; - validNames[0][1] = "method"; - forAll(names, i) + if + ( + dynamicCode::allowSystemOperations + && !dynamicCode::resolveTemplate(basicChemistryModel::typeName).empty() + ) { - const wordList cmpts(basicThermo::splitThermoName(names[i], 7)); + List> substitutions + ( + basicThermo::thermoNameComponents(thermo.thermoName()) + ); - if (SubList(cmpts, 5, 2) == SubList(thisCmpts, 5, 2)) + substitutions.append({"solver", solverName}); + substitutions.append({"method", methodName}); + + compileTemplate chemistryModel + ( + basicChemistryModel::typeName, + chemSolverNameName, + substitutions + ); + cstrIter = thermoConstructorTablePtr_->find(chemSolverNameName); + + if (cstrIter == thermoConstructorTablePtr_->end()) { - validNames.append(SubList(cmpts, 2)); + FatalErrorInFunction + << "Compilation and linkage of " + << basicChemistryModel::typeName << " type " << nl + << "chemistryType" << chemistryTypeDict << nl << nl + << "failed." << exit(FatalError); } } - - FatalErrorInFunction - << "Valid " << validNames[0][0] << '/' << validNames[0][1] - << " combinations for this thermodynamic model are:" - << endl << endl; - printTable(validNames, FatalErrorInFunction); - - FatalErrorInFunction << endl; - - List validCmpts; - validCmpts.append(wordList(7, word::null)); - validCmpts[0][0] = "solver"; - validCmpts[0][1] = "method"; - validCmpts[0][2] = "transport"; - validCmpts[0][3] = "thermo"; - validCmpts[0][4] = "equationOfState"; - validCmpts[0][5] = "specie"; - validCmpts[0][6] = "energy"; - forAll(names, i) + else { - validCmpts.append(basicThermo::splitThermoName(names[i], 7)); + FatalErrorInFunction + << "Unknown " << typeName_() << " type " << chemistryTypeDictNew + << endl; + + const wordList names(thermoConstructorTablePtr_->sortedToc()); + + wordList thisCmpts; + thisCmpts.append(word::null); + thisCmpts.append(word::null); + thisCmpts.append + ( + basicThermo::splitThermoName(thermo.thermoName(), 5) + ); + + List validNames; + validNames.append(wordList(2, word::null)); + validNames[0][0] = "solver"; + validNames[0][1] = "method"; + forAll(names, i) + { + const wordList cmpts(basicThermo::splitThermoName(names[i], 7)); + + if + ( + SubList(cmpts, 5, 2) + == SubList(thisCmpts, 5, 2) + ) + { + validNames.append(SubList(cmpts, 2)); + } + } + + FatalErrorInFunction + << "Valid " << validNames[0][0] << '/' << validNames[0][1] + << " combinations for this thermodynamic model are:" + << endl << endl; + printTable(validNames, FatalErrorInFunction); + + FatalErrorInFunction << endl; + + List validCmpts; + validCmpts.append(wordList(7, word::null)); + validCmpts[0][0] = "solver"; + validCmpts[0][1] = "method"; + validCmpts[0][2] = "transport"; + validCmpts[0][3] = "thermo"; + validCmpts[0][4] = "equationOfState"; + validCmpts[0][5] = "specie"; + validCmpts[0][6] = "energy"; + forAll(names, i) + { + validCmpts.append(basicThermo::splitThermoName(names[i], 7)); + } + + FatalErrorInFunction + << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] + << "/thermodynamics combinations are:" + << endl << endl; + printTable(validCmpts, FatalErrorInFunction); + + FatalErrorInFunction << exit(FatalError); } - - FatalErrorInFunction - << "All " << validCmpts[0][0] << '/' << validCmpts[0][1] - << "/thermodynamics combinations are:" - << endl << endl; - printTable(validCmpts, FatalErrorInFunction); - - FatalErrorInFunction << exit(FatalError); } return autoPtr(cstrIter()(thermo)); } + // ************************************************************************* //