Repository navigation
Keep the balanceSpecies of each reactor - #3043
Open
natozenbilek wants to merge 1 commit into
Open
natozenbilek wants to merge 1 commit into
natozenbilek wants to merge 1 commit into
Conversation
balanceSpecies is given per reactor block in the input file, but it was stored in a single RMG.balance_species attribute that every simpleReactor, constantVIdealGasReactor and constantTPIdealGasReactor block overwrote. That one value was then passed to the RMG_Memory of every reactor, so all ranged reactors were balanced with the balanceSpecies of the last of these blocks (or with none, if that block had none). If that species was not in the initialMoleFractions of a reactor, RMG stopped with an IndexError in RMG_Memory.__init__. Store the balance species on the reaction system and pass each reactor's own value to RMG_Memory. Reactor types that do not take a balanceSpecies get None. Also raise an InputError when balanceSpecies is not one of the species in initialMoleFractions, which used to fail with an UnboundLocalError. Fixes ReactionMechanismGenerator#2755
natozenbilek
marked this pull request as ready for review
November 22, 2026 21:53
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation or Problem
Fixes #2755.
balanceSpeciesis given per reactor block, butinput.pystored it in a singleRMG.balance_speciesthat everysimpleReactor,constantVIdealGasReactorandconstantTPIdealGasReactorblock overwrote.main.pythen passed that one value to theRMG_Memoryof every reactor, so all ranged reactors were balanced with the species of the last block (or with none, if that block had none). If that species was not in a reactor'sinitialMoleFractions,RMG_Memory.__init__raised anIndexError. AbalanceSpeciesmissing from its own block'sinitialMoleFractionsfailed with anUnboundLocalError.Description of Changes
rmgpy/solver/simple.pyx: newcdef public str balance_speciesonSimpleReactor(defaultNone).rmgpy/rmg/input.py: the three reactor functions setsystem.balance_speciesinstead ofrmg.balance_species, and raise anInputErrorwhenbalanceSpeciesis not ininitialMoleFractions.rmgpy/rmg/main.py:RMG.balance_speciesremoved; eachRMG_Memorygetsgetattr(reaction_system, "balance_species", None), so reactor types without abalanceSpeciesgetNoneas before.test/rmgpy/rmg/inputTest.py: two tests (each reactor keeps its own value; missing species raisesInputError).documentation/source/users/rmg/input.rst: one sentence saying the balance species applies to its own reactor.Testing
Run in the
reactionmechanismgenerator/rmg:latestimage, whose/rmg/RMG-Pyis at032e9d20e, the base of this branch. The five files this PR changes are the same there as onmain. After copying the changed files,python setup.py build_ext --inplacerebuilt onlyrmgpy/solver/simple.pyx.main(AttributeError: ... has no attribute 'balance_species', andUnboundLocalErrorforxbspcs) and pass on this branch.pytest test/rmgpy/rmg/inputTest.py test/rmgpy/solver: 75 passed, 1 skipped.pytest test/rmgpy/rmg/mainTest.py(its input has a rangedsimpleReactorwithbalanceSpecies='N2'and twoliquidReactors): 19 passed.simpleReactors (nSims=3), run withrmg.py:{'H2': [0.2, 0.3], 'O2': 0.1, 'N2': 0.7}withbalanceSpecies='N2', reactor 1 the same withArinstead ofN2andbalanceSpecies='Ar': onmainit stops withIndexErrorinRMG_Memory.__init__. On this branch it completes, and reactor 0 adjusts N2 while reactor 1 adjusts Ar (e.g.H2 = 0.2158, O2 = 0.1, N2 = 0.6842andH2 = 0.2158, O2 = 0.1, Ar = 0.6842).N2 0.4, Ar 0.3andN2 0.3, Ar 0.4): onmainboth adjust Ar, so reactor 0 logsN2 = 0.4, Ar = 0.2842. On this branch reactor 0 logsN2 = 0.3842, Ar = 0.3and reactor 1 still adjusts Ar.balanceSpeciesin reactor 1: onmainreactor 0 is not balanced with N2 (its chosen conditions only listH2). On this branch it adjusts N2.Reviewer Tips
simple.pyxchanges, so the extension has to be rebuilt (make build).