Пример #1
0
def test_arr_A():
    """Test when parameter A (for computing
    Arrrhenius reaction rate coeff)
    is missing from xml file"""
    with pytest.raises(ValueError):
        xml_filename = os.path.join(DATA_DIRECTORY, "A_arr.xml")
        parser = Parser.ReactionParser(xml_filename)
def test_graphics_dict():
    """Test if No# of Reactions consistent with No# of Specie Lists"""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxnset_long.xml")
    parser = Parser.ReactionParser(xml_filename)
    concentration = ({
        'H': 1,
        'H2': 1,
        'H2O': 0,
        'H2O2': 1,
        'HO2': 1,
        'O': 1,
        "O2": 1,
        "OH": 1
    })
    temperature = 1000
    rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                            parser.NASA_poly_coefs,
                                            temperature, concentration)
    target = "final/results"
    graphics_dict = {
        'node_color': "hello",
        'rate': False,
        'arrow_size': False,
        'arrow_color': True,
        'init_con': True,
        'prod_con': True
    }
    obj = visualizer.ReactionPathDiagram(target,
                                         rxnsys,
                                         integrate=False,
                                         time=None,
                                         cluster=False)
    obj.fit()
    with pytest.raises(ValueError):
        obj.connect(graphics_dict, size=5, separate=False)
Пример #3
0
def test_const_k():
    """Test when k (for computing
    constant reaction rate coeff)
    is missing from xml file"""
    with pytest.raises(ValueError):
        xml_filename = os.path.join(DATA_DIRECTORY, "k_const.xml")
        parser = Parser.ReactionParser(xml_filename)
Пример #4
0
def test_RxnParser_rate_coeffs_components():
    """Test get_rate_coeffs_components for reaction 1."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert (parser.reaction_list[0].rate_coeffs_components == {
        'A': 35200000000.0,
        'E': 71400.0
    })
Пример #5
0
def test_rxn_sys():
    """Returns a valid reaction system"""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxn.xml")
    parser = Parser.ReactionParser(xml_filename)
    temp = 500  # "low" temperature range in NASA coeffs database
    concentrations = {'H': 1, 'O2': 1, 'H2O': 1}
    rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                            parser.NASA_poly_coefs, temp,
                                            concentrations)
    return rxnsys
Пример #6
0
def test_RxnParser_product_stoich_coeffs():
    """Test get_product_stoich_coeffs for reaction 1."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert (parser.reaction_list[0].product_stoich_coeffs == {
        'H': 0,
        'H2': 0,
        'H2O': 0,
        'O': 1,
        'O2': 0,
        'OH': 1
    })
Пример #7
0
def test_RxnParser_species():
    """Test when reaction rate coefficient is modified
    Arrhenius but R is changed by user"""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert parser.get_species() == ({
        'H': None,
        'O': None,
        'OH': None,
        'H2': None,
        'H2O': None,
        'O2': None
    })
Пример #8
0
def test_rxn_sys_invalid_temperature():
    """Tests setting up reaction system with invalid temperatures."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns_mixed.xml")
    parser = Parser.ReactionParser(xml_filename)
    concentrations = {'H': 1, 'O2': 2, 'OH': 1, 'O': 4, 'H2O': 0, 'H2': 1}
    temp = 0
    with pytest.raises(ValueError):
        rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                                parser.NASA_poly_coefs, temp,
                                                concentrations)
    temp = -100
    with pytest.raises(ValueError):
        rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                                parser.NASA_poly_coefs, temp,
                                                concentrations)
Пример #9
0
def test_rxn_sys_get_reaction_rate_for_3_rxns():
    """Tests function to get reaction rate for a given system of reactions (more than 1 reaction)."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxnsys.xml")
    parser = Parser.ReactionParser(xml_filename)
    temp = 10
    concentrations = {'H': 1, 'O2': 1, 'OH': 1, 'O': 1, 'H2O': 1, 'H2': 1}
    rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                            parser.NASA_poly_coefs, temp,
                                            concentrations)
    rates = rxnsys.sort_reaction_rates()
    # assert rxnsys.get_reaction_rate() == -10.
    assert rates['H'] == -10.
    assert rates['O2'] == -15.
    assert rates['H2O'] == 40.
    assert rates['H2'] == -20.
    assert rates['O'] == -10.
    assert rates['OH'] == 0.
