|
5 | 5 |
|
6 | 6 | from pySDC.datatype_classes.complex_mesh import mesh, rhs_imex_mesh |
7 | 7 | from pySDC.sweeper_classes.imex_1st_order import imex_1st_order as imex |
8 | | -from examples.SWFW.ProblemClass import swfw_scalar |
| 8 | +from examples.fwsw.ProblemClass import swfw_scalar |
9 | 9 | import numpy as np |
10 | 10 |
|
| 11 | +import matplotlib.pyplot as plt |
| 12 | + |
11 | 13 | if __name__ == "__main__": |
12 | 14 |
|
| 15 | + N_s = 100 |
| 16 | + N_f = 400 |
| 17 | + |
| 18 | + lambda_s = 1j*np.linspace(0.0, 2.0, N_s) |
| 19 | + lambda_f = 1j*np.linspace(0.0, 8.0, N_f) |
| 20 | + |
13 | 21 | pparams = {} |
14 | | - pparams['lambda_s'] = np.array([-0.0], dtype='complex') |
15 | | - pparams['lambda_f'] = np.array([-1.0], dtype='complex') |
| 22 | + # the following are not used in the computation |
| 23 | + pparams['lambda_s'] = np.array([0.0]) |
| 24 | + pparams['lambda_f'] = np.array([0.0]) |
16 | 25 | pparams['u0'] = 1.0 |
17 | 26 | swparams = {} |
18 | 27 | swparams['collocation_class'] = collclass.CollGaussLobatto |
19 | | - swparams['num_nodes'] = 9 |
20 | | - K = 1 |
| 28 | + swparams['num_nodes'] = 2 |
| 29 | + K = 2 |
21 | 30 |
|
22 | 31 | # |
23 | 32 | # ...this is functionality copied from test_imexsweeper. Ideally, it should be available in one place. |
|
32 | 41 | nnodes = step.levels[0].sweep.coll.num_nodes |
33 | 42 | level = step.levels[0] |
34 | 43 | problem = level.prob |
| 44 | + |
35 | 45 | QE = level.sweep.QE[1:,1:] |
36 | 46 | QI = level.sweep.QI[1:,1:] |
37 | 47 | Q = level.sweep.coll.Qmat[1:,1:] |
38 | 48 |
|
39 | | - dt = step.status.dt |
40 | | - LHS = np.eye(nnodes) - step.status.dt*( problem.lambda_f[0]*QI + problem.lambda_s[0]*QE ) |
41 | | - RHS = step.status.dt*( (problem.lambda_f[0]+problem.lambda_s[0])*Q - (problem.lambda_f[0]*QI + problem.lambda_s[0]*QE) ) |
| 49 | + stab = np.zeros((N_f, N_s), dtype='complex') |
| 50 | + |
| 51 | + for i in range(0,N_s): |
| 52 | + for j in range(0,N_f): |
| 53 | + lambda_fast = lambda_f[j] |
| 54 | + lambda_slow = lambda_s[i] |
| 55 | + LHS = np.eye(nnodes) - step.status.dt*( lambda_fast*QI + lambda_slow*QE ) |
| 56 | + RHS = step.status.dt*( (lambda_fast+lambda_slow)*Q - (lambda_fast*QI + lambda_slow*QE) ) |
| 57 | + |
| 58 | + Pinv = np.linalg.inv(LHS) |
| 59 | + Mat_sweep = np.linalg.matrix_power(Pinv.dot(RHS), K) |
| 60 | + for k in range(0,K): |
| 61 | + Mat_sweep = Mat_sweep + np.linalg.matrix_power(Pinv.dot(RHS),k).dot(Pinv) |
| 62 | + stab_fh = 1.0 + (lambda_fast + lambda_slow)*level.sweep.coll.weights.dot(Mat_sweep.dot(np.ones(nnodes))) |
| 63 | + stab[j,i] = stab_fh |
42 | 64 |
|
43 | | - Pinv = np.linalg.inv(LHS) |
44 | | - Mat_sweep = np.linalg.matrix_power(Pinv.dot(RHS), K) |
45 | | - for i in range(0,K): |
46 | | - Mat_sweep = Mat_sweep + np.linalg.matrix_power(Pinv.dot(RHS),i).dot(Pinv) |
47 | | - stab_fh = 1.0 + (pparams['lambda_s'][0] + pparams['lambda_f'][0])*level.sweep.coll.weights.dot(Mat_sweep.dot(np.ones(nnodes))) |
48 | | - print abs(stab_fh) |
| 65 | + ### |
| 66 | + fig = plt.figure(figsize=(12,12)) |
| 67 | + #pcol = plt.pcolor(lambda_s.imag, lambda_f.imag, np.absolute(stab), vmin=0.99, vmax=2.01) |
| 68 | + #pcol.set_edgecolor('face') |
| 69 | + levels = np.array([0.95, 0.99, 1.01]) |
| 70 | + CS = plt.contour(lambda_s.imag, lambda_f.imag, np.absolute(stab), levels, colors='k') |
| 71 | + plt.clabel(CS, fontsize=9) |
| 72 | + plt.plot([0, 4], [0, 4], color='k', linewidth=2.5) |
| 73 | + plt.gca().set_xticks([0.0, 1.0, 2.0, 3.0]) |
| 74 | + plt.xlim([np.min(lambda_s.imag), np.max(lambda_s.imag)]) |
| 75 | + plt.xlabel('$\Delta t \lambda_{slow}$', fontsize=18, labelpad=0.0) |
| 76 | + plt.ylabel('$\Delta t \lambda_{fast}$', fontsize=18) |
| 77 | + plt.show() |
0 commit comments