Peano
Loading...
Searching...
No Matches
Parser.py
Go to the documentation of this file.
1# This file is part of the Peano multigrid project. For conditions of
2# distribution and use, please see the copyright notice at www.peano-framework.org
3import numpy as np
4import peano4.api
5import mghype
6import re
7
8
9def parse_residuals( file_name,
10 solver_name,
11 ):
12 """!
13
14 Parse residuals from input stream
15
16 @param file_name: String
17 We will open the file through ```open( file_name, "r").
18
19 @param solver_name: String
20 We have to know which solver to search for, as MGHyPE simulations might
21 host multiple solvers.
22
23 @return [Float], [Float], [Float]
24 Returns three sequences, all of the same size. The first sequence is the
25 development of the residuals in the max norm, the second in the 2 norm,
26 and the third one hosts the residuals in the h norm.
27
28 """
29 res_max = []
30 res_2 = []
31 res_h = []
32
33 pattern = r"([-+]?\d*\.?\d+(?:e[-+]?\d+)?)"
34 full_pattern = rf"\|r\|\_max={pattern},\s*\|r\|\_2={pattern},\s*\|r\|\_h={pattern}"
35 with open(file_name, 'r') as file:
36 for line in file.readlines():
37 norms = re.search(full_pattern, line)
38 if "endMeshSweep()" in line and solver_name in line and norms!=None:
39 r_max, r_2, r_h = map(float, norms.groups()) # Convert to floats
40 res_max.append(r_max)
41 res_2.append(r_2)
42 res_h.append(r_h)
43
44 return res_max, res_2, res_h
45
46
47def parse_solution_updates( file_name,
48 solver_name,
49 ):
50 """!
51
52 Parse residuals from input stream
53
54 @param file_name: String
55 We will open the file through ```open( file_name, "r").
56
57 @param solver_name: String
58 We have to know which solver to search for, as MGHyPE simulations might
59 host multiple solvers.
60
61 @return [Float], [Float], [Float]
62 Returns three sequences, all of the same size. The first sequence is the
63 development of the solution updates in the max norm, the second in the 2 norm,
64 and the third one hosts the deltas in the h norm.
65
66 """
67 result_max = []
68 result_2 = []
69 result_h = []
70
71 pattern = r"([-+]?\d*\.?\d+(?:e[-+]?\d+)?)"
72 full_pattern = rf"\|du\|\_max={pattern},\s*\|du\|\_2={pattern},\s*\|du\|\_h={pattern}"
73 with open(file_name, 'r') as file:
74 for line in file.readlines():
75 norms = re.search(full_pattern, line)
76 if "endMeshSweep()" in line and solver_name in line and norms!=None:
77 du_max, du_2, du_h = map(float, norms.groups()) # Convert to floats
78 result_max.append(du_max)
79 result_2.append(du_2)
80 result_h.append(du_h)
81
82 return result_max, result_2, result_h
83