def test_neg_concentration():
    reader = chemkin.XMLReader("tests/test_data1.xml")
    reaction_system = reader.get_reaction_systems()
    try:
        reaction_system[0].calculate_progress_rate([3., -1., 2., -3., 1.], 425)
    except ValueError as err:
        assert (type(err) == ValueError)
def test_neg_stoich_coeff():
    reader = chemkin.XMLReader("tests/rxns_negative_coeff.xml")
    reaction_system = reader.get_reaction_systems()
    try:
        reaction_system[0].calculate_progress_rate([1, 2, 3, 1, 2, 3, 1, 2],
                                                   800)
    except ValueError as err:
        assert (type(err) == ValueError)
def test_temp_range():
    reader = chemkin.XMLReader("tests/rxns_reversible.xml")
    reaction_system = reader.get_reaction_systems()[0]
    nu = (reaction_system.product_coefficients -
          reaction_system.reactant_coefficients)
    try:
        rxnset = thermodynamics.Rxnset(reaction_system.species, nu)
        rxnset.get_nasa_coefficients(50)
    except ValueError as err:
        assert (type(err) == ValueError)
def test_stochastic_simulator():
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    abundances = [10] * 5
    temperature = 400.
    t_span = (0, 0.001)
    system_volume = 1e-15
    stochastic_simulator = simulator.StochasticSimulator(
        reaction_system, abundances, temperature, t_span, system_volume)
    stochastic_simulator.simulate()
def test_neg_temp():
    concs = [1., 2., 1., 3., 1.]
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    try:
        simulator.DeterministicSimulator(reaction_system,
                                         concs,
                                         -800, [0, 2],
                                         dt=1)
    except ValueError as err:
        assert (type(err) == ValueError)
def test_other_simulate_type():
    concs = np.array([1., 2., 1., 3., 1.]) * 1e-05
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    try:
        det_sim = reaction_system.setup_reaction_simulator('other',
                                                           concs,
                                                           800, [0, 0.01],
                                                           dt=0.01)
    except ValueError as err:
        assert type(err) == ValueError
def test_reversible_reaction_rate():
    reader = chemkin.XMLReader("tests/rxns_reversible.xml")
    reaction_system = reader.get_reaction_systems()
    assert np.allclose(
        list(reaction_system[0].calculate_reaction_rate(
            [1, 2, 3, 1, 2, 3, 1, 2], 800)),
        [
            2.3553537901231184e+17, -2.2321034840197091e+17,
            -2.6059674644924278e+17, 37395259554341.125, 12661546307481366.0,
            2.3584012306405293e+17, -198181887233104.84, -69166904953671.859
        ])
def test_get_nasa_coefficients():
    reader = chemkin.XMLReader("tests/rxns_reversible.xml")
    reaction_system = reader.get_reaction_systems()[0]
    nu = (reaction_system.product_coefficients -
          reaction_system.reactant_coefficients)
    rxnset = thermodynamics.Rxnset(reaction_system.species, nu)
    coefficients = rxnset.get_nasa_coefficients(900)
    assert coefficients.shape == (8, 7)
    assert np.all(coefficients[0] == np.array([
        2.50000000e+00, 7.05332819e-13, -1.99591964e-15, 2.30081632e-18,
        -9.27732332e-22, 2.54736599e+04, -4.46682853e-01
    ]))
def test_solver_not_implemented():
    concs = np.array([1., 2., 1., 3., 1.]) * 1e-05
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    det_sim = simulator.DeterministicSimulator(reaction_system,
                                               concs,
                                               800, [0, 0.01],
                                               dt=0.01)
    try:
        det_sim.simulate('forward_euler')
    except ValueError as err:
        assert (type(err) == ValueError)
def test_sim_rk45_neg_concentration():
    concs = np.array([1., 2., 1., 3., 1.]) * 1e-05
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    det_sim = simulator.DeterministicSimulator(reaction_system,
                                               concs,
                                               800, [0, 0.01],
                                               dt=0.01)
    try:
        det_sim.simulate('rk45')
    except ValueError as err:
        assert (type(err) == ValueError)
def test_deterministic_flow():
    concs = np.array([1., 2., 1., 3., 1.]) * 1e-05
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    det_sim = reaction_system.setup_reaction_simulator('deterministic',
                                                       concs,
                                                       800, [0, 0.01],
                                                       dt=0.01)
    t, y = det_sim.simulate()
    y0 = y[0]
    y1 = y[1]
    assert np.allclose(t, [0, 0.01])
    assert np.allclose(y0, [
        1.00000000e-05, 2.00000000e-05, 1.00000000e-05, 3.00000000e-05,
        1.00000000e-05
    ])
    assert np.allclose(y1, [
        1.03778637e-05, 1.96221363e-05, 1.03927707e-05, 2.96146828e-05,
        9.99254648e-06
    ])
def test_sim_backward_euler():
    concs = np.array([1., 2., 1., 3., 1.]) * 1e-05
    reader = chemkin.XMLReader("tests/rxns.xml")
    reaction_system = reader.get_reaction_systems()[0]
    det_sim = simulator.DeterministicSimulator(reaction_system,
                                               concs,
                                               800, [0, 0.01],
                                               dt=0.01)
    t, y = det_sim.simulate('backward_euler')
    y0 = y[0]
    y1 = y[1]
    assert np.allclose(t, [0, 0.01])
    assert np.allclose(
        y0,
        np.array([
            1.00000000e-05, 2.00000000e-05, 1.00000000e-05, 3.00000000e-05,
            1.00000000e-05
        ]))
    assert np.allclose(
        y1,
        np.array([
            1.03940908e-05, 1.96059092e-05, 1.04083239e-05, 2.95987926e-05,
            9.99288345e-06
        ]))
def test_progress_rate():
    reader = chemkin.XMLReader("tests/test_data1.xml")
    reaction_system = reader.get_reaction_systems()
    result = [2.5589111307566812, 1110.2037988957545, 0.0070156249238785568]
    assert reaction_system[0].calculate_progress_rate([3., 1., 2., 3., 1.],
                                                      425) == result
def test_len():
    reader = chemkin.XMLReader("tests/test_data1.xml")
    reaction_system = reader.get_reaction_systems()
    assert len(reaction_system[0]) == 5
def test_if_elementary():
    reader = chemkin.XMLReader("tests/test_data_elementary.xml")
    try:
        reaction_system = reader.get_reaction_systems()
    except NotImplementedError as err:
        assert (type(err) == NotImplementedError)