|
| 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.fwsw.ProblemClass import swfw_scalar |
| 9 | +import numpy as np |
| 10 | + |
| 11 | +from pylab import rcParams |
| 12 | +import matplotlib.pyplot as plt |
| 13 | +from matplotlib.patches import Polygon |
| 14 | +from subprocess import call |
| 15 | +from matplotlib.ticker import ScalarFormatter |
| 16 | + |
| 17 | +if __name__ == "__main__": |
| 18 | + mvals = np.arange(2,10) |
| 19 | + kvals = [3, 5, 7] |
| 20 | + lambda_fast = 8j |
| 21 | + lambda_slow = 4j |
| 22 | + stabval = np.zeros((np.size(kvals), np.size(mvals))) |
| 23 | + |
| 24 | + for i in range(0,np.size(mvals)): |
| 25 | + pparams = {} |
| 26 | + # the following are not used in the computation |
| 27 | + pparams['lambda_s'] = np.array([0.0]) |
| 28 | + pparams['lambda_f'] = np.array([0.0]) |
| 29 | + pparams['u0'] = 1.0 |
| 30 | + |
| 31 | + swparams = {} |
| 32 | +# swparams['collocation_class'] = collclass.CollGaussLobatto |
| 33 | +# swparams['collocation_class'] = collclass.CollGaussLegendre |
| 34 | + swparams['collocation_class'] = collclass.CollGaussRadau_Right |
| 35 | + swparams['num_nodes'] = mvals[i] |
| 36 | + do_coll_update = True |
| 37 | + |
| 38 | + # |
| 39 | + # ...this is functionality copied from test_imexsweeper. Ideally, it should be available in one place. |
| 40 | + # |
| 41 | + step = stepclass.step(params={}) |
| 42 | + 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") |
| 43 | + step.register_level(L) |
| 44 | + step.status.dt = 1.0 # Needs to be 1.0, change dt through lambdas |
| 45 | + step.status.time = 0.0 |
| 46 | + u0 = step.levels[0].prob.u_exact(step.status.time) |
| 47 | + step.init_step(u0) |
| 48 | + nnodes = step.levels[0].sweep.coll.num_nodes |
| 49 | + level = step.levels[0] |
| 50 | + problem = level.prob |
| 51 | + |
| 52 | + QE = level.sweep.QE[1:,1:] |
| 53 | + QI = level.sweep.QI[1:,1:] |
| 54 | + Q = level.sweep.coll.Qmat[1:,1:] |
| 55 | + LHS, RHS = level.sweep.get_scalar_problems_sweeper_mats( lambdas = [ lambda_fast, lambda_slow ] ) |
| 56 | + |
| 57 | + for k in range(0,np.size(kvals)): |
| 58 | + Kmax = kvals[k] |
| 59 | + Mat_sweep = level.sweep.get_scalar_problems_manysweep_mat( nsweeps = Kmax, lambdas = [ lambda_fast, lambda_slow ] ) |
| 60 | + if do_coll_update: |
| 61 | + stab_fh = 1.0 + (lambda_fast + lambda_slow)*level.sweep.coll.weights.dot(Mat_sweep.dot(np.ones(nnodes))) |
| 62 | + else: |
| 63 | + q = np.zeros(nnodes) |
| 64 | + q[nnodes-1] = 1.0 |
| 65 | + stab_fh = q.dot(Mat_sweep.dot(np.ones(nnodes))) |
| 66 | + stabval[k,i] = np.absolute(stab_fh) |
| 67 | + |
| 68 | + rcParams['figure.figsize'] = 2.5, 2.5 |
| 69 | + fig = plt.figure() |
| 70 | + fs = 8 |
| 71 | + plt.plot(mvals, stabval[0,:], 'o-', color='b', label=(r"K=%1i" % kvals[0])) |
| 72 | + plt.plot(mvals, stabval[1,:], 's-', color='r', label=(r"K=%1i" % kvals[1])) |
| 73 | + plt.plot(mvals, stabval[2,:], 'd-', color='g', label=(r"K=%1i" % kvals[2])) |
| 74 | + plt.plot(mvals, 1.0+0.0*mvals, '--', color='k') |
| 75 | + plt.xlabel('Number of nodes M', fontsize=fs) |
| 76 | + plt.ylabel(r'Modulus of stability function $\left| R \right|$', fontsize=fs) |
| 77 | + plt.ylim([0.0, 1.8]) |
| 78 | + plt.legend(loc='lower right', fontsize=fs, prop={'size':fs}) |
| 79 | + plt.gca().get_xaxis().get_major_formatter().labelOnlyBase = False |
| 80 | + plt.gca().get_xaxis().set_major_formatter(ScalarFormatter()) |
| 81 | + plt.show() |
| 82 | + |
| 83 | +# filename = 'stablimit-M'+str(mvals[0])+'.pdf' |
| 84 | +# fig.savefig(filename, bbox_inches='tight') |
| 85 | +# call(["pdfcrop", filename, filename]) |
0 commit comments