def test_ODE_solver_functionality():
    """
    Test basic ODE solver functionality.
    """

    Ti = [1500]
    xi = [2., 1., .5, 1., 1., 1., .5,
          1.]  # specie concentrations 'rxns_reversible.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)
    #print(parsed_data_list)
    for parsed_data in parsed_data_list:

        species = parsed_data['species']
        #print(species)
        ki = parsed_data['ki']
        sys_vi_p = parsed_data['sys_vi_p']
        sys_vi_dp = parsed_data['sys_vi_dp']
        T = parsed_data['T']
        b_ki = parsed_data['b_ki']

        rxn = ElementaryRxn(ki, b_ki, xi, sys_vi_p, sys_vi_dp)
        my_solver = ODE_int_solver(T, rxn)

        error_msg = "Solver is not initiating properly"
        assert my_solver != None and isinstance(my_solver,
                                                ODE_int_solver), error_msg
def test_ODE_solver_solve():
    """
    Tests ODE solver solve() method.
    """

    Ti = [1500]
    xi = [2., 1., .5, 1., 1., 1., .5,
          1.]  # specie concentrations 'rxns_reversible.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)

    for parsed_data in parsed_data_list:

        species = parsed_data['species']
        ki = parsed_data['ki']
        sys_vi_p = parsed_data['sys_vi_p']
        sys_vi_dp = parsed_data['sys_vi_dp']
        T = parsed_data['T']
        b_ki = parsed_data['b_ki']

        rxn = ElementaryRxn(ki, b_ki, xi, sys_vi_p, sys_vi_dp)
        my_solver = ODE_int_solver(T, rxn)

        time_int = time_steps = np.linspace(0, 100, 101)

        s, t_c, t_o = my_solver.solve(time_int)

        error_msg1 = "The dimensions of input do not match output"

        assert s.shape == (len(s), len(xi)), error_msg1

        assert len(t_c) == len(ki) and len(t_c) == len(b_ki), error_msg1
Beispiel #3
0
def test_print_normal_irreversible():
    Ti = [2500]
    xi = [2.0, 1.0, 0.5, 1.0, 1.0]  # specie concentrations for 'rxns_hw5.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_hw5'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)
    test_flag = summary.print_reaction_rate(parsed_data_list, xi)
    assert test_flag == 0
Beispiel #4
0
def test_get_backward_coefs_normal():
    Ti = [750, 1500]
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(
        Ti)  # calling Thermo().get_backward_coefs()
    assert parsed_data_list[0]['T'] == 750
    assert parsed_data_list[1]['T'] == 1500
Beispiel #5
0
def test_plot_time_to_equilibrium_normal():
    Ti = [2500]
    xi = [2., 1., .5, 1., 1., 1., .5,
          1.]  # specie concentrations 'rxns_reversible.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)
    test_flag = summary.plot_time_to_equilibrium(parsed_data_list, xi)
    assert test_flag == 0
Beispiel #6
0
def test_plot_species_concentration_abnormal():
    Ti = [10]
    xi = [2., 1., .5, 1., 1., 1., .5,
          1.]  # specie concentrations 'rxns_reversible.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)
    test_flag = summary.plot_species_concentration(parsed_data_list, xi)
    assert test_flag == 1
Beispiel #7
0
def test_print_abnormal_reversible():
    Ti = [10000]
    xi = [2., 1., .5, 1., 1., 1., .5,
          1.]  # specie concentrations 'rxns_reversible.xml'
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(Ti)
    test_flag = summary.print_reaction_rate(parsed_data_list, xi)
    assert test_flag == 1
Beispiel #8
0
def test_badparse_negative_A_arr():
    """Ensures ChemKinError raised when A coefficient for one of the
    reactions is negative.
    """
    xml = XmlParser(pckg_xml_path('rxns_neg_A_2'))
    try:
        rxns = xml.load()
    except ChemKinError as err:
        assert type(err) == ChemKinError
        assert str(err).find(
            'A coeff < 0 in reaction with id = reaction02') != -1
