def particle_vector_functions(ptype, coord_names, vel_names, registry):
unit_system = registry.ds.unit_system
# This will column_stack a set of scalars to create vector fields.
def _get_vec_func(_ptype, names):
def particle_vectors(field, data):
v = [data[_ptype, name].in_units(field.units)
for name in names]
c = np.column_stack(v)
return data.apply_units(c, field.units)
return particle_vectors
registry.add_field((ptype, "particle_position"),
sampling_type="particle",
function=_get_vec_func(ptype, coord_names),
units = "code_length")
registry.add_field((ptype, "particle_velocity"),
sampling_type="particle",
function=_get_vec_func(ptype, vel_names),
units = unit_system["velocity"])
评论列表
文章目录