Skip to content

Commit

Permalink
thermophysicalModels: Centralised instantiation macros
Browse files Browse the repository at this point in the history
All models that require templating on the thermodynamic model, including
the thermodynamic models themselves, are now instantiated using a
centralised set of variadic macros. Seven macros exist to instantiate
models for different classes of thermodynamics model. These are:

   forGases:          All model combinations valid for gases

   forCommonGases:    The most commonly used gas models

   forAbsoluteGases:  A limited selection of gas models with absolute
                      forms of energy, for use with Xi-combustion models

   forLiquids:        All model combinations valid for liquids

   forCommonLiquids:  The most commonly used liquid models

   forPolynomials:    Model combinations with properties fitted to
                      polynomials

   forSolids:         All model combinations valid for solids

All the *ThermoPhysics typedefs have been removed, as this system was
fundamentally not extensible. The enormous lists of thermodynamic
instantiations that existed for reaction thermos, chemistry models,
tabulation methods, etc..., were extremely difficult to read and reason
about what combinations are valid under what circumstances. This change
centralises those decisions, makes them concise and readable, and makes
them consistent across the entire codebase.

Soot model selection has now been brought up to date in line with
chemistry, combustion, and others. The angle-bracketed part of the name
is no longer necessary; this information is determined directly from the
existing thermo model. So, now to select a mixture-fraction soot model,
the entry is simply:

    sootModel   mixtureFraction;

Rather than:

    sootModel   mixtureFraction<rhoReactionThermo,gasHThermoPhysics>;

The only place in which *ThermoPhysics typedefs are still required in
the selection name is in the thermalBaffle1D boundary condition. Here
there is no thermo model from which to determine a name. This eventually
needs resolving either by adding a selection mechanism similar to that
of the thermo packages themselves, or by removing this boundary
condition in favour of the (non-1D) thermal baffle boundary condition
and region model.
  • Loading branch information
Will Bainbridge committed Apr 30, 2020
1 parent 73a594c commit fe89082
Show file tree
Hide file tree
Showing 83 changed files with 1,999 additions and 4,318 deletions.
3 changes: 1 addition & 2 deletions applications/solvers/combustion/chemFoam/chemFoam.C
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -37,7 +37,6 @@ Description
#include "multiComponentMixture.H"
#include "chemistrySolver.H"
#include "OFstream.H"
#include "thermoPhysicsTypes.H"
#include "basicSpecieMixture.H"
#include "cellModeller.H"
#include "thermoTypeFunctions.H"
Expand Down
71 changes: 8 additions & 63 deletions applications/solvers/combustion/chemFoam/thermoTypeFunctions.H
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2018-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2018-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand All @@ -23,25 +23,21 @@ License
\*---------------------------------------------------------------------------*/

template<class ThermoType>
scalarList W(const rhoReactionThermo& thermo)
{
const PtrList<ThermoType>& specieData =
dynamicCast<const multiComponentMixture<ThermoType>>(thermo)
.speciesData();
const basicSpecieMixture& composition = thermo.composition();

scalarList W(specieData.size());
scalarList W(composition.Y().size());

forAll(specieData, i)
forAll(W, i)
{
W[i] = specieData[i].W();
W[i] = composition.Wi(i);
}

return W;
}


template<class ThermoType>
scalar h0
(
const rhoReactionThermo& thermo,
Expand All @@ -50,68 +46,17 @@ scalar h0
const scalar T
)
{
const PtrList<ThermoType>& specieData =
dynamic_cast<const multiComponentMixture<ThermoType>&>(thermo)
.speciesData();
const basicSpecieMixture& composition = thermo.composition();

scalar h0 = 0;

forAll(Y, i)
{
h0 += Y[i]*specieData[i].Hs(p, T);
h0 += Y[i]*composition.Hs(i, p, T);
}

return h0;
}


scalarList W(const rhoReactionThermo& thermo)
{
if (isA<multiComponentMixture<gasHThermoPhysics>>(thermo))
{
return W<gasHThermoPhysics>(thermo);
}
else if (isA<multiComponentMixture<constFluidHThermoPhysics>>(thermo))
{
return W<constFluidHThermoPhysics>(thermo);
}
else
{
FatalErrorInFunction
<< "Thermodynamics type " << thermo.type()
<< " not supported by chemFoam"
<< exit(FatalError);

return scalarList::null();
}
}


