-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_serial_err.py
46 lines (36 loc) · 1.38 KB
/
plot_serial_err.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy as np
disc_err_fine = 0.0
disc_err_coarse = 0.0
y_ref = np.array([])
y_fine = np.array([])
y_coarse = np.array([])
# load coarse serial
filename = "q_final_coarse.dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_coarse = np.append(y_coarse, [float(line)])
print ('Maximum of coarse solution: %6.3e' % np.linalg.norm(y_coarse, np.inf))
# load fine serial
filename = "q_final_fine.dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_fine = np.append(y_fine, [float(line)])
print ('Maximum of fine solution: %6.3e' % np.linalg.norm(y_fine, np.inf))
# load fine reference
filename = "q_final_fine_ref.dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_ref = np.append(y_ref, [float(line)])
print ('\n')
assert np.size(y_ref)==np.size(y_fine), 'Mismatch in length of fine and reference solution'
assert np.size(y_fine)==np.size(y_coarse), 'Mismatch in length of fine and coarse solution'
err_fine = y_fine - y_ref
err_coarse = y_coarse - y_ref
print ('Approximate discretization error of fine method: %6.3e' % (np.linalg.norm(err_fine, np.inf)/np.linalg.norm(y_ref, np.inf)))
print ('Approximate discretization error of coarse method: %6.3e' % (np.linalg.norm(err_coarse, np.inf)/np.linalg.norm(y_ref, np.inf)))