makeReactionThermos in OpenFOAM

makeReactionThermos in OpenFOAM

The makeReactionThermos is a macro defined in the makeReactionThermo.H, and used in the psiReactionThermos.C as an example. We pick one of the constructed “table” to study this macro. As in the thermophysicalProperties in the constant folder of the tutorial simplifiedSiwek such thermo profiles are defined:

1
2
3
4
5
6
7
8
9
10
11
thermoType
{
type hePsiThermo;
mixture reactingMixture;
transport sutherland;
thermo janaf;
energy sensibleEnthalpy;
equationOfState perfectGas;
specie specie;
}

By calling the following function, a typeName is constructed as:

1
2
3
4
5
6
7
8
9
10
const word thermoTypeName
(
word(thermoTypeDict.lookup("type")) + '<'
+ word(thermoTypeDict.lookup("mixture")) + '<'
+ word(thermoTypeDict.lookup("transport")) + '<'
+ word(thermoTypeDict.lookup("thermo")) + '<'
+ word(thermoTypeDict.lookup("equationOfState")) + '<'
+ word(thermoTypeDict.lookup("specie")) + ">>,"
+ word(thermoTypeDict.lookup("energy")) + ">>>"
);

and the typeName is:

1
hePsiThermo<reactingMixture<sutherland<janaf<perfectGas<specie>>,sensibleEnthalpy>>>

This type has been built in table psiReactionThermo::fvMeshConstructorTablePtr_ using the following macro:

1
2
3
4
5
6
7
8
9
10
// Reaction thermo for sensible enthalpy

makeThermoPhysicsReactionThermos
(
psiThermo,
psiReactionThermo,
hePsiThermo,
reactingMixture,
gasHThermoPhysics
);

The definition of the makeThermoPhysicsReactionThermos is in makeReactionThermo.H with a substitution of the above parameters:

1
2
3
4
5
6
7
8
9
10
11
12
defineThermoPhysicsReactionThermo                                         
(
psiReactionThermo,
hePsiThermo,
reactingMixture,
gasHThermoPhysics
);

addThermoPhysicsThermo(basicThermo,hePsiThermoreactingMixturegasHThermoPhysics);
addThermoPhysicsThermo(fluidThermo, CThermoMixtureThermoPhys);
addThermoPhysicsThermo(BaseThermo, CThermoMixtureThermoPhys);
addThermoPhysicsThermo(BaseReactionThermo, CThermoMixtureThermoPhys)

There are other macros defined in this macro which are defineThermoPhysicsReactionThermo and addThermoPhysicsThermo . Substitute the parameters in the defineThermoPhysicsReactionThermo which is defined in makeReactionThermo.Has:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
typedef hePsiThermo                                                       
<
psiReactionThermo,
SpecieMixture
<
reactingMixture
<
gasHThermoPhysics
>
>
> hePsiThermoreactingMixturegasHThermoPhysics;

defineTemplateTypeNameAndDebugWithName
(
hePsiThermoreactingMixturegasHThermoPhysics,
("hePsiThermo""<" + reactingMixture<gasHThermoPhysics>::typeName() + ">").c_str(),0
)

Here one thing to mention is the use of macro in C++. The single # symbol in the macro will return a string of the variable name. The another macro addThermoPhysicsThermo with a substitution of the parameters defined in makeThermo.H:

1
2
3
4
5
6
7
// Pick one of them as an example
addToRunTimeSelectionTable
(
fluidThermo,
CThermoMixtureThermoPhys,
fvMesh
);

And the addToRunTimeSelectionTable defined in the addToRunTimeSelectionTable.H with the substitution of the parameters:

1
2
 /* Add the thisType constructor function to the table */                 
fluidThermo::addfvMeshConstructorToTable<CThermoMixtureThermoPhys> addCThermoMixtureThermoPhysfvMeshConstructorTofluidThermoTable_ )

Then we go to the defineTemplateTypeNameAndDebugWithName macro with a substitution of parameters which is defined in className.H:

1
2
3
4
//- Define the typeName and debug information, lookup as \a Name
#define defineTemplateTypeNameAndDebugWithName(Type, Name, DebugSwitch) \
defineTemplateTypeNameWithName(Type, Name); \
defineTemplateDebugSwitchWithName(Type, Name, DebugSwitch)