Thermal Engineering Systems in Python (TESPy). This package provides a powerful simulation toolkit for thermal engineering plants such as power plants, district heating systems or heat pumps.
tespy.components.WaterElectrolyzer throws an error KeyError: 'H2' when specifying "hydrogen" instead of "H2" in the Network definition. The reason is that tespy\components\reactors\water_electrolyzer.py in line 312 tries to reference molar_masses["H2"] but the key does not exist. Instead, the key is called molar_masses["hydrogen"].
Minimum Error Example
nw = Network(fluids=['water', 'oxygen', 'hydrogen'], m_unit='kg / s', T_unit='C', p_unit='bar', h_unit='kJ / kg')
src_cool = Source('cooling water source')
src_water = Source('water source')
sink_cool = Sink('cooling water sink')
sink_h2 = Sink('H2 sink')
sink_o2 = Sink('O2 sink')
"""
Electrolyzer Inlets/Outlets
- in1 (cooling inlet), in2 (feed water inlet)
- out1 (cooling outlet), out2 (hydrogen outlet), out3 (oxigen outlet)
"""
electrolyzer = WaterElectrolyzer("electrolysis", eta=0.8)
nw.add_conns(
Connection(src_cool, 'out1', electrolyzer, 'in1', fluid={'water': 1}, p=1, T=30, m=1), # cooling water in
Connection(src_water, 'out1', electrolyzer, 'in2', fluid={'water': 1}, p=1, T=30, m=1), # process water in
Connection(electrolyzer, 'out1', sink_cool, 'in1'), # cooling water out
Connection(electrolyzer, 'out2', sink_h2, 'in1'), # h2 out
Connection(electrolyzer, 'out3', sink_o2, 'in1'), # o2 out
)
# solve
nw.solve('design')
Solution
A quick work around is to try all aliases:
M = [molar_masses[alias] for alias in CP.get_aliases('H2') if alias in molar_masses.keys()][0]
or to call CoolProps directly:
M = CP.PropsSI("M", "hydrogen")
Ultimately, it would be nice if there was a helper class which handles this automatically (i.e. returns the stored value in molar_mass no matter which alias is given).
@BenPortner, thank you for your contribution here! I will make a slight modification to your proposed solution, since the names of H2/O2/H2O within the network should be available in the class.
tespy.components.WaterElectrolyzer
throws an errorKeyError: 'H2'
when specifying "hydrogen" instead of "H2" in theNetwork
definition. The reason is that tespy\components\reactors\water_electrolyzer.py in line 312 tries to referencemolar_masses["H2"]
but the key does not exist. Instead, the key is calledmolar_masses["hydrogen"]
.Minimum Error Example
Solution
A quick work around is to try all aliases:
M = [molar_masses[alias] for alias in CP.get_aliases('H2') if alias in molar_masses.keys()][0]
or to call CoolProps directly:M = CP.PropsSI("M", "hydrogen")
Ultimately, it would be nice if there was a helper class which handles this automatically (i.e. returns the stored value inmolar_mass
no matter which alias is given).