Skip to content

Commit 6c0db09

Browse files
committed
add ranging mole fractions for simple reactor
1 parent 2b0200b commit 6c0db09

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

rmgpy/rmg/input.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,9 +1716,26 @@ def format_temperature(system):
17161716

17171717
return f'[({system.Trange[0].value:g}, "{system.Trange[0].units}"), ({system.Trange[1].value:g}, "{system.Trange[1].units}")],'
17181718

1719+
def format_pressure(system):
1720+
"""Get pressure string format for reaction system, whether single value or range"""
1721+
if system.P is not None:
1722+
return '({0:g},"{1!s}")'.format(system.P.value, system.P.units)
1723+
1724+
return f'[({system.Prange[0].value:g}, "{system.Prange[0].units}"), ({system.Prange[1].value:g}, "{system.Prange[1].units}")],'
1725+
1726+
def format_initial_mole_fractions(system):
1727+
"""Get initial mole fractions string format for reaction system"""
1728+
mole_fractions = ''
1729+
for spcs, molfrac in system.initial_mole_fractions.items():
1730+
if isinstance(molfrac, list):
1731+
mole_fractions += ' "{0!s}": [{1:g}, {2:g}],\n'.format(spcs.label, molfrac[0], molfrac[1])
1732+
else:
1733+
mole_fractions += ' "{0!s}": {1:g},\n'.format(spcs.label, molfrac)
1734+
return mole_fractions
1735+
1736+
17191737
# Reaction systems
17201738
for system in rmg.reaction_systems:
1721-
# TODO add ranging pressures
17221739
if rmg.solvent:
17231740
f.write('liquidReactor(\n')
17241741
f.write(' temperature = ' + format_temperature(system) + '\n')
@@ -1739,12 +1756,9 @@ def format_temperature(system):
17391756
else:
17401757
f.write('simpleReactor(\n')
17411758
f.write(' temperature = ' + format_temperature(system) + '\n')
1742-
# Convert the pressure from SI pascal units to bar here
1743-
# Do something more fancy later for converting to user's desired units for both T and P..
1744-
f.write(' pressure = ({0:g},"{1!s}"),\n'.format(system.P.value, system.P.units))
1759+
f.write(' pressure = ' + format_pressure(system) + '\n')
17451760
f.write(' initialMoleFractions={\n')
1746-
for spcs, molfrac in system.initial_mole_fractions.items():
1747-
f.write(' "{0!s}": {1:g},\n'.format(spcs.label, molfrac))
1761+
f.write(format_initial_mole_fractions(system))
17481762
f.write(' },\n')
17491763

17501764
# Termination criteria

0 commit comments

Comments
 (0)