|
| 1 | + |
| 2 | +from pySDC import CollocationClasses as collclass |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from ProblemClass import boussinesq_2d_imex |
| 7 | +from examples.boussinesq_2d_imex.TransferClass import mesh_to_mesh_2d |
| 8 | +from examples.boussinesq_2d_imex.HookClass import plot_solution |
| 9 | + |
| 10 | +from pySDC.datatype_classes.mesh import mesh, rhs_imex_mesh |
| 11 | +from pySDC.sweeper_classes.imex_1st_order import imex_1st_order |
| 12 | +import pySDC.PFASST_stepwise as mp |
| 13 | +from pySDC import Log |
| 14 | +from pySDC.Stats import grep_stats, sort_stats |
| 15 | + |
| 16 | +from matplotlib import pyplot as plt |
| 17 | +from mpl_toolkits.mplot3d import Axes3D |
| 18 | +from matplotlib import cm |
| 19 | +from matplotlib.ticker import LinearLocator, FormatStrFormatter |
| 20 | +from pylab import rcParams |
| 21 | + |
| 22 | +from unflatten import unflatten |
| 23 | + |
| 24 | +from standard_integrators import dirk |
| 25 | + |
| 26 | +if __name__ == "__main__": |
| 27 | + |
| 28 | + # set global logger (remove this if you do not want the output at all) |
| 29 | + logger = Log.setup_custom_logger('root') |
| 30 | + |
| 31 | + num_procs = 1 |
| 32 | + |
| 33 | + # This comes as read-in for the level class |
| 34 | + lparams = {} |
| 35 | + lparams['restol'] = 1E-15 |
| 36 | + |
| 37 | + swparams = {} |
| 38 | + swparams['collocation_class'] = collclass.CollGaussLobatto |
| 39 | + swparams['num_nodes'] = 3 |
| 40 | + swparams['do_LU'] = False |
| 41 | + |
| 42 | + sparams = {} |
| 43 | + sparams['maxiter'] = 3 |
| 44 | + |
| 45 | + dirk_order = 2 |
| 46 | + |
| 47 | + # setup parameters "in time" |
| 48 | + t0 = 0 |
| 49 | + Tend = 3000 |
| 50 | + Nsteps = 500 |
| 51 | + #Tend = 30 |
| 52 | + #Nsteps = 5 |
| 53 | + dt = Tend/float(Nsteps) |
| 54 | + |
| 55 | + # This comes as read-in for the problem class |
| 56 | + pparams = {} |
| 57 | + pparams['nvars'] = [(4,300,20)] |
| 58 | + #pparams['nvars'] = [(4,150,10)] |
| 59 | + pparams['u_adv'] = 0.02 |
| 60 | + pparams['c_s'] = 0.3 |
| 61 | + pparams['Nfreq'] = 0.01 |
| 62 | + pparams['x_bounds'] = [(-150.0, 150.0)] |
| 63 | + pparams['z_bounds'] = [( 0.0, 10.0)] |
| 64 | + pparams['order'] = [4] # [fine_level, coarse_level] |
| 65 | + pparams['order_upw'] = [5] |
| 66 | + pparams['gmres_maxiter'] = [500] |
| 67 | + pparams['gmres_restart'] = [10] |
| 68 | + pparams['gmres_tol'] = [1e-6] |
| 69 | + |
| 70 | + # This comes as read-in for the transfer operations |
| 71 | + tparams = {} |
| 72 | + tparams['finter'] = False |
| 73 | + |
| 74 | + # Fill description dictionary for easy hierarchy creation |
| 75 | + description = {} |
| 76 | + description['problem_class'] = boussinesq_2d_imex |
| 77 | + description['problem_params'] = pparams |
| 78 | + description['dtype_u'] = mesh |
| 79 | + description['dtype_f'] = rhs_imex_mesh |
| 80 | + description['sweeper_params'] = swparams |
| 81 | + description['sweeper_class'] = imex_1st_order |
| 82 | + description['level_params'] = lparams |
| 83 | + description['hook_class'] = plot_solution |
| 84 | + |
| 85 | + # quickly generate block of steps |
| 86 | + MS = mp.generate_steps(num_procs,sparams,description) |
| 87 | + |
| 88 | + # get initial values on finest level |
| 89 | + P = MS[0].levels[0].prob |
| 90 | + uinit = P.u_exact(t0) |
| 91 | + |
| 92 | + cfl_advection = pparams['u_adv']*dt/P.h[0] |
| 93 | + cfl_acoustic_hor = pparams['c_s']*dt/P.h[0] |
| 94 | + cfl_acoustic_ver = pparams['c_s']*dt/P.h[1] |
| 95 | + print ("CFL number of advection: %4.2f" % cfl_advection) |
| 96 | + print ("CFL number of acoustics (horizontal): %4.2f" % cfl_acoustic_hor) |
| 97 | + print ("CFL number of acoustics (vertical): %4.2f" % cfl_acoustic_ver) |
| 98 | + |
| 99 | + dirk = dirk(P, dirk_order) |
| 100 | + u0 = uinit.values.flatten() |
| 101 | + |
| 102 | + for i in range(0,Nsteps): |
| 103 | + u0 = dirk.timestep(u0, dt) |
| 104 | + |
| 105 | + # call main function to get things done... |
| 106 | + uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) |
| 107 | + |
| 108 | + u0 = unflatten(u0, 4, P.N[0], P.N[1]) |
| 109 | + |
| 110 | + fs = 8 |
| 111 | + rcParams['figure.figsize'] = 5.0, 2.5 |
| 112 | + fig = plt.figure() |
| 113 | + |
| 114 | + plt.plot(P.xx[:,5], uend.values[2,:,5], '-', color='b', label='SDC') |
| 115 | + plt.plot(P.xx[:,5], u0[2,:,5], '+', color='g', markevery=5, markersize=fs-2, label='DIRK') |
| 116 | + plt.legend(loc='lower left', fontsize=fs, prop={'size':fs}) |
| 117 | + plt.yticks(fontsize=fs) |
| 118 | + plt.xticks(fontsize=fs) |
| 119 | + plt.xlabel('x', fontsize=fs, labelpad=0) |
| 120 | + plt.ylabel('Bouyancy', fontsize=fs, labelpad=1) |
| 121 | + #plt.show() |
| 122 | + plt.savefig('boussinesq.pdf', bbox_inches='tight') |
| 123 | + |
| 124 | + print " #### Logging report for DIRK #### " |
| 125 | + print "Number of calls to implicit solver: %5i" % dirk.logger.solver_calls |
| 126 | + print "Total number of GMRES iterations: %5i" % dirk.logger.iterations |
| 127 | + print "Average number of iterations per call: %6.3f" % (float(dirk.logger.iterations)/float(dirk.logger.solver_calls)) |
| 128 | + |
| 129 | + print " #### Logging report for SDC #### " |
| 130 | + print "Number of calls to implicit solver: %5i" % P.logger.solver_calls |
| 131 | + print "Total number of GMRES iterations: %5i" % P.logger.iterations |
| 132 | + print "Average number of iterations per call: %6.3f" % (float(P.logger.iterations)/float(P.logger.solver_calls)) |
0 commit comments