etc/codeTemplates/dynamicCode: Added basicChemistryModel dynamic compilation support

for chemFoam, fireFoam, buoyantReactingFoam, reactingFoam, chtMultiRegionFoam,
buoyantReactingParticleFoam, reactingParticleFoam, simpleReactingParticleFoam

If the combination of chemistry model and solver selected in chemistryProperties
is not already compiled and present in the standard libraries for the selected
thermophysical properties the chemistry package will be constructed and compiled
automatically using the standard dynamicCode system provided in OpenFOAM.

The chemistry package is constructed automatically from the
etc/codeTemplates/dynamicCode/basicChemistryModel.* files, if these files do not
exist the standard chemistry lookup error message is generated as before.

As with all other dynamicCode options in OpenFOAM (codeStream,
codedFunctionObject etc.) dynamic compilation of the chemistry package is only
enabled if allowSystemOperations is set true.
This commit is contained in:
Henry Weller
2021-04-20 16:37:12 +01:00
parent 013a33a109
commit 78ef8e1eb0
17 changed files with 521 additions and 192 deletions

View File

@ -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
#};
// ************************************************************************* //

View File

@ -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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#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
);
}
// ************************************************************************* //

View File

@ -10,7 +10,7 @@ FoamFile
version 2.0; version 2.0;
format ascii; format ascii;
class dictionary; class dictionary;
object fluidThermo; object fluidReactionThermo;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -20,7 +20,7 @@ type
heRhoThermo heRhoThermo
); );
baseType typeBase
( (
hePsiThermo psiReactionThermo hePsiThermo psiReactionThermo
heRhoThermo rhoReactionThermo heRhoThermo rhoReactionThermo
@ -42,7 +42,7 @@ mixture
coefficientWilkeMultiComponentMixture coefficientWilkeMultiComponentMixture
); );
renameMixture mixtureRenamed
( (
pureMixture singleComponentMixture pureMixture singleComponentMixture
multiComponentMixture coefficientMultiComponentMixture multiComponentMixture coefficientMultiComponentMixture
@ -90,6 +90,11 @@ equationOfState
rPolynomial rPolynomial
); );
specie
(
specie
);
codeOptions codeOptions
#{ #{
EXE_INC = \ EXE_INC = \
@ -100,14 +105,5 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
#}; #};
codeLibs
#{
LIB_LIBS = \
-ltransportModels \
-lspecie \
-lfluidThermophysicalModels \
-lfiniteVolume
#};
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,7 @@ License
#include "forThermo.H" #include "forThermo.H"
#include "makeReactionThermo.H" #include "makeReactionThermo.H"
#include "specie.H" #include "${specie}.H"
#include "thermo.H" #include "thermo.H"
@ -41,9 +41,8 @@ License
#include "${transport}Transport.H" #include "${transport}Transport.H"
// psi/rho // psi/rho
#include "${baseType}.H" #include "${typeBase}.H"
#include "${type}.H" #include "${type}.H"
#include "psiReactionThermo.H"
// Mixture // Mixture
#include "${mixture}.H" #include "${mixture}.H"
@ -82,12 +81,13 @@ namespace Foam
${energy}, ${energy},
${thermo}Thermo, ${thermo}Thermo,
${equationOfState}, ${equationOfState},
specie, ${specie},
makeReactionThermo, makeReactionThermo,
${baseType}, ${typeBase},
${type}, ${type},
${mixture} ${mixture}
); );
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -20,7 +20,7 @@ type
heRhoThermo heRhoThermo
); );
baseType typeBase
( (
hePsiThermo psiThermo hePsiThermo psiThermo
heRhoThermo rhoThermo heRhoThermo rhoThermo
@ -81,6 +81,11 @@ equationOfState
rPolynomial rPolynomial
); );
specie
(
specie
);
codeOptions codeOptions
#{ #{
EXE_INC = \ EXE_INC = \
@ -91,15 +96,5 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
#}; #};
codeLibs
#{
LIB_LIBS = \
-ltransportModels \
-lspecie \
-lthermophysicalProperties \
-lfluidThermophysicalModels \
-lfiniteVolume
#};
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,7 @@ License
#include "forThermo.H" #include "forThermo.H"
#include "makeThermo.H" #include "makeThermo.H"
#include "specie.H" #include "${specie}.H"
#include "thermo.H" #include "thermo.H"
@ -41,7 +41,7 @@ License
#include "${transport}Transport.H" #include "${transport}Transport.H"
// psi/rho // psi/rho
#include "${baseType}.H" #include "${typeBase}.H"
#include "${type}.H" #include "${type}.H"
// Mixture // Mixture
@ -81,9 +81,9 @@ namespace Foam
${energy}, ${energy},
${thermo}Thermo, ${thermo}Thermo,
${equationOfState}, ${equationOfState},
specie, ${specie},
makeThermo, makeThermo,
${baseType}, ${typeBase},
${type}, ${type},
${mixture} ${mixture}
); );

