|
12 | 12 | from pySDC import Log |
13 | 13 | from pySDC.Stats import grep_stats, sort_stats |
14 | 14 |
|
15 | | -# Sharpclaw imports |
16 | | -#from clawpack import pyclaw |
17 | | -#from clawpack import riemann |
| 15 | +from standard_integrators import bdf2, dirk, trapezoidal |
| 16 | + |
18 | 17 | from matplotlib import pyplot as plt |
| 18 | +from pylab import rcParams |
19 | 19 |
|
| 20 | +fs = 8 |
20 | 21 |
|
21 | 22 | if __name__ == "__main__": |
22 | 23 |
|
|
55 | 56 | description['problem_params'] = pparams |
56 | 57 | description['dtype_u'] = mesh |
57 | 58 | description['dtype_f'] = rhs_imex_mesh |
58 | | - description['collocation_class'] = collclass.CollGaussLobatto |
59 | | - description['num_nodes'] = 3 |
| 59 | + description['collocation_class'] = collclass.CollGaussRadau_Right |
| 60 | + if sparams['maxiter']==2: |
| 61 | + description['num_nodes'] = 2 |
| 62 | + else: |
| 63 | + description['num_nodes'] = 3 |
60 | 64 | description['sweeper_class'] = imex_1st_order |
61 | 65 | description['level_params'] = lparams |
62 | 66 | description['hook_class'] = plot_solution |
|
73 | 77 | # call main function to get things done... |
74 | 78 | uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) |
75 | 79 |
|
76 | | - # compute exact solution and compare |
77 | | - uex = P.u_exact(Tend) |
| 80 | + # instantiate standard integrators to be run for comparison |
| 81 | + trap = trapezoidal( P.A+P.Dx, 0.5 ) |
| 82 | + bdf2 = bdf2( P.A+P.Dx) |
| 83 | + dirk = dirk( P.A+P.Dx, sparams['maxiter']) |
| 84 | + |
| 85 | + y0_tp = np.concatenate( (uinit.values[0,:], uinit.values[1,:]) ) |
| 86 | + y0_bdf = y0_tp |
| 87 | + y0_dirk = y0_tp |
| 88 | + |
| 89 | + # Perform 154 time steps with standard integrators |
| 90 | + for i in range(0,154): |
| 91 | + |
| 92 | + # trapezoidal rule step |
| 93 | + ynew_tp = trap.timestep(y0_tp, dt) |
| 94 | + |
| 95 | + # BDF-2 scheme |
| 96 | + if i==0: |
| 97 | + ynew_bdf = bdf2.firsttimestep( y0_bdf, dt) |
| 98 | + ym1_bdf = y0_bdf |
| 99 | + else: |
| 100 | + ynew_bdf = bdf2.timestep( y0_bdf, ym1_bdf, dt) |
78 | 101 |
|
79 | | - fig = plt.figure(figsize=(8,8)) |
| 102 | + # DIRK scheme |
| 103 | + ynew_dirk = dirk.timestep(y0_dirk, dt) |
| 104 | + |
| 105 | + y0_tp = ynew_tp |
| 106 | + ym1_bdf = y0_bdf |
| 107 | + y0_bdf = ynew_bdf |
| 108 | + y0_dirk = ynew_dirk |
| 109 | + |
| 110 | + # Finished running standard integrators |
| 111 | + unew_tp, pnew_tp = np.split(ynew_tp, 2) |
| 112 | + unew_bdf, pnew_bdf = np.split(ynew_bdf, 2) |
| 113 | + unew_dirk, pnew_dirk = np.split(ynew_dirk, 2) |
| 114 | + |
| 115 | + rcParams['figure.figsize'] = 5, 2.5 |
| 116 | + fig = plt.figure() |
80 | 117 |
|
81 | 118 | sigma_0 = 0.1 |
82 | 119 | k = 7.0*2.0*np.pi |
83 | 120 | x_0 = 0.75 |
84 | 121 | x_1 = 0.25 |
85 | 122 |
|
86 | | - #plt.plot(P.mesh, uex.values[0,:], '+', color='b', label='u (exact)') |
87 | | - plt.plot(P.mesh, uend.values[1,:], '-', color='b', label='SDC') |
| 123 | + plt.plot(P.mesh, pnew_tp, '-', color='c', label='Trapezoidal') |
| 124 | + plt.plot(P.mesh, uend.values[1,:], '-', color='b', label='SDC('+str(sparams['maxiter'])+')') |
| 125 | + plt.plot(P.mesh, pnew_bdf, '-', color='r', label='BDF-2') |
| 126 | + plt.plot(P.mesh, pnew_dirk, color='g', label='DIRK('+str(dirk.order)+')') |
88 | 127 | #plt.plot(P.mesh, uex.values[1,:], '+', color='r', label='p (exact)') |
89 | 128 | #plt.plot(P.mesh, uend.values[1,:], '-', color='b', linewidth=2.0, label='p (SDC)') |
90 | | - p_slow = np.exp(-np.square(P.mesh-x_0-pparams['cadv']*Tend)/(sigma_0*sigma_0)) |
91 | | - plt.plot(P.mesh, p_slow, '-', color='r', markersize=4, label='slow mode') |
92 | | - plt.legend(loc=2) |
93 | | - plt.xlim([0, 1]) |
94 | | - plt.ylim([-0.1, 1.1]) |
| 129 | + |
| 130 | + p_slow = np.exp(-np.square( np.mod( P.mesh-pparams['cadv']*Tend, 1.0 ) -x_0 )/(sigma_0*sigma_0)) |
| 131 | + plt.plot(P.mesh, p_slow, '+', color='k', markersize=fs-2, label='Slow mode', markevery=10) |
| 132 | + plt.xlabel('x', fontsize=fs, labelpad=0) |
| 133 | + plt.ylabel('Pressure', fontsize=fs, labelpad=0) |
| 134 | + fig.gca().set_xlim([0, 1.0]) |
| 135 | + fig.gca().set_ylim([-0.5, 1.1]) |
| 136 | + fig.gca().tick_params(axis='both', labelsize=fs) |
| 137 | + plt.legend(loc='upper left', fontsize=fs, prop={'size':fs}) |
95 | 138 | fig.gca().grid() |
96 | | - plt.show() |
97 | | - #plt.gcf().savefig('fwsw-sdc-K'+str(sparams['maxiter'])+'-M'+str(description['num_nodes'])+'.pdf', bbox_inches='tight') |
| 139 | + #plt.show() |
| 140 | + plt.gcf().savefig('fwsw-sdc-K'+str(sparams['maxiter'])+'-M'+str(description['num_nodes'])+'.pdf', bbox_inches='tight') |
0 commit comments