Ejemplo n.º 1
0
def get_rxn_strs(block_str, remove_bad_fits=False):
    """ Parses all of the chemical equations and corresponding fitting
        parameters in the reactions block of the mechanism input file
        and stores them in a list.

        :param block_str: raw string for the entire reactions block
        :type block_str: str
        :param remove_bad_fits: remove reactions with bad fits
        :type remove_bad_fits: bool
        :return rxn_strs: list of raw strings, one for each reaction
        :rtype: list(str)
    """

    if block_str.strip():
        rxn_strs = headlined_sections(string=block_str.strip(),
                                      headline_pattern=CHEMKIN_ARROW)
        if remove_bad_fits:
            rxn_strs = [
                dstr for dstr in rxn_strs
                if not any(string in dstr for string in BAD_STRS)
            ]
    else:
        rxn_strs = None

    return rxn_strs
Ejemplo n.º 2
0
def test__string_alter():
    """ test ioformat.headlined_sections
    """

    head_secs = ioformat.headlined_sections(INI_STR, '=')
    assert head_secs == [
        'A + B = C + D    1.00 0.00 0.00  \n  PLOG / 0.01  3.0E+8 2.0 100.0\n',
        'A + D = E        2.00 0.00 0.00  \n\n! From Experiment',
        'E = F            3.00 0.00 0.00  \n  PLOG / 0.01  6.0 2.5 105\n\n'
    ]
Ejemplo n.º 3
0
def test__string_alter():
    """ test ioformat.headlined_sections
        test ioformat.remove_whitespace
        test ioformat.remove_trail_whitespace
        test ioformat.remove_comment_lines
    """

    head_secs = ioformat.headlined_sections(INI_STR, '=')
    assert head_secs == [
        'A + B = C + D    1.00 0.00 0.00  \n  PLOG / 0.01  3.0E+8 2.0 100.0\n',
        'A + D = E        2.00 0.00 0.00  \n\n! From Experiment',
        'E = F            3.00 0.00 0.00  \n  PLOG / 0.01  6.0 2.5 105\n\n'
    ]

    out_str = ioformat.remove_whitespace(INI_STR)
    assert out_str == ('! From Theory\n'
                       'A + B = C + D    1.00 0.00 0.00\n'
                       'PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       'A + D = E        2.00 0.00 0.00\n'
                       '! From Experiment\n'
                       'E = F            3.00 0.00 0.00\n'
                       'PLOG / 0.01  6.0 2.5 105\n')

    out_str = ioformat.remove_trail_whitespace(INI_STR)
    assert out_str == ('! From Theory\n'
                       'A + B = C + D    1.00 0.00 0.00\n'
                       '  PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       'A + D = E        2.00 0.00 0.00\n'
                       '! From Experiment\n'
                       'E = F            3.00 0.00 0.00\n'
                       '  PLOG / 0.01  6.0 2.5 105\n')

    out_str = ioformat.remove_comment_lines(INI_STR, '!')
    assert out_str == ('\n'
                       'A + B = C + D    1.00 0.00 0.00  \n'
                       '  PLOG / 0.01  3.0E+8 2.0 100.0\n'
                       '\n'
                       'A + D = E        2.00 0.00 0.00  \n'
                       '\n'
                       '\n'
                       'E = F            3.00 0.00 0.00  \n'
                       '  PLOG / 0.01  6.0 2.5 105\n'
                       '\n'
                       '\n')
Ejemplo n.º 4
0
def data_strings(block_str):
    """ Parse all of the NASA polynomials given in the thermo block
        of the mechanism input file and stores them in a list.

        :param block_str: string for thermo block
        :type block_str: str
        :return thm_strs: strings containing NASA polynomials for all species
        :rtype: list(str)
    """

    headline_pattern = (app.LINE_START + app.not_followed_by(
        app.one_of_these([app.DIGIT, app.PLUS,
                          app.escape('=')])) +
                        app.one_or_more(app.NONNEWLINE) + app.escape('1') +
                        app.LINE_END)
    thm_strs = headlined_sections(string=block_str.strip(),
                                  headline_pattern=headline_pattern)

    return thm_strs
Ejemplo n.º 5
0
def data_strings(block_str, remove_bad_fits=False):
    """ Parses all of the chemical equations and corresponding fitting
        parameters in the reactions block of the mechanism input file
        and stores them in a list.

        :param block_str: string for reactions block
        :type block_str: str
        :param remove_bad_fits: remove reactions with bad fits
        :type remove_bad_fits: bool
        :return rxn_dstrs: strings containing eqns and params for all reactions
        :rtype: list(str)
    """

    rxn_dstrs = headlined_sections(string=block_str.strip(),
                                   headline_pattern=CHEMKIN_ARROW)

    if remove_bad_fits:
        rxn_dstrs = [
            dstr for dstr in rxn_dstrs
            if not any(string in dstr for string in BAD_STRS)
        ]
    return rxn_dstrs