11import sys
22
3- import numpy
3+ import numpy as np
44
55from pyro .mesh import patch
66from pyro .util import msg
@@ -13,7 +13,7 @@ def init_data(my_data, rp):
1313
1414 # make sure that we are passed a valid patch object
1515 if not isinstance (my_data , patch .CellCenterData2d ):
16- print ("ErrrrOrr : patch invalid in bubble .py" )
16+ print ("Error : patch invalid in gresho .py" )
1717 print (my_data .__class__ )
1818 sys .exit ()
1919
@@ -23,57 +23,55 @@ def init_data(my_data, rp):
2323 ymom = my_data .get_var ("y-momentum" )
2424 ener = my_data .get_var ("energy" )
2525
26- # grav = rp.get_param("compressible.grav")
26+ myg = my_data .grid
27+
28+ x_center = 0.5 * (myg .x [0 ] + myg .x [- 1 ])
29+ y_center = 0.5 * (myg .y [0 ] + myg .y [- 1 ])
30+ L_x = myg .xmax - myg .xmin
2731
2832 gamma = rp .get_param ("eos.gamma" )
2933
30- # scale_height = rp.get_param("gresho.scale_height")
31- dens_base = rp .get_param ("gresho.dens_base" )
32- dens_cutoff = rp .get_param ("gresho.dens_cutoff" )
34+ rho0 = rp .get_param ("gresho.rho0" )
35+ p0 = rp .get_param ("gresho.p0" )
3336
3437 rr = rp .get_param ("gresho.r" )
35- u0 = rp .get_param ("gresho.u0" )
36- p0 = rp .get_param ("gresho.p0" )
38+ t_r = rp .get_param ("gresho.t_r" )
3739
38- # initialize the components -- we'll get a psure too
39- # but that is used only to initialize the base state
40- xmom [:, :] = 0.0
41- ymom [:, :] = 0.0
42- dens [:, :] = dens_cutoff
40+ q_r = 0.4 * np .pi * L_x / t_r
4341
44- # set the density to be stratified in the y-direction
45- myg = my_data .grid
4642 pres = myg .scratch_array ()
43+ u_phi = myg .scratch_array ()
4744
48- dens [:, :] = dens_base
49-
45+ dens [:, :] = rho0
5046 pres [:, :] = p0
5147
52- x_centre = 0.5 * ( myg .x [ 0 ] + myg . x [ - 1 ])
53- y_centre = 0.5 * ( myg . y [ 0 ] + myg .y [ - 1 ] )
48+ rad = np . sqrt (( myg .x2d - x_center ) ** 2 +
49+ ( myg .y2d - y_center ) ** 2 )
5450
55- rad = numpy .sqrt ((myg .x2d - x_centre )** 2 + (myg .y2d - y_centre )** 2 )
51+ indx1 = rad < rr
52+ u_phi [indx1 ] = 5.0 * rad [indx1 ]
53+ pres [indx1 ] = p0 + 12.5 * rad [indx1 ]** 2
5654
57- pres [rad <= rr ] += 0.5 * (u0 * rad [rad <= rr ]/ rr )** 2
58- pres [(rad > rr ) & (rad <= 2 * rr )] += \
59- u0 ** 2 * (0.5 * (rad [(rad > rr ) & (rad <= 2 * rr )] / rr )** 2 +
60- 4 * (1 - rad [(rad > rr ) & (rad <= 2 * rr )]/ rr +
61- numpy .log (rad [(rad > rr ) & (rad <= 2 * rr )]/ rr )))
62- pres [rad > 2 * rr ] += u0 ** 2 * (4 * numpy .log (2 ) - 2 )
63- #
64- uphi = numpy .zeros_like (pres )
65- uphi [rad <= rr ] = u0 * rad [rad <= rr ]/ rr
66- uphi [(rad > rr ) & (rad <= 2 * rr )] = u0 * (2 - rad [(rad > rr ) & (rad <= 2 * rr )]/ rr )
55+ indx2 = np .logical_and (rad >= rr , rad < 2.0 * rr )
56+ u_phi [indx2 ] = 2.0 - 5.0 * rad [indx2 ]
57+ pres [indx2 ] = p0 + 12.5 * rad [indx2 ]** 2 + \
58+ 4.0 * (1.0 - 5.0 * rad [indx2 ] - np .log (rr ) + np .log (rad [indx2 ]))
6759
68- xmom [:, :] = - dens [:, :] * uphi [:, :] * (myg .y2d - y_centre ) / rad [:, :]
69- ymom [:, :] = dens [:, :] * uphi [:, :] * (myg .x2d - x_centre ) / rad [:, :]
60+ indx3 = rad >= 2.0 * rr
61+ u_phi [indx3 ] = 0.0
62+ pres [indx3 ] = p0 + 12.5 * (2.0 * rr )** 2 + \
63+ 4.0 * (1.0 - 5.0 * (2.0 * rr ) - np .log (rr ) + np .log (2.0 * rr ))
7064
71- ener [:, :] = pres [:, :]/ ( gamma - 1.0 ) + \
72- 0.5 * ( xmom [:, :]** 2 + ymom [:, :]** 2 ) / dens [:, :]
65+ xmom [:, :] = - dens [:, :] * q_r * u_phi [:, :] * ( myg . y2d - y_center ) / rad [:, :]
66+ ymom [:, :] = dens [:, :] * q_r * u_phi [:, :] * ( myg . x2d - x_center ) / rad [:, :]
7367
74- eint = pres [:, :]/ (gamma - 1.0 )
68+ ener [:, :] = pres [:, :] / (gamma - 1.0 ) + \
69+ 0.5 * (xmom [:, :]** 2 + ymom [:, :]** 2 ) / dens [:, :]
7570
76- dens [:, :] = pres [:, :]/ (eint [:, :]* (gamma - 1.0 ))
71+ # report peak Mach number
72+ cs = np .sqrt (gamma * pres / dens )
73+ M = np .abs (q_r * u_phi ).max () / cs .max ()
74+ print (f"peak Mach number = { M } " )
7775
7876
7977def finalize ():
0 commit comments