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