description['transfer_params'] = tparams # quickly generate block of steps MS = mp.generate_steps(num_procs,sparams,description) # setup parameters "in time" t0 = MS[0].levels[0].prob.t0 dt = 0.5 Tend = 8*dt # get initial values on finest level P = MS[0].levels[0].prob uinit = P.u_exact(t0) # call main function to get things done... uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) # df.plot(uend.values,interactive=True) # compute exact solution and compare uex = P.u_exact(Tend) print('(classical) error at time %s: %s' %(Tend,abs(uex-uend)/abs(uex))) uex = df.Expression('sin(a*x[0]) * cos(t)',a=np.pi,t=Tend) print('(fenics-style) error at time %s: %s' %(Tend,df.errornorm(uex,uend.values))) extract_stats = grep_stats(stats,iter=-1,type='residual') sortedlist_stats = sort_stats(extract_stats,sortby='step') print(extract_stats,sortedlist_stats)
# setup parameters "in time" t0 = 0 dt = 1/16*np.pi Tend = 16*dt#np.pi # get initial values on finest level P = MS[0].levels[0].prob uinit = P.u_exact(t0) print('Init:',uinit.pos.values,uinit.vel.values) # call main function to get things done... uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) extract_stats = grep_stats(stats,type='energy') sortedlist_stats = sort_stats(extract_stats,sortby='time') R0 = np.linalg.norm(uinit.pos.values[:]) H0 = 1/2*np.dot(uinit.vel.values[:],uinit.vel.values[:])+0.02/R0 energy_err = [abs(entry[1]-H0)/H0 for entry in sortedlist_stats] fig = plt.figure() plt.plot(energy_err,'bo--') plt.show() # rc('text', usetex=True) # rc('font', family='serif', size=20) # rc('legend', fontsize='small') # rc('xtick', labelsize='small')
MS = mp.generate_steps(num_procs, sparams, description) # setup parameters "in time" t0 = 0 dt = 0.1 Tend = 2 P = MS[0].levels[0].prob uinit = P.u_exact(t0) print('Init:', uinit.values) # call main function to get things done... uend, stats = mp.run_pfasst_serial(MS, u0=uinit, t0=t0, dt=dt, Tend=Tend) # get stats and error extract_stats = grep_stats(stats, type='niter') sortedlist_stats = sort_stats(extract_stats, sortby='time') uex = P.u_exact(Tend) print( 'Error:', np.linalg.norm(uex.values - uend.values, np.inf) / np.linalg.norm(uex.values, np.inf)) print('Min/Max/Sum number of iterations: %s/%s/%s' % (min(entry[1] for entry in sortedlist_stats), max(entry[1] for entry in sortedlist_stats), sum(entry[1] for entry in sortedlist_stats)))
description['num_nodes'] = 3 description['sweeper_class'] = imex_1st_order description['level_params'] = lparams description['transfer_class'] = mesh_to_mesh_1d description['transfer_params'] = tparams # quickly generate block of steps MS = mp.generate_steps(num_procs, sparams, description) # setup parameters "in time" t0 = 0 dt = 0.125 Tend = 4 * dt # get initial values on finest level P = MS[0].levels[0].prob uinit = P.u_exact(t0) # call main function to get things done... uend, stats = mp.run_pfasst_serial(MS, u0=uinit, t0=t0, dt=dt, Tend=Tend) # compute exact solution and compare uex = P.u_exact(Tend) print('error at time %s: %s' % (Tend, np.linalg.norm(uex.values - uend.values, np.inf) / np.linalg.norm(uex.values, np.inf))) extract_stats = grep_stats(stats, iter=-1, type='residual') sortedlist_stats = sort_stats(extract_stats, sortby='step') print(extract_stats, sortedlist_stats)
# quickly generate block of steps MS = mp.generate_steps(num_procs,sparams,description) # setup parameters "in time" t0 = 0 dt = 0.1 Tend = 4*dt # get initial values on finest level P = MS[0].levels[0].prob uinit = P.u_exact(t0) # call main function to get things done... uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend) # compute exact solution and compare uex = P.u_exact(Tend) print('error at time %s: %s' %(Tend,np.linalg.norm(uex.values-uend.values,np.inf)/np.linalg.norm( uex.values,np.inf))) # Get residual at last step (being the max of all residuals.. most likely) on the fine level extract_stats = grep_stats(stats,step=3,level=-1,type='residual') sortedlist_stats = sort_stats(extract_stats,sortby='iter')[1:] # remove '-1' entry print(sortedlist_stats) # Get the error against the analytical solution at the last step extract_stats = grep_stats(stats,step=3,level=-1,type='error') sortedlist_stats = sort_stats(extract_stats,sortby='iter') print(sortedlist_stats)
# setup parameters "in time" t0 = 0 dt = 0.1 Tend = 2 P = MS[0].levels[0].prob uinit = P.u_exact(t0) print("Init:", uinit.values) # call main function to get things done... uend, stats = mp.run_pfasst(MS, u0=uinit, t0=t0, dt=dt, Tend=Tend) # get stats and error extract_stats = grep_stats(stats, type="niter") sortedlist_stats = sort_stats(extract_stats, sortby="time") uex = P.u_exact(Tend) print("Error:", np.linalg.norm(uex.values - uend.values, np.inf) / np.linalg.norm(uex.values, np.inf)) print( "Min/Max/Sum number of iterations: %s/%s/%s" % ( min(entry[1] for entry in sortedlist_stats), max(entry[1] for entry in sortedlist_stats), sum(entry[1] for entry in sortedlist_stats), ) )