From 0c46aed051c5bbc4d88336937a0501a79e35c3fc Mon Sep 17 00:00:00 2001 From: Daniel Ruprecht Date: Tue, 29 Dec 2015 15:59:08 +0100 Subject: [PATCH 1/2] tweaked parameter for convergence plots; use two sine modes as initial data instead of only one --- examples/acoustic_1d_imex/ProblemClass_conv.py | 2 +- examples/acoustic_1d_imex/plotconvdata.py | 10 +++++----- examples/acoustic_1d_imex/runconvergence.py | 12 ++++-------- examples/acoustic_1d_imex/runitererror.py | 14 +++++++------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/examples/acoustic_1d_imex/ProblemClass_conv.py b/examples/acoustic_1d_imex/ProblemClass_conv.py index def5197ac5..761543262f 100644 --- a/examples/acoustic_1d_imex/ProblemClass_conv.py +++ b/examples/acoustic_1d_imex/ProblemClass_conv.py @@ -20,7 +20,7 @@ from buildWave1DMatrix import getWave1DMatrix, getWave1DAdvectionMatrix def u_initial(x, k): - return np.sin(k*2.0*np.pi*x) + return np.sin(k*2.0*np.pi*x) + np.sin(2.0*np.pi*x) class acoustic_1d_imex(ptype): """ diff --git a/examples/acoustic_1d_imex/plotconvdata.py b/examples/acoustic_1d_imex/plotconvdata.py index 67757f98b4..4d67f67cdf 100644 --- a/examples/acoustic_1d_imex/plotconvdata.py +++ b/examples/acoustic_1d_imex/plotconvdata.py @@ -45,17 +45,17 @@ plt.loglog(nsteps_plot[ii,:], error_plot[ii,:], shape[ii], markersize=fs, color=color[ii], label='p='+str(int(order_plot[ii]))) -plt.legend(loc='upper right', fontsize=fs, prop={'size':fs}) +plt.legend(loc='lower left', fontsize=fs, prop={'size':fs}) plt.xlabel('Number of time steps', fontsize=fs) plt.ylabel('Relative error', fontsize=fs, labelpad=2) plt.xlim([0.9*np.min(nsteps_plot), 1.1*np.max(nsteps_plot)]) -plt.ylim([1e-7, 1e1]) -plt.yticks([1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1],fontsize=fs) -plt.xticks([25, 50, 100], fontsize=fs) +plt.ylim([1e-5, 1e0]) +plt.yticks([1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e0],fontsize=fs) +plt.xticks([30, 40, 60, 80], fontsize=fs) plt.gca().get_xaxis().get_major_formatter().labelOnlyBase = False plt.gca().get_xaxis().set_major_formatter(ScalarFormatter()) plt.show() -filename = 'sdc_fwsw_convergence.pdf' +filename = 'sdc-fwsw-convergence.pdf' fig.savefig(filename,bbox_inches='tight') call(["pdfcrop", filename, filename]) diff --git a/examples/acoustic_1d_imex/runconvergence.py b/examples/acoustic_1d_imex/runconvergence.py index 064b70df0c..3386ea56b8 100644 --- a/examples/acoustic_1d_imex/runconvergence.py +++ b/examples/acoustic_1d_imex/runconvergence.py @@ -31,15 +31,11 @@ # This comes as read-in for the problem class pparams = {} - pparams['nvars'] = [(2,400)] - pparams['cadv'] = 0.05 + pparams['nvars'] = [(2,300)] + pparams['cadv'] = 0.1 pparams['cs'] = 1.00 pparams['order_adv'] = 5 - pparams['waveno'] = 2 - - # This comes as read-in for the transfer operations - tparams = {} - tparams['finter'] = True + pparams['waveno'] = 5 # Fill description dictionary for easy hierarchy creation description = {} @@ -53,7 +49,7 @@ description['level_params'] = lparams description['hook_class'] = plot_solution - Nsteps = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] + Nsteps = [30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] for order in [2, 3, 4]: diff --git a/examples/acoustic_1d_imex/runitererror.py b/examples/acoustic_1d_imex/runitererror.py index b06811a22e..0fa58c3dff 100644 --- a/examples/acoustic_1d_imex/runitererror.py +++ b/examples/acoustic_1d_imex/runitererror.py @@ -46,11 +46,11 @@ # This comes as read-in for the problem class pparams = {} - pparams['nvars'] = [(2,250)] - pparams['cadv'] = 0.05 + pparams['nvars'] = [(2,300)] + pparams['cadv'] = 0.1 pparams['cs'] = cs_v[cs_ind] pparams['order_adv'] = 5 - pparams['waveno'] = 1 + pparams['waveno'] = 5 # This comes as read-in for the transfer operations tparams = {} @@ -72,7 +72,7 @@ for nodes_ind in np.arange(np.size(nodes_v)): # setup parameters "in time" t0 = 0 - Tend = 0.05 + Tend = 0.025 description['num_nodes'] = nodes_v[nodes_ind] # quickly generate block of steps @@ -119,15 +119,15 @@ plt.plot(x, y, shape[ii], markersize=fs-2, color=color[ii], label=r'$C_{\rm fast}$=%4.2f' % (cs_v[ii]*dt/P.dx)) #plt.plot(x, 0.0*y+avg_convrate[ii,0], '--', color=color[ii]) - plt.legend(loc='upper right', fontsize=fs, prop={'size':fs}) + plt.legend(loc='upper right', fontsize=fs, prop={'size':fs-2}) plt.xlabel('Iteration', fontsize=fs) plt.ylabel(r'$|| r^{k+1} ||_{\infty}/|| r^k ||_{\infty}$', fontsize=fs, labelpad=2) plt.xlim([0, sparams['maxiter']]) - plt.ylim([0, 0.8]) + plt.ylim([0, 1.0]) plt.yticks(fontsize=fs) plt.xticks(fontsize=fs) plt.show() - filename = 'sdc_fwsw_iteration.pdf' + filename = 'sdc-fwsw-iteration.pdf' fig.savefig(filename,bbox_inches='tight') call(["pdfcrop", filename, filename]) From d506f96ccd898daa206359ecb0196bf6f588e2bf Mon Sep 17 00:00:00 2001 From: Daniel Ruprecht Date: Tue, 29 Dec 2015 16:45:36 +0100 Subject: [PATCH 2/2] added convergence plot script for scalar test problem to make sure order there is exactly equal to number of iterations K --- examples/fwsw/run_convergence.py | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/fwsw/run_convergence.py diff --git a/examples/fwsw/run_convergence.py b/examples/fwsw/run_convergence.py new file mode 100644 index 0000000000..a54c865da8 --- /dev/null +++ b/examples/fwsw/run_convergence.py @@ -0,0 +1,73 @@ +from __future__ import print_function + +from pySDC import CollocationClasses as collclass + +import numpy as np +import matplotlib.pyplot as plt + +from examples.fwsw.ProblemClass import swfw_scalar +from pySDC.datatype_classes.complex_mesh import mesh, rhs_imex_mesh +from pySDC.sweeper_classes.imex_1st_order import imex_1st_order +import pySDC.PFASST_stepwise as mp +from pySDC import Log + + + +if __name__ == "__main__": + + # set global logger (remove this if you do not want the output at all) + logger = Log.setup_custom_logger('root') + + num_procs = 1 + + # This comes as read-in for the level class + lparams = {} + lparams['restol'] = 1E-12 + + sparams = {} + sparams['maxiter'] = 4 + + # This comes as read-in for the problem class + pparams = {} + pparams['lambda_s'] = np.array([0.1j], dtype='complex') + pparams['lambda_f'] = np.array([1.0j], dtype='complex') + pparams['u0'] = 1 + + # Fill description dictionary for easy hierarchy creation + description = {} + description['problem_class'] = swfw_scalar + description['problem_params'] = pparams + description['dtype_u'] = mesh + description['dtype_f'] = rhs_imex_mesh + description['collocation_class'] = collclass.CollGaussLegendre + description['num_nodes'] = [3] + description['do_LU'] = False + description['sweeper_class'] = imex_1st_order + description['level_params'] = lparams + + # quickly generate block of steps + MS = mp.generate_steps(num_procs,sparams,description) + + Nsteps_v = np.array([1, 2, 4, 8, 10, 15, 20]) + Tend = 1.0 + t0 = 0 + + P = MS[0].levels[0].prob + uinit = P.u_exact(t0) + uex = P.u_exact(Tend) + error = np.zeros(np.size(Nsteps_v)) + convline = np.zeros(np.size(Nsteps_v)) + + for j in range(0,np.size(Nsteps_v)): + # setup parameters "in time" + dt = Tend/float(Nsteps_v[j]) + + # call main function to get things done... + uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) + error[j] = np.abs(uend.values - uex.values) + convline[j] = error[j]*(float(Nsteps_v[j])/float(Nsteps_v[j]))**sparams['maxiter'] + + plt.figure() + plt.loglog(Nsteps_v, error, 'bo', markersize=12) + plt.loglog(Nsteps_v, convline, '-', color='k') + plt.show() \ No newline at end of file