d0fus 2.9.2__tar.gz → 2.9.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_physical_functions.py +305 -225
  2. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_EXE/D0FUS_genetic.py +16 -123
  3. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_EXE/D0FUS_popcon.py +28 -11
  4. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_EXE/D0FUS_run.py +242 -100
  5. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_EXE/D0FUS_scan.py +14 -54
  6. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_EXE/D0FUS_uncertainty.py +19 -75
  7. {d0fus-2.9.2 → d0fus-2.9.4}/PKG-INFO +1 -1
  8. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/PKG-INFO +1 -1
  9. {d0fus-2.9.2 → d0fus-2.9.4}/pyproject.toml +1 -1
  10. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS.py +0 -0
  11. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_cost_data.py +0 -0
  12. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_cost_functions.py +0 -0
  13. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_figures.py +0 -0
  14. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_import.py +0 -0
  15. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_machine_presets.py +0 -0
  16. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_parameterization.py +0 -0
  17. {d0fus-2.9.2 → d0fus-2.9.4}/D0FUS_BIB/D0FUS_radial_build_functions.py +0 -0
  18. {d0fus-2.9.2 → d0fus-2.9.4}/LICENSE +0 -0
  19. {d0fus-2.9.2 → d0fus-2.9.4}/README.md +0 -0
  20. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/SOURCES.txt +0 -0
  21. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/dependency_links.txt +0 -0
  22. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/entry_points.txt +0 -0
  23. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/requires.txt +0 -0
  24. {d0fus-2.9.2 → d0fus-2.9.4}/d0fus.egg-info/top_level.txt +0 -0
  25. {d0fus-2.9.2 → d0fus-2.9.4}/setup.cfg +0 -0
@@ -254,7 +254,8 @@ if __name__ == "__main__":
254
254
  # with the chain results (V, nbar, pbar, P_rad, tau_E, Ip...)
255
255
  # so that every block consumes the outputs of the previous
256
256
  # ones, exactly like the production solver.
257
- # FROZEN : converged outputs of that deck (frozen 2026-06),
257
+ # FROZEN : converged outputs of that deck (frozen 2026-06,
258
+ # refreshed 2026-09 for the v2.10 ion dilution and bootstrap),
258
259
  # re-asserted by the final full-deck regression block. Chain
259
260
  # blocks read FROZEN only (i) to check consistency, and
260
261
  # (ii) as forward references where the file order places a
@@ -275,7 +276,7 @@ if __name__ == "__main__":
275
276
  P_fus=500.0,
276
277
  P_NBI=33.0, P_ECRH=6.7, P_ICRH=10.0, P_LH=0.0, # flat-top mix [Kim 2018]
277
278
  P_aux=33.0 + 6.7 + 10.0, # = 49.7 MW
278
- Tbar=7.754, # solved by resolve_Tbar for f_GW_target = 0.85
279
+ Tbar=8.0617, # solved by resolve_Tbar for f_GW_target = 0.85
279
280
  H=1.0, M=2.5,
280
281
  # Profiles (deck section 2c)
281
282
  nu_n=0.01, nu_T=2.80,
@@ -296,16 +297,16 @@ if __name__ == "__main__":
296
297
  FROZEN = dict(
297
298
  kappa=1.8792, kappa95=1.67785, delta=0.527517, delta95=0.351678,
298
299
  V=847.587, S=687.331,
299
- f_alpha=0.0297618, f_imp_dil=0.07103,
300
- nbar=0.98561, nbar_line=1.01245, pbar=0.267547, nG=1.19112,
301
- B0=5.300, W_th=340.154, betaT=0.023938, betaP=0.651514, betaN=1.63515,
302
- P_Ohm=0.3910, I_Ohm=8.52244,
303
- P_Brem=13.3005, P_syn=3.65678, P_line_core=24.9375, P_line=44.8641,
304
- tauE=3.14385, Ip=14.9681, q95=3.59843, Ib=4.81601,
305
- eta_LH=0.310283, eta_EC=0.0463759, eta_NBI=0.292349, I_CD=1.62962,
306
- Q=9.98184, P_sep=87.8792, P_LH_th=73.522,
307
- B_pol=0.715156, lambda_q_mm=1.12391, Gamma_n=0.58196,
308
- tau_alpha=11.9840, # = C_Alpha * tauE with the v2.8 chain C_Alpha
300
+ f_alpha=0.0290438, f_imp_dil=0.07103,
301
+ nbar=0.947461, nbar_line=0.973261, pbar=0.254868, nG=1.14464,
302
+ B0=5.300, W_th=324.035, betaT=0.0228138, betaP=0.675159, betaN=1.6293,
303
+ P_Ohm=0.385109, I_Ohm=8.66006,
304
+ P_Brem=12.5125, P_syn=4.82011, P_line_core=22.7941, P_line=41.162,
305
+ tauE=2.9485, Ip=14.351, q95=3.74455, Ib=3.9717,
306
+ eta_LH=0.314557, eta_EC=0.0479919, eta_NBI=0.300999, I_CD=1.74567,
307
+ Q=9.98184, P_sep=91.206, P_LH_th=71.4991,
308
+ B_pol=0.68725, lambda_q_mm=1.16497, Gamma_n=0.58196,
309
+ tau_alpha=11.2373, # = C_Alpha * tauE with the v2.8 chain C_Alpha
309
310
  )
310
311
 
311
312
  #%% Geometry formulas
@@ -1133,9 +1134,17 @@ def _profile_core_peak(nu, rho_ped, f_ped, Vprime_data=None):
1133
1134
  if rho_ped >= 1.0 and Vprime_data is None:
1134
1135
  return 1.0 + nu
1135
1136
 
1136
- # ── Cache lookup (id of rho_grid array is stable per design point) ─
1137
- geo_key = id(Vprime_data[0]) if Vprime_data is not None else None
1137
+ # ── Cache lookup, keyed on the geometry CONTENT ─────────────────────
1138
+ # id(Vprime_data[0]) is not a valid key: once a design point's arrays are
1139
+ # freed, CPython reuses the address for the next geometry and the cache
1140
+ # returned the previous design's X0/X̄ (seen in SCAN / GENETIC loops).
1141
+ if Vprime_data is not None:
1142
+ geo_key = hash(np.ascontiguousarray(Vprime_data[1]).tobytes())
1143
+ else:
1144
+ geo_key = None
1138
1145
  cache_key = (nu, rho_ped, f_ped, geo_key)
1146
+ if len(_profile_core_peak_cache) > 20000: # bound memory in long GA runs
1147
+ _profile_core_peak_cache.clear()
1139
1148
  cached = _profile_core_peak_cache.get(cache_key)
1140
1149
  if cached is not None:
1141
1150
  return cached