Пример #10
0
def test_rxn_sys_rev_reaction():
    """Tests setting up reaction system with reversible reaction."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rev_rxn.xml")
    parser = Parser.ReactionParser(xml_filename)
    temp = 500  # "low" temperature range in NASA coeffs database
    concentrations = {'H': 1, 'O2': 1, 'H2O': 1}
    rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                            parser.NASA_poly_coefs, temp,
                                            concentrations)
    # expected_nasa = numpy.array([[2.50000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
    #                             0.00000000e+00, 2.54716270e+04, -4.60117608e-01],
    #                             [3.38684249e+00, 3.47498246e-03, -6.35469633e-06, 6.96858127e-09,
    #                             -2.50658847e-12, -3.02081133e+04, 2.59023285e+00],
    #                             [3.21293640e+00, 1.12748635e-03, -5.75615047e-07, 1.31387723e-09,
    #                             -8.76855392e-13, -1.00524902e+03, 6.03473759e+00]])
    expected_nasa = {
        'O2':
        numpy.array([
            3.28253784e+00, 1.48308754e-03, -7.57966669e-07, 2.09470555e-10,
            -2.16717794e-14, -1.08845772e+03, 5.45323129e+00
        ]),
        'H2O':
        numpy.array([
            3.03399249e+00, 2.17691804e-03, -1.64072518e-07, -9.70419870e-11,
            1.68200992e-14, -3.00042971e+04, 4.96677010e+00
        ]),
        'H':
        numpy.array([
            2.50000001e+00, -2.30842973e-11, 1.61561948e-14, -4.73515235e-18,
            4.98197357e-22, 2.54736599e+04, -4.46682914e-01
        ])
    }
    rev_rxn_obj = parser.reaction_list[0]
    #assert numpy.isclose(rev_rxn_obj.NASA_poly_coefs, expected_nasa).all()
    assert (numpy.isclose(rev_rxn_obj.NASA_poly_coefs_dict['H2O'],
                          expected_nasa['H2O'])).all()
    assert (numpy.isclose(rev_rxn_obj.NASA_poly_coefs_dict['O2'],
                          expected_nasa['O2'])).all()
    assert (numpy.isclose(rev_rxn_obj.NASA_poly_coefs_dict['H'],
                          expected_nasa['H'])).all()
Пример #11
0
def test_rxn_sys_get_highT_nasa_matrix():
    """Tests function to fetch NASA coefficients of appropriate T and appropriate species in reaction."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxn.xml")
    parser = Parser.ReactionParser(xml_filename)
    temp = 5000  # "high" temperature range in NASA coeffs database
    concentrations = {'H': 1, 'O2': 1, 'H2O': 1}
    rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                            parser.NASA_poly_coefs, temp,
                                            concentrations)
    # Order of high T range NASA coefficients: H, H2O, O2
    expected_nasa = {
        'O2':
        numpy.array([
            3.78245636e+00, -2.99673416e-03, 9.84730201e-06, -9.68129509e-09,
            3.24372837e-12, -1.06394356e+03, 3.65767573e+00
        ]),
        'H2O':
        numpy.array([
            4.19864056e+00, -2.03643410e-03, 6.52040211e-06, -5.48797062e-09,
            1.77197817e-12, -3.02937267e+04, -8.49032208e-01
        ]),
        'H':
        numpy.array([
            2.50000000e+00, 7.05332819e-13, -1.99591964e-15, 2.30081632e-18,
            -9.27732332e-22, 2.54736599e+04, -4.46682853e-01
        ])
    }
    # expected_nasa = numpy.array([[2.50000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
    #                             0.00000000e+00, 2.54716270e+04, -4.60117608e-01],
    #                             [2.67214561e+00, 3.05629289e-03, -8.73026011e-07, 1.20099639e-10,
    #                             -6.39161787e-15, -2.98992090e+04, 6.86281681e+00],
    #                             [3.69757819e+00, 6.13519689e-04, -1.25884199e-07, 1.77528148e-11,
    #                             -1.13643531e-15, -1.23393018e+03, 3.18916559e+00]])
    #assert numpy.isclose(rxnsys.NASA_matrix, expected_nasa).all()
    assert (numpy.isclose(rxnsys.NASA_matrix['H2O'],
                          expected_nasa['H2O'])).all()
    assert (numpy.isclose(rxnsys.NASA_matrix['O2'], expected_nasa['O2'])).all()
    assert (numpy.isclose(rxnsys.NASA_matrix['H'], expected_nasa['H'])).all()
Пример #12
0
def test_RxnParser_rxn_equation():
    """Test get_rxn_equation for reaction 1."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert parser.reaction_list[0].rxn_equation == 'H + O2 =] OH + O'
Пример #13
0
def test_RxnParser_is_reversible():
    """Test get_is_reversible for reaction irreversible reaction."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert parser.reaction_list[0].is_reversible == False
Пример #14
0
def test_RxnParser_type():
    """Test get_rxn_type() for an elementary reaction."""
    xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
    parser = Parser.ReactionParser(xml_filename)
    assert parser.reaction_list[0].rxn_type == 'Elementary'
Пример #15
0
def test_get_coeffs_invalid_temp_range():
    """Test when invalid temperature range inputed"""
    with pytest.raises(ValueError):
        xml_filename = os.path.join(DATA_DIRECTORY, "rxns.xml")
        parser = Parser.ReactionParser(xml_filename)
        parser.get_coeffs('H', 'invalid_range')
Пример #16
0
"""Example of irreversible reaction."""

import os

from chemkinlib.utils import Parser
from chemkinlib.reactions import ReactionSystems
from chemkinlib.config import DATA_DIRECTORY
import numpy

# USER INPUT: reaction (xml) file
xml_filename = os.path.join(DATA_DIRECTORY, "rxnset_long.xml")

parser = Parser.ReactionParser(xml_filename)

# USER INPUTS (concentrations and temperatures)
concentration = ({
    'H': 1,
    'H2': 1,
    'H2O': 0,
    'H2O2': 1,
    'HO2': 1,
    'O': 1,
    "O2": 1,
    "OH": 1
})
temperature = 1000

# Set up reaction system
rxnsys = ReactionSystems.ReactionSystem(parser.reaction_list,
                                        parser.NASA_poly_coefs, temperature,
                                        concentration)
Пример #17
0
def test_RxnParser_file_not_found():
    """Test when xml file is nonexistent"""
    with pytest.raises(IOError):
        parser = Parser.ReactionParser("no_such_file")