def test_rev_reaction():
    """Returns a valid reaction (from rev_rxn.xml)"""
    return Reactions.ReversibleReaction(rxn_type="Elementary",
                                        is_reversible=True,
                                        rxn_equation="H + O2 [=] H2O ",
                                        species_list=['H', 'H2O', 'O2'],
                                        rate_coeffs_components={'k': 10},
                                        reactant_stoich_coeffs={
                                            'H': 2,
                                            'O2': 1
                                        },
                                        product_stoich_coeffs={'H2O': 2})
Example #2
0
    def get_reaction_list(self):
        """Appends a Reaction/Reaction-inherited object to each reaction
        described by input xml file to reaction_list.
        """
        for reactionData in self.rxns.findall('reactionData'):
            for reaction in reactionData.findall('reaction'):
                species = self.get_species()
                is_reversible = self.get_is_reversible(reaction)
                rxn_type = self.get_rxn_type(reaction)
                rxn_equation = self.get_rxn_equation(reaction)
                rate_coeffs_components = self.get_rate_coeffs_components(
                    reaction)
                reactant_stoich_coeffs = self.get_reactant_stoich_coeffs(
                    reaction)
                product_stoich_coeffs = self.get_product_stoich_coeffs(
                    reaction)

                # IRREVERSIBLE elementary reaction case
                if is_reversible == False and rxn_type == "Elementary":
                    rxn = Reactions.IrreversibleReaction(
                        rxn_type, is_reversible, rxn_equation, species,
                        rate_coeffs_components, reactant_stoich_coeffs,
                        product_stoich_coeffs)
                    self.reaction_list.append(rxn)

                # REVERSIBLE elementary reaction case
                elif is_reversible == True and rxn_type == "Elementary":
                    rxn = Reactions.ReversibleReaction(rxn_type, is_reversible,
                                                       rxn_equation, species,
                                                       rate_coeffs_components,
                                                       reactant_stoich_coeffs,
                                                       product_stoich_coeffs)
                    self.reaction_list.append(rxn)

                # Unhandled reaction case
                else:
                    raise NotImplementedError(
                        "This type of reaction has not been implemented yet!")
def test_base_reaction():
    """Returns a valid reaction (from rxns.xml)"""
    return Reactions.Reaction(rxn_type="Elementary",
                              is_reversible=False,
                              rxn_equation="H2 + OH =] H2O + H",
                              species_list=['H', 'O', 'OH', 'H2', 'H2O', 'O2'],
                              rate_coeffs_components={'k': 10},
                              reactant_stoich_coeffs={
                                  'H2': 1,
                                  'OH': 1
                              },
                              product_stoich_coeffs={
                                  'H2O': 1,
                                  'H': 1
                              })
def test_IrrevReaction_compute_reaction_rate_neg_product_stoich_coeffs(
        test_base_reaction):
    """Test compute_reaction_rate() for an elementary, irreversible reaction."""
    test = Reactions.IrreversibleReaction(rxn_type="Elementary",
                                          is_reversible=False,
                                          rxn_equation="A + B =] C",
                                          species_list=['A', 'B', 'C'],
                                          rate_coeffs_components={'k': 10},
                                          reactant_stoich_coeffs={
                                              'A': 2,
                                              'B': 1
                                          },
                                          product_stoich_coeffs={'C': -1})
    test.set_concentrations({'A': 1, 'B': 2, 'C': 3})
    with pytest.raises(ValueError):
        rxnrate = test.compute_reaction_rate()
def test_wrongly_classified_rev_rxn_nonElementary():
    """Tests initializing wrongly classified ReversibleReaction (actually non-elementary)"""
    with pytest.raises(Reactions.ReversibleReactionError):
        test = Reactions.ReversibleReaction(
            rxn_type="Non-elementary",
            is_reversible=True,
            rxn_equation="H2 + OH =] H2O + H",
            species_list=['H', 'O', 'OH', 'H2', 'H2O', 'O2'],
            rate_coeffs_components={'k': 10},
            reactant_stoich_coeffs={
                'H2': 1,
                'OH': 1
            },
            product_stoich_coeffs={
                'H2O': 1,
                'H': 1
            })
def test_IrrevReaction_compute_reaction_rate(test_irrev_reaction):
    """Test compute_reaction_rate() for an elementary,
    irreversible reaction."""
    test = Reactions.IrreversibleReaction(rxn_type="Elementary",
                                          is_reversible=False,
                                          rxn_equation="A + B =] C",
                                          species_list=['A', 'B', 'C'],
                                          rate_coeffs_components={'k': 10},
                                          reactant_stoich_coeffs={
                                              'A': 2,
                                              'B': 1
                                          },
                                          product_stoich_coeffs={'C': 1})
    test.set_concentrations({'A': 1, 'B': 2, 'C': 3})
    rxnrate = test.compute_reaction_rate()
    expected = numpy.array([-40.0, -20.0, 20.0])
    assert (rxnrate == expected).all()
def test_IrrevReaction_compute_reaction_rate_coeff_invalid_constant():
    """Test reaction constant reaction rate coefficient
    but invalid constant (non-positive)"""
    test_rxn = Reactions.IrreversibleReaction(
        rxn_type="Elementary",
        is_reversible=False,
        rxn_equation="H2 + OH =] H2O + H",
        species_list=['H', 'O', 'OH', 'H2', 'H2O', 'O2'],
        rate_coeffs_components={'k': -10},
        reactant_stoich_coeffs={
            'H2': 1,
            'OH': 1
        },
        product_stoich_coeffs={
            'H2O': 1,
            'H': 1
        })
    with pytest.raises(ValueError):
        test_rxn.compute_reaction_rate_coeff()
def test_irrev_reaction_arrhenius():
    """Returns a reaction with Arrhenius reaction rate coefficient."""
    return Reactions.IrreversibleReaction(
        rxn_type="Elementary",
        is_reversible=False,
        rxn_equation="H2 + OH =] H2O + H",
        species_list=['H', 'O', 'OH', 'H2', 'H2O', 'O2'],
        rate_coeffs_components={
            'A': 10,
            'E': 100
        },
        reactant_stoich_coeffs={
            'H2': 1,
            'OH': 1
        },
        product_stoich_coeffs={
            'H2O': 1,
            'H': 1
        })