Beispiel #1
0
def chebyshev_parameters(rxn_dstr, a_units='moles'):
    """ Parses the data string for a reaction in the reactions block
        for the lines containing the Chebyshevs fitting parameters,
        then reads the parameters from these lines.

        :param rxn_dstr: data string for species in reaction block
        :type rxn_dstr: str
        :return params: Chebyshev fitting parameters
        :rtype: dict[param: value]
    """
    original_rxn_dstr = rxn_dstr
    rxn_dstr = apf.remove(COMMENTS_PATTERN, rxn_dstr)

    tcheb_pattern = (
        'TCHEB' + app.zero_or_more(app.SPACE) + app.escape('/') +
        app.zero_or_more(app.SPACE) + app.capturing(app.NUMBER) +
        app.one_or_more(app.SPACE) + app.capturing(app.NUMBER) +
        app.zero_or_more(app.SPACE) + app.escape('/')
    )
    pcheb_pattern = (
        'PCHEB' + app.zero_or_more(app.SPACE) + app.escape('/') +
        app.zero_or_more(app.SPACE) + app.capturing(app.NUMBER) +
        app.one_or_more(app.SPACE) + app.capturing(app.NUMBER) +
        app.zero_or_more(app.SPACE) + app.escape('/')
    )
    cheb_pattern = ( 
        app.not_preceded_by(app.one_of_these(['T','P'])) + 'CHEB' + app.zero_or_more(app.SPACE) + app.escape('/') +
        app.capturing(app.one_or_more(app.WILDCARD2)) + app.escape('/')
    )  

    cheb_params_raw = apf.all_captures(cheb_pattern, rxn_dstr)

    if cheb_params_raw:
        params = {}
        # Get the temp and pressure limits; add the Chemkin default values if they don't exist
        cheb_temps = apf.first_capture(tcheb_pattern, rxn_dstr)
        cheb_pressures = apf.first_capture(pcheb_pattern, rxn_dstr)
        if cheb_temps is None: 
            cheb_temps = ('300.00', '2500.00')
            print(f'No Chebyshev temperature limits specified for the below reaction. Assuming 300 and 2500 K. \n \n {original_rxn_dstr}\n')
        if cheb_pressures is None: 
            cheb_pressures = ('0.001', '100.00')
            print(f'No Chebyshev pressure limits specified for the below reaction. Assuming 0.001 and 100 atm. \n \n {original_rxn_dstr}\n')
    
        # Get all the numbers from the CHEB parameters 
        cheb_params = []
        for cheb_line in cheb_params_raw:
            cheb_params.extend(cheb_line.split())
    
        # Get the cheb array dimensions N and M, which are the first two entries of the CHEB params
        cheb_n = int(math.floor(float(cheb_params[0])))  # rounds down to match the Chemkin parser, although it should be an integer already
        cheb_m = int(math.floor(float(cheb_params[1]))) 
    
        # Start on the third value (after N and M) and get all the polynomial coefficients
        coeffs = [] 
        for idx, coeff in enumerate(cheb_params[2:]):
            if idx+1 > (cheb_n*cheb_m):  # there are allowed to be extra coefficients, but just ignore them
                break
            coeffs.append(coeff)
        assert len(coeffs) == (cheb_n*cheb_m), (
            f'For the below reaction, there should be {cheb_n*cheb_m} Chebyshev polynomial coefficients, but there are only {len(coeffs)}. \n \n {original_rxn_dstr}\n'
        ) 
        alpha = numpy.array(list(map(float,coeffs)))

        params['t_limits'] = [float(val) for val in cheb_temps]
        params['p_limits'] = [float(val) for val in cheb_pressures]
        params['alpha_elm'] = alpha.reshape([cheb_n, cheb_m])
        params['a_units'] = a_units

    else:
        params = None

    return params
Beispiel #2
0
NAVO = 6.0221409e+23
CAL2KCAL = qcc.conversion_factor('cal/mol', 'kcal/mol')
J2KCAL = qcc.conversion_factor('J/mol', 'kcal/mol')
KJ2KCAL = qcc.conversion_factor('kJ/mol', 'kcal/mol')
KEL2KCAL = qcc.conversion_factor('kelvin', 'kcal/mol')

# Various strings needed to parse the data sections of the Reaction block
CHEMKIN_ARROW = (app.maybe(app.escape('<')) + app.escape('=') +
                 app.maybe(app.escape('>')))
CHEMKIN_PLUS_EM = app.PLUS + 'M'
CHEMKIN_PAREN_PLUS_EM = app.escape('(') + app.PLUS + 'M' + app.escape(')')

SPECIES_NAME_PATTERN = (r'[^\s=+\-]' + app.zero_or_more(
    app.one_of_these([
        app.LETTER, app.DIGIT,
        app.escape('(+)'), r'[#,()\-]',
        app.escape('['),
        app.escape(']')
    ])) + app.zero_or_more(app.PLUS))
SPECIES_NAMES_PATTERN = app.series(app.padded(SPECIES_NAME_PATTERN),
                                   app.padded(app.PLUS))

REACTION_PATTERN = (SPECIES_NAMES_PATTERN + app.padded(CHEMKIN_ARROW) +
                    SPECIES_NAMES_PATTERN)
COEFF_PATTERN = (app.NUMBER + app.LINESPACES + app.NUMBER + app.LINESPACES +
                 app.NUMBER)

# Constants
NAVO = 6.02214076e23

Beispiel #3
0
import autoparse.find as apf
from autoparse import cast as ap_cast
from ioformat import headlined_sections
from ioformat import phycon


# Various strings needed to parse the data sections of the Reaction block
CHEMKIN_ARROW = (app.maybe(app.escape('<')) + app.escape('=') +
                 app.maybe(app.escape('>')))
CHEMKIN_PLUS_EM = app.PLUS + 'M'
CHEMKIN_PAREN_PLUS_EM = app.escape('(') + app.PLUS + 'M' + app.escape(')')

SPECIES_NAME_PATTERN = (
    r'[^\s=+\-]' +
    app.zero_or_more(app.one_of_these(
        [app.LETTER, app.DIGIT, r'[#,()\-_]',
         app.escape('*'), app.escape('(+)'),
         app.escape('['), app.escape(']')])) +
    app.zero_or_more(app.PLUS)
)
SPECIES_NAMES_PATTERN = app.series(
    app.padded(SPECIES_NAME_PATTERN), app.padded(app.PLUS))

REACTION_PATTERN = (SPECIES_NAMES_PATTERN + app.padded(CHEMKIN_ARROW) +
                    SPECIES_NAMES_PATTERN)
COEFF_PATTERN = (app.NUMBER + app.LINESPACES + app.NUMBER +
                 app.LINESPACES + app.NUMBER)
COMMENTS_PATTERN = app.escape('!') + app.capturing(app.one_or_more(app.WILDCARD2))  

BAD_STRS = ['inf', 'INF', 'nan']