Dear all,
I have a question on calculating the mass flux across surfaces in yt,
particularly why the flux values differ between two methods. The surface,
for example, is a circle a few kpcs above the central XY plane, and I'm
calculating the mass flux in the perpendicular (velocity_z) direction. A
simplified code snippet looks like this.
ds = yt.load('Enzo_AMR_output')
box_length_kpc = ds.domain_width[0].in_units('kpc').value # constant,
simulation box length in kpc
*Method 1.* Create a 2D yt.slice object and calculate the flux manually
(faster).
slice = ds.r[:, :, 0.5 + 2/box_length_kpc] # selecting a slice at z=2 kpc
(relative to domain center)
# creating a boolean mask: a circle with a radius of 10 kpc
radius_mask =
np.sqrt((slice['gas','x'].in_units("kpc").value-box_length_kpc/2.)**2 +\
(slice_plus['gas','y'].in_units("kpc").value-box_length_kpc/2.)**2) <= 10
# mdot = rho * v dot dA, where dA = dx * dy
mass_flux = np.sum((slice['gas', 'density'][radius_mask_] *\
slice['gas', 'velocity_z'][radius_mask] *\
slice['gas', 'dx'][radius_mask] *\
slice['gas',
'dy'][radius_mask])).in_units("Msun/yr")
*Method 2.* Create a yt.surface object and use the calculate_flux()
function.
# defining a disk object of radius 10 kpc, then selecting the upper surface
where z=2 kpc (relative to domain center), and calculate the mass flux
my_disk = ds.disk(ds.domain_center, [0.0, 0.0, 1.0], 10 * kpc, 2.02 * kpc)
disk_upper_surf = ds.surface(my_disk, ("gas", "cylindrical_z"), 2)
mass_flux = disk_upper_surf.calculate_flux(("gas", "velocity_x"),("gas",
"velocity_y"),("gas", "velocity_z"),("gas", "density")).in_units("Msun/yr")
The two methods always return different results (off by ~48% for this
selected input), but I wonder why. Another sanity check I did was to print
out the cell numbers selected in each method. Method 2 (marching cubes,
triangular vertices) consistently selected 2 times the cell numbers in
method 1 (slicing). Could anyone point out what might be wrong with the way
I implemented either method? Thanks so much!
Best,
Jingyao
--
Jingyao Zhu (she/her/hers)
Columbia University | Dept of Astronomy