@@ -1782,13 +1791,14 @@ def f_nbar(P_fus, nu_n, nu_T, f_alpha, Tbar, R0, a, kappa,
1782
1791
 
1783
1792
  def f_pbar(nu_n, nu_T, n_bar, Tbar,
1784
1793
  rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0,
1785
- Vprime_data=None, tau_i_e=1.0):
1794
+ Vprime_data=None, tau_i_e=1.0, n_ion_frac=1.0):
1786
1795
  """
1787
- Volume-averaged plasma pressure p̄ = (1 + τ_ie)⟨nT⟩_vol [MPa].
1796
+ Volume-averaged plasma pressure p̄ = (1 + f_i τ_ie)⟨n_e T_e⟩_vol [MPa].
1788
1797
 
1789
- The total pressure is p = p_e + p_i = n_e T_e + n_i T_i. With n_i ≈ n_e
1790
- and the prescribed ratio T_i = τ_ie · T_e, the single-temperature prefactor
1791
- 2 generalises to (1 + τ_ie); τ_ie = 1 recovers p̄ = 2⟨nT⟩ (T_i = T_e).
1798
+ The total pressure is p = p_e + p_i = n_e T_e + n_i T_i, with the total
1799
+ ion density n_i = f_i n_e from quasi-neutrality (f_i = n_ion_frac, below 1
1800
+ with He ash and impurities) and the prescribed ratio T_i = τ_ie · T_e.
1801
+ f_i = 1 and τ_ie = 1 recover p̄ = 2⟨nT⟩.
1792
1802
  The integral ⟨nT⟩_vol = ∫ n(ρ)·T(ρ)·w(ρ) dρ uses:
1793
1803
 
1794
1804
  Academic mode:
@@ -1807,6 +1817,8 @@ def f_pbar(nu_n, nu_T, n_bar, Tbar,
1807
1817
  n_ped_frac : float n_ped / n̄.
1808
1818
  T_ped_frac : float T_ped / T̄.
1809
1819
  Vprime_data : tuple or None Precomputed Miller data (refined mode).
1820
+ tau_i_e : float T_i / T_e.
1821
+ n_ion_frac : float n_i,tot / n_e = 1 - f_He - sum_j (Z_j - 1) c_j.
1810
1822
 
1811
1823
  Returns
1812
1824
  -------
@@ -1832,24 +1844,24 @@ def f_pbar(nu_n, nu_T, n_bar, Tbar,
1832
1844
  T_hat = f_Tprof(1.0, nu_T, rho_grid, rho_ped, T_ped_frac,
1833
1845
  Vprime_data)
1834
1846
  C_vol = float(np.trapezoid(n_hat * T_hat * Vprime, rho_grid)) / V_total
1835
- # p = p_e + p_i = (1 + tau_i_e) n_e T_e (n_i ~ n_e, T_i = tau_i_e T_e)
1836
- profile_factor = (1.0 + tau_i_e) * C_vol
1847
+ # p = p_e + p_i = (1 + f_i tau_i_e) n_e T_e (n_i = f_i n_e, T_i = tau_i_e T_e)
1848
+ profile_factor = (1.0 + n_ion_frac * tau_i_e) * C_vol
1837
1849
 
1838
1850
  elif rho_ped >= 1.0:
1839
1851
  # Academic mode, parabolic: closed-form analytical result.
1840
- # Prefactor (1 + tau_i_e): p = p_e + p_i with T_i = tau_i_e T_e.
1841
- profile_factor = (1.0 + tau_i_e) * (1.0 + nu_n) * (1.0 + nu_T) / (1.0 + nu_n + nu_T)
1852
+ # Prefactor (1 + f_i tau_i_e): p = p_e + p_i, n_i = f_i n_e, T_i = tau_i_e T_e.
1853
+ profile_factor = (1.0 + n_ion_frac * tau_i_e) * (1.0 + nu_n) * (1.0 + nu_T) / (1.0 + nu_n + nu_T)
1842
1854
 
1843
1855
  else:
1844
1856
  # Academic mode, pedestal: numerical with cylindrical weight 2ρ dρ
1845
1857
  # C_vol = <n̂ T̂>_vol = 2 ∫₀¹ n̂(ρ) T̂(ρ) ρ dρ (cylindrical volume average)
1846
- # profile_factor = (1 + tau_i_e) × C_vol (p = p_e + p_i, T_i = tau_i_e T_e)
1858
+ # profile_factor = (1 + f_i tau_i_e) × C_vol (p = p_e + p_i)
1847
1859
  rho_arr = np.linspace(0.0, 1.0, 2000)
1848
1860
  n_hat = f_nprof(1.0, nu_n, rho_arr, rho_ped, n_ped_frac)
1849
1861
  T_hat = f_Tprof(1.0, nu_T, rho_arr, rho_ped, T_ped_frac)
1850
1862
  C_vol = 2.0 * float(np.trapezoid(n_hat * T_hat * rho_arr, rho_arr))
1851
- profile_factor = (1.0 + tau_i_e) * C_vol
1852
-
1863
+ profile_factor = (1.0 + n_ion_frac * tau_i_e) * C_vol
1864
+
1853
1865
  # Convert: n [10²⁰ m⁻³] × T [keV] → p [Pa] → [MPa]
1854
1866
  p_bar = profile_factor * (n_bar * 1e20) * (Tbar * E_ELEM * 1e3) / 1e6
1855
1867
 
@@ -1997,19 +2009,21 @@ def f_n_limit_zanca(P_tot, Ip, a, Z_eff, Z_i=1.0, f0=0.5):
1997
2009
  * (P_tot / Ip)**(4.0/9.0) * nGW**(8.0/9.0))
1998
2010
 
1999
2011
 
2000
- def f_n_edge_ratio(nu_n, rho_ped=1.0, n_ped_frac=0.0, rho_edge=0.9):
2012
+ def f_n_edge_ratio(nu_n, rho_ped=1.0, n_ped_frac=0.0, rho_edge=0.9,
2013
+ Vprime_data=None):
2001
2014
  """
2002
2015
  Near-separatrix to volume-average density ratio n(rho_edge)/nbar [-].
2003
2016
 
2004
2017
  The Giacomin et al. (2022) density limit bounds the NEAR-SEPARATRIX
2005
2018
  density, measured around rho ~ 0.9 in the reference paper (edge Thomson
2006
2019
  at MARFE onset), not the separatrix density itself. This helper
2007
- evaluates n(rho_edge)/nbar from the parameterised density profile
2008
- (cylindrical normalisation) for use as the edge-to-average conversion
2009
- of f_density_limit.
2020
+ evaluates n(rho_edge)/nbar from the parameterised density profile, with
2021
+ the same volume element as nbar (Miller V' in refined geometry,
2022
+ cylindrical otherwise), for use as the edge-to-average conversion of
2023
+ f_density_limit.
2010
2024
  """
2011
2025
  return float(f_nprof(1.0, nu_n, np.array([rho_edge]),
2012
- rho_ped, n_ped_frac)[0])
2026
+ rho_ped, n_ped_frac, Vprime_data)[0])
2013
2027
 
2014
2028
 
2015
2029
  def f_density_limit(model, Ip, a, P_sol=None, P_tot=None, R0=None, kappa=None,
@@ -2136,10 +2150,13 @@ if __name__ == "__main__":
2136
2150
  rho_ped=ITER['rho_ped'], n_ped_frac=ITER['n_ped_frac'],
2137
2151
  T_ped_frac=ITER['T_ped_frac'],
2138
2152
  Vprime_data=ITER_Vpd, f_imp=FROZEN['f_imp_dil'], tau_i_e=1.0)
2153
+ # Total ion density over n_e (quasi-neutrality with He ash and W + Ne)
2154
+ _n_ion_frac = (1.0 - FROZEN['f_alpha'] - FROZEN['f_imp_dil']
2155
+ + sum(ITER['imp'].values()))
2139
2156
  _p = f_pbar(ITER['nu_n'], ITER['nu_T'], _n, ITER['Tbar'],
2140
2157
  rho_ped=ITER['rho_ped'], n_ped_frac=ITER['n_ped_frac'],
2141
2158
  T_ped_frac=ITER['T_ped_frac'],
2142
- Vprime_data=ITER_Vpd, tau_i_e=1.0)
2159
+ Vprime_data=ITER_Vpd, tau_i_e=1.0, n_ion_frac=_n_ion_frac)
2143
2160
  _nl = f_nbar_line(_n, ITER['nu_n'], ITER['rho_ped'], ITER['n_ped_frac'])
2144
2161
  _nl_flat = f_nbar_line(1.0, 0.0) # analytic identity for a flat profile
2145
2162
  ITER.update(nbar=_n, pbar=_p, nbar_line=_nl)
@@ -2463,133 +2480,102 @@ def f_beta_N(beta, a, B0, Ip_MA):
2463
2480
  return beta_N
2464
2481
 
2465
2482
 
2466
- def f_beta_fast_alpha(P_alpha_MW, Te_keV, ne_20, B0, V_m3, Z_eff=1.65,
2467
- A_DT=2.5):
2483
+ def _alpha_slowing_down(Te_keV, ne_20, A_DT=2.5):
2468
2484
  """
2469
- Fast-alpha contribution to toroidal beta from slowing-down pressure.
2485
+ Local alpha slowing-down quantities (vectorised in Te_keV, ne_20).
2470
2486
 
