Skip to content

Commit dbdb56d

Browse files
author
Daniel Ruprecht
committed
script to plot maximum singular value versus coarse time step
1 parent f024efb commit dbdb56d

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

scripts/plot_dispersion.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from parareal import parareal
55
from impeuler import impeuler
66
from intexact import intexact
7+
from trapezoidal import trapezoidal
78
from special_integrator import special_integrator
89
from solution_linear import solution_linear
910
import numpy as np
@@ -22,7 +23,7 @@ def solve_omega(R):
2223

2324
def findroots(R, n):
2425
assert abs(n - float(int(n)))<1e-14, "n must be an integer or a float equal to an integer"
25-
p = np.zeros(n+1, dtype='complex')
26+
p = np.zeros(int(n)+1, dtype='complex')
2627
p[-1] = -R
2728
p[0] = 1.0
2829
return np.roots(p)
@@ -60,8 +61,8 @@ def normalise(R, T, target):
6061
for i in range(0,np.size(k_vec)):
6162

6263
symb = -(1j*U_speed*k_vec[i] + nu*k_vec[i]**2)
63-
symb_coarse = symb
64-
# symb_coarse = -(1.0/dx)*(1.0 - np.exp(-1j*k_vec[i]*dx))
64+
# symb_coarse = symb
65+
symb_coarse = -(1.0/dx)*(1.0 - np.exp(-1j*k_vec[i]*dx))
6566

6667
# Solution objects define the problem
6768
u0 = solution_linear(u0_val, np.array([[symb]],dtype='complex'))
@@ -94,24 +95,24 @@ def normalise(R, T, target):
9495
#
9596

9697
# for stab = r*exp(i*theta), r defines the amplitude factor and theta the phase speed
97-
stab_tailor = abs(stab_coarse[0,0])*np.exp(1j*np.angle(stab_ex)) # exact phase speed
98+
# stab_tailor = abs(stab_coarse[0,0])*np.exp(1j*np.angle(stab_ex)) # exact phase speed
9899
# stab_tailor = abs(stab_ex)*np.exp(1j*np.angle(stab_coarse[0,0])) # exact amplification factor
99100

100101
# coarse method with exact phase but amplification factor corresponding to a single large backward Euler step
101-
stab_coarse_limit = 1.0/(1.0 - Tend*symb_coarse)
102-
stab_tailor = abs(stab_coarse_limit)*np.exp(1j*np.angle(stab_ex)) # exact phase speed, massively diffusive amplification factor
102+
#stab_coarse_limit = 1.0/(1.0 - Tend*symb_coarse)
103+
#stab_tailor = abs(stab_coarse_limit)*np.exp(1j*np.angle(stab_ex)) # exact phase speed, massively diffusive amplification factor
103104

104105
# stab_tailor = abs(stab_ex)*np.exp(1j*np.angle(stab_ex)) ## for testing
105106
# stab_tailor = abs(stab_coarse[0,0])*np.exp(1j*np.angle(stab_coarse[0,0])) ## for testing
106107

107108
# Re-Create the parareal object to be used in the remainder
108-
stab_tailor = sparse.csc_matrix(np.array([stab_tailor], dtype='complex'))
109-
para = parareal(0.0, Tend, nslices, intexact, stab_tailor, nfine, ncoarse, 0.0, niter_v[0], u0)
109+
# stab_tailor = sparse.csc_matrix(np.array([stab_tailor], dtype='complex'))
110+
# para = parareal(0.0, Tend, nslices, intexact, stab_tailor, nfine, ncoarse, 0.0, niter_v[0], u0)
110111

111112
#################################################
112113

113114
# Compute Parareal phase velocity and amplification factor
114-
#svds[0,i] = para.get_max_svd(ucoarse=ucoarse)
115+
svds[0,i] = para.get_max_svd(ucoarse=ucoarse)
115116
for jj in range(0,3):
116117
stab_para = para.get_parareal_stab_function(k=niter_v[jj], ucoarse=ucoarse)
117118

scripts/plot_sine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
err = np.zeros(nslices)
3434
para_show = np.zeros((3,Nx))
35-
niter_show = [5, 10, 15]
35+
niter_show = [2, 4, 6]
3636

3737
symb = -(1j*U_speed*k + nu*k**2)
3838
u0_val = np.array([[1.0]], dtype='complex')
@@ -41,7 +41,7 @@
4141

4242
stab_ex = np.exp(-1j*U_speed*k*Tend)*np.exp(-nu*k**2*Tend)
4343

