Skip to content

Commit 183d283

Browse files
committed
unified scripts for figures 13 to 16
1 parent 34226a8 commit 183d283

File tree

2 files changed

+59
-125
lines changed

2 files changed

+59
-125
lines changed

scripts/pseudo-spectrum/figure_13-14.py renamed to scripts/pseudo-spectrum/figure_13-16.py

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,89 @@
77
import scipy.sparse.linalg as linalg
88

99
from parareal import parareal
10+
from integrator_dedalus import integrator_dedalus
11+
12+
from solution_dedalus import solution_dedalus
13+
from solution_linear import solution_linear
14+
15+
from get_matrix import get_upwind, get_centered
1016
from impeuler import impeuler
1117
from intexact import intexact
1218
from trapezoidal import trapezoidal
13-
from solution_linear import solution_linear
14-
from get_matrix import get_upwind, get_centered
19+
1520
from pseudo_spectral_radius import pseudo_spectral_radius
1621
from parameter import parameter
1722

1823
from pylab import rcParams
1924
import matplotlib.pyplot as plt
2025
from subprocess import call
2126

22-
par = parameter(dedalus = False)
23-
Tend, nslices, maxiter, nfine, ncoarse, tol, epsilon, ndof_f = par.getpar()
24-
ndof_c = 24
25-
26-
xaxis_f = np.linspace(0.0, 2.0, ndof_f+1)[0:ndof_f]
27-
dx_f = xaxis_f[1] - xaxis_f[0]
28-
29-
xaxis_c = np.linspace(0.0, 2.0, ndof_c+1)[0:ndof_c]
30-
dx_c = xaxis_c[1] - xaxis_c[0]
31-
32-
# 1 = advection with implicit Euler / upwind FD
33-
# 2 = advection with trapezoidal rule / centered FD
3427
try:
3528
figure = int(sys.argv[1]) # 1 generates figure_1, 2 generates figure_2
3629
except:
37-
print("No or wrong command line argument provided, creating figure 13. Use 13 or 14 as command line argument.")
38-
figure = 13
30+
print("No or wrong command line argument provided, creating figure 13. Use 13, 14, 15 or 16 as command line argument.")
31+
figure = 5
32+
assert 13<= figure <= 16, "Figure should be 13, 14, 15 or 16"
33+
34+
if figure==13 or figure==14:
35+
par = parameter(dedalus = False)
36+
ndof_c = 24
37+
elif figure==15:
38+
par = parameter(dedalus = True)
39+
ndof_c = 24
40+
elif figure==16:
41+
par = parameter(dedalus = True)
42+
ndof_c = 30
43+
else:
44+
sys.exit("This should have been caught above")
45+
46+
Tend, nslices, maxiter, nfine, ncoarse, tol, epsilon, ndof_f = par.getpar()
3947