2471
- Fusion-born alpha particles (E_alpha = 3.52 MeV) slow down on thermal
2472
- electrons and ions over a characteristic time tau_se. During this
2473
- transient, they carry a stored energy W_fast that exerts a real
2474
- MHD-relevant pressure but is NOT included in the thermal energy W_th
2475
- (which enters the confinement scaling law).
2476
-
2477
- The fast-alpha beta must be added to the thermal beta when comparing
2478
- against the MHD stability limit (beta_N < beta_N_crit), because
2479
- kink, ballooning, and NTM modes respond to the total pressure.
2480
-
2481
- Model
2482
- -----
2483
- The Stix (1972) isotropic slowing-down distribution gives the
2484
- steady-state fast-particle energy content as:
2487
+ Returns (tau_se [s], E_c [keV], G_eff [-]) with
2488
+ tau_se = 6.27e14 A_a/Z_a^2 Te[eV]^1.5 / (ne[m^-3] lnLambda) (NRL),
2489
+ E_c = 14.8 A_a Te (1/A_DT)^(2/3) (Stix),
2490
+ G_eff = (E_c/E_a) I_w / 3, I_w = int_0^u0 w^(2/3)/(w+1) dw (Cordey-Core),
2491
+ so that the local stored fast-alpha energy density is s_a tau_se G_eff.
2492
+ """
2493
+ A_alpha, Z_alpha, E_alpha = 4.0, 2.0, 3520.0
2494
+ Te = np.maximum(np.asarray(Te_keV, dtype=float), 0.1)
2495
+ ne = np.maximum(np.asarray(ne_20, dtype=float), 1e-3)
2496
+ ln_Lambda = np.maximum(15.2 - 0.5 * np.log(ne) + np.log(Te), 10.0)
2497
+ tau_se = 6.27e14 * A_alpha / Z_alpha**2 * (Te * 1e3)**1.5 / (ne * 1e20 * ln_Lambda)
2498
+ E_c = 14.8 * A_alpha * Te * (1.0 / A_DT)**(2.0 / 3.0)
2499
+ # Analytical integral, partial fractions of t^4/(t^3+1), y = v0/vc > 1
2500
+ y = np.sqrt(np.maximum(E_alpha / np.maximum(E_c, 1.0), 1.01))
2501
+ I_t4 = (y**2 / 2.0 + np.log(y + 1.0) / 3.0 - np.log(y**2 - y + 1.0) / 6.0
2502
+ - (np.arctan((2.0 * y - 1.0) / np.sqrt(3.0)) + np.pi / 6.0) / np.sqrt(3.0))
2503
+ G_eff = (E_c / E_alpha) * 3.0 * I_t4 / 3.0
2504
+ return tau_se, E_c, G_eff
2485
2505
 
2486
- W_fast = P_alpha * tau_se * G_eff(E_alpha/E_c)
2487
2506
 
2488
- where tau_se is the Spitzer electron-drag time defined via
2489
- dv/dt = -v/tau_se, E_alpha is the alpha birth energy, and E_c
2490
- is the critical velocity (electron/ion drag crossover).
2491
- G_eff is the dimensionless Cordey & Core (1974) energy-integral
2492
- function. It rises monotonically from zero to its asymptotic
2493
- value 1/2 as E_alpha/E_c -> infinity, taking values close to
2494
- 0.40 for E_alpha/E_c ~ 10 (ITER and EU-DEMO operating
2495
- conditions). The simple textbook formula W_fast = P_alpha
2496
- * tau_se / 3 is an order-of-magnitude estimate, not an
2497
- asymptotic limit; the analytical Cordey-Core integral evaluated
2498
- here gives the correct value at finite E_alpha/E_c.
2507
+ def f_beta_fast_alpha(P_alpha_MW, Tbar, nbar, B0, V_m3, nu_n, nu_T,
2508
+ rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0,
2509
+ Vprime_data=None, tau_i_e=1.0, A_DT=2.5, fuel='DT'):
2510
+ """
2511
+ Fast-alpha contribution to toroidal beta from the slowing-down pressure,
2512
+ integrated over the kinetic profiles.
2499
2513
 
2500
- The Spitzer electron-drag time (NRL Plasma Formulary):
2514
+ Fusion-born alphas (E_alpha = 3.52 MeV) slow down on electrons and ions
2515
+ over tau_se. Their stored energy is an MHD-relevant pressure not included
2516
+ in W_th (hence not in the confinement scaling), and is added to the
2517
+ thermal beta for the Troyon check.
2501
2518
 
2502
- tau_se [s] = 6.27e14 * A_alpha / Z_alpha^2
2503
- * T_e[eV]^{3/2} / (n_e[m^-3] * ln Lambda)
2519
+ Model
2520
+ -----
2521
+ Local isotropic Stix (1972) slowing-down, alphas deposited where born:
2522
+ w_fast(rho) = s_alpha(rho) tau_se(rho) G_eff(E_alpha / E_c(rho))
2523
+ s_alpha(rho) proportional to n^2(rho) <sigma v>(T_i(rho)), with
2524
+ int s_alpha dV = P_alpha
2525
+ W_fast = int w_fast dV, <p_fast> = (2/3) W_fast / V
2526
+ tau_se ~ T_e^1.5 / n_e and E_c ~ T_e are evaluated with the LOCAL T_e(rho)
2527
+ and n_e(rho) where the alphas are born: a volume-averaged evaluation
2528
+ underestimates W_fast by a factor ~1.8 on peaked reactor profiles, because
2529
+ the source sits where T_e is highest.
2504
2530
 
2505
2531
  Parameters
2506
2532
  ----------
2507
- P_alpha_MW : float
2508
- Total alpha heating power deposited in the plasma [MW].
2509
- Typically P_alpha = 0.2 * P_fus (D-T: E_alpha/E_n = 3.52/14.06).
2510
- Te_keV : float
2511
- Volume-averaged electron temperature [keV].
2512
- ne_20 : float
2513
- Volume-averaged electron density [10^20 m^-3].
2514
- B0 : float
2515
- On-axis toroidal magnetic field [T].
2516
- V_m3 : float
2517
- Plasma volume [m^3].
2518
- Z_eff : float, optional
2519
- Effective charge (enters Coulomb logarithm and critical energy).
2520
- Default 1.65.
2521
- A_DT : float, optional
2522
- Effective fuel mass number (2.5 for 50/50 D-T). Default 2.5.
2533
+ P_alpha_MW : float Alpha heating power [MW].
2534
+ Tbar : float Volume-averaged electron temperature [keV].
2535
+ nbar : float Volume-averaged electron density [10^20 m^-3].
2536
+ B0 : float On-axis toroidal field [T].
2537
+ V_m3 : float Plasma volume [m^3].
2538
+ nu_n, nu_T : float Density / temperature peaking exponents.
2539
+ rho_ped, n_ped_frac, T_ped_frac : float Pedestal parameters.
2540
+ Vprime_data : tuple or None Miller volume element (None: cylindrical 2 rho).
2541
+ tau_i_e : float T_i / T_e (reactivity evaluated on T_i).
2542
+ A_DT : float Effective fuel mass number (2.5 for 50/50 D-T).
2543
+ fuel : str 'DT' or 'DD' (source shape from DDn + DDp).
2523
2544
 
2524
2545
  Returns
2525
2546
  -------
2526
- beta_fast : float
2527
- Fast-alpha contribution to toroidal beta (dimensionless).
2528
- tau_se : float
2529
- Spitzer electron-drag time [s].
2530
- W_fast : float
2531
- Stored fast-alpha energy [MJ].
2547
+ beta_fast : float Fast-alpha toroidal beta [-].
2548
+ tau_se : float Source-weighted electron-drag time [s].
2549
+ W_fast : float Stored fast-alpha energy [MJ].
2532
2550
 
2533
2551
  References
2534
2552
  ----------
2535
2553
  Stix, Plasma Physics 14 (1972) 367 — slowing-down distribution.
2536
2554
  Cordey & Core, Phys. Fluids 17 (1974) 1626 — energy integral.
2537
2555
  Wesson, Tokamaks 4th ed. (2011), §14.5 — critical velocity.
