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