Dear yt-users,
I am trying to define a new field, SFR_Density, which includes if
statements.
That is defined by,
f_sf * rho / t_ff if rho > rho_threshold
0 if rho < rho_threshold
(f_sf is star formation efficiency, rho is gas density, and t_ff is free
fall time)
Here is my definition I tried.
def _SFR_Density(field, data):
f_sf = 0.01
rho_thresh = 57.5 * Mu * hydrogen_mass
if data["density"] > rho_thresh:
return f_sf * data["density"] / (3*pi/32/Grav/data["density"])**(0.5)
else:
return 0.0 * f_sf * data["density"] / (3*pi/32/Grav/data["density"
])**(0.5)
add_field("SFR_Density", function=_SFR_Density)
But it fails with an error message of "ValueError: The truth value of an
array with more than one element is ambiguous. Use a.any() or a.all()"
I am sure this is because data["density"] is a list, so I need to specify
the exact index number of elements at the if statement. I have tried many
tests, but now I am in stuck.
Any help would be very appreciated.
Thanks,
Yusuke