scalar h0
(
const rhoReactionThermo& thermo,
const scalarList& Y,
const scalar p,
const scalar T
)
{
if (isA<multiComponentMixture<gasHThermoPhysics>>(thermo))
{
return h0<gasHThermoPhysics>(thermo, Y, p, T);
}
else if (isA<multiComponentMixture<constFluidHThermoPhysics>>(thermo))
{
return h0<constFluidHThermoPhysics>(thermo, Y, p, T);
}
else
{
FatalErrorInFunction
<< "Thermodynamics type " << thermo.type()
<< " not supported by chemFoam"
<< exit(FatalError);

return 0;
}
}


// ************************************************************************* //
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -315,8 +315,8 @@ List<specieElement> currentSpecieComposition(5);
scalar currentLowT = 0;
scalar currentHighT = 0;
scalar currentCommonT = 0;
gasHThermoPhysics::coeffArray highCpCoeffs(scalarList(7));
gasHThermoPhysics::coeffArray lowCpCoeffs(scalarList(7));
chemkinReader::thermoPhysics::coeffArray highCpCoeffs(scalarList(7));
chemkinReader::thermoPhysics::coeffArray lowCpCoeffs(scalarList(7));

specieCoeffs currentSpecieCoeff;

Expand Down Expand Up @@ -633,7 +633,7 @@ bool finishReaction = false;