44-
stab_coarse = para.timemesh.slices[0].get_coarse_update_matrix(u0)
44+
stab_coarse = para.timemesh.slices[0].get_coarse_update_matrix(u0)
4545
stab_coarse = stab_coarse**nslices
4646

4747
stab_fine = para.timemesh.slices[0].get_fine_update_matrix(u0)
@@ -67,7 +67,7 @@
6767
plt.plot(x, para_show[0,:], 'r--+', label='Parareal k='+str(niter_show[0]), markevery=(5, 20), markersize=fs/2, mew=1)
6868
plt.plot(x, para_show[1,:], 'r:s', label='Parareal k='+str(niter_show[1]), markevery=(10,20), markersize=fs/2, mew=1)
6969
plt.plot(x, para_show[2,:], 'r-o', label='Parareal k='+str(niter_show[2]), markevery=(15,20), markersize=fs/2, mew=1)
70-
plt.plot(x, y_ex.real, 'g--', label='Fine')
70+
#plt.plot(x, y_ex.real, 'g--', label='Fine')
7171
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs-2}, handlelength=3)
7272
plt.title((r'$\kappa$ = %4.2f' % k), fontsize=fs)
7373
plt.ylim([-2.5, 1.5])

scripts/plot_svd_vs_dt.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
sys.path.append('../src')
3+
4+
from parareal import parareal
5+
from impeuler import impeuler
6+
from intexact import intexact
7+
from trapezoidal import trapezoidal
8+
from special_integrator import special_integrator
9+
from solution_linear import solution_linear
10+
import numpy as np
11+
import scipy.sparse as sparse
12+
import math
13+
14+
from pylab import rcParams
15+
import matplotlib.pyplot as plt
16+
from matplotlib.patches import Polygon
17+
from subprocess import call
18+
import sympy
19+
from pylab import rcParams
20+
21+
if __name__ == "__main__":
22+
23+
Tend = 16.0
24+
nslices = int(Tend) # Make sure each time slice has length 1
25+
U_speed = 1.0
26+
nu = 0.0
27+
ncoarse_v = range(1,11)
28+
nfine = 10
29+
niter_v = [5, 10, 15]
30+
dx = 1.0
31+
Nsamples = 60
32+
u0_val = np.array([[1.0]], dtype='complex')
33+
34+
k_vec = np.linspace(0.0, np.pi, Nsamples+1, endpoint=False)
35+
k_vec = k_vec[1:]
36+
waveno = k_vec[-1]
37+
38+
svds = np.zeros((1,np.size(ncoarse_v)))
39+
dt_v = np.zeros((1,np.size(ncoarse_v)))
40+
41+
symb = -(1j*U_speed*waveno + nu*waveno**2)
42+
symb_coarse = symb
43+
# symb_coarse = -(1.0/dx)*(1.0 - np.exp(-1j*waveno*dx))
44+
45+
# Solution objects define the problem
46+
u0 = solution_linear(u0_val, np.array([[symb]],dtype='complex'))
47+
ucoarse = solution_linear(u0_val, np.array([[symb_coarse]],dtype='complex'))
48+
49+
for i in range(0,np.size(ncoarse_v)):
50+
para = parareal(0.0, Tend, nslices, intexact, impeuler, nfine, ncoarse_v[i], 0.0, niter_v[2], u0)
51+
dt_v[0,i] = Tend/float(ncoarse_v[i]*nslices)
52+
svds[0,i] = para.get_max_svd(ucoarse=ucoarse)
53+
54+
rcParams['figure.figsize'] = 7.5, 7.5
55+
fs = 8
56+
fig = plt.figure()
57+
plt.plot(dt_v[0,:], svds[0,:])
58+
plt.show()

scripts/plot_wave_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def normalise(R, T, target):
6060
u0 = solution_linear(u0_val, np.array([[symb]],dtype='complex'))
6161
ucoarse = solution_linear(u0_val, np.array([[symb_coarse]],dtype='complex'))
6262

63-
para = parareal(0.0, Tend, nslices, intexact, trapezoidal, nfine, ncoarse, 0.0, niter_v[0], u0)
63+
para = parareal(0.0, Tend, nslices, intexact, impeuler, nfine, ncoarse, 0.0, niter_v[0], u0)
6464

6565
# get update matrix for imp Euler over one slice
6666
stab_fine = para.timemesh.slices[0].get_fine_update_matrix(u0)

0 commit comments

Comments
 (0)