[docs]definitialize(self):""" Initialize the grid and variables for advection and set the initial conditions for the chosen problem. """# create grid, self.rp contains mesh.nx and mesh.nymy_grid=grid_setup(self.rp,ng=4)# create the variablesmy_data=patch.CellCenterData2d(my_grid)# outputs: bc, bc_xodd and bc_yodd for reflection boundary condbc=bc_setup(self.rp)[0]# register variables in the data# burgers equation advects velocitymy_data.register_var("x-velocity",bc)my_data.register_var("y-velocity",bc)my_data.create()# holds various data, like time and registered variable.self.cc_data=my_dataifself.rp.get_param("particles.do_particles")==1:n_particles=self.rp.get_param("particles.n_particles")particle_generator=self.rp.get_param("particles.particle_generator")self.particles=particles.Particles(self.cc_data,bc,n_particles,particle_generator)# now set the initial conditions for the problemself.problem_func(self.cc_data,self.rp)
[docs]defmethod_compute_timestep(self):""" The timestep() function computes the advective timestep (CFL) constraint. The CFL constraint says that information cannot propagate further than one zone per timestep. We use the driver.cfl parameter to control what fraction of the CFL step we actually take. """cfl=self.rp.get_param("driver.cfl")u=self.cc_data.get_var("x-velocity")v=self.cc_data.get_var("y-velocity")# the timestep is min(dx/|u|, dy|v|)xtmp=self.cc_data.grid.dx/max(abs(u).max(),self.SMALL)ytmp=self.cc_data.grid.dy/max(abs(v).max(),self.SMALL)self.dt=cfl*min(xtmp,ytmp)
[docs]defevolve(self):""" Evolve the burgers equation through one timestep. """myg=self.cc_data.griddtdx=self.dt/myg.dxdtdy=self.dt/myg.dyu=self.cc_data.get_var("x-velocity")v=self.cc_data.get_var("y-velocity")# --------------------------------------------------------------------------# monotonized central differences# --------------------------------------------------------------------------limiter=self.rp.get_param("advection.limiter")# Give da/dx and da/dy using input: (state, grid, direction, limiter)ldelta_ux=reconstruction.limit(u,myg,1,limiter)ldelta_uy=reconstruction.limit(u,myg,2,limiter)ldelta_vx=reconstruction.limit(v,myg,1,limiter)ldelta_vy=reconstruction.limit(v,myg,2,limiter)# Get u, v fluxesu_xl,u_xr,u_yl,u_yr,v_xl,v_xr,v_yl,v_yr=burgers_interface.get_interface_states(myg,self.dt,u,v,ldelta_ux,ldelta_vx,ldelta_uy,ldelta_vy)u_xl,u_xr,u_yl,u_yr,v_xl,v_xr,v_yl,v_yr=burgers_interface.apply_transverse_corrections(myg,self.dt,u_xl,u_xr,u_yl,u_yr,v_xl,v_xr,v_yl,v_yr)u_flux_x,u_flux_y,v_flux_x,v_flux_y=burgers_interface.construct_unsplit_fluxes(myg,u_xl,u_xr,u_yl,u_yr,v_xl,v_xr,v_yl,v_yr)""" do the differencing for the fluxes now. Here, we use slices so we avoid slow loops in python. This is equivalent to: myPatch.data[i,j] = myPatch.data[i,j] + \ dtdx*(flux_x[i,j] - flux_x[i+1,j]) + \ dtdy*(flux_y[i,j] - flux_y[i,j+1]) """u.v()[:,:]=u.v()+dtdx*(u_flux_x.v()-u_flux_x.ip(1))+ \
dtdy*(u_flux_y.v()-u_flux_y.jp(1))v.v()[:,:]=v.v()+dtdx*(v_flux_x.v()-v_flux_x.ip(1))+ \
dtdy*(v_flux_y.v()-v_flux_y.jp(1))ifself.particlesisnotNone:u2d=uv2d=vself.particles.update_particles(self.dt,u2d,v2d)# increment the timeself.cc_data.t+=self.dtself.n+=1