Peano
Loading...
Searching...
No Matches
runTest1.py
Go to the documentation of this file.
1import subprocess
2import os
3import numpy as np
4from postProcess import parse_patch_file
5
6
7"""
8Perform git clean -xdf,
9Execute test1.py -m release,
10Run ./peano4matrixfree > out.txt
11Post-process
12"""
13
14# git clean
15subprocess.run(["git", "clean", "-xdf"], check=True)
16
17# Run test Python script
18poly_degree = 3
19subprocess.run(["python3", "test1.py", "-m", "release", "-p", str(poly_degree)], check=True)
20
21# Get path to the generated executable peano4matrixfree
22exec_path = os.path.join(os.getcwd(), "peano4matrixfree")
23
24# Run the executable ./peano4matrixfree
25output = subprocess.run([exec_path], capture_output=True, text=True, check=True)
26output_filename = "out.txt" # executable terminal output will be saved in this file
27with open(output_filename, "w") as outfile:
28 outfile.write(output.stdout)
29 print("Executable output saved to out.txt")
30
31# Post-process
32# subprocess.run(["python3", "parseTest1.py"], check=True
33v_solution = parse_patch_file("DGPoisson.solution-1.peano-patch-file", "DG")
34v_random = parse_patch_file("DGPoisson.rand-0.peano-patch-file", "DG")
35
36diff_norm = 0.0 # |v_solution - v_random|_{max}
37
38# Iterate over all cell keys in the solution dictionary
39# keys are coordinates of the left-bottom vertex of each cell
40for key in v_solution.keys():
41 cell_values_solution = np.asarray(v_solution[key])
42 # Access the same key in v_random
43 cell_values_random = np.asarray(v_random[key])
44 # Update global max norm with local cell max norm
45 diff_norm = max( diff_norm, np.max(np.abs(cell_values_solution - cell_values_random)) )
46
47# Check the criterion
48pass_tolerance = 1e-8
49if diff_norm < pass_tolerance:
50 print(f'Test 1: \033[{ "32" }m{ "PASSED" }\033[0m')
51else:
52 print(f'Test 1: \033[{ "31" }m{ "FAILED" }\033[0m')