Example #1
0
def test_equality_checking():
    """ test species and reaction equality checking"""
    _, specs_ck, reacs_ck = read_mech(ck_file, None)
    _, specs_cti, reacs_cti = read_mech_ct(cti_file)

    assert reacs_ck[0] == reacs_cti[0]
    for i in range(1, len(reacs_ck)):
        assert reacs_ck[0] != reacs_cti[i]
    assert specs_ck[0] == specs_cti[0]
    for i in range(1, len(specs_ck)):
        assert specs_ck[0] != specs_cti[i]
Example #2
0
def test_mech_interpret_runs():
    """ test mechanism intpreter for both cantera and chemkin, and that results
        match"""
    _, specs_ck, reacs_ck = read_mech(ck_file, None)
    _, specs_cti, reacs_cti = read_mech_ct(cti_file)

    assert len(reacs_ck) == len(reacs_cti)
    for i in range(len(reacs_ck)):
        assert reacs_ck[i] == reacs_cti[i]
    assert len(specs_ck) == len(specs_cti)
    for i in range(len(specs_ck)):
        specs_ck[i] == specs_cti[i]
Example #3
0
def test_mechanism_sorting():
    # perform sort
    _, specs_ck, reacs_ck = read_mech(ck_file, None, reaction_sorting.simd)
    # ensure we have a good sort
    from pyjac.core.enum_types import (reaction_type, falloff_form,
                                       reversible_type, thd_body_type)

    enum_order = (reaction_type, falloff_form, thd_body_type, reversible_type)

    def check(start=0, end=len(reacs_ck), depth=0):
        if depth == len(enum_order):
            return
        for enum in enum_order[depth]:
            this_start = None
            this_end = None
            # pass #1, find start and end of this enum
            for i in range(start, end):
                if reacs_ck[i].match(enum) and this_start is None:
                    this_start = i
                    continue
                if not reacs_ck[i].match(enum) and (this_end is None and
                                                    this_start is not None):
                    # end of this section
                    this_end = i - 1
                    break
                elif this_start is not None:
                    # should all by of this type
                    assert reacs_ck[i].match(enum)

            if this_start is None:
                # no matches, nothing futher to check for this enum
                continue
            if this_end is None:
                # all matches
                this_end = end

            check(this_start, this_end, depth + 1)

    check()