d0fus 2.7.0__tar.gz → 2.7.2__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 (28) hide show
  1. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_EXE/D0FUS_genetic.py +21 -5
  2. d0fus-2.7.2/PKG-INFO +297 -0
  3. d0fus-2.7.2/README.md +253 -0
  4. d0fus-2.7.2/d0fus.egg-info/PKG-INFO +297 -0
  5. {d0fus-2.7.0 → d0fus-2.7.2}/pyproject.toml +1 -1
  6. d0fus-2.7.0/PKG-INFO +0 -660
  7. d0fus-2.7.0/README.md +0 -616
  8. d0fus-2.7.0/d0fus.egg-info/PKG-INFO +0 -660
  9. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS.py +0 -0
  10. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_cost_data.py +0 -0
  11. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_cost_functions.py +0 -0
  12. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_figures.py +0 -0
  13. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_import.py +0 -0
  14. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_machine_presets.py +0 -0
  15. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_parameterization.py +0 -0
  16. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_physical_functions.py +0 -0
  17. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_BIB/D0FUS_radial_build_functions.py +0 -0
  18. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_EXE/D0FUS_popcon.py +0 -0
  19. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_EXE/D0FUS_run.py +0 -0
  20. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_EXE/D0FUS_scan.py +0 -0
  21. {d0fus-2.7.0 → d0fus-2.7.2}/D0FUS_EXE/D0FUS_uncertainty.py +0 -0
  22. {d0fus-2.7.0 → d0fus-2.7.2}/LICENSE +0 -0
  23. {d0fus-2.7.0 → d0fus-2.7.2}/d0fus.egg-info/SOURCES.txt +0 -0
  24. {d0fus-2.7.0 → d0fus-2.7.2}/d0fus.egg-info/dependency_links.txt +0 -0
  25. {d0fus-2.7.0 → d0fus-2.7.2}/d0fus.egg-info/entry_points.txt +0 -0
  26. {d0fus-2.7.0 → d0fus-2.7.2}/d0fus.egg-info/requires.txt +0 -0
  27. {d0fus-2.7.0 → d0fus-2.7.2}/d0fus.egg-info/top_level.txt +0 -0
  28. {d0fus-2.7.0 → d0fus-2.7.2}/setup.cfg +0 -0
