|
| 1 | +"""A RT problem with two distinct modes: short wave length on the |
| 2 | +left and long wavelenght on the right. This allows one to see |
| 3 | +how the growth rate depends on wavenumber. |
| 4 | +""" |
| 5 | + |
| 6 | +from __future__ import print_function |
| 7 | + |
| 8 | +import numpy as np |
| 9 | + |
| 10 | +import sys |
| 11 | +import mesh.patch as patch |
| 12 | +from util import msg |
| 13 | + |
| 14 | + |
| 15 | +def init_data(my_data, rp): |
| 16 | + |
| 17 | + """ initialize the rt problem """ |
| 18 | + |
| 19 | + msg.bold("initializing the rt problem...") |
| 20 | + |
| 21 | + # make sure that we are passed a valid patch object |
| 22 | + if not isinstance(my_data, patch.CellCenterData2d): |
| 23 | + print("ERROR: patch invalid in rt2.py") |
| 24 | + print(my_data.__class__) |
| 25 | + sys.exit() |
| 26 | + |
| 27 | + # get the density, momenta, and energy as separate variables |
| 28 | + dens = my_data.get_var("density") |
| 29 | + xmom = my_data.get_var("x-momentum") |
| 30 | + ymom = my_data.get_var("y-momentum") |
| 31 | + ener = my_data.get_var("energy") |
| 32 | + |
| 33 | + gamma = rp.get_param("eos.gamma") |
| 34 | + |
| 35 | + grav = rp.get_param("compressible.grav") |
| 36 | + |
| 37 | + dens1 = rp.get_param("rt2.dens1") |
| 38 | + dens2 = rp.get_param("rt2.dens2") |
| 39 | + p0 = rp.get_param("rt2.p0") |
| 40 | + amp = rp.get_param("rt2.amp") |
| 41 | + sigma = rp.get_param("rt2.sigma") |
| 42 | + |
| 43 | + # initialize the components, remember, that ener here is |
| 44 | + # rho*eint + 0.5*rho*v**2, where eint is the specific |
| 45 | + # internal energy (erg/g) |
| 46 | + xmom[:, :] = 0.0 |
| 47 | + ymom[:, :] = 0.0 |
| 48 | + dens[:, :] = 0.0 |
| 49 | + |
| 50 | + f_l = 18 |
| 51 | + f_r = 3 |
| 52 | + |
| 53 | + # set the density to be stratified in the y-direction |
| 54 | + myg = my_data.grid |
| 55 | + |
| 56 | + xcenter = 0.5*(myg.xmin + myg.xmax) |
| 57 | + ycenter = 0.5*(myg.ymin + myg.ymax) |
| 58 | + |
| 59 | + p = myg.scratch_array() |
| 60 | + |
| 61 | + j = myg.jlo |
| 62 | + while j <= myg.jhi: |
| 63 | + if (myg.y[j] < ycenter): |
| 64 | + dens[:, j] = dens1 |
| 65 | + p[:, j] = p0 + dens1*grav*myg.y[j] |
| 66 | + |
| 67 | + else: |
| 68 | + dens[:, j] = dens2 |
| 69 | + p[:, j] = p0 + dens1*grav*ycenter + dens2*grav*(myg.y[j] - ycenter) |
| 70 | + |
| 71 | + j += 1 |
| 72 | + |
| 73 | + idx_l = myg.x2d < (myg.xmax - myg.xmin)/3.0 |
| 74 | + idx_r = myg.x2d >= (myg.xmax - myg.xmin)/3.0 |
| 75 | + |
| 76 | + ymom[idx_l] = amp*np.sin(4.0*np.pi*f_l*myg.x2d[idx_l]/(myg.xmax-myg.xmin))*np.exp(-(myg.y2d[idx_l]-ycenter)**2/sigma**2) |
| 77 | + ymom[idx_r] = amp*np.sin(4.0*np.pi*f_r*myg.x2d[idx_r]/(myg.xmax-myg.xmin))*np.exp(-(myg.y2d[idx_r]-ycenter)**2/sigma**2) |
| 78 | + |
| 79 | + print(ymom[:,100]) |
| 80 | + |
| 81 | + ymom *= dens |
| 82 | + |
| 83 | + # set the energy (P = cs2*dens) |
| 84 | + ener[:, :] = p[:, :]/(gamma - 1.0) + \ |
| 85 | + 0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :] |
| 86 | + |
| 87 | + |
| 88 | +def finalize(): |
| 89 | + """ print out any information to the user at the end of the run """ |
| 90 | + pass |
0 commit comments