def _particle_specific_angular_momentum(field, data): """ Calculate the angular of a particle velocity. Returns a vector for each particle. """ center = data.get_field_parameter('center') pos, vel, normal, bv = get_angular_momentum_components(ptype, data, spos, svel) L, r_vec, v_vec = modify_reference_frame(center, normal, P=pos, V=vel) # adding in the unit registry allows us to have a reference to the dataset # and thus we will always get the correct units after applying the cross product. return -ucross(r_vec, v_vec, registry=data.ds.unit_registry)
def manual_jz(data, type="all", r_filter=None, AMR=True): # vx * y - yv * x # if data.has_field_parameter("bulk_velocity"): # data.field_data.pop((type, 'particle_position_relative_x')) # data.field_data.pop((type, 'particle_position_relative_y')) # data.field_data.pop((type, 'particle_velocity_relative_x')) # data.field_data.pop((type, 'particle_velocity_relative_y')) if AMR == True and type == "gas": from yt.utilities.math_utils import modify_reference_frame from yt.units.yt_array import ucross if data.has_field_parameter("normal"): normal = data.get_field_parameter("normal") else: normal = data.ds.arr([0.0, 0.0, 1.0], "code_length") # default to simulation axis bv = data.get_field_parameter("bulk_velocity") pos = data.ds.arr([data["%s" % ax] for ax in "xyz"]).T vel = data.ds.arr([ data["gas", "velocity_%s" % ax] - bv[iax] for iax, ax in enumerate("xyz") ]).T center = data.get_field_parameter('center') L, r_vec, v_vec = modify_reference_frame(center, normal, P=pos, V=vel) ang_momentum = -ucross(r_vec, v_vec, registry=data.ds.unit_registry) jz = ang_momentum[:, "2"] if r_filter != None: jz = jz[r_filter] else: if r_filter != None: vrot = (data[type, "particle_position_relative_x"][r_filter] * data[type, "particle_velocity_relative_y"][r_filter]) vrot = vrot - ( data[type, "particle_position_relative_y"][r_filter] * data[type, "particle_velocity_relative_x"][r_filter]) else: vrot = (data[type, "particle_position_relative_x"] * data[type, "particle_velocity_relative_y"]) vrot = vrot - (data[type, "particle_position_relative_y"] * data[type, "particle_velocity_relative_x"]) jz = vrot return jz