View File

@ -19,7 +19,7 @@ type
hePsiThermo hePsiThermo
); );
baseType typeBase
( (
hePsiThermo psiThermo hePsiThermo psiThermo
); );
@ -66,6 +66,11 @@ equationOfState
perfectGas perfectGas
); );
specie
(
specie
);
codeOptions codeOptions
#{ #{
EXE_INC = \ EXE_INC = \
@ -76,15 +81,5 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
#}; #};
codeLibs
#{
LIB_LIBS = \
-ltransportModels \
-lspecie \
-lthermophysicalProperties \
-lfluidThermophysicalModels \
-lfiniteVolume
#};
// ************************************************************************* // // ************************************************************************* //

View File

@ -19,7 +19,7 @@ type
heheuPsiThermo heheuPsiThermo
); );
baseType typeBase
( (
heheuPsiThermo psiuReactionThermo heheuPsiThermo psiuReactionThermo
); );
@ -65,6 +65,11 @@ equationOfState
perfectGas perfectGas
); );
specie
(
specie
);
codeOptions codeOptions
#{ #{
EXE_INC = \ EXE_INC = \
@ -75,13 +80,5 @@ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude -I$(LIB_SRC)/finiteVolume/lnInclude
#}; #};
codeLibs
#{
LIB_LIBS = \
-lfluidThermophysicalModels \
-lspecie \
-lfiniteVolume
#};
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,7 @@ License
#include "forThermo.H" #include "forThermo.H"
#include "makeReactionThermo.H" #include "makeReactionThermo.H"
#include "specie.H" #include "${specie}.H"
#include "thermo.H" #include "thermo.H"
@ -41,7 +41,7 @@ License
#include "${transport}Transport.H" #include "${transport}Transport.H"
// psi/rho // psi/rho
#include "${baseType}.H" #include "${typeBase}.H"
#include "${type}.H" #include "${type}.H"
// Mixture // Mixture
@ -81,7 +81,7 @@ namespace Foam
${energy}, ${energy},
${thermo}Thermo, ${thermo}Thermo,
${equationOfState}, ${equationOfState},
specie, ${specie},
makePsiuReactionThermo, makePsiuReactionThermo,
${mixture} ${mixture}
); );

View File

@ -268,6 +268,7 @@ $(dll)/dlLibraryTable/dlLibraryTable.C
$(dll)/dynamicCode/dynamicCode.C $(dll)/dynamicCode/dynamicCode.C
$(dll)/dynamicCode/dynamicCodeContext.C $(dll)/dynamicCode/dynamicCodeContext.C
$(dll)/codedBase/codedBase.C $(dll)/codedBase/codedBase.C
$(dll)/compileTemplate/compileTemplate.C
db/functionObjects/functionObject/functionObject.C db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C db/functionObjects/functionObjectList/functionObjectList.C

View File