<readThermoLineLabel4>{thermoLineLabel4} {

HashPtrTable<gasHThermoPhysics>::iterator specieThermoIter
HashPtrTable<chemkinReader::thermoPhysics>::iterator specieThermoIter
(
speciesThermo_.find(currentSpecieName)
);
Expand All @@ -646,7 +646,7 @@ bool finishReaction = false;
speciesThermo_.insert
(
currentSpecieName,
new gasHThermoPhysics
new chemkinReader::thermoPhysics
(
janafThermo<perfectGas<specie>>
(
Expand All @@ -671,15 +671,15 @@ bool finishReaction = false;
}

<readThermoSpecieName>{end} {
Reaction<gasHThermoPhysics>::TlowDefault = max
Reaction<chemkinReader::thermoPhysics>::TlowDefault = max
(
Reaction<gasHThermoPhysics>::TlowDefault,
Reaction<chemkinReader::thermoPhysics>::TlowDefault,
currentLowT
);

Reaction<gasHThermoPhysics>::ThighDefault = min
Reaction<chemkinReader::thermoPhysics>::ThighDefault = min
(
Reaction<gasHThermoPhysics>::ThighDefault,
Reaction<chemkinReader::thermoPhysics>::ThighDefault,
currentHighT
);

Expand Down
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -172,9 +172,9 @@ void Foam::chemkinReader::addReactionType
{
reactions_.append
(
new IrreversibleReaction<gasHThermoPhysics, ReactionRateType>
new IrreversibleReaction<thermoPhysics, ReactionRateType>
(
ReactionProxy<gasHThermoPhysics>
ReactionProxy<thermoPhysics>
(
speciesTable_,
lhs.shrink(),
Expand All @@ -191,9 +191,9 @@ void Foam::chemkinReader::addReactionType
{
reactions_.append
(
new ReversibleReaction<gasHThermoPhysics, ReactionRateType>
new ReversibleReaction<thermoPhysics, ReactionRateType>
(
ReactionProxy<gasHThermoPhysics>
ReactionProxy<thermoPhysics>
(
speciesTable_,
lhs.shrink(),
Expand Down Expand Up @@ -480,11 +480,11 @@ void Foam::chemkinReader::addReaction
(
new NonEquilibriumReversibleReaction
<
gasHThermoPhysics,
thermoPhysics,
ArrheniusReactionRate
>
(
ReactionProxy<gasHThermoPhysics>
ReactionProxy<thermoPhysics>
(
speciesTable_,
lhs.shrink(),
Expand Down Expand Up @@ -535,11 +535,11 @@ void Foam::chemkinReader::addReaction
(
new NonEquilibriumReversibleReaction
<
gasHThermoPhysics,
thermoPhysics,
thirdBodyArrheniusReactionRate
>
(
ReactionProxy<gasHThermoPhysics>
ReactionProxy<thermoPhysics>
(
speciesTable_,
lhs.shrink(),
Expand Down Expand Up @@ -640,11 +640,11 @@ void Foam::chemkinReader::addReaction
(
new NonEquilibriumReversibleReaction
<
gasHThermoPhysics,
thermoPhysics,
LandauTellerReactionRate
>
(
ReactionProxy<gasHThermoPhysics>
ReactionProxy<thermoPhysics>
(
speciesTable_,
lhs.shrink(),
Expand Down Expand Up @@ -776,8 +776,8 @@ void Foam::chemkinReader::read
const fileName& transportFileName
)
{
Reaction<gasHThermoPhysics>::TlowDefault = 0;
Reaction<gasHThermoPhysics>::ThighDefault = great;
Reaction<thermoPhysics>::TlowDefault = 0;
Reaction<thermoPhysics>::ThighDefault = great;

transportDict_.read(IFstream(transportFileName)());

Expand Down
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -46,7 +46,13 @@ SourceFiles
#include "speciesTable.H"
#include "specieElement.H"
#include "atomicWeights.H"
#include "reactionTypes.H"

#include "specie.H"
#include "perfectGas.H"
#include "janafThermo.H"
#include "sensibleEnthalpy.H"
#include "sutherlandTransport.H"
#include "thermo.H"

#include <FlexLexer.h>

Expand All @@ -55,6 +61,8 @@ SourceFiles
namespace Foam
{



typedef HashTable<List<specieElement>> speciesCompositionTable;

/*---------------------------------------------------------------------------*\
Expand All @@ -77,6 +85,21 @@ public:
gas
};

// Public typedefs

typedef
sutherlandTransport
<
species::thermo
<
janafThermo
<
perfectGas<specie>
>,
sensibleEnthalpy
>
> thermoPhysics;


private:

Expand Down Expand Up @@ -173,13 +196,13 @@ private:
HashTable<phase> speciePhase_;

//- Table of the thermodynamic data given in the CHEMKIN file
HashPtrTable<gasHThermoPhysics> speciesThermo_;
HashPtrTable<thermoPhysics> speciesThermo_;

//- Table of species composition
speciesCompositionTable speciesComposition_;

//- List of the reactions
ReactionList<gasHThermoPhysics> reactions_;
ReactionList<thermoPhysics> reactions_;

//- Transport properties dictionary
dictionary transportDict_;
Expand Down Expand Up @@ -351,13 +374,13 @@ public:
}

//- Table of the thermodynamic data given in the CHEMKIN file
const HashPtrTable<gasHThermoPhysics>& speciesThermo() const
const HashPtrTable<thermoPhysics>& speciesThermo() const
{
return speciesThermo_;
}

//- List of the reactions
const ReactionList<gasHThermoPhysics>& reactions() const
const ReactionList<thermoPhysics>& reactions() const
{
return reactions_;
}
Expand Down
Expand Up @@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
Expand Down Expand Up @@ -65,7 +65,8 @@ int main(int argc, char *argv[])

speciesTable species;
chemkinReader cr(species, args[1], args[3], args[2], newFormat);
const HashPtrTable<gasHThermoPhysics>& speciesThermo = cr.speciesThermo();
const HashPtrTable<chemkinReader::thermoPhysics>& speciesThermo =
cr.speciesThermo();

dictionary thermoDict;
thermoDict.add("species", cr.species());
Expand All @@ -82,7 +83,12 @@ int main(int argc, char *argv[])
// pending complete integration into the thermodynamics structure

// Add elements
forAllConstIter(HashPtrTable<gasHThermoPhysics>, speciesThermo, iter)
forAllConstIter
(
HashPtrTable<chemkinReader::thermoPhysics>,
speciesThermo,
iter
)
{
const word specieName(iter.key());

Expand Down

0 comments on commit fe89082

Please sign in to comment.