tespy icon indicating copy to clipboard operation
tespy copied to clipboard

Include enthalpies of formation to support chemical reactions

Open BenPortner opened this issue 2 years ago • 4 comments

Requesting comments by @fwitte before finishing the last todos.

Changes overview

  • Added new component AdiabaticConstPressureReactor: can be used to model gas phase chemical reactions with arbitrary stoichiometry (under adiabatic, constant pressure conditions)
  • Added test for new component
  • Added helper module tespy.tools.reaction: implements helper functions to parse reaction formulas, calculate reaction enthalpies, etc.
  • Major tespy.tools.fluid_properties overhaul: include enthalpies of formation in order to correctly represent enthalpy changes during chemical reactions
  • Fixes to several existing components and tests to deal with changed enthalpy values

Motivation

Coolprop, the library which is currently used to calculate fluid properties, uses arbitrary reference points for the calculation of species' enthalpies. Furthermore, the enthalpies do not account for the enthalpy of formation (see https://github.com/CoolProp/CoolProp/issues/1360, https://github.com/CoolProp/CoolProp/issues/58). As a consequence, it is currently very tedious to simulate chemical reactions in TESPy. The reaction enthalpy must be accounted for manually, leading to hardcoded values and a limited number of implemented reactions. This PR addresses the issue by:

  • Making sure enthalpy values returned by tespy.tools.fluid_properties account for each species' enthalpy of formation, thus making manual accounting for reaction enthalpies obsolete
  • Implementing a new component AdiabaticConstPressureReactor, which can be used to model arbitrary stoichiometric reactions (in gas phase, under constant pressure and adiabatic conditions)

New component: AdiabaticConstPressureReactor

The new component can be used to model arbitrary chemical gas phase reactions (under adiabatic, constant pressure conditions). The component accepts a reaction formula (e.g. CH4 + 2 O2 -> CO2 + 2 H2O) and a yield parameter X describing how much of the limiting substance is converted (1: complete conversion, 0: no reaction). Example usage:

from tespy.networks import Network
from tespy.components import Sink, Source
from tespy.components.reactors.adiabatic_const_pressure_reactor import AdiabaticConstPressureReactor
from tespy.connections import Connection

nw = Network(fluids=['CH4', 'O2', 'CO2', 'H2O'], m_unit='kg / s', T_unit='C', p_unit='bar', h_unit='kJ / kg')
src = Source('source')
sink = Sink('sink')

reactor = AdiabaticConstPressureReactor("reactor", X=1, formula="CH4 + 2 O2 -> CO2 + 2 H2O")

nw.add_conns(
    Connection(src, 'out1', reactor, 'in1', fluid={'CH4': 0.05, 'O2': 0.2, 'CO2': 0.75, "H2O":0}, p=1, T=20, m=1),
    Connection(reactor, 'out1', sink, 'in1'),
)

nw.solve('design')
nw.print_results()

reactor.outl[0].p.val  # 1 bar
reactor.outl[0].T.val  # 1855°C
reactor.outl[0].fluid.val # OrderedDict([('CH4', 0), ('CO2', 0.8871638890296235), ('H2O', 0.11229505817838446), ('O2', 0.0005410527919919749)])

Possible weak points

Additional dependencies

I had to introduce two new libraries in order to realize the changes:

  • pyromat: provides enthalpies of formation for various species
  • pyvalem: used to parse chemical reaction formulas

The libraries are lightweight and should not add too much overhead.

Missing data

Not all species, which exist in Coolprop are also available in pyromat. For non-existent species, the enthalpy of formation is assumed to be zero.

Large negative enthalpies

The new enthalpy values, which now include the enthalpy of formation, are large negative numbers (e.g. -15e6 for water), which seem a bit unintuitive at first. However, large thermal engineering softwares like ASPEN+ also produce such negative numbers. In fact, with the new changes, ASPEN+ and TESPy seem to produce the same enthalpy values (at least for the examples I tried).

Todos

[x] make sure tests run successfully [ ] fix doctests [x] implement tests for new components [ ] update API documentation [ ] update online documentation [ ] update What's New file

BenPortner avatar May 17 '22 12:05 BenPortner

Hello @BenPortner! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 36:80: E501 line too long (90 > 79 characters) Line 37:80: E501 line too long (94 > 79 characters) Line 38:80: E501 line too long (101 > 79 characters) Line 39:80: E501 line too long (99 > 79 characters)

Comment last updated at 2022-05-17 16:37:32 UTC

pep8speaks avatar May 17 '22 12:05 pep8speaks

This pull request introduces 7 alerts when merging a980d8328d7da16abfaa36b677473f6fa3eb4635 into a7fe99e9087c3bfe6e9ead0286aa8983270afa4d - view on LGTM.com

new alerts:

  • 7 for Unused import

lgtm-com[bot] avatar May 17 '22 12:05 lgtm-com[bot]

@BenPortner, thank you so much for your great input! I‘ll have a look at it in the upcoming days.

fwitte avatar May 17 '22 13:05 fwitte

Can we have a short call before you put too much work into fixing all doc tests? :D just want so see, if that is necessary or if we can find a different solution. especially for larger systems I fear that the current convergence checks and helpers might not like the changes.

fwitte avatar May 17 '22 14:05 fwitte

This had broken with a couple of things, so I am closing it again for now. I like the idea of the generic reactor. And, with the new structure and capabilities of the fluid property module, it might actually be much easier to implement it than before, only have to find the time for it.

Thank you still for putting in the effort!

fwitte avatar Jan 14 '24 10:01 fwitte