3from .StandardPlotHelper
import StandardPlotHelper
23 do_normalization=True,
24 min_normalization=1e-9,
26 """Render a slice of the By magnetic field component.
28 The MHD solver stores ``B/rho`` (a 3-vector) so By is recovered as ``(B/rho)_y * rho``.
31 def compute_By_slice(helper):
32 def custom_getter(size: int, dic_out: dict) -> np.array:
33 B_over_rho_y = dic_out[
"B/rho"][:, 1]
34 pmass = model.get_particle_mass()
35 hfact = model.get_hfact()
36 rho = pmass * (hfact / dic_out[
"hpart"]) ** 3
37 return B_over_rho_y * rho
39 arr_By = helper.slice_render(
44 custom_getter=custom_getter,
49 return StandardPlotHelper(
59 compute_function=compute_By_slice,
73 do_normalization=True,
74 min_normalization=1e-9,
76 """Render a slice of the azimuthal magnetic field component B_theta.
78 the azimuthal projection is ``(-y * Bx + x * By) / r``.
81 def compute_Btheta_slice(helper):
83 size: int, x: np.array, y: np.array, Bx: np.array, By: np.array, rho: np.array
85 r_safe = np.sqrt(x**2 + y**2) + 1e-9
86 B_over_rho_theta = (-y * Bx + x * By) / r_safe
87 return B_over_rho_theta * rho
90 internal = njit(internal)
92 def custom_getter(size: int, dic_out: dict) -> np.array:
97 dic_out[
"B/rho"][:, 0],
98 dic_out[
"B/rho"][:, 1],
102 arr_Btheta = helper.slice_render(
107 custom_getter=custom_getter,
112 return StandardPlotHelper(
122 compute_function=compute_Btheta_slice,
126def SliceBVerticalShearGradient(
136 do_normalization=True,
137 min_normalization=1e-9,
139 """Render a slice of the vertical shear gradient of the azimuthal magnetic field,
142 ``B_theta`` is recovered from the stored ``B/rho`` field as
143 ``(B/rho)_theta * rho``.
146 def compute_B_vertical_shear_gradient(helper):
148 size: int, x: np.array, y: np.array, Bx: np.array, By: np.array, rho: np.array
150 r_safe = np.sqrt(x**2 + y**2) + 1e-9
151 B_over_rho_theta = (-y * Bx + x * By) / r_safe
152 return B_over_rho_theta * rho
155 internal = njit(internal)
157 def custom_getter(size: int, dic_out: dict) -> np.array:
160 dic_out[
"xyz"][:, 0],
161 dic_out[
"xyz"][:, 1],
162 dic_out[
"B/rho"][:, 0],
163 dic_out[
"B/rho"][:, 1],
167 arr_Btheta = helper.slice_render(
172 custom_getter=custom_getter,
175 extent = helper.get_extent()
176 dy = (extent[3] - extent[2]) / helper.ny
178 B_vertical_shear_gradient = np.gradient(arr_Btheta, dy, axis=0)
180 return B_vertical_shear_gradient
182 return StandardPlotHelper(
192 compute_function=compute_B_vertical_shear_gradient,