|
7 | 7 | import scipy.sparse.linalg as linalg |
8 | 8 |
|
9 | 9 | 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 |
10 | 16 | from impeuler import impeuler |
11 | 17 | from intexact import intexact |
12 | 18 | from trapezoidal import trapezoidal |
13 | | -from solution_linear import solution_linear |
14 | | -from get_matrix import get_upwind, get_centered |
| 19 | + |
15 | 20 | from pseudo_spectral_radius import pseudo_spectral_radius |
16 | 21 | from parameter import parameter |
17 | 22 |
|
18 | 23 | from pylab import rcParams |
19 | 24 | import matplotlib.pyplot as plt |
20 | 25 | from subprocess import call |
21 | 26 |
|
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 |
34 | 27 | try: |
35 | 28 | figure = int(sys.argv[1]) # 1 generates figure_1, 2 generates figure_2 |
36 | 29 | 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() |
39 | 47 |
|
40 | 48 | 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] |
41 | 53 | A_f = get_upwind(ndof_f, dx_f) |
42 | 54 | 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) |
43 | 58 | 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())) |
44 | 61 | 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] |
45 | 66 | A_f = get_centered(ndof_f, dx_f) |
46 | 67 | 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) |
47 | 71 | 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' |
48 | 82 | else: |
49 | | - sys.exit("Figure should be set to 13 or 14") |
| 83 | + sys.exit("Wrong value for figure") |
50 | 84 |
|
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 | + |
54 | 88 | defect_inf = np.zeros((1,maxiter)) |
55 | 89 | defect_l2 = np.zeros((1,maxiter)) |
56 | 90 | slopes = np.zeros(1) |
57 | 91 | psr = np.zeros(1) |
58 | 92 |
|
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 | | - |
67 | 93 | ### Parareal iteration: y^k+1 = Pmat*y^k + Bmat*b |
68 | 94 | E_norm = np.linalg.norm(Pmat.todense(),2) |
69 | 95 |
|
|
94 | 120 | plt.semilogy(range(1,maxiter+1), defect_l2[0,:], 'bo-', markersize=ms, label=r'$|| e^k ||$') |
95 | 121 | 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) |
96 | 122 | 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 | + |
98 | 128 | plt.xlim([1, maxiter+1]) |
99 | 129 | plt.ylim([1e-5, 1e3]) |
100 | 130 |
|
|
0 commit comments