Skip to content

Commit c84421d

Browse files
committed
Vectorize profile plotting
1 parent 4623a16 commit c84421d

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

process/io/plot_proc.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,7 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
36203620
nd_protons,
36213621
nd_impurities,
36223622
nd_ions_total,
3623+
nd_plasma_electrons_vol_avg,
36233624
])
36243625
/ nd_plasma_electrons_vol_avg
36253626
)
@@ -3628,28 +3629,50 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
36283629

36293630
# build species density profiles from electron profile and fractions
36303631
# fracs = [fuel, alpha, protons, impurities, ions_total]
3631-
n_fuel = ne * fracs[0]
3632-
n_alpha = ne * fracs[1]
3633-
n_proton = ne * fracs[2]
3634-
n_imp = ne * fracs[3]
3635-
n_ions = ne * fracs[4]
3632+
# Create a density profile for each species by multiplying ne by each fraction in fracs
3633+
density_profiles = np.array([ne * frac for frac in fracs])
36363634

36373635
# convert to 1e19 m^-3 units for plotting (vectorised)
3638-
ne_plot = ne / 1e19
3639-
n_fuel_plot = n_fuel / 1e19
3640-
n_alpha_plot = n_alpha / 1e19
3641-
n_proton_plot = n_proton / 1e19
3642-
n_imp_plot = n_imp / 1e19
3643-
n_ions_plot = n_ions / 1e19
3636+
density_profiles_plotting = density_profiles / 1e19
36443637

36453638
prof.plot(
3646-
rho, n_fuel_plot, label=r"$n_{\text{fuel}}$", color="#2ca02c", linewidth=1.5
3639+
rho,
3640+
density_profiles_plotting[0],
3641+
label=r"$n_{\text{fuel}}$",
3642+
color="#2ca02c",
3643+
linewidth=1.5,
3644+
)
3645+
prof.plot(
3646+
rho,
3647+
density_profiles_plotting[1],
3648+
label=r"$n_{\alpha}$",
3649+
color="#d62728",
3650+
linewidth=1.5,
3651+
)
3652+
prof.plot(
3653+
rho,
3654+
density_profiles_plotting[2],
3655+
label=r"$n_{p}$",
3656+
color="#17becf",
3657+
linewidth=1.5,
3658+
)
3659+
prof.plot(
3660+
rho,
3661+
density_profiles_plotting[3],
3662+
label=r"$n_{Z}$",
3663+
color="#9467bd",
3664+
linewidth=1.5,
3665+
)
3666+
prof.plot(
3667+
rho,
3668+
density_profiles_plotting[4],
3669+
label=r"$n_{i,total}$",
3670+
color="#ff7f0e",
3671+
linewidth=1.5,
3672+
)
3673+
prof.plot(
3674+
rho, density_profiles_plotting[5], label=r"$n_{e}$", color="blue", linewidth=1.5
36473675
)
3648-
prof.plot(rho, ne_plot, label=r"$n_{e}$", color="blue", linewidth=1.5)
3649-
prof.plot(rho, n_alpha_plot, label=r"$n_{\alpha}$", color="#d62728", linewidth=1.5)
3650-
prof.plot(rho, n_proton_plot, label=r"$n_{p}$", color="#17becf", linewidth=1.5)
3651-
prof.plot(rho, n_imp_plot, label=r"$n_{Z}$", color="#9467bd", linewidth=1.5)
3652-
prof.plot(rho, n_ions_plot, label=r"$n_{i,total}$", color="#ff7f0e", linewidth=1.5)
36533676

36543677
# make legend use multiple columns (up to 4) and place it to the right to avoid overlapping the plots
36553678
handles, labels = prof.get_legend_handles_labels()

0 commit comments

Comments
 (0)