2538
- Kovari et al., Fus. Eng. Des. 89 (2014) 3054, §17 — PROCESS model.
2539
- """
2540
- # ── Alpha parameters ──
2541
- A_alpha = 4.0 # alpha mass number
2542
- Z_alpha = 2.0 # alpha charge
2543
- E_alpha = 3520.0 # alpha birth energy [keV]
2544
-
2545
- # ── Coulomb logarithm (alpha-electron) ──
2546
- ln_Lambda = max(15.2 - 0.5 * np.log(max(ne_20, 1e-3))
2547
- + np.log(max(Te_keV, 0.1)), 10.0)
2548
-
2549
- # ── Spitzer electron-drag time ──
2550
- # tau_se = (3/(4 sqrt(2 pi))) * (4 pi eps_0)^2 * m_alpha * (kT_e)^1.5
2551
- # / (Z_alpha^2 * e^4 * n_e * sqrt(m_e) * ln Lambda)
2552
- # In practical units (derived from SI, verified numerically):
2553
- # tau_se = 6.27e14 * A_alpha/Z_alpha^2 * Te[eV]^1.5 / (ne[m^-3] * lnL)
2554
- ne_m3 = ne_20 * 1e20
2555
- Te_eV = Te_keV * 1e3
2556
- tau_se = (6.27e14 * A_alpha / Z_alpha**2
2557
- * Te_eV**1.5 / (ne_m3 * ln_Lambda))
2558
-
2559
- # ── Critical energy (electron/ion drag crossover) ──
2560
- # E_c = 14.8 * A_alpha * Te[keV] * (sum_j n_j Z_j^2 / (n_e A_j))^{2/3}
2561
- # For DT plasma: sum = (1/A_DT) approximately (fuel dominates)
2562
- # Wesson (2011) Eq. 14.5.5; Stix (1972) Eq. 18.
2563
- sigma_Zi = 1.0 / A_DT # simplified: pure fuel, Z=1, <1/A> = 1/A_DT
2564
- E_c = 14.8 * A_alpha * Te_keV * sigma_Zi**(2.0/3.0) # [keV]
2565
-
2566
- # ── Stix energy integral (Cordey & Core 1974) ──
2567
- # W_fast = (P_α/E_α) × (τ_se/3) × E_c × ∫₀^u₀ w^{2/3}/(w+1) dw
2568
- # where u₀ = (E₀/E_c)^{3/2}. Substituting w = t³:
2569
- # ∫ = 3 × ∫₀^y t⁴/(t³+1) dt, y = sqrt(E₀/E_c) = v₀/v_c
2570
- # Analytical result (partial fractions):
2571
- # ∫₀^y t⁴/(t³+1) dt = y²/2 + (1/3)ln(y+1) - (1/6)ln(y²-y+1)
2572
- # - (1/√3)[arctan((2y-1)/√3) + π/6]
2573
- y = np.sqrt(max(E_alpha / max(E_c, 1.0), 1.01)) # v₀/v_c, clamp > 1
2574
- I_t4 = (y**2 / 2.0
2575
- + np.log(y + 1.0) / 3.0
2576
- - np.log(y**2 - y + 1.0) / 6.0
2577
- - (np.arctan((2.0*y - 1.0) / np.sqrt(3.0)) + np.pi/6.0) / np.sqrt(3.0))
2578
- I_w = 3.0 * I_t4 # = ∫₀^{u₀} w^{2/3}/(w+1) dw
2579
-
2580
- # Effective G factor: W_fast = P_α × τ_se × G_eff
2581
- G_eff = (E_c / E_alpha) * I_w / 3.0
2582
-
2583
- # ── Fast-alpha stored energy and pressure ──
2584
- P_alpha_W = P_alpha_MW * 1e6 # MW → W
2585
- W_fast_J = P_alpha_W * tau_se * G_eff # [J]
2586
- p_fast = (2.0 / 3.0) * W_fast_J / V_m3 # [Pa], isotropic
2587
-
2588
- # ── Fast-alpha beta ──
2589
- μ0 = 4.0e-7 * np.pi
2590
- beta_fast = 2.0 * μ0 * p_fast / B0**2
2591
-
2592
- return beta_fast, tau_se, W_fast_J / 1e6 # beta [-], tau [s], W [MJ]
2556
+ """
2557
+ if Vprime_data is not None:
2558
+ rho = np.asarray(Vprime_data[0], dtype=float)
2559
+ w_vol = np.asarray(Vprime_data[1], dtype=float) / float(Vprime_data[2])
2560
+ else:
2561
+ rho = np.linspace(0.0, 1.0, 400)
2562
+ w_vol = 2.0 * rho
2563
+ Te = np.maximum(f_Tprof(Tbar, nu_T, rho, rho_ped, T_ped_frac, Vprime_data), 0.1)
2564
+ ne = np.maximum(f_nprof(nbar, nu_n, rho, rho_ped, n_ped_frac, Vprime_data), 1e-3)
2565
+ Ti = tau_i_e * Te
2566
+ sv = (f_sigmav(Ti, 'DT') if fuel == 'DT'
2567
+ else f_sigmav(Ti, 'DDn') + f_sigmav(Ti, 'DDp'))
2568
+ src = ne**2 * sv # shape of s_alpha
2569
+ norm = float(np.trapezoid(src * w_vol, rho))
2570
+ if not (np.isfinite(norm) and norm > 0):
2571
+ return 0.0, np.nan, 0.0
2572
+ s_alpha = P_alpha_MW * 1e6 * src / (norm * V_m3) # [W/m^3]
2573
+ tau_se, _, G_eff = _alpha_slowing_down(Te, ne, A_DT)
2574
+ W_fast_J = V_m3 * float(np.trapezoid(s_alpha * tau_se * G_eff * w_vol, rho))
2575
+ tau_se_src = float(np.trapezoid(src * tau_se * w_vol, rho)) / norm
2576
+ p_fast = (2.0 / 3.0) * W_fast_J / V_m3 # [Pa], isotropic
2577
+ beta_fast = 2.0 * (4.0e-7 * np.pi) * p_fast / B0**2
2578
+ return beta_fast, tau_se_src, W_fast_J / 1e6 # beta [-], tau [s], W [MJ]
2593
2579
 
2594
2580
 
2595
2581
  if __name__ == "__main__":
@@ -2612,7 +2598,8 @@ if __name__ == "__main__":
2612
2598
  # (defined in the next section, re-checked in chain 7).
2613
2599
  _bfa, _tau_se, _W_fast = f_beta_fast_alpha(
2614
2600
  ITER['P_fus'] / 5.0, ITER['Tbar'], ITER['nbar'], _B0, ITER['V'],
2615
- Z_eff=ITER['Zeff'])
2601
+ ITER['nu_n'], ITER['nu_T'], rho_ped=ITER['rho_ped'],
2602
+ n_ped_frac=ITER['n_ped_frac'], T_ped_frac=ITER['T_ped_frac'])
2616
2603
  ITER.update(B0=_B0, W_th=_W, betaN=_bN)
