Skip to content

Commit 02f1a2d

Browse files
committed
Merge pull request #59 from danielru/add/beautify_stabilityplot
Nicer stability plot
2 parents 5ca8a02 + 4299f74 commit 02f1a2d

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

examples/fwsw/plot_stability.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010

1111
from pylab import rcParams
1212
import matplotlib.pyplot as plt
13+
from matplotlib.patches import Polygon
1314
from subprocess import call
1415

1516
if __name__ == "__main__":
1617

1718
N_s = 100
1819
N_f = 400
19-
20-
lambda_s = 1j*np.linspace(0.0, 2.0, N_s)
21-
lambda_f = 1j*np.linspace(2.0, 8.0, N_f)
20+
21+
lam_s_max = 5.0
22+
lam_f_max = 12.0
23+
lambda_s = 1j*np.linspace(0.0, lam_s_max, N_s)
24+
lambda_f = 1j*np.linspace(0.0, lam_f_max, N_f)
2225

2326
pparams = {}
2427
# the following are not used in the computation
2528
pparams['lambda_s'] = np.array([0.0])
2629
pparams['lambda_f'] = np.array([0.0])
2730
pparams['u0'] = 1.0
2831
swparams = {}
29-
swparams['collocation_class'] = collclass.CollGaussLobatto
30-
swparams['num_nodes'] = 4
31-
K = 5
32+
swparams['collocation_class'] = collclass.CollGaussLegendre
33+
swparams['num_nodes'] = 2
34+
K = 3
35+
do_coll_update = True
3236

3337
#
3438
# ...this is functionality copied from test_imexsweeper. Ideally, it should be available in one place.
@@ -61,7 +65,13 @@
6165
Mat_sweep = np.linalg.matrix_power(Pinv.dot(RHS), K)
6266
for k in range(0,K):
6367
Mat_sweep = Mat_sweep + np.linalg.matrix_power(Pinv.dot(RHS),k).dot(Pinv)
68+
if do_coll_update:
6469
stab_fh = 1.0 + (lambda_fast + lambda_slow)*level.sweep.coll.weights.dot(Mat_sweep.dot(np.ones(nnodes)))
70+
else:
71+
q = np.zeros(nnodes)
72+
q[nnodes-1] = 1.0
73+
stab_fh = q.dot(Mat_sweep.dot(np.ones(nnodes)))
74+
#
6575
stab[j,i] = stab_fh
6676

6777
###
@@ -70,19 +80,24 @@
7080
fig = plt.figure()
7181
#pcol = plt.pcolor(lambda_s.imag, lambda_f.imag, np.absolute(stab), vmin=0.99, vmax=2.01)
7282
#pcol.set_edgecolor('face')
73-
levels = np.array([0.95, 0.99, 1.01, 1.05])
83+
levels = np.array([0.25, 0.5, 0.75, 0.9, 1.1])
7484
# levels = np.array([1.0])
75-
CS1 = plt.contour(lambda_s.imag, lambda_f.imag, np.absolute(stab), levels, colors='k',linestyles='dashed')
76-
CS2 = plt.contour(lambda_s.imag, lambda_f.imag, np.absolute(stab), [1.0], colors='k')
77-
plt.clabel(CS1, fontsize=fs-2)
78-
plt.clabel(CS2, fontsize=fs-2)
79-
#plt.plot([0, 2], [0, 2], color='k', linewidth=1)
80-
plt.gca().set_xticks([0.0, 1.0, 2.0, 3.0])
85+
CS1 = plt.contour(lambda_s.imag, lambda_f.imag, np.absolute(stab), levels, colors='k', linestyles='dashed')
86+
CS2 = plt.contour(lambda_s.imag, lambda_f.imag, np.absolute(stab), [1.0], colors='k')
87+
plt.clabel(CS1, inline=True, fmt='%3.2f', fontsize=fs-2)
88+
manual_locations = [(1.5, 2.5)]
89+
plt.clabel(CS2, inline=True, fmt='%3.2f', fontsize=fs-2, manual=manual_locations)
90+
plt.gca().add_patch(Polygon([[0, 0], [lam_s_max,0], [lam_s_max,lam_s_max]], visible=True, fill=True, facecolor='.75',edgecolor='k', linewidth=1.0, zorder=11))
91+
#plt.plot([0, 2], [0, 2], color='k', linewidth=1, zorder=12)
92+
plt.gca().set_xticks(np.arange(0, int(lam_s_max)+1))
93+
plt.gca().set_yticks(np.arange(0, int(lam_f_max)+2, 2))
8194
plt.gca().tick_params(axis='both', which='both', labelsize=fs)
82-
plt.xlim([np.min(lambda_s.imag), np.max(lambda_s.imag)])
95+
plt.xlim([0.0, lam_s_max])
96+
plt.ylim([0.0, lam_f_max])
8397
plt.xlabel('$\Delta t \lambda_{slow}$', fontsize=fs, labelpad=2.0)
8498
plt.ylabel('$\Delta t \lambda_{fast}$', fontsize=fs)
8599
plt.title(r'$M=%1i$, $K=%1i$' % (swparams['num_nodes'],K), fontsize=fs)
100+
#plt.show()
86101
filename = 'sdc-fwsw-stability-K'+str(K)+'-M'+str(swparams['num_nodes'])+'.pdf'
87102
fig.savefig(filename, bbox_inches='tight')
88103
call(["pdfcrop", filename, filename])

0 commit comments

Comments
 (0)