Skip to content

Commit 2133c42

Browse files
author
Daniel Ruprecht
committed
added script to plot spectral radius of error propagation matrix in stiff limit
1 parent 5674573 commit 2133c42

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from pySDC import Level as lvl
2+
from pySDC import Hooks as hookclass
3+
from pySDC import CollocationClasses as collclass
4+
from pySDC import Step as stepclass
5+
6+
from pySDC.datatype_classes.complex_mesh import mesh, rhs_imex_mesh
7+
from pySDC.sweeper_classes.imex_1st_order import imex_1st_order as imex
8+
from examples.SWFW.ProblemClass import swfw_scalar
9+
import numpy as np
10+
11+
from matplotlib import pyplot as plt
12+
from pylab import rcParams
13+
14+
if __name__ == "__main__":
15+
16+
fs = 8
17+
18+
pparams = {}
19+
pparams['lambda_s'] = np.array([1.0*1j], dtype='complex')
20+
pparams['lambda_f'] = np.array([50.0*1j], dtype='complex')
21+
pparams['u0'] = 1.0
22+
swparams = {}
23+
swparams['collocation_class'] = collclass.CollGaussLobatto
24+
25+
nodes_v = np.arange(2,10)
26+
specrad = np.zeros((2,np.size(nodes_v)))
27+
for i in range(0,np.size(nodes_v)):
28+
swparams['num_nodes'] = nodes_v[i]
29+
#
30+
# ...this is functionality copied from test_imexsweeper. Ideally, it should be available in one place.
31+
#
32+
step = stepclass.step(params={})
33+
L = lvl.level(problem_class=swfw_scalar, problem_params=pparams, dtype_u=mesh, dtype_f=rhs_imex_mesh, sweeper_class=imex, sweeper_params=swparams, level_params={}, hook_class=hookclass.hooks, id="stability")
34+
step.register_level(L)
35+
step.status.dt = 1.0
36+
step.status.time = 0.0
37+
u0 = step.levels[0].prob.u_exact(step.status.time)
38+
step.init_step(u0)
39+
nnodes = step.levels[0].sweep.coll.num_nodes
40+
level = step.levels[0]
41+
problem = level.prob
42+
QE = level.sweep.QE[1:,1:]
43+
QI = level.sweep.QI[1:,1:]
44+
Q = level.sweep.coll.Qmat[1:,1:]
45+
46+
dt = step.status.dt
47+
LHS = np.eye(nnodes) - step.status.dt*( problem.lambda_f[0]*QI + problem.lambda_s[0]*QE )
48+
RHS = step.status.dt*( (problem.lambda_f[0]+problem.lambda_s[0])*Q - (problem.lambda_f[0]*QI + problem.lambda_s[0]*QE) )
49+
evals, evecs = np.linalg.eig( np.linalg.inv(LHS).dot(RHS) )
50+
specrad[1,i] = np.linalg.norm( evals, np.inf )
51+
52+
if swparams['collocation_class']==collclass.CollGaussLobatto:
53+
# For Lobatto nodes, first column and row are all zeros, since q_1 = q_0; hence remove them
54+
QI = QI[1:,1:]
55+
Q = Q[1:,1:]
56+
# Eigenvalue of error propagation matrix in stiff limit: E = I - inv(QI)*Q
57+
evals, evecs = np.linalg.eig( np.eye(nnodes-1) - np.linalg.inv(QI).dot(Q) )
58+
specrad[0,i] = np.linalg.norm( evals, np.inf )
59+
60+
### Plot result
61+
rcParams['figure.figsize'] = 2.5, 2.5
62+
fig = plt.figure()
63+
plt.plot(nodes_v, specrad[0,:], 'rd-', markersize=fs-2, label=r'$\lambda_{\rm fast} = \infty$')
64+
plt.plot(nodes_v, specrad[1,:], 'bo-', markersize=fs-2, label=r'$\lambda_{\rm fast} = %2.0f i$' % problem.lambda_f[0].imag)
65+
plt.xlabel(r'Number of nodes $M$', fontsize=fs)
66+
plt.ylabel(r'Spectral radius $\sigma\left( \mathbf{E} \right)$', fontsize=fs, labelpad=2)
67+
plt.legend(loc='lower right', fontsize=fs, prop={'size':fs})
68+
plt.xlim([np.min(nodes_v), np.max(nodes_v)])
69+
plt.ylim([0, 1.0])
70+
plt.yticks(fontsize=fs)
71+
plt.xticks(fontsize=fs)
72+
#plt.show()
73+
fig.savefig('sdc_fwsw_stifflimit_specrad.pdf',bbox_inches='tight')
74+

0 commit comments

Comments
 (0)