Skip to content

Commit 5674573

Browse files
author
Daniel Ruprecht
committed
can compute value of stabilty function for single pair of values for lambda_f and lambda_s
1 parent 884b57f commit 5674573

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

examples/SWFW/plot_stability.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
if __name__ == "__main__":
12+
13+
pparams = {}
14+
pparams['lambda_s'] = np.array([-0.0], dtype='complex')
15+
pparams['lambda_f'] = np.array([-1.0], dtype='complex')
16+
pparams['u0'] = 1.0
17+
swparams = {}
18+
swparams['collocation_class'] = collclass.CollGaussLobatto
19+
swparams['num_nodes'] = 3
20+
K = 1
21+
22+
23+
step = stepclass.step(params={})
24+
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")
25+
step.register_level(L)
26+
step.status.dt = 1.0
27+
step.status.time = 0.0
28+
u0 = step.levels[0].prob.u_exact(step.status.time)
29+
step.init_step(u0)
30+
nnodes = step.levels[0].sweep.coll.num_nodes
31+
level = step.levels[0]
32+
problem = level.prob
33+
QE = level.sweep.QE[1:,1:]
34+
QI = level.sweep.QI[1:,1:]
35+
Q = level.sweep.coll.Qmat[1:,1:]
36+
37+
dt = step.status.dt
38+
LHS = np.eye(nnodes) - step.status.dt*( problem.lambda_f[0]*QI + problem.lambda_s[0]*QE )
39+
RHS = step.status.dt*( (problem.lambda_f[0]+problem.lambda_s[0])*Q - (problem.lambda_f[0]*QI + problem.lambda_s[0]*QE) )
40+
41+
Pinv = np.linalg.inv(LHS)
42+
Mat_sweep = np.linalg.matrix_power(Pinv.dot(RHS), K)
43+
for i in range(0,K):
44+
Mat_sweep = Mat_sweep + np.linalg.matrix_power(Pinv.dot(RHS),i).dot(Pinv)
45+
stab_fh = 1.0 + (pparams['lambda_s'][0] + pparams['lambda_f'][0])*level.sweep.coll.weights.dot(Mat_sweep.dot(np.ones(nnodes)))
46+
print abs(stab_fh)

0 commit comments

Comments
 (0)