From cb9d637b755d56fe1c6b5b8ee691df389be354f8 Mon Sep 17 00:00:00 2001 From: Daniel Ruprecht Date: Thu, 10 Sep 2015 11:19:58 +0100 Subject: [PATCH 1/3] hook class for boussinesq example now creates images which can be collated into a movie --- examples/boussinesq_2d_imex/HookClass.py | 29 ++++++++++++++--------- examples/boussinesq_2d_imex/playground.py | 14 +++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/boussinesq_2d_imex/HookClass.py b/examples/boussinesq_2d_imex/HookClass.py index df1194b9d6..782233df50 100644 --- a/examples/boussinesq_2d_imex/HookClass.py +++ b/examples/boussinesq_2d_imex/HookClass.py @@ -20,8 +20,8 @@ def __init__(self): # add figure object for further use # self.fig = plt.figure(figsize=(18,6)) - self.fig = plt.figure(figsize=(9,9)) - + self.fig = plt.figure(figsize=(15,5)) + self.counter = 0 def dump_step(self,status): """ @@ -40,23 +40,30 @@ def dump_step(self,status): #plt.ylim([-1.1, 1.1]) #plt.show(block=False) #plt.pause(0.00001) - + + fs = 18 + if True: yplot = self.level.uend.values xx = self.level.prob.xx zz = self.level.prob.zz - self.fig.clear() + #self.fig.clear() levels = [-5e-3, -4e-3, -3e-3, -2e-3, -1e3, 1e-3, 2e-3, 3e-3, 4e-3, 5e-3] CS = plt.contourf(xx, zz, yplot[2,:,:], rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False) # CS = plt.contour(xx, zz, yplot[2,:,:], rstride=1, cstride=1, linewidth=0, antialiased=False) - cbar = plt.colorbar(CS) +# cbar = plt.colorbar(CS) plt.axes().set_xlim(xmin = self.level.prob.x_bounds[0], xmax = self.level.prob.x_bounds[1]) plt.axes().set_ylim(ymin = self.level.prob.z_bounds[0], ymax = self.level.prob.z_bounds[1]) - #plt.axes().set_aspect('equal') - plt.xlabel('x') - plt.ylabel('z') + plt.axes().set_aspect('auto') + plt.xlabel('x in km', fontsize=fs) + plt.ylabel('z in km', fontsize=fs) + plt.tick_params(axis='both', which='major', labelsize=fs) #plt.tight_layout() - plt.show(block=False) - plt.pause(0.00001) - + #plt.show(block=False) + #plt.show() + plt.draw() + plt.gcf().savefig('images/boussinesq-'+"%04d" % self.counter +'.png', bbox_inches='tight') + self.counter = self.counter + 1 + plt.pause(0.001) + return None diff --git a/examples/boussinesq_2d_imex/playground.py b/examples/boussinesq_2d_imex/playground.py index f634b511cd..434b7a1379 100644 --- a/examples/boussinesq_2d_imex/playground.py +++ b/examples/boussinesq_2d_imex/playground.py @@ -36,24 +36,24 @@ swparams['do_LU'] = True sparams = {} - sparams['maxiter'] = 15 + sparams['maxiter'] = 4 # setup parameters "in time" t0 = 0 - Tend = 3 - Nsteps = 1 + Tend = 3000 + Nsteps = 500 dt = Tend/float(Nsteps) # This comes as read-in for the problem class pparams = {} - pparams['nvars'] = [(4,300,10)] + pparams['nvars'] = [(4,450,30)] pparams['u_adv'] = 0.02 pparams['c_s'] = 0.3 pparams['Nfreq'] = 0.01 pparams['x_bounds'] = [(-150.0, 150.0)] pparams['z_bounds'] = [( 0.0, 10.0)] pparams['order'] = [0, 0] # [fine_level, coarse_level] - pparams['gmres_maxiter'] = [50, 5] + pparams['gmres_maxiter'] = [50, 50] pparams['gmres_restart'] = 20 pparams['gmres_tol'] = 1e-14 @@ -90,9 +90,9 @@ print('error at time %s: %9.5e' %(Tend,np.linalg.norm(uex.values[2,:,:].flatten()-uend.values[2,:,:].flatten(),np.inf)/np.linalg.norm( uex.values.flatten(),np.inf))) - P.report_log() + #P.report_log() - plt.show() + #plt.show() # extract_stats = grep_stats(stats,iter=-1,type='residual') # sortedlist_stats = sort_stats(extract_stats,sortby='step') From ff5f4fffcf4a168bd57bae787a0bdc791a6e3ddb Mon Sep 17 00:00:00 2001 From: Daniel Ruprecht Date: Thu, 10 Sep 2015 12:06:51 +0100 Subject: [PATCH 2/3] now printing cfl numbers prior to simulation --- examples/boussinesq_2d_imex/HookClass.py | 2 +- examples/boussinesq_2d_imex/playground.py | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/boussinesq_2d_imex/HookClass.py b/examples/boussinesq_2d_imex/HookClass.py index 782233df50..61c23f085a 100644 --- a/examples/boussinesq_2d_imex/HookClass.py +++ b/examples/boussinesq_2d_imex/HookClass.py @@ -43,7 +43,7 @@ def dump_step(self,status): fs = 18 - if True: + if False: yplot = self.level.uend.values xx = self.level.prob.xx zz = self.level.prob.zz diff --git a/examples/boussinesq_2d_imex/playground.py b/examples/boussinesq_2d_imex/playground.py index 434b7a1379..096de0d3b7 100644 --- a/examples/boussinesq_2d_imex/playground.py +++ b/examples/boussinesq_2d_imex/playground.py @@ -28,7 +28,7 @@ # This comes as read-in for the level class lparams = {} - lparams['restol'] = 1E-12 + lparams['restol'] = 1E-6 swparams = {} swparams['collocation_class'] = collclass.CollGaussLobatto @@ -41,7 +41,7 @@ # setup parameters "in time" t0 = 0 Tend = 3000 - Nsteps = 500 + Nsteps = 250 dt = Tend/float(Nsteps) # This comes as read-in for the problem class @@ -52,10 +52,10 @@ pparams['Nfreq'] = 0.01 pparams['x_bounds'] = [(-150.0, 150.0)] pparams['z_bounds'] = [( 0.0, 10.0)] - pparams['order'] = [0, 0] # [fine_level, coarse_level] - pparams['gmres_maxiter'] = [50, 50] + pparams['order'] = [0] # [fine_level, coarse_level] + pparams['gmres_maxiter'] = [50] pparams['gmres_restart'] = 20 - pparams['gmres_tol'] = 1e-14 + pparams['gmres_tol'] = 1e-6 # This comes as read-in for the transfer operations tparams = {} @@ -80,6 +80,13 @@ # get initial values on finest level P = MS[0].levels[0].prob uinit = P.u_exact(t0) + + cfl_advection = pparams['u_adv']*dt/P.h[0] + cfl_acoustic_hor = pparams['c_s']*dt/P.h[0] + cfl_acoustic_ver = pparams['c_s']*dt/P.h[1] + print ("CFL number of advection: %4.2f" % cfl_advection) + print ("CFL number of acoustics (horizontal): %4.2f" % cfl_acoustic_hor) + print ("CFL number of acoustics (vertical): %4.2f" % cfl_acoustic_ver) # call main function to get things done... uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) From eeda0f21a16174e9f35521b8e49df455b500915f Mon Sep 17 00:00:00 2001 From: Daniel Ruprecht Date: Sat, 12 Sep 2015 13:44:45 +0100 Subject: [PATCH 3/3] added a couple of useful notes to hook class --- examples/boussinesq_2d_imex/HookClass.py | 4 ++++ examples/boussinesq_2d_imex/playground.py | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/boussinesq_2d_imex/HookClass.py b/examples/boussinesq_2d_imex/HookClass.py index 61c23f085a..d435988c94 100644 --- a/examples/boussinesq_2d_imex/HookClass.py +++ b/examples/boussinesq_2d_imex/HookClass.py @@ -66,4 +66,8 @@ def dump_step(self,status): self.counter = self.counter + 1 plt.pause(0.001) + # NOTE: Can use ffmpeg to collate images into movie. + # HELPFUL WEBSITE: http://hamelot.co.uk/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/ + # USEFUL COMMAND: ffmpeg -r 25 -i boussinesq-%04d.jpeg -vcodec libx264 -crf 25 test1800.avi + # WEBSITE TO CONVERT TO MP4: http://video.online-convert.com/convert-to-mp4 return None diff --git a/examples/boussinesq_2d_imex/playground.py b/examples/boussinesq_2d_imex/playground.py index 096de0d3b7..377c67f407 100644 --- a/examples/boussinesq_2d_imex/playground.py +++ b/examples/boussinesq_2d_imex/playground.py @@ -28,7 +28,7 @@ # This comes as read-in for the level class lparams = {} - lparams['restol'] = 1E-6 + lparams['restol'] = 1E-14 swparams = {} swparams['collocation_class'] = collclass.CollGaussLobatto @@ -41,7 +41,9 @@ # setup parameters "in time" t0 = 0 Tend = 3000 - Nsteps = 250 + Nsteps = 500 + Tend = 30 + Nsteps = 5 dt = Tend/float(Nsteps) # This comes as read-in for the problem class @@ -71,8 +73,8 @@ description['sweeper_class'] = imex_1st_order description['level_params'] = lparams description['hook_class'] = plot_solution - description['transfer_class'] = mesh_to_mesh_2d - description['transfer_params'] = tparams + #description['transfer_class'] = mesh_to_mesh_2d + #description['transfer_params'] = tparams # quickly generate block of steps MS = mp.generate_steps(num_procs,sparams,description) @@ -97,10 +99,10 @@ print('error at time %s: %9.5e' %(Tend,np.linalg.norm(uex.values[2,:,:].flatten()-uend.values[2,:,:].flatten(),np.inf)/np.linalg.norm( uex.values.flatten(),np.inf))) - #P.report_log() + P.report_log() #plt.show() - # extract_stats = grep_stats(stats,iter=-1,type='residual') - # sortedlist_stats = sort_stats(extract_stats,sortby='step') - # print(extract_stats,sortedlist_stats) \ No newline at end of file + #extract_stats = grep_stats(stats,iter=-1,type='residual') + #sortedlist_stats = sort_stats(extract_stats,sortby='step') + #print(extract_stats,sortedlist_stats) \ No newline at end of file