예제 #1
0
def get_default_temp_limits(block_str):
    """ Gets the default temperatures from the header of a thermo block str

    """
    block_str = apf.remove(COMMENTS_PATTERN, block_str)
    line_lst = list(apf.split_lines(block_str))

    # Loop over each line
    for line in line_lst:
        try:
            # Note that this order is different than
            # that in the individual thermo entries
            low_limit = float(line[0:10])
            midpoint = float(line[10:20])
            high_limit = float(line[20:30])
            break
        except ValueError:
            pass
        # Check if the first thermo entry has been reached
        if len(line) >= 80 and line[79] == '1':
            low_limit, midpoint, high_limit = None, None, None

    # Note that this order is different than
    # that in the individual thermo entries
    default_temp_limits = [low_limit, midpoint, high_limit]

    return default_temp_limits
예제 #2
0
def temperatures(thm_dstr):
    """ get the common temperature from a thermo data string
    """
    headline = apf.split_lines(thm_dstr)[0]
    pattern = (app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT) +
               app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT) +
               app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT))
    captures = apf.first_capture(pattern, headline)
    assert captures
    tmps = tuple(map(float, captures))
    return tmps
예제 #3
0
def create_entry_list(block_str, add_spaces=True):
    """ Creates a list with each line of the thermo block_str as an
        entry in that list
    
        :param block_str: string for thermo block

        :return line_lst: list of strs for each line

    """
    block_str = apf.remove(COMMENTS_PATTERN, block_str)
    #    print('type of block_str\n', type(block_str))
    line_lst = list(apf.split_lines(block_str))
    #line_lst = list(block_str.splitlines)
    #    print(type(line_lst))

    # Get the indices of the entry header lines
    header_idxs = []
    for idx, line in enumerate(line_lst):
        if len(line) >= 80 and line[79] == '1':
            header_idxs.append(idx)
    if not header_idxs:
        raise ImportError(
            'No thermo headers in the file could be read. A "1" in column 80 marks this.'
        )
    header_idxs.append(
        len(line_lst))  # adds an entry to mark the end of the block_str

    # Check that there are at least 4 lines in each entry
    for idx, difference in enumerate(np.diff(header_idxs)):
        assert difference >= 4, (
            f'There are less than 4 lines for this thermo entry: \n{line_lst[header_idxs[idx]]}'
        )

    # Put together the thermo entries into a list of tuples
    entry_lst = []
    for idx in range(len(header_idxs) - 1):  # skips the last entry
        entry = line_lst[header_idxs[idx]:header_idxs[idx + 1]]
        entry_lst.append(entry)

    # Fix the problem of the missing spaces at the beginning of lines without negative signs
    entry_lst = fix_lines(entry_lst)

    return entry_lst
예제 #4
0
def temperatures(thm_dstr):
    """ Parses the temperatures from the NASA polynomial
        given in the data string for a species in the thermo block.

        :param thm_dstr: data string for species in thermo block
        :type thm_dstr: str
        :return temps: temperatures (K)
        :rtype: tuple(float)
    """

    headline = apf.split_lines(thm_dstr)[0]
    pattern = (app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT) +
               app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT) +
               app.LINESPACES + app.capturing(app.UNSIGNED_FLOAT))
    captures = apf.first_capture(pattern, headline)
    assert captures
    temps = tuple(map(float, captures))

    return temps
예제 #5
0
def temperatures(thm_dstr):
    """ Parses the temperatures from the NASA polynomial
        given in the data string for a species in the thermo block.

        :param thm_dstr: data string for species in thermo block
        :type thm_dstr: str
        :return temps: temperatures (K)
        :rtype: tuple(float)
    """

    headline = apf.split_lines(thm_dstr)[0]
    pattern = (app.one_or_more(app.SPACE) + app.capturing(app.NUMBER) +
               app.one_or_more(app.SPACE) + app.capturing(app.NUMBER) +
               app.one_or_more(app.SPACE) + app.capturing(app.NUMBER) +
               app.one_or_more(app.SPACE) + app.DIGIT + app.STRING_END)
    captures = apf.first_capture(pattern, headline)
    assert captures, (
        f'No temperatures were captured for the datastring {thm_dstr}')
    temps = tuple(map(float, captures))

    return temps