Skip to content

Commit

Permalink
Merge pull request #71 from danielru/fix/plots_readibility
Browse files Browse the repository at this point in the history
Fix/plots readibility
  • Loading branch information
pancetta committed Feb 2, 2016
2 parents 15e3a7d + b735a53 commit 77fcc92
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
14 changes: 7 additions & 7 deletions examples/acoustic_1d_imex/plot_dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def findomega(stab_fh):
swparams = {}
swparams['collocation_class'] = collclass.CollGaussLegendre
swparams['num_nodes'] = 3
K = 5
K = 4
dirk_order = K

c_speed = 1.0
Expand Down Expand Up @@ -128,14 +128,14 @@ def findomega(stab_fh):
fig = plt.figure()
plt.plot(k_vec, (U_speed+c_speed)+np.zeros(np.size(k_vec)), '--', color='k', linewidth=1.5, label='Exact')
plt.plot(k_vec, phase[1,:], '-', color='g', linewidth=1.5, label='DIRK('+str(dirkts.order)+')')
plt.plot(k_vec, phase[2,:], '-', color='r', linewidth=1.5, label='RK-IMEX('+str(rkimex.order)+')')
plt.plot(k_vec, phase[0,:], '-', color='b', linewidth=1.5, label='SDC('+str(K)+')')
plt.plot(k_vec, phase[2,:], '-+', color='r', linewidth=1.5, label='RK-IMEX('+str(rkimex.order)+')', markevery=5, mew=1.0)
plt.plot(k_vec, phase[0,:], '-o', color='b', linewidth=1.5, label='SDC('+str(K)+')', markevery=5, markersize=fs/2)
plt.xlabel('Wave number', fontsize=fs, labelpad=0.25)
plt.ylabel('Phase speed', fontsize=fs, labelpad=0.5)
plt.xlim([k_vec[0], k_vec[-1:]])
plt.ylim([0.0, 1.1*(U_speed+c_speed)])
fig.gca().tick_params(axis='both', labelsize=fs)
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs})
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs-2})
plt.xticks([0, 1, 2, 3], fontsize=fs)
#plt.show()
filename = 'sdc-fwsw-disprel-phase-K'+str(K)+'-M'+str(swparams['num_nodes'])+'.pdf'
Expand All @@ -145,14 +145,14 @@ def findomega(stab_fh):
fig = plt.figure()
plt.plot(k_vec, 1.0+np.zeros(np.size(k_vec)), '--', color='k', linewidth=1.5, label='Exact')
plt.plot(k_vec, amp_factor[1,:], '-', color='g', linewidth=1.5, label='DIRK('+str(dirkts.order)+')')
plt.plot(k_vec, amp_factor[2,:], '-', color='r', linewidth=1.5, label='RK-IMEX('+str(rkimex.order)+')')
plt.plot(k_vec, amp_factor[0,:], '-', color='b', linewidth=1.5, label='SDC('+str(K)+')')
plt.plot(k_vec, amp_factor[2,:], '-+', color='r', linewidth=1.5, label='RK-IMEX('+str(rkimex.order)+')', markevery=5, mew=1.0)
plt.plot(k_vec, amp_factor[0,:], '-o', color='b', linewidth=1.5, label='SDC('+str(K)+')', markevery=5, markersize=fs/2)
plt.xlabel('Wave number', fontsize=fs, labelpad=0.25)
plt.ylabel('Amplification factor', fontsize=fs, labelpad=0.5)
fig.gca().tick_params(axis='both', labelsize=fs)
plt.xlim([k_vec[0], k_vec[-1:]])
plt.ylim([k_vec[0], k_vec[-1:]])
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs})
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs-2})
plt.gca().set_ylim([0.0, 1.1])
plt.xticks([0, 1, 2, 3], fontsize=fs)
#plt.show()
Expand Down
37 changes: 27 additions & 10 deletions examples/acoustic_1d_imex/runmultiscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
lparams['restol'] = 1E-10

sparams = {}
sparams['maxiter'] = 2
sparams['maxiter'] = 4

# setup parameters "in time"
t0 = 0.0
Expand All @@ -59,7 +59,7 @@
description['dtype_f'] = rhs_imex_mesh
description['collocation_class'] = collclass.CollGaussLegendre
# Number of nodes
description['num_nodes'] = 2
description['num_nodes'] = 3
description['sweeper_class'] = imex_1st_order
description['level_params'] = lparams
description['hook_class'] = plot_solution
Expand Down Expand Up @@ -118,7 +118,7 @@
unew_dirk, pnew_dirk = np.split(ynew_dirk, 2)
unew_imex, pnew_imex = np.split(ynew_imex, 2)

rcParams['figure.figsize'] = 5, 2.5
rcParams['figure.figsize'] = 2.5, 2.5
fig = plt.figure()

sigma_0 = 0.1
Expand All @@ -131,24 +131,41 @@
print ('Maximum pressure in RK-IMEX: %5.3e' % np.linalg.norm(pnew_imex, np.inf))

