From 29bbbd6984f32881e3915c030c36446aba6ddef1 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 16 Apr 2021 18:42:38 +0100 Subject: [PATCH] etc/codeTemplates/dynamicCode: Added fluidReactionThermo dynamic compilation support for chemFoam, fireFoam, buoyantReactingFoam, reactingFoam, chtMultiRegionFoam, buoyantReactingParticleFoam, reactingParticleFoam, simpleReactingParticleFoam If the combination of property models selected in thermophysicalProperties is not already compiled and present in the standard libraries the thermophysical property package will be constructed and compiled automatically using the standard dynamicCode system provided in OpenFOAM. The thermophysical property package is constructed automatically from the etc/codeTemplates/dynamicCode files for the corresponding base thermo type, fluidThermo, fluidReactionThermo etc. If the corresponding codeTemplates files do not exist the standard thermo lookup error message is generated as before. As with all other dynamicCode options in OpenFOAM (codeStream, codedFunctionObject etc.) dynamic compilation of the thermophysical property package is only enabled if allowSystemOperations is set true. --- .../dynamicCode/fluidReactionThermo | 113 ++++++++++++++++++ .../dynamicCode/fluidReactionThermo.C | 93 ++++++++++++++ etc/codeTemplates/dynamicCode/fluidThermo.C | 2 +- .../dynamicCode/psiuReactionThermo.C | 2 +- .../basic/basicThermo/compileThermo.C | 53 +++++++- .../basic/basicThermo/compileThermo.H | 16 +++ .../reactionThermo/makeReactionThermo.H | 13 ++ 7 files changed, 285 insertions(+), 7 deletions(-) create mode 100644 etc/codeTemplates/dynamicCode/fluidReactionThermo create mode 100644 etc/codeTemplates/dynamicCode/fluidReactionThermo.C diff --git a/etc/codeTemplates/dynamicCode/fluidReactionThermo b/etc/codeTemplates/dynamicCode/fluidReactionThermo new file mode 100644 index 0000000000..8c8875327d --- /dev/null +++ b/etc/codeTemplates/dynamicCode/fluidReactionThermo @@ -0,0 +1,113 @@ +/*--------------------------------*- 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 fluidThermo; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +type +( + hePsiThermo + heRhoThermo +); + +baseType +( + hePsiThermo psiReactionThermo + heRhoThermo rhoReactionThermo +); + +energy +( + sensibleEnthalpy + absoluteEnthalpy + sensibleInternalEnergy + absoluteInternalEnergy +); + +mixture +( + singleComponentMixture + coefficientMultiComponentMixture + valueMultiComponentMixture + coefficientWilkeMultiComponentMixture +); + +renameMixture +( + pureMixture singleComponentMixture + multiComponentMixture coefficientMultiComponentMixture +); + +transport +( + const + icoTabulated + logPolynomial + polynomial + sutherland + tabulated + WLF +); + +thermo +( + eConst + eIcoTabulated + ePolynomial + ePower + eTabulated + hConst + hIcoTabulated + hPolynomial + hPower + hTabulated + janaf +); + +equationOfState +( + adiabaticPerfectFluid + Boussinesq + icoPolynomial + icoTabulated + incompressiblePerfectGas + linear + PengRobinsonGas + perfectFluid + perfectGas + rhoConst + rhoTabulated + rPolynomial +); + +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)/finiteVolume/lnInclude +#}; + +codeLibs +#{ +LIB_LIBS = \ + -ltransportModels \ + -lspecie \ + -lfluidThermophysicalModels \ + -lfiniteVolume +#}; + + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidReactionThermo.C b/etc/codeTemplates/dynamicCode/fluidReactionThermo.C new file mode 100644 index 0000000000..04218c2876 --- /dev/null +++ b/etc/codeTemplates/dynamicCode/fluidReactionThermo.C @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "forThermo.H" +#include "makeReactionThermo.H" + +#include "specie.H" + +#include "thermo.H" + +// EoS +#include "${equationOfState}.H" + +// Thermo +#include "${thermo}Thermo.H" +#include "${energy}.H" + +// Transport +#include "${transport}Transport.H" + +// psi/rho +#include "${baseType}.H" +#include "${type}.H" +#include "psiReactionThermo.H" + +// Mixture +#include "${mixture}.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 + } + } +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + forThermo + ( + ${transport}Transport, + ${energy}, + ${thermo}Thermo, + ${equationOfState}, + specie, + makeReactionThermo, + ${baseType}, + ${type}, + ${mixture} + ); +} + +// ************************************************************************* // diff --git a/etc/codeTemplates/dynamicCode/fluidThermo.C b/etc/codeTemplates/dynamicCode/fluidThermo.C index 2d82103fef..4c835e49f3 100644 --- a/etc/codeTemplates/dynamicCode/fluidThermo.C +++ b/etc/codeTemplates/dynamicCode/fluidThermo.C @@ -82,7 +82,7 @@ namespace Foam ${thermo}Thermo, ${equationOfState}, specie, - makeThermos, + makeThermo, ${baseType}, ${type}, ${mixture} diff --git a/etc/codeTemplates/dynamicCode/psiuReactionThermo.C b/etc/codeTemplates/dynamicCode/psiuReactionThermo.C index af657745ed..947e99f18c 100644 --- a/etc/codeTemplates/dynamicCode/psiuReactionThermo.C +++ b/etc/codeTemplates/dynamicCode/psiuReactionThermo.C @@ -82,7 +82,7 @@ namespace Foam ${thermo}Thermo, ${equationOfState}, specie, - makePsiuReactionThermos, + makePsiuReactionThermo, ${mixture} ); } diff --git a/src/thermophysicalModels/basic/basicThermo/compileThermo.C b/src/thermophysicalModels/basic/basicThermo/compileThermo.C index cb9aaaaa7d..a1b178d7e1 100644 --- a/src/thermophysicalModels/basic/basicThermo/compileThermo.C +++ b/src/thermophysicalModels/basic/basicThermo/compileThermo.C @@ -70,11 +70,11 @@ void Foam::compileThermo::setFilterVariable ( dynamicCode& dynCode, const dynamicCodeContext& context, - const word& name + const word& name, + const word& type ) const { const HashSet types(context.dict().lookup(name)); - const word type(thermoTypeDict_.lookup(name)); if (!types.found(type)) { FatalIOErrorInFunction(thermoTypeDict_) @@ -87,6 +87,50 @@ void Foam::compileThermo::setFilterVariable } +void Foam::compileThermo::setFilterVariable +( + dynamicCode& dynCode, + const dynamicCodeContext& context, + const word& name +) 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)); + + if (context.dict().found(typeRenameMapName)) + { + const HashTable renameMap + ( + context.dict().lookup(typeRenameMapName) + ); + + if (renameMap.found(type)) + { + type = renameMap[type]; + } + } + + setFilterVariable(dynCode, context, name, type); +} + + void Foam::compileThermo::prepare ( dynamicCode& dynCode, @@ -95,14 +139,13 @@ void Foam::compileThermo::prepare { dynCode.setFilterVariable("typeName", codeName()); - const HashTable typeToBaseMap(context.dict().lookup("baseType")); - const word type(thermoTypeDict_.lookup("type")); dynCode.setFilterVariable("type", type); + const HashTable typeToBaseMap(context.dict().lookup("baseType")); dynCode.setFilterVariable("baseType", typeToBaseMap[type]); - setFilterVariable(dynCode, context, "mixture"); + setFilterRenamedVariable(dynCode, context, "mixture", "renameMixture"); setFilterVariable(dynCode, context, "transport"); setFilterVariable(dynCode, context, "thermo"); setFilterVariable(dynCode, context, "equationOfState"); diff --git a/src/thermophysicalModels/basic/basicThermo/compileThermo.H b/src/thermophysicalModels/basic/basicThermo/compileThermo.H index e9112c3b6e..7eee5259f7 100644 --- a/src/thermophysicalModels/basic/basicThermo/compileThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/compileThermo.H @@ -59,6 +59,14 @@ class compileThermo const word& instantiatedThermoName ) const; + void setFilterVariable + ( + dynamicCode& dynCode, + const dynamicCodeContext& context, + const word& name, + const word& type + ) const; + void setFilterVariable ( dynamicCode& dynCode, @@ -66,6 +74,14 @@ class compileThermo const word& name ) const; + void setFilterRenamedVariable + ( + dynamicCode& dynCode, + const dynamicCodeContext& context, + const word& name, + const word& typeRenameMapName + ) const; + //- Adapt the context for the current object virtual void prepare(dynamicCode&, const dynamicCodeContext&) const; diff --git a/src/thermophysicalModels/reactionThermo/makeReactionThermo.H b/src/thermophysicalModels/reactionThermo/makeReactionThermo.H index d2d555b29b..96a23d7490 100644 --- a/src/thermophysicalModels/reactionThermo/makeReactionThermo.H +++ b/src/thermophysicalModels/reactionThermo/makeReactionThermo.H @@ -81,6 +81,19 @@ License addReactionThermo(BaseReactionThermo, CThermo, Mixture, ThermoPhys) +#define makePsiuReactionThermo(Mixture, ThermoPhys) \ + \ + defineReactionThermo \ + ( \ + psiuReactionThermo, \ + heheuPsiThermo, \ + Mixture, \ + ThermoPhys \ + ); \ + \ + addThermo(psiuReactionThermo, heheuPsiThermo, Mixture, ThermoPhys) + + #define makePsiuReactionThermos(Mixture, ThermoPhys) \ \ defineReactionThermo \