-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_parareal_conv.py
66 lines (59 loc) · 1.96 KB
/
plot_parareal_conv.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
from matplotlib import pyplot as plt
fs = 18
Nproc = 24
Niter_max = 5
type="mpi"
defect = np.zeros(Niter_max-1)
y_fine = np.array([])
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)])
fobj.close()
Nfine = np.size(y_fine)
# Plot defect of Parareal to serial fine solution
for niter in range(1,Niter_max):
y_para = np.array([])
niter_s = '%0.2i' % niter
nproc_s = '%0.2i' % Nproc
nproc_m1_s = '%0.2i' % (Nproc-1)
filename = "q_final_"+niter_s+"_"+nproc_m1_s+"_"+nproc_s+"_"+type+".dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_para = np.append(y_para, [float(line)])
fobj.close()
Npara = np.size(y_para)
assert Npara == Nfine, 'Mismatch in length of serial and parallel solution.'
diff = y_fine - y_para
defect[niter-1] = np.linalg.norm(diff, np.inf)/np.linalg.norm(y_fine, np.inf)
for niter in range(1,Niter_max):
print ('Defect of Parareal to fine method after %1i iterations: %6.3e' % (niter,defect[niter-1]))
# Plot norm of update between iterations
y_para_old = np.array([])
niter_s = '%0.2i' % 1
filename = "q_final_"+niter_s+"_"+nproc_m1_s+"_"+nproc_s+"_"+type+".dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_para_old = np.append(y_para_old, [float(line)])
fobj.close()
print "\n"
for niter in range(2,Niter_max):
y_para = np.array([])
niter_s = '%0.2i' % niter
filename = "q_final_"+niter_s+"_"+nproc_m1_s+"_"+nproc_s+"_"+type+".dat"
with open(filename,'r') as fobj:
while True:
line = fobj.readline()
if not line: break
y_para = np.append(y_para, [float(line)])
fobj.close()
update = y_para - y_para_old
print ('Update of Parareal in iteration %1i: %6.3e' % (niter,np.linalg.norm(update, np.inf)/np.linalg.norm(y_para, np.inf)))
y_para_old = y_para