@@ -1433,17 +1433,31 @@ def run_genetic_algorithm(pop_size, n_generations, cxpb, mutpb,
1433
1433
  pop = toolbox.population(n=pop_size)
1434
1434
  hof = tools.HallOfFame(10)
1435
1435
 
1436
- # Statistics
1436
+ # Statistics.
1437
+ # Fitness values fall into three regimes: feasible designs carry the
1438
+ # objective value, infeasible ones are mapped into the band
1439
+ # [floor, PENALTY_VALUE) by compute_feasibility_fitness, and structurally
1440
+ # invalid ones return PENALTY_VALUE. Population statistics must describe
1441
+ # feasible designs only, so the cut is the band floor, not
1442
+ # PENALTY_VALUE / 2. The floor is deck-overridable, so it is resolved here
1443
+ # exactly as in evaluate_individual.
1444
+ _floor_stats = _opt_float(static_inputs.get('infeasible_floor'))
1445
+ if _floor_stats is None:
1446
+ _floor_stats = DEFAULT_INFEASIBLE_FLOOR
1447
+
1448
+ def _feasible(values):
1449
+ return [v[0] for v in values if v[0] < _floor_stats]
1450
+
1437
1451
  def safe_mean(values):
1438
- valid = [v[0] for v in values if v[0] < PENALTY_VALUE / 2]
1452
+ valid = _feasible(values)
1439
1453
  return np.mean(valid) if valid else float('nan')
1440
1454
 
1441
1455
  def safe_std(values):
1442
- valid = [v[0] for v in values if v[0] < PENALTY_VALUE / 2]
1456
+ valid = _feasible(values)
1443
1457
  return np.std(valid) if len(valid) > 1 else float('nan')
1444
1458
 
1445
1459
  def count_valid(values):
1446
- return sum(1 for v in values if v[0] < PENALTY_VALUE / 2)
1460
+ return len(_feasible(values))
1447
1461
 
1448
1462
  stats = tools.Statistics(lambda ind: ind.fitness.values)
1449
1463
  stats.register("min", lambda x: min(v[0] for v in x))
@@ -1498,7 +1512,9 @@ def run_genetic_algorithm(pop_size, n_generations, cxpb, mutpb,
1498
1512
  _append_to_cloud(ind, 0)
1499
1513
 
1500
1514
  # ── Diagnostic: abort early if entire initial population is invalid ───
1501
- n_init_valid = sum(1 for f in fitnesses if f[0] < PENALTY_VALUE / 2)
1515
+ # Same feasibility cut as the population statistics above: a design sitting
1516
+ # in the infeasible band is not a valid starting point.
1517
+ n_init_valid = sum(1 for f in fitnesses if f[0] < _floor_stats)
1502
1518
  if n_init_valid == 0:
1503
1519
  print(f"\n *** WARNING: 0 / {pop_size} initial designs are valid! ***")
1504
1520
  print(f" The parameter ranges likely produce unphysical configurations")
d0fus-2.7.2/PKG-INFO ADDED
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.4
2
+ Name: d0fus
3
+ Version: 2.7.2
4
+ Summary: Design 0-dimensional for Fusion Systems - Tokamak power plant design and optimization tool
5
+ Author-email: Timothé Auclair <timothe.auclair@gmail.com>
6
+ Maintainer-email: Timothé Auclair <timothe.auclair@gmail.com>
7
+ License: CeCILL-C
8
+ Project-URL: Homepage, https://github.com/IRFM/D0FUS
9
+ Project-URL: Repository, https://github.com/IRFM/D0FUS
10
+ Project-URL: Documentation, https://github.com/IRFM/D0FUS#readme
11
+ Project-URL: Bug Tracker, https://github.com/IRFM/D0FUS/issues
12
+ Keywords: fusion,tokamak,plasma,power-plant,design,nuclear,superconductor,magnetic-confinement,ITER,DEMO
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Operating System :: OS Independent
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.20.0
29
+ Requires-Dist: matplotlib>=3.4.0
30
+ Requires-Dist: scipy>=1.7.0
31
+ Requires-Dist: tqdm>=4.60.0
32
+ Requires-Dist: pandas>=1.3.0
33
+ Requires-Dist: sympy>=1.9
34
+ Requires-Dist: deap>=1.3.0
35
+ Requires-Dist: joblib>=1.1.0
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
39
+ Requires-Dist: black>=23.0.0; extra == "dev"
40
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
41
+ Provides-Extra: viz3d
42
+ Requires-Dist: pyvista>=0.40; extra == "viz3d"
43
+ Dynamic: license-file
44
+
45
+ <a name="readme-top"></a>
46
+
47
+ <p align="center">
48
+ <img src="docs/figures/D0FUS_logo.png" alt="D0FUS logo" width="190">
49
+ </p>
50
+
51
+ <h1 align="center">D0FUS</h1>
52
+
53
+ <p align="center">
54
+ <a href="https://cecill.info/licences/Licence_CeCILL-C_V1-en.html"><img src="https://img.shields.io/badge/License-CeCILL--C-blue.svg" alt="License: CeCILL-C"></a>
55
+ <a href="https://pypi.org/project/d0fus/"><img src="https://badge.fury.io/py/d0fus.svg" alt="PyPI version"></a>
56
+ </p>
57
+
58
+ <p align="center">
59
+ <img src="docs/figures/d0fus_capabilities_banner.png" alt="D0FUS capabilities" width="100%">
60
+ </p>
61
+
62
+ <p align="center">
63
+ <sub>Top: plasma geometry (Miller surfaces), kinetic profiles, safety factor, radiative cooling, and fusion reactivity. Bottom: radial build, superconductor critical current, TF and CS coil cross-sections, CICC conductors, and a multi-machine comparison. Right: the full poloidal radial build, from plasma out to the TF coil.</sub>
64
+ </p>
65
+
66
+ **D0FUS** (Design 0-dimensional for Fusion Systems) is a Python tokamak systems code for fast 0D/1D design-space exploration, covering plasma physics, superconducting magnet engineering, and techno-economic assessment. It is developed at CEA-IRFM.
67
+
68
+ About 39 000 lines of pure Python: a core library of seven modules and over 500 functions, plus five execution modes. The code is fully documented in the PhD thesis of T. Auclair (2026), whose Appendix D serves as the reference manual; release **v2.7.0** is the version archived with the thesis.
69
+
70
+ ---
71
+
72
+ ## Highlights
73
+
74
+ - **Pure Python**, NumPy/SciPy only. No compilation, runs in Spyder, Jupyter or as a batch job.
75
+ - **Two fidelity levels** (Academic and Refined), with a per-model selector in `GlobalConfig` for any mixed combination, and `preset_academic()` / `preset_refined()` factories for coherent sets.
76
+ - **Five execution modes** (RUN, SCAN, OPTIMIZATION, POPCON, UNCERTAINTY), auto-detected from the input file syntax.
77
+ - **Library mode**: every function is callable in isolation, outside the solver loop.
78
+ - **Distinctive engineering scope**: radially graded TF coils, REBCO Jc scalings, three TF mechanical configurations (wedging, bucking, plug), quench-protection sizing.
79
+
80
+ ---
81
+
82
+ ## Installation
83
+
84
+ ### Option A — Spyder standalone (recommended, no Python knowledge required)
85
+
86
+ 1. Install Spyder from [spyder-ide.org](https://www.spyder-ide.org/) (bundled Python included).
87
+ 2. Get the code: `git clone https://github.com/IRFM/D0FUS.git`, or **Code → Download ZIP** on [github.com/IRFM/D0FUS](https://github.com/IRFM/D0FUS) and extract.
88
+ 3. In Spyder, **File → Open…** `D0FUS.py`. The working directory is set to `D0FUS/` automatically.
89
+ 4. In the IPython console: `%pip install -r requirements.txt` (falls back to `!pip install -r requirements.txt` if `%pip` fails).
90
+ 5. Press **F5** and select `D0FUS_INPUTS/1_run_ITER.txt` in the file picker. Results print to the console, figures open automatically.
91
+
92
+ ### Option B — Miniforge (conda users)
93
+
94
+ ```bash
95
+ conda create -n d0fus python=3.11 && conda activate d0fus
96
+ conda install pip spyder
97
+ git clone https://github.com/IRFM/D0FUS.git && cd D0FUS
98
+ pip install -r requirements.txt
99
+ python D0FUS.py D0FUS_INPUTS/1_run_ITER.txt
100
+ ```
101
+
102
+ ### Option C — pip (headless / library use)
103
+
104
+ ```bash
105
+ pip install d0fus
106
+ ```
107
+
108
+ Deck-driven run from a script or terminal:
109
+
110
+ ```python
111
+ from D0FUS_EXE import D0FUS_run
112
+ D0FUS_run.main("D0FUS_INPUTS/1_run_ITER.txt") # full run + report files + figures
113
+ ```
114
+
115
+ Programmatic single point, no files involved:
116
+
117
+ ```python
118
+ from dataclasses import replace
119
+ from D0FUS_BIB.D0FUS_parameterization import DEFAULT_CONFIG
120
+ from D0FUS_EXE import D0FUS_run
121
+
122
+ cfg = replace(DEFAULT_CONFIG, R0=8.0, Bmax_TF=13.0, Supra_choice="REBCO")
123
+ results = D0FUS_run.run(cfg) # tuple of 93 scalar outputs (np.nan if no solution)
124
+ ```
125
+
126
+ > Input decks (`D0FUS_INPUTS/`) are not shipped in the PyPI package: clone the repository to get them.
127
+
128
+ ---
129
+
130
+ ## Project structure
131
+
132
+ ```
133
+ D0FUS/
134
+ ├── D0FUS_BIB/ # Core library
135
+ │ ├── D0FUS_import.py # Centralised imports
136
+ │ ├── D0FUS_parameterization.py # Physical constants, GlobalConfig dataclass
137
+ │ ├── D0FUS_physical_functions.py # Plasma physics (profiles, limits, currents, exhaust, RE)
138
+ │ ├── D0FUS_radial_build_functions.py # Magnets (TF/CS, CICC, quench, ripple)
139
+ │ ├── D0FUS_cost_functions.py # Techno-economics (Sheffield, Whyte)
140
+ │ ├── D0FUS_cost_data.py # Reference cost data
141
+ │ └── D0FUS_figures.py # Figure catalogue
142
+ ├── D0FUS_EXE/ # Execution modes
143
+ │ ├── D0FUS_run.py # Single design point
144
+ │ ├── D0FUS_scan.py # 2D parameter scan
145
+ │ ├── D0FUS_genetic.py # Genetic optimisation
146
+ │ ├── D0FUS_popcon.py # POPCON operating-space map
147
+ │ └── D0FUS_uncertainty.py # Monte-Carlo uncertainty propagation
148
+ ├── D0FUS_INPUTS/ # Example decks, 1_run_ITER.txt … 5_popcon_ITER.txt
149
+ ├── D0FUS_OUTPUTS/ # Auto-created, timestamped result folders
150
+ ├── D0FUS.py # Entry point (mode auto-detection)
151
+ ├── pyproject.toml · requirements.txt · CITATION.cff
152
+ └── README.md
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Execution modes
158
+
159
+ The mode is detected from the input file syntax:
160
+
161
+ | Mode | Purpose | Trigger in the deck |
162
+ |------|---------|---------------------|
163
+ | **RUN** | Single design point, 93 outputs, report files, 17 figures | Fixed values only (`R0 = 9`) |
164
+ | **SCAN** | 2D feasibility map, 32 registered output quantities | Exactly 2 entries `[min, max, n_points]` |
165
+ | **OPTIMIZATION** | Genetic cost minimisation (DEAP) | 2+ entries `[min, max]` |
166
+ | **POPCON** | Operating map (n̄, T̄) at fixed machine | `[POPCON]` section |
167
+ | **UNCERTAINTY** | Monte-Carlo propagation of input uncertainties | `[UNCERTAINTY]` section |
168
+
169
+ **RUN** solves the coupled design point: in pulsed mode a scalar root-finding on the helium ash fraction (Brent), in steady-state a 2D solve on (f_α, Q) (Powell). Post-convergence: TF/CS sizing, flux budget, divertor loads, L-H margin, costs, runaway-electron indicators.
170
+
171
+ **SCAN** evaluates an independent grid in parallel (`joblib`/`loky`), overlaying the operational limits (Greenwald, Troyon, kink) and the radial-build closure on any registered output.
172
+
173
+ **OPTIMIZATION** minimises `COE` (default), `C_invest`, `volume`, or maximises `P_elec`, under soft penalties on the plasma limits and an optional capital-cost ceiling, so the search converges toward the feasible boundary rather than fleeing it.
174
+
175
+ **POPCON** freezes the deck's converged machine and sweeps (n̄_line, T̄), returning Q, powers and the H-mode access margin at every node, bounded by the Greenwald and L-H limits (logic of the open-source `cfspopcon`, reusing the D0FUS physics chain).
176
+
177
+ **UNCERTAINTY** assigns distributions (`norm()`, `tri()`, `unif()`) to any inputs and discrete model switches with `envelope(A | B)`, draws Latin-Hypercube samples, and returns output distributions with feasibility shares, the no-solution draws being counted as failures.
178
+
179
+ ### Execution time (14-core laptop)
180
+
181
+ | Mode | Configuration | Wall time |
182
+ |------|---------------|-----------|
183
+ | RUN | single point | ~200 ms |
184
+ | SCAN | 50 × 50 grid | ~25 s |
185
+ | OPTIMIZATION | 50 × 10 generations | ~2 min 30 |
186
+ | POPCON / UNCERTAINTY | N nodes or samples | ~N × 200 ms / n_cores |
187
+
188
+ ---
189
+
190
+ ## Two fidelity levels
191
+
192
+ Each model carries its own selector in `GlobalConfig`; the factories `preset_academic()` and `preset_refined()` set a coherent bundle. Both levels share the same interface and solver, with comparable run times.
193
+
194
+ | Model | Academic | Refined |
195
+ |-------|----------|---------|
196
+ | Plasma geometry | Elliptical torus | Miller flux surfaces, κ(ρ), δ(ρ) |
197
+ | Volume element | V′ = 4π²R₀a²κρ | Numerical Miller Jacobian |
198
+ | Bootstrap current | Segal-Cerfon-Freidberg fit | Sauter (1999/2002) refitted by Redl (2021) |
199
+ | q(ρ) profile | Parametric j(ρ) ∝ (1−ρ²)^αJ | Self-consistent Picard on j_Ω + j_CD + j_bs |
200
+ | Resistivity | Spitzer | Sauter/Redl neoclassical |
201
+ | TF stress model | Thin-cylinder, two-layer | Thick-cylinder, composite CICC (or CIRCE0D) |
202
+ | CS stress model | Hoop only | Hoop + axial fringe-field |
203
+
204
+ ---
205
+
206
+ ## Inputs
207
+
208
+ All parameters live in one typed dataclass, `GlobalConfig` (149 fields), each with a physically motivated default. A deck overrides only what it names; everything else keeps its default, so a complete machine fits in a few lines:
209
+
210
+ ```ini
211
+ R0 = 7
212
+ Bmax_TF = 14
213
+ Supra_choice = REBCO
214
+ ```
215
+
216
+ Key parameters and their actual defaults:
217
+
218
+ | Parameter | Description | Default | Options |
219
+ |-----------|-------------|---------|---------|
220
+ | `P_fus` / `R0` / `a` / `b` | Fusion power [MW], radii [m], blanket+shield [m] | 2000 / 9.0 / 3.0 / 1.2 | |
221
+ | `Bmax_TF` / `Bmax_CS_adm` | Peak field on TF / admissible on CS [T] | 12.0 / 25.0 | |
222
+ | `Supra_choice` | Superconductor | `Nb3Sn` | `NbTi`, `Nb3Sn`, `REBCO` |
223
+ | `Choice_Buck_Wedg` | TF mechanical configuration | `Wedging` | `Wedging`, `Bucking`, `Plug` |
224
+ | `Chosen_Steel` | Structural steel | `316L` | `316L`, `N50H`, `Manual` |
225
+ | `Scaling_Law` | Confinement scaling | `IPB98(y,2)` | `ITPA20`, `ITPA20-IL`, `DS03`, `L-mode`, `L-mode OK`, `ITER89-P` |
226
+ | `Option_Kappa` | Elongation model | `Blend` | `Wenninger`, `Stambaugh`, `Freidberg`, `Manual` |
227
+ | `Option_q95` | q₉₅ formula | `ITER_1989` | `Sauter` |
228
+ | `density_limit_model` | Density limit | `greenwald` | `zanca`, `giacomin` |
229
+ | `Plasma_profiles` | Profile preset | `H` | `L`, `Advanced`, `EU-DEMO`, `Manual` |
230
+ | `Bootstrap_choice` | Bootstrap model | `Sauter-Redl` | `Segal` |
231
+ | `Operation_mode` | Scenario | `Pulsed` (3600 s, 50 MW) | `Steady-State` |
232
+ | `CD_source` | Current-drive model | `Academic` (γ_CD 0.20, η_WP 0.40) | `LHCD`, `ECCD`, `NBCD`, `Multi` |
233
+ | `Zeff` | Effective charge | computed from the impurity inventory | or fixed value |
234
+ | `rho_rad_core` | Core/edge radiation boundary | 0.6 | 1.0 = conservative preset |
235
+ | `cost_model` | Cost model | `Sheffield` | `Whyte`, `None` |
236
+
237
+ The complete field list, with units, defaults and provenance comments, is in `D0FUS_parameterization.py`, reproduced in Appendix D of the thesis; every run also writes it to `output_detailed.txt`.
238
+
239
+ ### Deck syntax by mode
240
+
241
+ ```ini
242
+ # RUN: fixed values # SCAN: exactly two brackets
243
+ R0 = 9 R0 = [3, 9, 25]
244
+ Bmax_TF = 13 a = [1, 3, 25]
245
+
246
+ # OPTIMIZATION: 2+ ranges # POPCON: full RUN deck, then
247
+ R0 = [3, 9] [POPCON]
248
+ Bmax_TF = [10, 16] nbar_line = [0.35, 1.45, 45]
249
+ fitness_objective = COE Tbar = [3.5, 24.0, 36]
250
+
251
+ # UNCERTAINTY: full RUN deck, then
252
+ [UNCERTAINTY]
253
+ H = norm(0.75, 1.50) # truncated normal around the deck value
254
+ Scaling_Law = envelope(IPB98(y,2) | ITPA20) # model switch (pipe-separated)
255
+ [CONTROLS]
256
+ n_samples = 1500
257
+ ```
258
+
259
+ Continuous distributions: `norm(sigma)`, `norm(lo, hi)`, `norm(lo, centre, hi)`, `tri(...)`, `unif(lo, hi)`. One worked example per mode ships in `D0FUS_INPUTS/`.
260
+
261
+ ---
262
+
263
+ ## Outputs
264
+
265
+ Every mode writes a timestamped folder under `D0FUS_OUTPUTS/`. A RUN produces `input_parameters.txt` (the deck), `output_highlight.txt` (key results), `output_detailed.txt` (every input including defaults, every output), and 17 figures (cross-section, Miller surfaces, profiles, q(ρ), radiation, divertor two-point, radial build, coil and CICC drawings, cost breakdown, temperature and density maps, optional PyVista 3D view). SCAN writes the 2D map, OPTIMIZATION the convergence history and Hall of Fame, POPCON the operating-contour map, UNCERTAINTY the per-output distributions with the feasibility verdict and figures.
266
+
267
+ ---
268
+
269
+ ## Models in brief
270
+
271
+ Plasma geometry follows the Miller parameterisation (Miller 1998) with on-axis regularity enforced (Ball & Parra 2015). The three first-order plasma limits are Greenwald, Troyon and the kink limit on q₉₅, with the density-limit model selectable (Greenwald, Zanca 2019, Giacomin 2022 near-separatrix). Impurity radiation uses the Mavrin (2018) cooling rates; the divertor is characterised by an Eich attached estimate or a two-point model with a Lengyel seeding closure on non-coronal OpenADAS curves. The L-H threshold offers Martin (2008) and two Delabie (ITPA TC-26) regressions. Current drive follows the METIS efficiency models, matched to METIS within 1.5 %. Runaway-electron indicators combine a hot-tail seed (Smith 2008) and avalanche amplification (Breizman 2019), for comparative ranking only.
272
+
273
+ The TF inboard leg is a Princeton-D (File, Mills & Sheffield 1971); conductors are CICC-like with a helium-fraction hierarchy; critical currents use ITER parameterisations (NbTi, Nb₃Sn) and REBCO datasets (Senatore 2024, Fujikura 2019); quench protection is sized on the Maddock hot-spot criterion; the winding pack can be radially graded. Costing follows Sheffield & Milora (2016), with a surface-proportional Whyte (2024) model for cross-checks; costs never feed back into the physics.
274
+
275
+ Full derivations, validity domains and references: thesis, Chapter 1 and Appendices B-C.
276
+
277
+ ---
278
+
279
+ ## Version and citation
280
+
281
+ The tag **v2.7.0** is the reference version of the thesis: the manuscript documents this exact state of the code, and the benchmarks of its Chapter 2 (module level, coil-by-coil against six machines, EU-DEMO 2017 and ITER device level) were produced with it. To cite D0FUS, use `CITATION.cff` (GitHub's *Cite this repository* button) or cite the thesis:
282
+
283
+ > T. Auclair, *Apport des supraconducteurs à haute température critique au dimensionnement de machines de fusion nucléaire par confinement magnétique*, PhD thesis, Aix-Marseille Université / CEA-IRFM, 2026.
284
+
285
+ ---
286
+
287
+ ## Contributing
288
+
289
+ Contributions and questions are welcome: timothe.auclair@cea.fr
290
+
291
+ ## License
292
+
293
+ [CeCILL-C](https://cecill.info/licences/Licence_CeCILL-C_V1-en.html), a French free software license compatible with the GNU LGPL. See [LICENSE](LICENSE).
294
+
295
+ © 2025-2026 CEA/IRFM
296
+
297
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
d0fus-2.7.2/README.md ADDED
@@ -0,0 +1,253 @@
1
+ <a name="readme-top"></a>
2
+
3
+ <p align="center">
4
+ <img src="docs/figures/D0FUS_logo.png" alt="D0FUS logo" width="190">
5
+ </p>
6
+
7
+ <h1 align="center">D0FUS</h1>
8
+
9
+ <p align="center">
10
+ <a href="https://cecill.info/licences/Licence_CeCILL-C_V1-en.html"><img src="https://img.shields.io/badge/License-CeCILL--C-blue.svg" alt="License: CeCILL-C"></a>
11
+ <a href="https://pypi.org/project/d0fus/"><img src="https://badge.fury.io/py/d0fus.svg" alt="PyPI version"></a>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <img src="docs/figures/d0fus_capabilities_banner.png" alt="D0FUS capabilities" width="100%">
16
+ </p>
17
+
18
+ <p align="center">
19
+ <sub>Top: plasma geometry (Miller surfaces), kinetic profiles, safety factor, radiative cooling, and fusion reactivity. Bottom: radial build, superconductor critical current, TF and CS coil cross-sections, CICC conductors, and a multi-machine comparison. Right: the full poloidal radial build, from plasma out to the TF coil.</sub>
20
+ </p>
21
+
22
+ **D0FUS** (Design 0-dimensional for Fusion Systems) is a Python tokamak systems code for fast 0D/1D design-space exploration, covering plasma physics, superconducting magnet engineering, and techno-economic assessment. It is developed at CEA-IRFM.
23
+
24
+ About 39 000 lines of pure Python: a core library of seven modules and over 500 functions, plus five execution modes. The code is fully documented in the PhD thesis of T. Auclair (2026), whose Appendix D serves as the reference manual; release **v2.7.0** is the version archived with the thesis.
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **Pure Python**, NumPy/SciPy only. No compilation, runs in Spyder, Jupyter or as a batch job.
31
+ - **Two fidelity levels** (Academic and Refined), with a per-model selector in `GlobalConfig` for any mixed combination, and `preset_academic()` / `preset_refined()` factories for coherent sets.
32
+ - **Five execution modes** (RUN, SCAN, OPTIMIZATION, POPCON, UNCERTAINTY), auto-detected from the input file syntax.
33
+ - **Library mode**: every function is callable in isolation, outside the solver loop.
34
+ - **Distinctive engineering scope**: radially graded TF coils, REBCO Jc scalings, three TF mechanical configurations (wedging, bucking, plug), quench-protection sizing.
35
+
36
+ ---
37
+
38
+ ## Installation
39
+
40
+ ### Option A — Spyder standalone (recommended, no Python knowledge required)
41
+
42
+ 1. Install Spyder from [spyder-ide.org](https://www.spyder-ide.org/) (bundled Python included).
43
+ 2. Get the code: `git clone https://github.com/IRFM/D0FUS.git`, or **Code → Download ZIP** on [github.com/IRFM/D0FUS](https://github.com/IRFM/D0FUS) and extract.
44
+ 3. In Spyder, **File → Open…** `D0FUS.py`. The working directory is set to `D0FUS/` automatically.
45
+ 4. In the IPython console: `%pip install -r requirements.txt` (falls back to `!pip install -r requirements.txt` if `%pip` fails).
46
+ 5. Press **F5** and select `D0FUS_INPUTS/1_run_ITER.txt` in the file picker. Results print to the console, figures open automatically.
47
+
48
+ ### Option B — Miniforge (conda users)
49
+
50
+ ```bash
51
+ conda create -n d0fus python=3.11 && conda activate d0fus
52
+ conda install pip spyder
53
+ git clone https://github.com/IRFM/D0FUS.git && cd D0FUS
54
+ pip install -r requirements.txt
55
+ python D0FUS.py D0FUS_INPUTS/1_run_ITER.txt
56
+ ```
57
+
58
+ ### Option C — pip (headless / library use)
59
+
60
+ ```bash
61
+ pip install d0fus
62
+ ```
63
+
64
+ Deck-driven run from a script or terminal:
65
+
66
+ ```python
67
+ from D0FUS_EXE import D0FUS_run
68
+ D0FUS_run.main("D0FUS_INPUTS/1_run_ITER.txt") # full run + report files + figures
69
+ ```
70
+
71
+ Programmatic single point, no files involved:
72
+
73
+ ```python
74
+ from dataclasses import replace
75
+ from D0FUS_BIB.D0FUS_parameterization import DEFAULT_CONFIG
76
+ from D0FUS_EXE import D0FUS_run
77
+
78
+ cfg = replace(DEFAULT_CONFIG, R0=8.0, Bmax_TF=13.0, Supra_choice="REBCO")
79
+ results = D0FUS_run.run(cfg) # tuple of 93 scalar outputs (np.nan if no solution)
80
+ ```
81
+
82
+ > Input decks (`D0FUS_INPUTS/`) are not shipped in the PyPI package: clone the repository to get them.
83
+
84
+ ---
85
+
86
+ ## Project structure
87
+
88
+ ```
89
+ D0FUS/
90
+ ├── D0FUS_BIB/ # Core library
91
+ │ ├── D0FUS_import.py # Centralised imports
92
+ │ ├── D0FUS_parameterization.py # Physical constants, GlobalConfig dataclass
93
+ │ ├── D0FUS_physical_functions.py # Plasma physics (profiles, limits, currents, exhaust, RE)
94
+ │ ├── D0FUS_radial_build_functions.py # Magnets (TF/CS, CICC, quench, ripple)
95
+ │ ├── D0FUS_cost_functions.py # Techno-economics (Sheffield, Whyte)
96
+ │ ├── D0FUS_cost_data.py # Reference cost data
97
+ │ └── D0FUS_figures.py # Figure catalogue
98
+ ├── D0FUS_EXE/ # Execution modes
99
+ │ ├── D0FUS_run.py # Single design point
100
+ │ ├── D0FUS_scan.py # 2D parameter scan
101
+ │ ├── D0FUS_genetic.py # Genetic optimisation
102
+ │ ├── D0FUS_popcon.py # POPCON operating-space map
103
+ │ └── D0FUS_uncertainty.py # Monte-Carlo uncertainty propagation
104
+ ├── D0FUS_INPUTS/ # Example decks, 1_run_ITER.txt … 5_popcon_ITER.txt
105
+ ├── D0FUS_OUTPUTS/ # Auto-created, timestamped result folders
106
+ ├── D0FUS.py # Entry point (mode auto-detection)
107
+ ├── pyproject.toml · requirements.txt · CITATION.cff
108
+ └── README.md
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Execution modes
114
+
115
+ The mode is detected from the input file syntax:
116
+
117
+ | Mode | Purpose | Trigger in the deck |
118
+ |------|---------|---------------------|
119
+ | **RUN** | Single design point, 93 outputs, report files, 17 figures | Fixed values only (`R0 = 9`) |
120
+ | **SCAN** | 2D feasibility map, 32 registered output quantities | Exactly 2 entries `[min, max, n_points]` |
121
+ | **OPTIMIZATION** | Genetic cost minimisation (DEAP) | 2+ entries `[min, max]` |
122
+ | **POPCON** | Operating map (n̄, T̄) at fixed machine | `[POPCON]` section |
123
+ | **UNCERTAINTY** | Monte-Carlo propagation of input uncertainties | `[UNCERTAINTY]` section |
124
+
125
+ **RUN** solves the coupled design point: in pulsed mode a scalar root-finding on the helium ash fraction (Brent), in steady-state a 2D solve on (f_α, Q) (Powell). Post-convergence: TF/CS sizing, flux budget, divertor loads, L-H margin, costs, runaway-electron indicators.
126
+
127
+ **SCAN** evaluates an independent grid in parallel (`joblib`/`loky`), overlaying the operational limits (Greenwald, Troyon, kink) and the radial-build closure on any registered output.
128
+
129
+ **OPTIMIZATION** minimises `COE` (default), `C_invest`, `volume`, or maximises `P_elec`, under soft penalties on the plasma limits and an optional capital-cost ceiling, so the search converges toward the feasible boundary rather than fleeing it.
130
+
131
+ **POPCON** freezes the deck's converged machine and sweeps (n̄_line, T̄), returning Q, powers and the H-mode access margin at every node, bounded by the Greenwald and L-H limits (logic of the open-source `cfspopcon`, reusing the D0FUS physics chain).
132
+
133
+ **UNCERTAINTY** assigns distributions (`norm()`, `tri()`, `unif()`) to any inputs and discrete model switches with `envelope(A | B)`, draws Latin-Hypercube samples, and returns output distributions with feasibility shares, the no-solution draws being counted as failures.
134
+
135
+ ### Execution time (14-core laptop)
136
+
137
+ | Mode | Configuration | Wall time |
138
+ |------|---------------|-----------|
139
+ | RUN | single point | ~200 ms |
140
+ | SCAN | 50 × 50 grid | ~25 s |
141
+ | OPTIMIZATION | 50 × 10 generations | ~2 min 30 |
142
+ | POPCON / UNCERTAINTY | N nodes or samples | ~N × 200 ms / n_cores |
143
+
144
+ ---
145
+
146
+ ## Two fidelity levels
147
+
148
+ Each model carries its own selector in `GlobalConfig`; the factories `preset_academic()` and `preset_refined()` set a coherent bundle. Both levels share the same interface and solver, with comparable run times.
149
+
150
+ | Model | Academic | Refined |
151
+ |-------|----------|---------|
152
+ | Plasma geometry | Elliptical torus | Miller flux surfaces, κ(ρ), δ(ρ) |
153
+ | Volume element | V′ = 4π²R₀a²κρ | Numerical Miller Jacobian |
154
+ | Bootstrap current | Segal-Cerfon-Freidberg fit | Sauter (1999/2002) refitted by Redl (2021) |
155
+ | q(ρ) profile | Parametric j(ρ) ∝ (1−ρ²)^αJ | Self-consistent Picard on j_Ω + j_CD + j_bs |
156
+ | Resistivity | Spitzer | Sauter/Redl neoclassical |
157
+ | TF stress model | Thin-cylinder, two-layer | Thick-cylinder, composite CICC (or CIRCE0D) |
158
+ | CS stress model | Hoop only | Hoop + axial fringe-field |
159
+
160
+ ---
161
+
162
+ ## Inputs
163
+
164
+ All parameters live in one typed dataclass, `GlobalConfig` (149 fields), each with a physically motivated default. A deck overrides only what it names; everything else keeps its default, so a complete machine fits in a few lines:
165
+
166
+ ```ini
167
+ R0 = 7
168
+ Bmax_TF = 14
169
+ Supra_choice = REBCO
170
+ ```
171
+
172
+ Key parameters and their actual defaults:
173
+
174
+ | Parameter | Description | Default | Options |
175
+ |-----------|-------------|---------|---------|
176
+ | `P_fus` / `R0` / `a` / `b` | Fusion power [MW], radii [m], blanket+shield [m] | 2000 / 9.0 / 3.0 / 1.2 | |
177
+ | `Bmax_TF` / `Bmax_CS_adm` | Peak field on TF / admissible on CS [T] | 12.0 / 25.0 | |
178
+ | `Supra_choice` | Superconductor | `Nb3Sn` | `NbTi`, `Nb3Sn`, `REBCO` |
179
+ | `Choice_Buck_Wedg` | TF mechanical configuration | `Wedging` | `Wedging`, `Bucking`, `Plug` |
180
+ | `Chosen_Steel` | Structural steel | `316L` | `316L`, `N50H`, `Manual` |
181
+ | `Scaling_Law` | Confinement scaling | `IPB98(y,2)` | `ITPA20`, `ITPA20-IL`, `DS03`, `L-mode`, `L-mode OK`, `ITER89-P` |
182
+ | `Option_Kappa` | Elongation model | `Blend` | `Wenninger`, `Stambaugh`, `Freidberg`, `Manual` |
183
+ | `Option_q95` | q₉₅ formula | `ITER_1989` | `Sauter` |
184
+ | `density_limit_model` | Density limit | `greenwald` | `zanca`, `giacomin` |
185
+ | `Plasma_profiles` | Profile preset | `H` | `L`, `Advanced`, `EU-DEMO`, `Manual` |
186
+ | `Bootstrap_choice` | Bootstrap model | `Sauter-Redl` | `Segal` |
187
+ | `Operation_mode` | Scenario | `Pulsed` (3600 s, 50 MW) | `Steady-State` |
188
+ | `CD_source` | Current-drive model | `Academic` (γ_CD 0.20, η_WP 0.40) | `LHCD`, `ECCD`, `NBCD`, `Multi` |
189
+ | `Zeff` | Effective charge | computed from the impurity inventory | or fixed value |
190
+ | `rho_rad_core` | Core/edge radiation boundary | 0.6 | 1.0 = conservative preset |
191
+ | `cost_model` | Cost model | `Sheffield` | `Whyte`, `None` |
192
+
193
+ The complete field list, with units, defaults and provenance comments, is in `D0FUS_parameterization.py`, reproduced in Appendix D of the thesis; every run also writes it to `output_detailed.txt`.
194
+
195
+ ### Deck syntax by mode
196
+
197
+ ```ini
198
+ # RUN: fixed values # SCAN: exactly two brackets
199
+ R0 = 9 R0 = [3, 9, 25]
200
+ Bmax_TF = 13 a = [1, 3, 25]
201
+
202
+ # OPTIMIZATION: 2+ ranges # POPCON: full RUN deck, then
203
+ R0 = [3, 9] [POPCON]
204
+ Bmax_TF = [10, 16] nbar_line = [0.35, 1.45, 45]
205
+ fitness_objective = COE Tbar = [3.5, 24.0, 36]
206
+
207
+ # UNCERTAINTY: full RUN deck, then
208
+ [UNCERTAINTY]
209
+ H = norm(0.75, 1.50) # truncated normal around the deck value
210
+ Scaling_Law = envelope(IPB98(y,2) | ITPA20) # model switch (pipe-separated)
211
+ [CONTROLS]
212
+ n_samples = 1500
213
+ ```
214
+
215
+ Continuous distributions: `norm(sigma)`, `norm(lo, hi)`, `norm(lo, centre, hi)`, `tri(...)`, `unif(lo, hi)`. One worked example per mode ships in `D0FUS_INPUTS/`.
216
+
217
+ ---
218
+
219
+ ## Outputs
220
+
221
+ Every mode writes a timestamped folder under `D0FUS_OUTPUTS/`. A RUN produces `input_parameters.txt` (the deck), `output_highlight.txt` (key results), `output_detailed.txt` (every input including defaults, every output), and 17 figures (cross-section, Miller surfaces, profiles, q(ρ), radiation, divertor two-point, radial build, coil and CICC drawings, cost breakdown, temperature and density maps, optional PyVista 3D view). SCAN writes the 2D map, OPTIMIZATION the convergence history and Hall of Fame, POPCON the operating-contour map, UNCERTAINTY the per-output distributions with the feasibility verdict and figures.
222
+
223
+ ---
224
+
225
+ ## Models in brief
226
+
227
+ Plasma geometry follows the Miller parameterisation (Miller 1998) with on-axis regularity enforced (Ball & Parra 2015). The three first-order plasma limits are Greenwald, Troyon and the kink limit on q₉₅, with the density-limit model selectable (Greenwald, Zanca 2019, Giacomin 2022 near-separatrix). Impurity radiation uses the Mavrin (2018) cooling rates; the divertor is characterised by an Eich attached estimate or a two-point model with a Lengyel seeding closure on non-coronal OpenADAS curves. The L-H threshold offers Martin (2008) and two Delabie (ITPA TC-26) regressions. Current drive follows the METIS efficiency models, matched to METIS within 1.5 %. Runaway-electron indicators combine a hot-tail seed (Smith 2008) and avalanche amplification (Breizman 2019), for comparative ranking only.
228
+
229
+ The TF inboard leg is a Princeton-D (File, Mills & Sheffield 1971); conductors are CICC-like with a helium-fraction hierarchy; critical currents use ITER parameterisations (NbTi, Nb₃Sn) and REBCO datasets (Senatore 2024, Fujikura 2019); quench protection is sized on the Maddock hot-spot criterion; the winding pack can be radially graded. Costing follows Sheffield & Milora (2016), with a surface-proportional Whyte (2024) model for cross-checks; costs never feed back into the physics.
230
+
231
+ Full derivations, validity domains and references: thesis, Chapter 1 and Appendices B-C.
232
+
233
+ ---
234
+
235
+ ## Version and citation
236
+
237
+ The tag **v2.7.0** is the reference version of the thesis: the manuscript documents this exact state of the code, and the benchmarks of its Chapter 2 (module level, coil-by-coil against six machines, EU-DEMO 2017 and ITER device level) were produced with it. To cite D0FUS, use `CITATION.cff` (GitHub's *Cite this repository* button) or cite the thesis:
238
+
239
+ > T. Auclair, *Apport des supraconducteurs à haute température critique au dimensionnement de machines de fusion nucléaire par confinement magnétique*, PhD thesis, Aix-Marseille Université / CEA-IRFM, 2026.
240
+
241
+ ---
242
+
243
+ ## Contributing
244
+
245
+ Contributions and questions are welcome: timothe.auclair@cea.fr
246
+
247
+ ## License
248
+
249
+ [CeCILL-C](https://cecill.info/licences/Licence_CeCILL-C_V1-en.html), a French free software license compatible with the GNU LGPL. See [LICENSE](LICENSE).
250
+
251
+ © 2025-2026 CEA/IRFM
252
+
253
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>