Paste #2152
Welcome To LodgeIt
Welcome to the LodgeIt pastebin. In order to use the notification feature a 31 day cookie with an unique ID was created for you. The lodgeit database does not store any information about you, it's just used for an advanced pastebin experience :-). Read more on the about lodgeit page. Have fun :-)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | import yt from yt import derived_field from yt.fields.vector_operations import obtain_relative_velocity_vector, get_cyl_r_component import numpy as np def radial_derivative_azimuthal_velocity( x, y, dvx_dx, dvx_dy, dvy_dx, dvy_dy, ): """ Compute ∂v_theta/∂r from the Cartesian derivatives of the velocity components v_x and v_y. Parameters ---------- x, y : float or array_like Cartesian coordinates. dvx_dx, dvx_dy : float or array_like ∂v_x/∂x and ∂v_x/∂y. dvy_dx, dvy_dy : float or array_like ∂v_y/∂x and ∂v_y/∂y. Returns ------- float or ndarray Radial derivative ∂v_theta/∂r. """ r = np.sqrt(x**2 + y**2) cos_theta = x / r sin_theta = y / r # Radial derivatives of v_x and v_y dvx_dr = cos_theta * dvx_dx + sin_theta * dvx_dy dvy_dr = cos_theta * dvy_dx + sin_theta * dvy_dy # v_theta = -v_x sin(theta) + v_y cos(theta) dv_theta_dr = -sin_theta * dvx_dr + cos_theta * dvy_dr return dv_theta_dr if __name__ == "__main__": iout = 21 path = "." ds = yt.load(f"{path}/output_{iout:05}/info_{iout:05}.txt") ds.add_gradient_fields(("gas", "velocity_x")) ds.add_gradient_fields(("gas", "velocity_y")) def _kappa(field, data): x = data["gas", "x"] - 0.5*ds.units.code_length y = data["gas", "y"] - 0.5*ds.units.code_length dvxdx = data["gas","velocity_x_gradient_x"] dvxdy = data["gas","velocity_x_gradient_y"] dvydx = data["gas","velocity_y_gradient_x"] dvydy = data["gas","velocity_y_gradient_y"] r = np.sqrt(x**2 + y**2) dv_theta_dr = radial_derivative_azimuthal_velocity( x, y, dvxdx, dvxdy, dvydx, dvydy, ) vtheta = data["gas","velocity_cylindrical_theta"] return (2 * vtheta) * (vtheta + r * dv_theta_dr) / (r**2) ds.add_field(name=("gas", "kappa"), function=_kappa, sampling_type="cell") ds.force_periodicity() proj = yt.ProjectionPlot(ds, "z", [("gas", "kappa")], weight_field=("gas", "density"), width=(6, "cm"), buff_size=(512, 512)) # slc = yt.SlicePlot(ds, "z", ("gas", "R2Omega"), width=(8, "cm"), buff_size=(1024, 1024)) proj.save(f"{path}/figures/snap_{iout:05}") |