Skip to content

Commit 118bfb5

Browse files
author
Daniel Ruprecht
committed
add script that plots maximum singular value against diffusion coefficient nu
1 parent 2598c9f commit 118bfb5

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

scripts/plot_svd_vs_nu.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
ncoarse = 1
27+
nfine = 10
28+
dx = 1.0
29+
Nsamples = 60
30+
u0_val = np.array([[1.0]], dtype='complex')
31+
32+
k_vec = np.linspace(0.0, np.pi, Nsamples+1, endpoint=False)
33+
k_vec = k_vec[1:]
34+
waveno = k_vec[-1]
35+
36+
propagators = [impeuler, trapezoidal]
37+
38+
nu_v = np.logspace(-16, 0, num=80, endpoint=True)
39+
# insert nu=0 as first value
40+
nu_v = np.insert(nu_v, 0, 0.0)
41+
svds = np.zeros((np.size(propagators),np.size(nu_v)))
42+
43+
for i in range(0,np.size(nu_v)):
44+
symb = -(1j*U_speed*waveno + nu_v[i]*waveno**2)
45+
symb_coarse = symb
46+
47+
# Solution objects define the problem
48+
u0 = solution_linear(u0_val, np.array([[symb]],dtype='complex'))
49+
ucoarse = solution_linear(u0_val, np.array([[symb_coarse]],dtype='complex'))
50+
51+
for j in range(2):
52+
para = parareal(0.0, Tend, nslices, intexact, propagators[j], nfine, ncoarse, 0.0, 0, u0)
53+
svds[j,i] = para.get_max_svd(ucoarse=ucoarse)
54+
55+
rcParams['figure.figsize'] = 2.5, 2.5
56+
fs = 8
57+
fig = plt.figure()
58+
plt.semilogx(nu_v, svds[0,:], 'b', label='Implicit Euler')
59+
plt.semilogx(nu_v, svds[1,:], 'r', label='Trapezoidal')
60+
plt.semilogx(nu_v, 0.0*nu_v+1.0, 'k--')
61+
plt.gca().tick_params(axis='both', which='major', labelsize=fs-2)
62+
plt.gca().tick_params(axis='x', which='minor', bottom='off')
63+
plt.gca().set_xticks(np.logspace(-16, 0, num=5))
64+
plt.xlabel(r'Diffusion coefficient $\nu$', fontsize=fs, labelpad=1)
65+
plt.ylabel(r'Maximum singular value $\sigma$', fontsize=fs, labelpad=0)
66+
plt.legend(loc='center left', fontsize=fs, prop={'size':fs-2})
67+
filename='svd_vs_nu.pdf'
68+
fig.savefig(filename, bbox_inches='tight')
69+
call(["pdfcrop", filename, filename])
70+
# plt.show()

0 commit comments

Comments
 (0)