xref: /libCEED/examples/fluids/stdoutParsing.py (revision edab612303ce5c583510db4ec9520fcda426d3c1)
1import re
2import pandas as pd
3from pathlib import Path
4
5# Regex to parse STDOUT of the navierstokes run
6logreg = re.compile(
7    r".*(?:^Degree of FEM Space: (\d+)).*(?:^Global FEM nodes: (\d{2,})).*(?:^dm_plex_box_faces: (\S+)).*(?:^Time taken for solution: (\d*\.?\d+)).*(?:^Relative Error: (\d*\.?\d+))",
8    re.DOTALL | re.MULTILINE,
9)
10
11
12def parseFile(file):
13    """Returns dictionary of parsed logfile contents.
14
15    Parameters
16    ----------
17    file : Path-like object
18        Path to the file to be parsed.
19
20    Returns
21    -------
22    dict
23        Values of "dofs",  "time", "error", "degree", and "box_faces"'
24    """
25
26    values = {}
27    with file.open() as filer:
28        filestring = filer.read()
29    match = logreg.match(filestring)
30    values["degree"] = match[1]
31    values["dofs"] = match[2]
32    box_faceStr = match[3]
33    values["time"] = match[4]
34    values["error"] = match[5]
35
36    # Splitting box_face argument str into individual entries
37    box_faceList = box_faceStr.split(",")
38    for i, box_face in enumerate(box_faceList):
39        values["box_face" + str(i)] = box_face
40
41    return values
42
43
44if __name__ == "__main__":
45    # Directory location of log files
46    runlogDir = Path("./")
47
48    results = pd.DataFrame()
49    for file in runlogDir.glob("*.log"):
50        values = parseFile(file)
51        results = results.append(values, ignore_index=True)
52
53    # Convert string values to numeric type
54    results = results.apply(lambda col: pd.to_numeric(col, errors="coerce"))
55