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