Beispiel #9
0
def test_parse_reactants_products():
    """Ensures reactants and products parsed correctly."""
    xml = XmlParser(pckg_xml_path('rxns_ideal.xml'))
    species, rxns = xml.load()

    err_msg = 'reactants not parsed correctly.'
    assert rxns[0].reactants == {'H': 1, 'O2': 1}, err_msg
    assert rxns[1].reactants == {'H2': 1, 'O': 1}, err_msg

    err_msg = 'products not parsed correctly.'
    assert rxns[0].products == {'OH': 1, 'O': 1}, err_msg
    assert rxns[1].products == {'OH': 1, 'H': 1}, err_msg
Beispiel #10
0
def test_rxndata_equation():
    """Ensures equation representation of RxnData is correct."""
    xml = XmlParser(pckg_xml_path('rxns_ideal.xml'))
    species, rxns = xml.load()

    err_msg = 'equation() method result different than expected.'
    expected_0 = 'H + O2 [=] O + OH'
    print(rxns[0].equation())
    assert rxns[0].equation() == expected_0, err_msg

    err_msg = 'equation() method result different than expected.'
    expected_1 = 'H2 + O [=] H + OH'
    assert rxns[1].equation() == expected_1, err_msg
Beispiel #11
0
def test_parse_rxn_coeff():
    """Ensures reaction coefficients are what we expect them to be."""
    xml = XmlParser(pckg_xml_path('rxns.xml'))
    species, rxns = xml.load()

    rxn1_coeff = rxns[0].rate_coeff
    rxn2_coeff = rxns[1].rate_coeff
    rxn3_coeff = rxns[2].rate_coeff

    # reaction01
    assert rxn1_coeff[0] == approx(3.52e+10)
    assert rxn1_coeff[1] == approx(7.14e+04)

    # reaction02
    assert rxn2_coeff[0] == approx(5.06e-2)
    assert rxn2_coeff[1] == approx(2.7)
    assert rxn2_coeff[2] == approx(2.63e+04)

    # reaction03
    assert rxn3_coeff == approx(1.0e+03)
Beispiel #12
0
def test_parse_basic_functionality():
    """Ensures number of reactions returned is correct and that attributes
    of the <reaction> element in the XML file are parsed correctly.
    """
    xml = XmlParser(pckg_xml_path('rxns_ideal.xml'))
    species, rxns = xml.load()

    # Correct number of reactions returned.
    err_msg = 'Expected 2 reactions but received {}.'.format(len(rxns))
    assert len(rxns) == 2, err_msg

    # Attributes of <reaction> element parsed properly.
    err_msg = 'reversible attribute not parsed properly.'
    assert rxns[0].reversible == False, err_msg
    assert rxns[1].reversible == False, err_msg

    err_msg = 'rxn_id attribute not parsed properly.'
    assert rxns[0].rxn_id == 'reaction01', err_msg
    assert rxns[1].rxn_id == 'reaction02', err_msg

    err_msg = 'type attribute not parsed properly.'
    assert rxns[0].type == RxnType.Elementary, err_msg
    assert rxns[1].type == RxnType.Elementary, err_msg
#####################################################
# Additional Feature of the chemkin library
# 1. Solving the evolution of species concentration
# 2. Visualizing the solver's results
#####################################################

from chemkin import pckg_xml_path
from chemkin.preprocessing.parse_xml import XmlParser
from chemkin.viz import summary

Ti = [900, 2500]
xi = [2., 1., .5, 1., 1., 1., .5, 1.]  # specie concentrations
xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
parsed_data_list = xml_parser.parsed_data_list(Ti)

# Print the species concentration
summary.print_species_concentration(parsed_data_list, xi, end_t=1e-12)

# Plot the species concentration
summary.plot_species_concentration(parsed_data_list, xi, end_t=1e-12)

# Print the time to equilibrium of all reactions
summary.print_time_to_equilibrium(parsed_data_list, xi)

# Plot the time to equilibrium of all reactions
summary.plot_time_to_equilibrium(parsed_data_list, xi)
Beispiel #14
0
def test_get_backward_coefs_low_range_err():
    Ti = [100]
    xml_parser = XmlParser(pckg_xml_path('rxns_reversible'))
    parsed_data_list = xml_parser.parsed_data_list(
        Ti)  # calling Thermo().get_backward_coefs()
    assert parsed_data_list[0]['b_ki'] == 'Not Defined'