[docs]classSimulation(compressible.Simulation):"""The main simulation class for the method of lines compressible hydrodynamics solver"""
[docs]defsubstep(self,myd):""" take a single substep in the RK timestepping starting with the conservative state defined as part of myd """self.clean_state(myd.data)myg=myd.grid# source terms -- note: this dt is the entire dt, not the# stage's dtS=compressible.get_external_sources(myd.t,self.dt,myd.data,self.ivars,self.rp,myg,problem_source=self.problem_source)k=myg.scratch_array(nvar=self.ivars.nvar)flux_x,flux_y=flx.fluxes(myd,self.rp,self.ivars,self.solid,self.tc)forninrange(self.ivars.nvar):k.v(n=n)[:,:]= \
(flux_x.v(n=n)-flux_x.ip(1,n=n))/myg.dx+ \
(flux_y.v(n=n)-flux_y.jp(1,n=n))/myg.dy+S.v(n=n)# finally, add the sponge source, if desiredifself.rp.get_param("sponge.do_sponge"):kappa_f=compressible.get_sponge_factor(myd.data,self.ivars,self.rp,myg)# momentumk.v(n=self.ivars.ixmom)[:,:]-=kappa_f.v()*myd.data.v(n=self.ivars.ixmom)k.v(n=self.ivars.iymom)[:,:]-=kappa_f.v()*myd.data.v(n=self.ivars.iymom)# total energyk.v(n=self.ivars.iener)[:,:]-=kappa_f.v()*(myd.data.v(n=self.ivars.ixmom)**2/myd.data.v(n=self.ivars.idens)+myd.data.v(n=self.ivars.iymom)**2/myd.data.v(n=self.ivars.idens))returnk
[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")# get the variables we needu,v,cs=self.cc_data.get_var(["velocity","soundspeed"])# the timestep is min(dx/(|u| + cs), dy/(|v| + cs))xtmp=(abs(u)+cs)/self.cc_data.grid.dxytmp=(abs(v)+cs)/self.cc_data.grid.dyself.dt=cfl*float(np.min(1.0/(xtmp+ytmp)))
[docs]defevolve(self):""" Evolve the equations of compressible hydrodynamics through a timestep dt. """tm_evolve=self.tc.timer("evolve")tm_evolve.begin()myd=self.cc_datamethod=self.rp.get_param("compressible.temporal_method")rk=integration.RKIntegrator(myd.t,self.dt,method=method)rk.set_start(myd)forsinrange(rk.nstages()):ytmp=rk.get_stage_start(s)ytmp.fill_BC_all()k=self.substep(ytmp)rk.store_increment(s,k)rk.compute_final_update()ifself.particlesisnotNone:self.particles.update_particles(self.dt)# increment the timemyd.t+=self.dtself.n+=1tm_evolve.end()