@@ -3577,42 +3577,107 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
35773577 Arguments:
35783578 prof --> axis object to add plot to
35793579 """
3580+ nd_alphas = mfile_data .data ["nd_plasma_alphas_vol_avg" ].get_scan (scan )
3581+ nd_protons = mfile_data .data ["nd_plasma_protons_vol_avg" ].get_scan (scan )
3582+ nd_impurities = mfile_data .data ["nd_plasma_impurities_vol_avg" ].get_scan (scan )
3583+ nd_ions_total = mfile_data .data ["nd_plasma_ions_total_vol_avg" ].get_scan (scan )
3584+ nd_fuel_ions = mfile_data .data ["nd_plasma_fuel_ions_vol_avg" ].get_scan (scan )
35803585
35813586 prof .set_xlabel (r"$\rho \quad [r/a]$" )
3582- prof .set_ylabel (r"$n $ $ [10^{19} \mathrm{m}^{-3}]$" )
3587+ prof .set_ylabel (r"$n \ [10^{19}\ \mathrm{m}^{-3}]$" )
35833588 prof .set_title ("Density profile" )
35843589
3590+ # build electron profile and species profiles (scale with electron profile shape)
35853591 if i_plasma_pedestal == 1 :
35863592 rhocore = np .linspace (0 , radius_plasma_pedestal_density_norm )
35873593 necore = (
35883594 nd_plasma_pedestal_electron
35893595 + (ne0 - nd_plasma_pedestal_electron )
35903596 * (1 - rhocore ** 2 / radius_plasma_pedestal_density_norm ** 2 ) ** alphan
35913597 )
3592- nicore = necore * (nd_plasma_fuel_ions_vol_avg / nd_plasma_electrons_vol_avg )
35933598
35943599 rhosep = np .linspace (radius_plasma_pedestal_density_norm , 1 )
35953600 neesep = nd_plasma_separatrix_electron + (
35963601 nd_plasma_pedestal_electron - nd_plasma_separatrix_electron
35973602 ) * (1 - rhosep ) / (1 - min (0.9999 , radius_plasma_pedestal_density_norm ))
3598- nisep = neesep * (nd_plasma_fuel_ions_vol_avg / nd_plasma_electrons_vol_avg )
35993603
36003604 rho = np .append (rhocore , rhosep )
36013605 ne = np .append (necore , neesep )
3602- ni = np . append ( nicore , nisep )
3606+
36033607 else :
36043608 rho1 = np .linspace (0 , 0.95 )
36053609 rho2 = np .linspace (0.95 , 1 )
36063610 rho = np .append (rho1 , rho2 )
36073611 ne = ne0 * (1 - rho ** 2 ) ** alphan
3608- ni = (ne0 * (nd_plasma_fuel_ions_vol_avg / nd_plasma_electrons_vol_avg )) * (
3609- 1 - rho ** 2
3610- ) ** alphan
3611- ne = ne / 1e19
3612- ni = ni / 1e19
3613- prof .plot (rho , ni , label = r"$n_{\text{i,fuel}}$" , color = "red" )
3614- prof .plot (rho , ne , label = "$n_{e}$" , color = "blue" )
3615- prof .legend ()
3612+
3613+ # species profiles scaled by their average fraction relative to electrons
3614+
3615+ if nd_plasma_electrons_vol_avg != 0 :
3616+ fracs = (
3617+ np .array ([
3618+ nd_fuel_ions ,
3619+ nd_alphas ,
3620+ nd_protons ,
3621+ nd_impurities ,
3622+ nd_ions_total ,
3623+ nd_plasma_electrons_vol_avg ,
3624+ ])
3625+ / nd_plasma_electrons_vol_avg
3626+ )
3627+ else :
3628+ fracs = np .zeros (5 )
3629+
3630+ # build species density profiles from electron profile and fractions
3631+ # fracs = [fuel, alpha, protons, impurities, ions_total]
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 ])
3634+
3635+ # convert to 1e19 m^-3 units for plotting (vectorised)
3636+ density_profiles_plotting = density_profiles / 1e19
3637+
3638+ prof .plot (
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
3675+ )
3676+
3677+ # make legend use multiple columns (up to 4) and place it to the right to avoid overlapping the plots
3678+ handles , labels = prof .get_legend_handles_labels ()
3679+ ncol = min (4 , max (1 , len (labels )))
3680+ prof .legend (loc = "upper center" , bbox_to_anchor = (0.5 , - 0.1 ), ncol = ncol )
36163681
36173682 # Ranges
36183683 # ---
@@ -3644,7 +3709,7 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
36443709 linewidth = 0.4 ,
36453710 alpha = 0.4 ,
36463711 )
3647- prof .minorticks_on ()
3712+ prof .minorticks_on ()
36483713
36493714 # Add text box with density profile parameters
36503715 textstr_density = "\n " .join ((
@@ -3667,7 +3732,7 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
36673732 props_density = {"boxstyle" : "round" , "facecolor" : "wheat" , "alpha" : 0.5 }
36683733 prof .text (
36693734 0.0 ,
3670- - 0.16 ,
3735+ - 0.25 ,
36713736 textstr_density ,
36723737 transform = prof .transAxes ,
36733738 fontsize = 9 ,
@@ -7235,7 +7300,7 @@ def plot_physics_info(axis, mfile_data, scan):
72357300 ("beta_norm_thermal" , r"$\beta_N$, thermal" , "% m T MA$^{-1}$" ),
72367301 ("beta_norm_toroidal" , r"$\beta_N$, toroidal" , "% m T MA$^{-1}$" ),
72377302 ("beta_thermal_poloidal_vol_avg" , r"$\beta_P$, thermal" , "" ),
7238- ("beta_poloidal " , r"$\beta_P$, total" , "" ),
7303+ ("beta_poloidal_vol_avg " , r"$\beta_P$, total" , "" ),
72397304 ("temp_plasma_electron_vol_avg_kev" , r"$\langle T_e \rangle$" , "keV" ),
72407305 ("nd_plasma_electrons_vol_avg" , r"$\langle n_e \rangle$" , "m$^{-3}$" ),
72417306 (nong , r"$\langle n_{\mathrm{e,line}} \rangle \ / \ n_G$" , "" ),
@@ -12175,7 +12240,7 @@ def main_plot(
1217512240
1217612241 # Plot current density profile
1217712242 ax12 = fig4 .add_subplot (4 , 3 , 10 )
12178- ax12 .set_position ([0.075 , 0.125 , 0.25 , 0.15 ])
12243+ ax12 .set_position ([0.075 , 0.105 , 0.25 , 0.15 ])
1217912244 plot_jprofile (ax12 )
1218012245
1218112246 # Plot q profile
0 commit comments