Source code for pyro.compressible_fv4.problems.gresho
"""The Gresho vortex problem sets up a toroidal velocity field that isbalanced by a radial pressure gradient. This is in equilibrium andthe state should remain unchanged in time. This version of the problemis based on Miczek, Roepke, and Edelmann 2014."""importnumpyasnpfrompyro.utilimportmsgDEFAULT_INPUTS="inputs.gresho"PROBLEM_PARAMS={"gresho.rho0":1.0,# density in the domain"gresho.r":0.2,# radial location of peak velocity"gresho.mach":0.1,# Mach number"gresho.t_r":1.0}# reference time (used for setting peak velocity)
[docs]definit_data(my_data,rp):""" initialize the Gresho vortex problem """ifrp.get_param("driver.verbose"):msg.bold("initializing the Gresho vortex problem...")# get the density and velocitiesdens=my_data.get_var("density")xmom=my_data.get_var("x-momentum")ymom=my_data.get_var("y-momentum")ener=my_data.get_var("energy")myg=my_data.gridx_center=0.5*(myg.x[0]+myg.x[-1])y_center=0.5*(myg.y[0]+myg.y[-1])L_x=myg.xmax-myg.xmingamma=rp.get_param("eos.gamma")rho0=rp.get_param("gresho.rho0")M=rp.get_param("gresho.mach")rr=rp.get_param("gresho.r")t_r=rp.get_param("gresho.t_r")q_r=0.4*np.pi*L_x/t_r# pressure peaks at r = rr, and has the value# p0 + 12.5 * rr**2## Mach number is M = q |u_phi| / sqrt(gamma p / rho),## so p0 is found as:## p0 + 12.5 rr**2 = rho q**2 |u_phi|**2 / (gamma M**2)## where u_phi peaks at 5 * rrp0=rho0*q_r**2*(5*rr)**2/(gamma*M**2)-12.5*rr**2pres=myg.scratch_array()u_phi=myg.scratch_array()dens[:,:]=rho0pres[:,:]=p0rad=np.sqrt((myg.x2d-x_center)**2+(myg.y2d-y_center)**2)indx1=rad<rru_phi[indx1]=5.0*rad[indx1]pres[indx1]=p0+12.5*rad[indx1]**2indx2=np.logical_and(rad>=rr,rad<2.0*rr)u_phi[indx2]=2.0-5.0*rad[indx2]pres[indx2]=p0+12.5*rad[indx2]**2+ \
4.0*(1.0-5.0*rad[indx2]-np.log(rr)+np.log(rad[indx2]))indx3=rad>=2.0*rru_phi[indx3]=0.0pres[indx3]=p0+12.5*(2.0*rr)**2+ \
4.0*(1.0-5.0*(2.0*rr)-np.log(rr)+np.log(2.0*rr))xmom[:,:]=-dens[:,:]*q_r*u_phi[:,:]*(myg.y2d-y_center)/rad[:,:]ymom[:,:]=dens[:,:]*q_r*u_phi[:,:]*(myg.x2d-x_center)/rad[:,:]ener[:,:]=pres[:,:]/(gamma-1.0)+ \
0.5*(xmom[:,:]**2+ymom[:,:]**2)/dens[:,:]# report peak Mach numbercs=np.sqrt(gamma*pres/dens)M=np.abs(q_r*u_phi).max()/cs.max()print(f"peak Mach number = {M}")
[docs]deffinalize():""" print out any information to the userad at the end of the run """