@ -23,8 +23,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "basicThermo.H" #include "compileTemplate.H"
#include "compileThermo.H"
#include "dynamicCodeContext.H" #include "dynamicCodeContext.H"
#include "Time.H" #include "Time.H"
#include "IFstream.H" #include "IFstream.H"
@ -33,40 +32,40 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<> template<>
const Foam::wordList Foam::CodedBase<Foam::compileThermo>::codeKeys_ = const Foam::wordList Foam::CodedBase<Foam::compileTemplate>::codeKeys_ =
{}; {};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::dictionary Foam::compileThermo::optionsDict Foam::dictionary Foam::compileTemplate::optionsDict
( (
const word& thermoTypeName, const word& templateName,
const word& instantiatedThermoName const word& instantiatedName
) const ) const
{ {
IFstream optionsFile(dynamicCode::resolveTemplate(thermoTypeName)); IFstream optionsFile(dynamicCode::resolveTemplate(templateName));
if (!optionsFile.good()) if (!optionsFile.good())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Failed to open dictionary file " << thermoTypeName << "Failed to open dictionary file " << templateName
<< exit(FatalError); << exit(FatalError);
} }
dictionary dict(optionsFile); dictionary dict(optionsFile);
fileName thermoTypeFileName(instantiatedThermoName); fileName templateFileName(instantiatedName);
thermoTypeFileName.replaceAll(',', '_'); templateFileName.replaceAll(',', '_');
thermoTypeFileName.replaceAll('<', '_'); templateFileName.replaceAll('<', '_');
thermoTypeFileName.replaceAll('>', '_'); templateFileName.replaceAll('>', '_');
dict.add("name", thermoTypeFileName); dict.add("name", templateFileName);
return dict; return dict;
} }
void Foam::compileThermo::setFilterVariable void Foam::compileTemplate::setFilterVariable
( (
dynamicCode& dynCode, dynamicCode& dynCode,
const dynamicCodeContext& context, const dynamicCodeContext& context,
@ -74,45 +73,32 @@ void Foam::compileThermo::setFilterVariable
const word& type const word& type
) const ) const
{ {
const HashSet<word> types(context.dict().lookup(name)); if (context.dict().found(name))
if (!types.found(type))
{ {
FatalIOErrorInFunction(thermoTypeDict_) const HashSet<word> types(context.dict().lookup(name));
<< "Unknown " << name << " type " << type << nl if (!types.found(type))
<< "Supported " << name << " types: " << types {
<< exit(FatalIOError); FatalIOErrorInFunction(context.dict())
<< "Unknown " << name << " type " << type << nl
<< "Supported " << name << " types: " << types
<< exit(FatalIOError);
}
} }
dynCode.setFilterVariable(name, type); dynCode.setFilterVariable(name, type);
} }
void Foam::compileThermo::setFilterVariable void Foam::compileTemplate::setFilterVariable
( (
dynamicCode& dynCode, dynamicCode& dynCode,
const dynamicCodeContext& context, const dynamicCodeContext& context,
const word& name const Pair<word>& substitution
) const ) const
{ {
setFilterVariable const word& name(substitution.first());
( word type(substitution.second());
dynCode, const word typeRenameMapName(name + "Renamed");
context,
name,
thermoTypeDict_.lookup<word>(name)
);
}
void Foam::compileThermo::setFilterRenamedVariable
(
dynamicCode& dynCode,
const dynamicCodeContext& context,
const word& name,
const word& typeRenameMapName
) const
{
word type(thermoTypeDict_.lookup<word>(name));
if (context.dict().found(typeRenameMapName)) if (context.dict().found(typeRenameMapName))
{ {
@ -128,10 +114,17 @@ void Foam::compileThermo::setFilterRenamedVariable
} }
setFilterVariable(dynCode, context, name, type); setFilterVariable(dynCode, context, name, type);
const word typeBase(name + "Base");
if (context.dict().found(typeBase))
{
const HashTable<word> typeToBaseMap(context.dict().lookup(typeBase));
dynCode.setFilterVariable(typeBase, typeToBaseMap[type]);
}
} }
void Foam::compileThermo::prepare void Foam::compileTemplate::prepare
( (
dynamicCode& dynCode, dynamicCode& dynCode,
const dynamicCodeContext& context const dynamicCodeContext& context
@ -139,20 +132,13 @@ void Foam::compileThermo::prepare
{ {
dynCode.setFilterVariable("typeName", codeName()); dynCode.setFilterVariable("typeName", codeName());
const word type(thermoTypeDict_.lookup<word>("type")); forAll(substitutions_, i)
dynCode.setFilterVariable("type", type); {
setFilterVariable(dynCode, context, substitutions_[i]);
const HashTable<word> 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");
// Compile filtered C template // Compile filtered C template
dynCode.addCompileFile(thermoTypeName_ + ".C"); dynCode.addCompileFile(templateName_ + ".C");
// Define Make/options // Define Make/options
dynCode.setMakeOptions(context.options() + "\n\n" + context.libs()); dynCode.setMakeOptions(context.options() + "\n\n" + context.libs());
@ -169,19 +155,19 @@ void Foam::compileThermo::prepare
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::compileThermo::compileThermo Foam::compileTemplate::compileTemplate
( (
const word& thermoTypeName, const word& templateName,
const word& instantiatedThermoName, const word& instantiatedName,
const dictionary& thermoTypeDict const List<Pair<word>>& substitutions
) )
: :
CodedBase<compileThermo> CodedBase<compileTemplate>
( (
optionsDict(thermoTypeName, instantiatedThermoName) optionsDict(templateName, instantiatedName)
), ),
thermoTypeName_(thermoTypeName), templateName_(templateName),
thermoTypeDict_(thermoTypeDict) substitutions_(substitutions)
{ {
this->updateLibrary(); this->updateLibrary();
} }

View File

@ -23,8 +23,8 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef compileThermo_H #ifndef compileTemplate_H
#define compileThermo_H #define compileTemplate_H
#include "CodedBase.H" #include "CodedBase.H"
#include "dynamicCode.H" #include "dynamicCode.H"
@ -35,28 +35,28 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class compileThermo Declaration Class compileTemplate Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class compileThermo class compileTemplate
: :
public CodedBase<compileThermo> public CodedBase<compileTemplate>
{ {
// Private Member Data // Private Member Data
//- Name of the class Thermo basicThermo is instantiated on //- Name of the class Thermo basicThermo is instantiated on
const word thermoTypeName_; const word templateName_;
//- Reference to the dictionary containing the thermo components //- List of template argument substitutions
const dictionary& thermoTypeDict_; const List<Pair<word>> substitutions_;
// Private Member Functions // Private Member Functions
dictionary optionsDict dictionary optionsDict
( (
const word& thermoTypeName, const word& templateName,
const word& instantiatedThermoName const word& instantiatedName
) const; ) const;
void setFilterVariable void setFilterVariable
@ -71,15 +71,7 @@ class compileThermo
( (
dynamicCode& dynCode, dynamicCode& dynCode,
const dynamicCodeContext& context, const dynamicCodeContext& context,
const word& name const Pair<word>& substitution
) const;
void setFilterRenamedVariable
(
dynamicCode& dynCode,
const dynamicCodeContext& context,
const word& name,
const word& typeRenameMapName
) const; ) const;
//- Adapt the context for the current object //- Adapt the context for the current object
@ -95,11 +87,11 @@ public:
// Constructors // Constructors
//- Construct from name and dictionary //- Construct from name and dictionary
compileThermo compileTemplate
( (
const word& thermoTypeName, const word& templateName,
const word& instantiatedThermoName, const word& instantiatedName,
const dictionary& thermoTypeDict const List<Pair<word>>& substitutions
); );
}; };

View File

@ -1,5 +1,4 @@
basicThermo/basicThermo.C basicThermo/basicThermo.C
basicThermo/compileThermo.C
fluidThermo/fluidThermo.C fluidThermo/fluidThermo.C

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -179,6 +179,24 @@ Foam::wordList Foam::basicThermo::splitThermoName
} }
Foam::List<Foam::Pair<Foam::word>> Foam::basicThermo::thermoNameComponents
(
const word& thermoName
)
{
const wordList components(splitThermoName(thermoName, 5));
return List<Pair<word>>
{
{"transport", components[0]},
{"thermo", components[1]},
{"equationOfState", components[2]},
{"specie", components[3]},
{"energy", components[4]}
};
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::wordList Foam::basicThermo::heBoundaryBaseTypes() Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()

View File

@ -169,6 +169,12 @@ public:
const int nCmpt const int nCmpt
); );
//- Split name of thermo package into a list of named components names
static List<Pair<word>> thermoNameComponents
(
const word& thermoName
);
// Selectors // Selectors

View File

@ -25,7 +25,7 @@ License
#include "basicThermo.H" #include "basicThermo.H"
#include "wordIOList.H" #include "wordIOList.H"
#include "compileThermo.H" #include "compileTemplate.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -50,11 +50,23 @@ typename Table::iterator Foam::basicThermo::lookupCstrIter
&& !dynamicCode::resolveTemplate(Thermo::typeName).empty() && !dynamicCode::resolveTemplate(Thermo::typeName).empty()
) )
{ {
compileThermo thermo compileTemplate thermo
( (
Thermo::typeName, Thermo::typeName,
thermoTypeName, thermoTypeName,
thermoTypeDict List<Pair<word>>
{
{"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); cstrIter = tablePtr->find(thermoTypeName);

View File

@ -25,6 +25,7 @@ License
#include "basicChemistryModel.H" #include "basicChemistryModel.H"
#include "basicThermo.H" #include "basicThermo.H"
#include "compileTemplate.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
@ -94,63 +95,105 @@ Foam::autoPtr<Foam::basicChemistryModel> Foam::basicChemistryModel::New
if (cstrIter == thermoConstructorTablePtr_->end()) if (cstrIter == thermoConstructorTablePtr_->end())
{ {
FatalErrorInFunction if
<< "Unknown " << typeName_() << " type " << chemistryTypeDictNew (
<< endl; dynamicCode::allowSystemOperations
&& !dynamicCode::resolveTemplate(basicChemistryModel::typeName).empty()
const wordList names(thermoConstructorTablePtr_->sortedToc()); )
wordList thisCmpts;
thisCmpts.append(word::null);
thisCmpts.append(word::null);
thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5));
List<wordList> 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)); List<Pair<word>> substitutions
(
basicThermo::thermoNameComponents(thermo.thermoName())
);
if (SubList<word>(cmpts, 5, 2) == SubList<word>(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<word>(cmpts, 2)); FatalErrorInFunction
<< "Compilation and linkage of "
<< basicChemistryModel::typeName << " type " << nl
<< "chemistryType" << chemistryTypeDict << nl << nl
<< "failed." << exit(FatalError);
} }
} }
else
FatalErrorInFunction
<< "Valid " << validNames[0][0] << '/' << validNames[0][1]
<< " combinations for this thermodynamic model are:"
<< endl << endl;
printTable(validNames, FatalErrorInFunction);
FatalErrorInFunction << endl;
List<wordList> 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
<< "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<wordList> 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<word>(cmpts, 5, 2)
== SubList<word>(thisCmpts, 5, 2)
)
{
validNames.append(SubList<word>(cmpts, 2));
}
}
FatalErrorInFunction
<< "Valid " << validNames[0][0] << '/' << validNames[0][1]
<< " combinations for this thermodynamic model are:"
<< endl << endl;
printTable(validNames, FatalErrorInFunction);
FatalErrorInFunction << endl;
List<wordList> 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<basicChemistryModel>(cstrIter()(thermo)); return autoPtr<basicChemistryModel>(cstrIter()(thermo));
} }
// ************************************************************************* // // ************************************************************************* //