|
2 | 2 | from pySDC import CollocationClasses as collclass |
3 | 3 |
|
4 | 4 | import numpy as np |
| 5 | +import scipy.sparse.linalg as LA |
5 | 6 |
|
6 | 7 | from ProblemClass_conv import acoustic_1d_imex |
7 | 8 | from examples.acoustic_1d_imex.HookClass import plot_solution |
|
14 | 15 | from pySDC.Stats import grep_stats, sort_stats |
15 | 16 |
|
16 | 17 | from matplotlib import pyplot as plt |
| 18 | +from pylab import rcParams |
17 | 19 |
|
18 | 20 |
|
19 | 21 | if __name__ == "__main__": |
20 | 22 |
|
| 23 | + fs = 8 |
| 24 | + |
21 | 25 | # set global logger (remove this if you do not want the output at all) |
22 | 26 | logger = Log.setup_custom_logger('root') |
23 | 27 |
|
|
29 | 33 |
|
30 | 34 | sparams = {} |
31 | 35 |
|
32 | | - cs_v = [0.5, 1.0, 1.5] |
33 | | - sparams['maxiter'] = 25 |
34 | | - nodes_v = [2, 3] |
| 36 | + cs_v = [0.5, 1.0, 1.5, 5.0] |
| 37 | + sparams['maxiter'] = 15 |
| 38 | + nodes_v = [3] |
35 | 39 |
|
36 | 40 | residual = np.zeros((np.size(cs_v), np.size(nodes_v), sparams['maxiter'])) |
37 | | - |
38 | | - for cs_ind in np.arange(np.size(cs_v)): |
| 41 | + convrate = np.zeros((np.size(cs_v), np.size(nodes_v), sparams['maxiter']-1)) |
| 42 | + lastiter = np.zeros(( np.size(cs_v), np.size(nodes_v) )) + sparams['maxiter'] |
| 43 | + avg_convrate = np.zeros(( np.size(cs_v), np.size(nodes_v) )) |
| 44 | + |
| 45 | + for cs_ind in range(0,np.size(cs_v)): |
39 | 46 |
|
40 | 47 | # This comes as read-in for the problem class |
41 | 48 | pparams = {} |
|
83 | 90 | for k,v in stats.items(): |
84 | 91 | iter = getattr(k,'iter') |
85 | 92 | if iter is not -1: |
86 | | - residual[cs_ind, nodes_ind, iter-1] = v |
87 | | -# print residual |
| 93 | + residual[cs_ind, nodes_ind, iter-1] = v |
| 94 | + |
| 95 | + # Compute convergence rates |
| 96 | + for iter in range(0,sparams['maxiter']-1): |
| 97 | + if residual[cs_ind, nodes_ind, iter]<lparams['restol']: |
| 98 | + lastiter[cs_ind,nodes_ind] = iter |
| 99 | + else: |
| 100 | + convrate[cs_ind, nodes_ind, iter] = residual[cs_ind, nodes_ind, iter+1]/residual[cs_ind, nodes_ind, iter] |
| 101 | + |
| 102 | + # Compute estimate |
| 103 | + #lambda_fast = LA.eigsh(P.A, k=1, which='LM') |
| 104 | + #lambda_slow = LA.eigsh(P.Dx, k=1, which='LM') |
| 105 | + avg_convrate[cs_ind, nodes_ind] = np.sum(convrate[cs_ind, nodes_ind, :])/float(lastiter[cs_ind,nodes_ind]) |
| 106 | + |
| 107 | + #### end of for loops #### |
| 108 | + |
| 109 | + color = [ 'r', 'b', 'g', 'c' ] |
| 110 | + shape = ['o-', 'd-', 's-', '>-'] |
| 111 | + rcParams['figure.figsize'] = 2.5, 2.5 |
| 112 | + fig = plt.figure() |
| 113 | + for ii in range(0,np.size(cs_v)): |
| 114 | + x = np.arange(1,lastiter[ii,0]) |
| 115 | + y = convrate[ii, 0, 0:lastiter[ii,0]-1] |
| 116 | + plt.plot(x, y, shape[ii], markersize=fs-2, color=color[ii], label=r'$c_{s}$=%4.2f' % cs_v[ii]) |
| 117 | + #plt.plot(x, 0.0*y+avg_convrate[ii,0], '--', color=color[ii]) |
| 118 | + |
| 119 | + plt.legend(loc='upper right', fontsize=fs, prop={'size':fs}) |
| 120 | + plt.xlabel('Iteration', fontsize=fs) |
| 121 | + plt.ylabel('Convergence rate', fontsize=fs, labelpad=2) |
| 122 | + plt.xlim([0, sparams['maxiter']]) |
| 123 | + plt.ylim([0, 0.8]) |
| 124 | + plt.yticks(fontsize=fs) |
| 125 | + plt.xticks(fontsize=fs) |
| 126 | + plt.show() |
| 127 | + fig.savefig('sdc_fwsw_iteration.pdf',bbox_inches='tight') |
88 | 128 |
|
89 | 129 |
|
0 commit comments