#plt.plot(P.mesh, pnew_tp, '-', color='c', label='Trapezoidal')
plt.plot(P.mesh, pnew_imex, '-', color='c', label='IMEX('+str(rkimex.order)+')')
plt.plot(P.mesh, uend.values[1,:], '--', color='b', label='SDC('+str(sparams['maxiter'])+')')
plt.plot(P.mesh, pnew_bdf, '-', color='r', label='BDF-2')
plt.plot(P.mesh, pnew_dirk, color='g', label='DIRK('+str(dirk.order)+')')
if dirk.order==2:
plt.plot(P.mesh, pnew_bdf, 'd-', color='c', label='BDF-2',markevery=(50,75))
p_slow = np.exp(-np.square( np.mod( P.mesh-pparams['cadv']*Tend, 1.0 ) -x_0 )/(sigma_0*sigma_0))
plt.plot(P.mesh, p_slow, '--', color='k', markersize=fs-2, label='Slow mode', dashes=(10,2))
if np.linalg.norm(pnew_imex, np.inf)<=2:
plt.plot(P.mesh, pnew_imex, '+-', color='r', label='IMEX('+str(rkimex.order)+')',markevery=(1,75),mew=1.0)
plt.plot(P.mesh, uend.values[1,:], 'o-', color='b', label='SDC('+str(sparams['maxiter'])+')',markevery=(25,75))
plt.plot(P.mesh, pnew_dirk, '-', color='g', label='DIRK('+str(dirk.order)+')')
#plt.plot(P.mesh, uex.values[1,:], '+', color='r', label='p (exact)')
#plt.plot(P.mesh, uend.values[1,:], '-', color='b', linewidth=2.0, label='p (SDC)')

p_slow = np.exp(-np.square( np.mod( P.mesh-pparams['cadv']*Tend, 1.0 ) -x_0 )/(sigma_0*sigma_0))
plt.plot(P.mesh, p_slow, '+', color='k', markersize=fs-2, label='Slow mode', markevery=10)
plt.xlabel('x', fontsize=fs, labelpad=0)
plt.ylabel('Pressure', fontsize=fs, labelpad=0)
fig.gca().set_xlim([0, 1.0])
fig.gca().set_ylim([-0.5, 1.1])
fig.gca().tick_params(axis='both', labelsize=fs)
plt.legend(loc='upper left', fontsize=fs, prop={'size':fs})
plt.legend(loc='upper left', fontsize=fs, prop={'size':fs}, handlelength=3)
fig.gca().grid()
#plt.show()
filename = 'sdc-fwsw-multiscale-K'+str(sparams['maxiter'])+'-M'+str(description['num_nodes'])+'.pdf'
plt.gcf().savefig(filename, bbox_inches='tight')
call(["pdfcrop", filename, filename])

#plt.plot(P.mesh, uend.values[1,:], '-', color='b', linewidth=2.0, label='p (SDC)')

fig = plt.figure()
p_slow = np.exp(-np.square( np.mod( P.mesh-pparams['cadv']*Tend, 1.0 ) -x_0 )/(sigma_0*sigma_0))
plt.plot(P.mesh, uinit.values[1,:], '-', color='b')
plt.xlabel('x', fontsize=fs, labelpad=0)
plt.ylabel('Pressure', fontsize=fs, labelpad=0)
fig.gca().set_xlim([0, 1.0])
fig.gca().set_ylim([-0.5, 1.1])
fig.gca().tick_params(axis='both', labelsize=fs)
fig.gca().grid()
#plt.show()
filename = 'sdc-fwsw-multiscale-initial.pdf'
plt.gcf().savefig(filename, bbox_inches='tight')
call(["pdfcrop", filename, filename])
4 changes: 2 additions & 2 deletions examples/fwsw/plot_stifflimit_specrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
rcParams['figure.figsize'] = 2.5, 2.5
fig = plt.figure()
plt.plot(nodes_v, specrad[0,:], 'rd-', markersize=fs-2, label=r'$\lambda_{\rm fast} = \infty$')
plt.plot(nodes_v, specrad[1,:], 'bo-', markersize=fs-2, label=r'$\lambda_{\rm fast} = %2.0f i$' % problem.lambda_f[0].imag)
plt.plot(nodes_v, specrad[1,:], 'bo-', markersize=fs-2, label=r'$\lambda_{\rm fast} = %2.0f $' % problem.lambda_f[0].imag)
plt.xlabel(r'Number of nodes $M$', fontsize=fs)
plt.ylabel(r'Spectral radius $\sigma\left( \mathbf{E} \right)$', fontsize=fs, labelpad=2)
#plt.title(r'$\Delta t \left| \lambda_{\rm slow} \right|$ = %2.1f' % step.status.dt*abs(problem.lambda_s[0]), fontsize=fs)
Expand All @@ -83,7 +83,7 @@

fig = plt.figure()
plt.plot(nodes_v, norm[0,:], 'rd-', markersize=fs-2, label=r'$\lambda_{\rm fast} = \infty$')
plt.plot(nodes_v, norm[1,:], 'bo-', markersize=fs-2, label=r'$\lambda_{\rm fast} = %2.0f i$' % problem.lambda_f[0].imag)
plt.plot(nodes_v, norm[1,:], 'bo-', markersize=fs-2, label=r'$\lambda_{\rm fast} = %2.0f $' % problem.lambda_f[0].imag)
plt.xlabel(r'Number of nodes $M$', fontsize=fs)
plt.ylabel(r'Norm $\left|| \mathbf{E} \right||_{\infty}$', fontsize=fs, labelpad=2)
#plt.title(r'$\Delta t \left| \lambda_{\rm slow} \right|$ = %2.1f' % step.status.dt*abs(problem.lambda_s[0]), fontsize=fs)
Expand Down

0 comments on commit 77fcc92

Please sign in to comment.