[docs]definitialize(self):""" Initialize the grid and variables for advection and set the initial conditions for the chosen problem. """my_grid=grid_setup(self.rp,ng=4)# create the variablesmy_data=fv.FV2d(my_grid)bc=bc_setup(self.rp)[0]my_data.register_var("density",bc)my_data.create()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]defsubstep(self,myd):""" take a single substep in the RK timestepping starting with the conservative state defined as part of myd """# this is identical to the RK version, but we need to# dupe it here to pull in the correct fluxesmyg=myd.gridk=myg.scratch_array()flux_x,flux_y=flx.fluxes(myd,self.rp)F_x=ai.ArrayIndexer(d=flux_x,grid=myg)F_y=ai.ArrayIndexer(d=flux_y,grid=myg)k.v()[:,:]= \
(F_x.v()-F_x.ip(1))/myg.dx+ \
(F_y.v()-F_y.jp(1))/myg.dyreturnk
[docs]defpreevolve(self):"""Since we are 4th order accurate we need to make sure that we initialized with accurate zone-averages, so the preevolve for this solver assumes that the initialization was done to cell-centers and converts it to cell-averages."""# we just initialized cell-centers, but we need to store averagesforvarinself.cc_data.names:self.cc_data.from_centers(var)