4048
if figure==13:
49+
xaxis_f = np.linspace(0.0, 2.0, ndof_f+1)[0:ndof_f]
50+
dx_f = xaxis_f[1] - xaxis_f[0]
51+
xaxis_c = np.linspace(0.0, 2.0, ndof_c+1)[0:ndof_c]
52+
dx_c = xaxis_c[1] - xaxis_c[0]
4153
A_f = get_upwind(ndof_f, dx_f)
4254
A_c = get_upwind(ndof_c, dx_c)
55+
u0fine = solution_linear(np.zeros(ndof_f), A_f)
56+
u0coarse = solution_linear(np.zeros(ndof_c), A_c)
57+
para = parareal(0.0, Tend, nslices, impeuler, impeuler, nfine, ncoarse, tol, maxiter, u0fine, u0coarse)
4358
filename = 'figure_13.pdf'
59+
D = A_f*A_f.H - A_f.H*A_f
60+
print("Normality number of the system matrix (this should be zero): %5.3f" % np.linalg.norm(D.todense()))
4461
elif figure==14:
62+
xaxis_f = np.linspace(0.0, 2.0, ndof_f+1)[0:ndof_f]
63+
dx_f = xaxis_f[1] - xaxis_f[0]
64+
xaxis_c = np.linspace(0.0, 2.0, ndof_c+1)[0:ndof_c]
65+
dx_c = xaxis_c[1] - xaxis_c[0]
4566
A_f = get_centered(ndof_f, dx_f)
4667
A_c = get_centered(ndof_c, dx_c)
68+
u0fine = solution_linear(np.zeros(ndof_f), A_f)
69+
u0coarse = solution_linear(np.zeros(ndof_c), A_c)
70+
para = parareal(0.0, Tend, nslices, trapezoidal, trapezoidal, nfine, ncoarse, tol, maxiter, u0fine, u0coarse)
4771
filename = 'figure_14.pdf'
72+
D = A_f*A_f.H - A_f.H*A_f
73+
print("Normality number of the system matrix (this should be zero): %5.3f" % np.linalg.norm(D.todense()))
74+
elif figure==15 or figure==16:
75+
u0fine = solution_dedalus(np.zeros(ndof_f), ndof_f)
76+
u0coarse = solution_dedalus(np.zeros(ndof_c), ndof_c)
77+
para = parareal(0.0, Tend, nslices, integrator_dedalus, integrator_dedalus, nfine, ncoarse, tol, maxiter, u0fine, u0coarse)
78+
if figure==15:
79+
filename = 'figure_15.pdf'
80+
elif figure==16:
81+
filename = 'figure_16.pdf'
4882
else:
49-
sys.exit("Figure should be set to 13 or 14")
83+
sys.exit("Wrong value for figure")
5084

51-
D = A_f*A_f.H - A_f.H*A_f
52-
print("Normality number of the system matrix (this should be zero): %5.3f" % np.linalg.norm(D.todense()))
53-
u0fine = solution_linear(np.zeros(ndof_f), A_f)
85+
86+
Pmat, Bmat = para.get_parareal_matrix()
87+
5488
defect_inf = np.zeros((1,maxiter))
5589
defect_l2 = np.zeros((1,maxiter))
5690
slopes = np.zeros(1)
5791
psr = np.zeros(1)
5892

59-
u0coarse = solution_linear(np.zeros(ndof_c), A_c)
60-
61-
if figure==13:
62-
para = parareal(0.0, Tend, nslices, impeuler, impeuler, nfine, ncoarse, tol, maxiter, u0fine, u0coarse)
63-
else:
64-
para = parareal(0.0, Tend, nslices, trapezoidal, trapezoidal, nfine, ncoarse, tol, maxiter, u0fine, u0coarse)
65-
Pmat, Bmat = para.get_parareal_matrix()
66-
6793
### Parareal iteration: y^k+1 = Pmat*y^k + Bmat*b
6894
E_norm = np.linalg.norm(Pmat.todense(),2)
6995

@@ -94,7 +120,11 @@
94120
plt.semilogy(range(1,maxiter+1), defect_l2[0,:], 'bo-', markersize=ms, label=r'$|| e^k ||$')
95121
plt.semilogy(range(1,5), [E_norm**(val-1)*2.0*defect_l2[0,0] for val in range(1,5)], 'b-.', label=r'$|| E ||_2^k$', linewidth=2)
96122
plt.semilogy(range(1,5), [psr**(val-1)*2.0*defect_l2[0,0] for val in range(1,5)], 'r--', label=r'$\sigma_{\epsilon}(E)^k$', linewidth=2)
97-
plt.legend(loc='upper right', fontsize=fs, prop={'size':fs-2}, handlelength=3)
123+
if figure==15:
124+
plt.legend(loc='lower right', fontsize=fs, prop={'size':fs-2}, handlelength=3)
125+
else:
126+
plt.legend(loc='upper right', fontsize=fs, prop={'size':fs-2}, handlelength=3)
127+
98128
plt.xlim([1, maxiter+1])
99129
plt.ylim([1e-5, 1e3])
100130

scripts/pseudo-spectrum/figure_15-16.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)