2617
2604
  _bench("ITER chain 3/12 - field, stored energy and beta", [
2618
2605
  ("B0 on axis [T]", _B0, 5.30, 1e-3, "Shimada 2007"),
@@ -2843,6 +2830,45 @@ def f_P_elec(P_fus, P_CD, eta_T, M_blanket=1.0, eta_WP=1.0, f_neutron=0.8):
2843
2830
 
2844
2831
  #%% Radiation losses
2845
2832
 
2833
+ _albajar_exponent_cache = {}
2834
+
2835
+
2836
+ def _albajar_profile_exponents(nu_n, nu_T, rho_ped=1.0, n_ped_frac=0.0,
2837
+ T_ped_frac=0.0, Vprime_data=None, tbeta=2.0):
2838
+ """
2839
+ Shape exponents (alpha_n, alpha_T, beta_T) of the Albajar (2001) K factor
2840
+ that best describe the D0FUS profiles.
2841
+
2842
+ Albajar's K was fitted for n = n0 (1 - rho^2)^alpha_n and
2843
+ T = T0 (1 - rho^beta_T)^alpha_T. Purely parabolic profiles map exactly
2844
+ (alpha_n = nu_n, alpha_T = nu_T, beta_T = tbeta). With a pedestal, the
2845
+ core exponents nu_n, nu_T no longer describe the normalised profile
2846
+ shape (up to 10 % rms deviation in T/T0), so the three exponents are
2847
+ least-squares fitted to n(rho)/n0 and T(rho)/T0 on the core,
2848
+ rho <= rho_ped, where the synchrotron power is emitted.
2849
+ """
2850
+ if rho_ped >= 1.0:
2851
+ return nu_n, nu_T, tbeta
2852
+ geo = (hash(np.ascontiguousarray(Vprime_data[1]).tobytes())
2853
+ if Vprime_data is not None else None)
2854
+ key = (nu_n, nu_T, rho_ped, n_ped_frac, T_ped_frac, geo)
2855
+ if key in _albajar_exponent_cache:
2856
+ return _albajar_exponent_cache[key]
2857
+ rho = np.linspace(0.0, rho_ped, 200)
2858
+ t = f_Tprof(1.0, nu_T, rho, rho_ped, T_ped_frac, Vprime_data)
2859
+ n = f_nprof(1.0, nu_n, rho, rho_ped, n_ped_frac, Vprime_data)
2860
+ t, n = t / t[0], n / n[0]
2861
+ rT = lambda p: np.maximum(1.0 - rho**p[1], 0.0)**p[0] - t
2862
+ rN = lambda p: np.maximum(1.0 - rho**2, 0.0)**p[0] - n
2863
+ aT, bT = least_squares(rT, [max(nu_T, 0.5), 2.0],
2864
+ bounds=([0.1, 0.5], [10.0, 10.0])).x
2865
+ an = least_squares(rN, [max(nu_n, 0.0)], bounds=([0.0], [10.0])).x[0]
2866
+ if len(_albajar_exponent_cache) > 5000:
2867
+ _albajar_exponent_cache.clear()
2868
+ _albajar_exponent_cache[key] = (float(an), float(aT), float(bT))
2869
+ return _albajar_exponent_cache[key]
2870
+
2871
+
2846
2872
  def f_P_synchrotron(Tbar, R0, a, B0, nbar, kappa, nu_n, nu_T, r_synch,
2847
2873
  tbeta=2.0,
2848
2874
  rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0,
@@ -2864,7 +2890,9 @@ def f_P_synchrotron(Tbar, R0, a, B0, nbar, kappa, nu_n, nu_T, r_synch,
2864
2890
  p_a0 = 6.04e3 × a × ne0[10²⁰] / B₀
2865
2891
  - Profile factor K (Albajar Eq. 13), depends on (αn, αT, βT):
2866
2892
  The temperature profile is T ∝ (1 − ρ^βT)^αT.
2867
- αT = nu_T (peaking), βT = tbeta (radial shape, default 2).
2893
+ Parabolic profiles: αn = nu_n, αT = nu_T, βT = tbeta.
2894
+ Pedestal profiles: (αn, αT, βT) fitted to the actual core
2895
+ profile shape (_albajar_profile_exponents).
2868
2896
  - Aspect-ratio factor G (Albajar Eq. 15):
2869
2897
  G = 0.93 (1 + 0.85 exp(−0.82 A))
2870
2898
  - Wall reflection (Fidone 2001):
@@ -2889,9 +2917,9 @@ def f_P_synchrotron(Tbar, R0, a, B0, nbar, kappa, nu_n, nu_T, r_synch,
2889
2917
  r_synch : float
2890
2918
  First-wall reflectivity for synchrotron photons [0, 1).
2891
2919
  tbeta : float, optional
2892
- Temperature profile radial exponent βT in T ∝ (1−ρ^βT)^αT.
2893
- Default 2.0 (standard parabolic: (1−ρ²)^αT).
2894
- This enters the K factor only (Albajar Eq. 13).
2920
+ Temperature profile radial exponent βT in T ∝ (1−ρ^βT)^αT for
2921
+ parabolic profiles (default 2.0). Fitted when a pedestal is present.
2922
+ Enters the K factor only (Albajar Eq. 13).
2895
2923
  rho_ped, n_ped_frac, T_ped_frac : float
2896
2924
  Pedestal parameters forwarded to f_Tprof / f_nprof.
2897
2925
  Default values correspond to purely parabolic profiles.
@@ -2915,20 +2943,22 @@ def f_P_synchrotron(Tbar, R0, a, B0, nbar, kappa, nu_n, nu_T, r_synch,
2915
2943
 
2916
2944
  pa0 = 6.04e3 * a * ne0 / B0 # opacity parameter (Eq. 7)
2917
2945
 
2918
- # Profile factor K (Albajar 2001, Eq. 13).
2919
- # K depends on αn (= nu_n), αT (= nu_T), and βT (= tbeta).
2946
+ # Profile factor K (Albajar 2001, Eq. 13), with the shape exponents of
2947
+ # the actual profiles (exact for parabolic ones, fitted with a pedestal).
2920
2948
  # The denominator (βT^1.53 + 1.87·αT − 0.16) vanishes for small βT;
2921
2949
  # clamp βT to 0.5 minimum for numerical safety.
2922
- bT = max(tbeta, 0.5)
2923
- nu_T_K = max(nu_T, 0.1)
2924
- if nu_T < 0.1:
2950
+ a_n, a_T, b_T = _albajar_profile_exponents(nu_n, nu_T, rho_ped, n_ped_frac,
2951
+ T_ped_frac, Vprime_data, tbeta)
2952
+ bT = max(b_T, 0.5)
2953
+ nu_T_K = max(a_T, 0.1)
2954
+ if a_T < 0.1:
2925
2955
  warnings.warn(
2926
- f"f_P_synchrotron: nu_T = {nu_T:.3f} < 0.1; clamped to 0.1 "
2927
- "for the Albajar K-factor (valid for nu_T >= 0.5).",
2956
+ f"f_P_synchrotron: alpha_T = {a_T:.3f} < 0.1; clamped to 0.1 "
2957
+ "for the Albajar K-factor (valid for alpha_T >= 0.5).",
2928
2958
  RuntimeWarning, stacklevel=2
2929
2959
  )
2930
2960
 
2931
- K = ((nu_n + 3.87*nu_T_K + 1.46)**(-0.79) # Albajar Eq. 13
2961
+ K = ((a_n + 3.87*nu_T_K + 1.46)**(-0.79) # Albajar Eq. 13
2932
2962
  * (1.98 + nu_T_K)**1.36 * bT**2.14
2933
2963
  / (bT**1.53 + 1.87*nu_T_K - 0.16)**1.33)
2934
2964
 
@@ -4402,7 +4432,8 @@ if __name__ == "__main__":
4402
4432
  _bench("Published anchors - ECCD (Giruzzi/Lin-Liu) vs METIS", _rows)
4403
4433
 
4404
4434
  def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4405
- rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0):
4435
+ rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0,
4436
+ Vprime_data=None):
4406
4437
  """
4407
4438
  Effective CD figure of merit γ_CD [MA/(MW·m²)] for the active heating mix.
4408
4439
 
@@ -4448,6 +4479,9 @@ def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4448
4479
  nu_n, nu_T : float Density and temperature peaking exponents.
4449
4480
  Z_eff : float Effective plasma charge.
4450
4481
  rho_ped, n_ped_frac, T_ped_frac : float Pedestal parameters.
4482
+ Vprime_data : tuple or None Miller volume element used for nbar, Tbar,
4483
+ so that the local T_e and n_e at deposition share their
4484
+ normalisation.
4451
4485
 
4452
4486
  Returns
4453
4487
  -------
@@ -4473,7 +4507,7 @@ def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4473
4507
  config.rho_EC,
4474
4508
  theta_EC_pol_deg=config.theta_EC_pol_deg,
4475
4509
  rho_ped=rho_ped, n_ped_frac=n_ped_frac,
4476
- T_ped_frac=T_ped_frac)
4510
+ T_ped_frac=T_ped_frac, Vprime_data=Vprime_data)
4477
4511
 
4478
4512
  elif CD_source == 'NBCD':
4479
4513
  return f_etaCD_NBI_physics(
@@ -4483,7 +4517,8 @@ def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4483
4517
  f_alpha=getattr(config, '_f_alpha', 0.04),
4484
4518
  angle_NBI_deg=config.angle_NBI_deg,
4485
4519
  rho_ped=rho_ped, n_ped_frac=n_ped_frac,
4486
- T_ped_frac=T_ped_frac, fuel=config.Fuel)
4520
+ T_ped_frac=T_ped_frac, Vprime_data=Vprime_data,
4521
+ fuel=config.Fuel)
4487
4522
 
4488
4523
 
4489
4524
  elif CD_source == 'Multi':
@@ -4493,7 +4528,7 @@ def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4493
4528
  config.rho_EC,
4494
4529
  theta_EC_pol_deg=config.theta_EC_pol_deg,
4495
4530
  rho_ped=rho_ped, n_ped_frac=n_ped_frac,
4496
- T_ped_frac=T_ped_frac)
4531
+ T_ped_frac=T_ped_frac, Vprime_data=Vprime_data)
4497
4532
  gamma_NBI = f_etaCD_NBI_physics(
4498
4533
  config.A_beam, config.E_beam_keV,
4499
4534
  a, R0, Tbar, nbar, Z_eff, nu_T, nu_n,
@@ -4501,7 +4536,8 @@ def f_etaCD_effective(config, a, R0, B0, nbar, Tbar, nu_n, nu_T, Z_eff,
4501
4536
  f_alpha=getattr(config, '_f_alpha', 0.04),
4502
4537
  angle_NBI_deg=config.angle_NBI_deg,
4503
4538
  rho_ped=rho_ped, n_ped_frac=n_ped_frac,
4504
- T_ped_frac=T_ped_frac, fuel=config.Fuel)
4539
+ T_ped_frac=T_ped_frac, Vprime_data=Vprime_data,
4540
+ fuel=config.Fuel)
4505
4541
 
4506
4542
  # Power-weighted average: ICRH contributes heating but zero current drive
4507
4543
  f_LH = config.f_heat_LH
@@ -5338,8 +5374,10 @@ def f_Reff(a, kappa, R0, Tbar, nbar, Z_eff, q95, nu_T, nu_n,
5338
5374
 
5339
5375
  def _eta_local(rho):
5340
5376
  """Neoclassical resistivity [Ohm.m] at normalised radius rho."""
5341
- T_loc = max(float(f_Tprof(Tbar, nu_T, rho, rho_ped, T_ped_frac)), 0.1)
5342
- n_loc = float(f_nprof(nbar, nu_n, rho, rho_ped, n_ped_frac))
5377
+ T_loc = max(float(f_Tprof(Tbar, nu_T, rho, rho_ped, T_ped_frac,
5378
+ Vprime_data)), 0.1)
5379
+ n_loc = float(f_nprof(nbar, nu_n, rho, rho_ped, n_ped_frac,
5380
+ Vprime_data))
5343
5381
  n_loc_m3 = n_loc * 1e20
5344
5382
  epsilon_loc = rho * a / R0
5345
5383
 
@@ -5509,8 +5547,10 @@ def f_I_Ohm(Ip, Ib, I_CD):
5509
5547
  In steady state the total plasma current is the sum of inductive,
5510
5548
  bootstrap, and externally driven contributions:
5511
5549
  Ip = I_Ohm + I_b + I_CD
5512
- Inverting gives I_Ohm as the remainder. The absolute value guards
5513
- against small numerical over-shoots that would produce a negative result.
5550
+ Inverting gives I_Ohm as the remainder. When I_b + I_CD exceed Ip
5551
+ (overdrive) the inductive current is set to zero rather than folded back
5552
+ to a positive value: the excess non-inductive current does not dissipate
5553
+ ohmic power in this 0D balance.
5514
5554
 
5515
5555
  Parameters
5516
5556
  ----------
@@ -5522,7 +5562,7 @@ def f_I_Ohm(Ip, Ib, I_CD):
5522
5562
  -------
5523
5563
  I_Ohm : float Inductive (Ohmic) current component [MA].
5524
5564
  """
5525
- return abs(Ip - Ib - I_CD)
5565
+ return max(Ip - Ib - I_CD, 0.0)
5526
5566
 
5527
5567
 
5528
5568
  def f_I_CD_from_balance(Ip, Ib, I_Ohm):
@@ -5548,9 +5588,10 @@ def f_I_CD_from_balance(Ip, Ib, I_Ohm):
5548
5588
 
5549
5589
  Returns
5550
5590
  -------
5551
- I_CD : float Required non-inductive driven current [MA].
5591
+ I_CD : float Required non-inductive driven current [MA]; zero when the
5592
+ bootstrap current alone already covers Ip - I_Ohm.
5552
5593
  """
5553
- return abs(Ip - Ib - I_Ohm)
5594
+ return max(Ip - Ib - I_Ohm, 0.0)
5554
5595
 
5555
5596
 
5556
5597
 
@@ -5779,18 +5820,28 @@ This module provides:
5779
5820
  2. An integrated 0D bootstrap current estimate assuming parabolic profiles -
5780
5821
  suitable for system codes like D0FUS
5781
5822
 
5782
- Implementation follows Sauter Eq. 5 directly:
5823
+ Implementation follows Sauter Eq. 5 in the flux coordinate psi:
5824
+
5825
+ <j_bs . B> = -F(psi) * p * [ L31 * d(ln p)/d(psi)
5826
+ + L32 * R_pe * d(ln Te)/d(psi)
5827
+ + L34 * alpha * (1-R_pe) * d(ln Ti)/d(psi) ]
5828
+
5829
+ Gradients are evaluated in rho and converted with the poloidal-flux derivative
5783
5830
 
5784
- <j_bs . B> = -I(psi) * p * [ L31 * d(ln p)/d(psi_hat)
5785
- + L32 * R_pe * d(ln Te)/d(psi_hat)
5786
- + L34 * alpha * (1-R_pe) * d(ln Ti)/d(psi_hat) ]
5831
+ d(psi)/d(rho) = R0 * F * <1/R^2> * (dA/drho) / (2*pi*q)
5787
5832
 
5788
- j_bs [A/m^2] = <j_bs . B> / <B^2>
5789
- I_bs [MA] = integral( j_bs * 2*pi*rho*a^2*kappa(rho) drho )
5833
+ so that <j_bs . B> / B0 = -F * p * C_rho / (B0 * dpsi/drho), with C_rho the
5834
+ bracket above written with d/drho. F = R0*B0, p is the LOCAL total pressure
5835
+ (n_i = n_i,tot/n_e * n_e from quasi-neutrality), and dA/drho, <1/R^2> come from
5836
+ the flux-surface geometry (Vprime_data) when it is supplied, or from the
5837
+ elliptic / circular approximations otherwise.
5790
5838
 
5791
- where I(psi) = R0*B0, p is the LOCAL total pressure, and <B^2> = B0^2*(1+eps^2/2)
5792
- in the large aspect ratio approximation. This is consistent with the recommendation
5793
- on the NEOS page (https://crppwww.epfl.ch/~sauter/neoclassical/):
5839
+ I_bs [MA] = integral( j_bs * dA/drho drho )
5840
+
5841
+ This assembly is the one of TORAX (calculate_analytic_bootstrap_current,
5842
+ v1.4.3). The Redl coefficients (L31, L32, alpha) agree with TORAX to 1e-16.
5843
+ The recommendation on the NEOS page
5844
+ (https://crppwww.epfl.ch/~sauter/neoclassical/) is followed:
5794
5845
  "Total pressure should be used for p and pe/p should be used where stated
5795
5846
  and not some approximations with Te and Ti for example."
5796
5847
 
@@ -5820,10 +5871,9 @@ coefficients (L31/L32/L34/alpha) are identical to NEOS, the j_bs assembly differ
5820
5871
  - Prefactor: 0.5 * 1e6 * (-B0*rho_circ)/(0.2*pi*R0*q)
5821
5872
  - Factor 0.5 compensates a convention in beta_p averaging (sum vs mean)
5822
5873
 
5823
- refined (Sauter Eq. 5 direct):
5824
- - Uses d(ln p)/dr directly (total pressure gradient)
5825
- - Multiplies by p(rho) / <B^2>(rho) with <B^2> = B0^2*(1+eps^2/2)
5826
- - Prefactor: -R0*B0 (= I(psi))
5874
+ D0FUS (Sauter Eq. 5, TORAX assembly):
5875
+ - Uses d(ln p)/d(psi) with the flux-surface-averaged psi derivative above
5876
+ - Prefactor: -F(psi) = -R0*B0
5827
5877
  - No additional numerical factors
5828
5878
 
5829
5879
  The PROCESS documentation itself acknowledges (April 2025):
@@ -5833,12 +5883,11 @@ The PROCESS documentation itself acknowledges (April 2025):
5833
5883
  flux surfaces across the plasma."
5834
5884
  (https://ukaea.github.io/PROCESS/physics-models/plasma_current/bootstrap_current/)
5835
5885
 
5836
- A dedicated comparison (bootstrap_comparison.py) feeding IDENTICAL profiles and
5837
- IDENTICAL Sauter coefficients into both assembly formulas yields:
5838
- I_bs(Sauter Eq.5) / I_bs(Fable) = 1.40 (+40%)
5839
- for EU-DEMO 2017 conditions. The ratio is approximately constant (~1.43) from
5840
- rho = 0.3 to the pedestal top, indicating a systematic geometric prefactor
5841
- difference rather than a localised numerical artifact.
5886
+ Before v2.10 D0FUS used d(ln p)/dr with <B^2> in the denominator, without the
5887
+ d(psi)/d(rho) normalisation. A comparison with that former assembly gave
5888
+ I_bs(D0FUS) / I_bs(Fable) = 1.40 for EU-DEMO 2017 conditions. The missing
5889
+ d(psi)/d(rho) factor most likely explains most of this ratio. The ratio with
5890
+ the present assembly has not been re-measured.
5842
5891
 
5843
5892
  References for this validation
5844
5893
  ------------------------------
@@ -6412,12 +6461,15 @@ def _L32_Redl(f_t, nu_e, Z):
6412
6461
 
6413
6462
  # ── Electron-electron: F32_ee [Eqs. 13–14] ──
6414
6463
  # Effective trapped fraction [Eq. 14] — new Z^2 and f_t² terms
6464
+ # Redl Eq. 14: the 0.13 (1 - 0.38 f_t) nu / Z^2 prefactor multiplies
6465
+ # [sqrt(1 + 2 sqrt(Z-1)) + f_t^2 sqrt((0.075 + 0.25 (Z-1)^2) nu)]
6466
+ # (checked against TORAX 1.4.3, neoclassical/formulas/redl.py).
6415
6467
  Zm1 = np.maximum(Z - 1.0, 0.0)
6416
6468
  ee_t1 = 0.23 * (1.0 - 0.96 * f_t) * sqrt_nu / np.sqrt(Z)
6417
- ee_t2 = (0.13 * (1.0 - 0.38 * f_t) * nu_e
6418
- / (Z**2 * np.sqrt(1.0 + 2.0 * np.sqrt(Zm1))))
6419
- ee_t3 = f_t**2 * np.sqrt((0.075 + 0.25 * Zm1**2) * nu_e)
6420
- f_t_ee = f_t / (1.0 + ee_t1 + ee_t2 + ee_t3)
6469
+ ee_t2 = (0.13 * (1.0 - 0.38 * f_t) * nu_e / Z**2
6470
+ * (np.sqrt(1.0 + 2.0 * np.sqrt(Zm1))
6471
+ + f_t**2 * np.sqrt((0.075 + 0.25 * Zm1**2) * nu_e)))
6472
+ f_t_ee = f_t / (1.0 + ee_t1 + ee_t2)
6421
6473
 
6422
6474
  X = f_t_ee
6423
6475
  # F32_ee polynomial [Eq. 13] — different denominators from Sauter
@@ -6475,7 +6527,8 @@ def f_Sauter_Redl_Ib(R0, a, kappa, B0, nbar, Tbar, q95, Z_eff, nu_n, nu_T, n_rho
6475
6527
  rho_ped=1.0, n_ped_frac=0.0, T_ped_frac=0.0,
6476
6528
  Vprime_data=None, kappa_95=None, rho_95=0.95,
6477
6529
  return_profile=False, q_profile=None,
6478
- trapped_fraction_model='Sauter2002', tau_i_e=1.0):
6530
+ trapped_fraction_model='Sauter2002', tau_i_e=1.0,
6531
+ n_ion_frac=1.0):
6479
6532
  """
6480
6533
  Bootstrap current using the Sauter-Redl neoclassical model.
6481
6534
 
@@ -6521,15 +6574,30 @@ def f_Sauter_Redl_Ib(R0, a, kappa, B0, nbar, Tbar, q95, Z_eff, nu_n, nu_T, n_rho
6521
6574
  Defaults to f_Kappa_95(kappa) (ITER 1989 guideline: kappa_edge / 1.12).
6522
6575
  rho_95 : float, optional
6523
6576
  Normalised position of the 95% flux surface (default 0.95).
6577
+ n_ion_frac : float, optional
6578
+ Total ion density over electron density, n_i,tot / n_e, from
6579
+ quasi-neutrality with He ash and impurities (1 = pure hydrogenic).
6524
6580
 
6525
6581
  Returns
6526
6582
  -------
6527
6583
  I_bs : float
6528
6584
  Bootstrap current [MA]
6529
6585
 
6586
+ Notes
6587
+ -----
6588
+ Sauter Eq. 5 is written with d/dpsi. The gradients are taken in rho and
6589
+ converted with the poloidal-flux derivative (per radian)
6590
+ psi'(rho) = R0 F <1/R^2>(rho) (dA/drho) / (2 pi q(rho)),
6591
+ the same uniform-B_p closure as f_q_profile_refined (cylindrical limit
6592
+ psi' = B0 a^2 rho / q), so that
6593
+ j_bs = -F p [L31 dln p + L32 R_pe dln Te + L34 alpha (1-R_pe) dln Ti]
6594
+ / (B0 psi'), derivatives in rho,
6595
+ as in TORAX (formulas.calculate_analytic_bootstrap_current).
6596
+
6530
6597
  References
6531
6598
  ----------
6532
6599
  Redl et al., Phys. Plasmas 28, 022502 (2021).
6600
+ Sauter et al., Phys. Plasmas 6, 2834 (1999), Eq. 5.
6533
6601
  Ball & Parra, PPCF 57 (2015) 035006 — kappa radial penetration.
6534
6602
  """
6535
6603
  if kappa_95 is None:
@@ -6549,11 +6617,11 @@ def f_Sauter_Redl_Ib(R0, a, kappa, B0, nbar, Tbar, q95, Z_eff, nu_n, nu_T, n_rho
6549
6617
  T_arr = f_Tprof(Tbar, nu_T, rho_arr, rho_ped, T_ped_frac, Vprime_data)
6550
6618
  n_arr = f_nprof(nbar, nu_n, rho_arr, rho_ped, n_ped_frac, Vprime_data)
6551
6619
 
6552
- # Numerical logarithmic gradients [m^-1]
6620
+ # Numerical logarithmic gradients in rho [-]
6553
6621
  dT_drho = np.gradient(T_arr, rho_arr)
6554
6622
  dn_drho = np.gradient(n_arr, rho_arr)
6555
- dln_T = np.where(T_arr > 0.01, dT_drho / (T_arr * a), 0.0)
6556
- dln_n = np.where(n_arr > 1e-3, dn_drho / (n_arr * a), 0.0)
6623
+ dln_T = np.where(T_arr > 0.01, dT_drho / T_arr, 0.0)
6624
+ dln_n = np.where(n_arr > 1e-3, dn_drho / n_arr, 0.0)
6557
6625
 
6558
6626
  # ── Vectorised local quantities ───────────────────────────────────────
6559
6627
  eps_arr = rho_arr * a / R0
@@ -6568,7 +6636,7 @@ def f_Sauter_Redl_Ib(R0, a, kappa, B0, nbar, Tbar, q95, Z_eff, nu_n, nu_T, n_rho
6568
6636
  n_e = n_arr * 1e20 # [m^-3]
6569
6637
  T_eV = T_arr * 1e3 # [eV] electron temperature
6570
6638
  Ti_eV = tau_i_e * T_eV # [eV] ion temperature, T_i = tau_i_e * T_e
6571
- n_i = n_e / Z_eff
6639
+ n_i = n_e * n_ion_frac # [m^-3] total ion density (quasi-neutrality)
6572
6640
 
6573
6641
  # Pressure [Pa]
6574
6642
  p_e = n_e * T_eV * E_ELEM
@@ -6601,25 +6669,31 @@ def f_Sauter_Redl_Ib(R0, a, kappa, B0, nbar, Tbar, q95, Z_eff, nu_n, nu_T, n_rho
6601
6669
  # Bootstrap coefficient [Redl Eq. 5]
6602
6670
  C_bs = L31 * dln_p + L32 * R_pe * dln_T + L34 * alp * (1.0 - R_pe) * dln_Ti
6603
6671
 
6604
- # Local j_bs [A/m^2]
6605
- B_sq = B0**2 * (1.0 + eps_arr**2 / 2.0)
6606
- j_bs = -I_psi * p_tot * C_bs / B_sq
6672
+ # Poloidal cross-section area element dA/drho and perimeter average
6673
+ # <1/R^2>: Miller-consistent profiles from Vprime_data when available
6674
+ # (kappa(rho), delta(rho)); otherwise the ellipse dA/drho = 2 pi rho a^2
6675
+ # kappa and the circular-surface <1/R^2> = 1/(R0^2 (1-eps^2)^1.5).
6676
+ if (Vprime_data is not None and len(Vprime_data) >= 5
6677
+ and Vprime_data[3] is not None):
6678
+ dA_per_drho = interpolate_dA(rho_arr, Vprime_data[0], Vprime_data[3])
6679
+ else:
6680
+ dA_per_drho = 2.0 * np.pi * rho_arr * a**2 * kappa_arr
6681
+ if Vprime_data is not None and len(Vprime_data) >= 6:
6682
+ inv_R2 = np.interp(rho_arr, Vprime_data[0], Vprime_data[5])
6683
+ else:
6684
+ inv_R2 = 1.0 / (R0**2 * (1.0 - eps_arr**2)**1.5)
6685
+
6686
+ # Poloidal-flux derivative per radian [Wb/rad], same closure as the q profile
6687
+ psi_p = R0 * I_psi * inv_R2 * dA_per_drho / (2.0 * np.pi * q_arr)
6688
+
6689
+ # Local j_bs [A/m^2] (Sauter Eq. 5 with d/dpsi = (1/psi') d/drho)
6690
+ j_bs = np.where(psi_p > 0, -I_psi * p_tot * C_bs / (B0 * np.where(psi_p > 0, psi_p, 1.0)), 0.0)
6607
6691
 
6608
6692
  # Grid spacing for area-weighted integration
6609
6693
  drho = np.zeros_like(rho_arr)
6610
6694
  drho[0] = rho_arr[1] - rho_arr[0]
6611
6695
  drho[-1] = rho_arr[-1] - rho_arr[-2]
6612
6696
  drho[1:-1] = (rho_arr[2:] - rho_arr[:-2]) / 2.0
6613
-
6614
- # Poloidal cross-section area element dA = (dA_pol/dρ) × dρ.
6615
- # Use the precomputed Miller-consistent profile from Vprime_data
6616
- # when available (includes κ(ρ) and δ(ρ)); otherwise fall back to
6617
- # the exact ellipse expression 2πρa²κ (valid at constant κ, no δ).
6618
- if (Vprime_data is not None and len(Vprime_data) >= 5
6619
- and Vprime_data[3] is not None):
6620
- dA_per_drho = interpolate_dA(rho_arr, Vprime_data[0], Vprime_data[3])
6621
- else:
6622
- dA_per_drho = 2.0 * np.pi * rho_arr * a**2 * kappa_arr
6623
6697
  dA = dA_per_drho * drho
6624
6698
 
6625
6699
  # Mask out unphysical points (eps too small, n or T too low)
@@ -6653,7 +6727,7 @@ def f_q_profile_refined(
6653
6727
  rho_CD=0.3, delta_CD=0.15,
6654
6728
  q_init=None,
6655
6729
  n_rho=200, tol=1e-3, max_iter=15, damping=0.5,
6656
- N_theta_inv_R2=400, tau_i_e=1.0):
6730
+ N_theta_inv_R2=400, tau_i_e=1.0, n_ion_frac=1.0):
6657
6731
  """
6658
6732
  Self-consistent safety-factor and current-density profiles (Mode 'refined').
6659
6733
 
@@ -6934,8 +7008,12 @@ def f_q_profile_refined(
6934
7008
  Vprime_data_internal[1])
6935
7009
 
6936
7010
  # == Profiles of T(rho), n(rho), epsilon(rho) ============================
6937
- T_arr = f_Tprof(Tbar, nu_T, rho, rho_ped, T_ped_frac, Vprime_data_internal)
6938
- n_arr = f_nprof(nbar, nu_n, rho, rho_ped, n_ped_frac, Vprime_data_internal)
7011
+ # Kinetic profiles and bootstrap use the CALLER's volume element (None in
7012
+ # Academic geometry), i.e. the normalisation under which nbar and Tbar were
7013
+ # defined by the chain; the internal Miller surfaces above only provide the
7014
+ # geometric weights (dA, Lp, <1/R^2>) of the q formula.
7015
+ T_arr = f_Tprof(Tbar, nu_T, rho, rho_ped, T_ped_frac, Vprime_data)
7016
+ n_arr = f_nprof(nbar, nu_n, rho, rho_ped, n_ped_frac, Vprime_data)
6939
7017
  eps_arr = rho * a / R0
6940
7018
 
6941
7019
  # == Current-drive deposition profile (Gaussian, geometric only) =========
@@ -7012,9 +7090,10 @@ def f_q_profile_refined(
7012
7090
  R0, a, kappa, B0, nbar, Tbar, q95_cur, Z_eff, nu_n, nu_T,
7013
7091
  n_rho=len(rho), rho_ped=rho_ped,
7014
7092
  n_ped_frac=n_ped_frac, T_ped_frac=T_ped_frac,
7015
- Vprime_data=Vprime_data_internal, kappa_95=kappa_95, rho_95=rho_95,
7093
+ Vprime_data=Vprime_data, kappa_95=kappa_95, rho_95=rho_95,
7016
7094
  return_profile=True, q_profile=q_dict,
7017
- trapped_fraction_model=trapped_fraction_model, tau_i_e=tau_i_e)
7095
+ trapped_fraction_model=trapped_fraction_model, tau_i_e=tau_i_e,
7096
+ n_ion_frac=n_ion_frac)
7018
7097
  j_bs = np.interp(rho, bs_res['rho'], bs_res['j_bs'])
7019
7098
  I_bs_A = float(np.clip(bs_res['I_bs'] * 1e6, 0.0, Ip_A))
7020
7099
 
@@ -7067,9 +7146,10 @@ def f_q_profile_refined(
7067
7146
  R0, a, kappa, B0, nbar, Tbar, q95_cur, Z_eff, nu_n, nu_T,
7068
7147
  n_rho=len(rho), rho_ped=rho_ped,
7069
7148
  n_ped_frac=n_ped_frac, T_ped_frac=T_ped_frac,
7070
- Vprime_data=Vprime_data_internal, kappa_95=kappa_95, rho_95=rho_95,
7149
+ Vprime_data=Vprime_data, kappa_95=kappa_95, rho_95=rho_95,
7071
7150
  return_profile=True, q_profile=q_dict_final,
7072
- trapped_fraction_model=trapped_fraction_model, tau_i_e=tau_i_e)
7151
+ trapped_fraction_model=trapped_fraction_model, tau_i_e=tau_i_e,
7152
+ n_ion_frac=n_ion_frac)
7073
7153
  j_bs = np.interp(rho, bs_res['rho'], bs_res['j_bs'])
7074
7154
  I_bs_A = float(np.clip(bs_res['I_bs'] * 1e6, 0.0, Ip_A))
7075
7155
  I_Ohm_A = max(Ip_A - I_CD_A - I_bs_A, 0.0)
@@ -7144,7 +7224,7 @@ if __name__ == "__main__":
7144
7224
  n_ped_frac=ITER['n_ped_frac'],
7145
7225
  T_ped_frac=ITER['T_ped_frac'],
7146
7226
  Vprime_data=ITER_Vpd, kappa_95=ITER['kappa95'],
7147
- tau_i_e=1.0)
7227
+ tau_i_e=1.0, n_ion_frac=_n_ion_frac)
7148
7228
  _Ib_seg = f_Segal_Ib(ITER['nu_n'], ITER['nu_T'], ITER['a'] / ITER['R0'],
7149
7229
  ITER['kappa'], ITER['nbar'], ITER['Tbar'],
7150
7230
  ITER['R0'], FROZEN['Ip'],
@@ -9587,7 +9667,7 @@ if __name__ == "__main__":
9587
9667
  if __name__ == "__main__":
9588
9668
  # ─────────────────────────────────────────────────────────────────────
9589
9669
  # Full-device regression: the shipped reference deck must reproduce
9590
- # the frozen 2026-06 values (anti-drift guard; intentional physics
9670
+ # the frozen 2026-09 values (anti-drift guard; intentional physics
9591
9671
  # changes must update these anchors AND the FROZEN dict at the top of
9592
9672
  # this file). Skipped gracefully if the deck is absent. Indices
9593
9673
  # follow the save_run_output tuple map of D0FUS_EXE/D0FUS_run.py.
@@ -9598,17 +9678,17 @@ if __name__ == "__main__":
9598
9678
  os.path.abspath(__file__))), 'D0FUS_INPUTS', '1_run_ITER.txt')
9599
9679
  _res = run(load_config_from_file(_deck), verbose=0)
9600
9680
  _frozen_idx = [
9601
- (0, "B0 [T]", 5.300), (3, "tau_E [s]", 3.144),
9602
- (5, "Q [-]", 9.982), (8, "Ip [MA]", 14.968),
9603
- (9, "I_bs [MA]", 4.816), (13, "n_line [1e20 m-3]", 1.012),
9604
- (14, "n_GW [1e20 m-3]", 1.191), (16, "beta_N [-]", 1.635),
9605
- (20, "q95 [-]", 3.598), (23, "P_LH [MW]", 73.522),
9606
- (40, "f_alpha [-]", 0.029762),
9681
+ (0, "B0 [T]", 5.620), (3, "tau_E [s]", 3.2554),
9682
+ (5, "Q [-]", 9.973), (8, "Ip [MA]", 14.821),
9683
+ (9, "I_bs [MA]", 2.838), (13, "n_line [1e20 m-3]", 1.0025),
9684
+ (14, "n_GW [1e20 m-3]", 1.1794), (16, "beta_N [-]", 1.5792),
9685
+ (20, "q95 [-]", 3.194), (23, "P_LH [MW]", 76.523),
9686
+ (40, "f_alpha [-]", 0.041776),
9607
9687
  ]
9608
9688
  _rows = [(f"deck[{_i}] {_nm}", float(_res[_i]), _v, 5e-3,
9609
- "frozen 2026-06") for _i, _nm, _v in _frozen_idx]
9610
- _rows.append(("deck[4] W_th [MJ]", float(_res[4]) / 1e6, 340.15,
9611
- 5e-3, "frozen 2026-06"))
9689
+ "frozen 2026-09") for _i, _nm, _v in _frozen_idx]
9690
+ _rows.append(("deck[4] W_th [MJ]", float(_res[4]) / 1e6, 332.71,
9691
+ 5e-3, "frozen 2026-09"))
9612
9692
  _bench("Full-device regression - shipped ITER deck", _rows, notes=[
9613
9693
  "Closes the chain: every forward reference (f_alpha, "
9614
9694
  "f_imp_dil, q95, I_Ohm) and every chain output is "