Skip to content

Commit 22f368f

Browse files
jcitrinTorax team
authored and
Torax team
committed
Cleanups and documentation updates
PiperOrigin-RevId: 659960040
1 parent 8ae5ccc commit 22f368f

7 files changed

+79
-23
lines changed

README.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# What is TORAX?
44

5-
TORAX is a differentiable tokamak core transport simulator aimed for fast and accurate forward modelling, pulse-design, trajectory optimization, and controller design workflows. TORAX is written in Python-JAX, with the following motivations:
5+
TORAX is a differentiable tokamak core transport simulator aimed for fast and accurate forward modelling, pulse-design, trajectory optimization, and controller design workflows. TORAX is written in Python using JAX, with the following motivations:
66

77
- Open-source and extensible, aiding with flexible workflow coupling
88
- JAX provides auto-differentiation capabilities and code compilation for fast runtimes. Differentiability allows for gradient-based nonlinear PDE solvers for fast and accurate modelling, and for sensitivity analysis of simulation results to arbitrary parameter inputs, enabling applications such as trajectory optimization and data-driven parameter identification for semi-empirical models. Auto-differentiability allows for these applications to be easily extended with the addition of new physics models, or new parameter inputs, by avoiding the need to hand-derive Jacobians
@@ -14,14 +14,15 @@ TORAX now has the following physics feature set:
1414

1515
- Coupled PDEs of ion and electron heat transport, electron particle transport, and current diffusion
1616
- Finite-volume-method
17-
- Multiple solver options: linear with Pereverzev-Corrigan terms, nonlinear with Newton-Raphson, nonlinear with optimization using the jaxopt library
18-
- Ohmic power, ion-electron heat exchange, fusion power, bootstrap current with the analytical Sauter model
19-
- Time dependent boundary conditions and sources
17+
- Multiple solver options: linear with Pereverzev-Corrigan terms and the predictor-corrector method, nonlinear with Newton-Raphson, nonlinear with optimization using the jaxopt library
18+
- Ohmic power, ion-electron heat exchange, fusion power, Bremsstrahlung, and bootstrap current with the analytical Sauter model
19+
- Time dependent boundary conditions, sources, geometry.
2020
- Coupling to the QLKNN10D [[van de Plassche et al, Phys. Plasmas 2020]](https://doi.org/10.1063/1.5134126) QuaLiKiz-neural-network surrogate for physics-based turbulent transport
21-
- General geometry, provided via CHEASE equilibrium files
21+
- General geometry, provided via CHEASE or FBT equilibrium files
2222
- For testing and demonstration purposes, a single CHEASE equilibrium file is available in the data/geo directory. It corresponds to an ITER hybrid scenario equilibrium based on simulations in [[Citrin et al, Nucl. Fusion 2010]](https://doi.org/10.1088/0029-5515/50/11/115007), and was obtained from [PINT](https://gitlab.com/qualikiz-group/pyntegrated_model). A PINT license file is available in data/geo.
23+
- Time dependent geometry is supported by provided a time series of geometry files
2324

24-
Additional heating and current drive sources can be provided by prescribed formulas, or user-provided analytical models.
25+
Additional heating and current drive sources can be provided by prescribed formulas, user-provided analytical models, or user-provided prescribed data.
2526

2627
Model implementation was verified through direct comparison of simulation outputs to the RAPTOR [[Felici et al, Plasma Phys. Control. Fusion 2012]](https://iopscience.iop.org/article/10.1088/0741-3335/54/2/025002) tokamak transport simulator.
2728

@@ -31,10 +32,8 @@ This is not an officially supported Google product.
3132

3233
Short term development plans include:
3334

34-
- Time dependent geometry
35-
- More flexible initial conditions
35+
- Extension of and more flexible data structures for prescribed input data
3636
- Implementation of forward sensitivity calculations w.r.t. control inputs and parameters
37-
- Implementation of persistent compilation cache for CPU
3837
- More extensive documentation and tutorials
3938
- Visualisation improvements
4039

@@ -44,7 +43,6 @@ Longer term desired features include:
4443
- Neoclassical tearing modes (modified Rutherford equation)
4544
- Radiation sinks
4645
- Cyclotron radiation
47-
- Bremsstrahlung
4846
- Line radiation
4947
- Neoclassical transport + multi-ion transport, with a focus on heavy impurities
5048
- IMAS coupling
@@ -192,6 +190,14 @@ If false, JAX does not compile internal TORAX functions. Used for debugging. Def
192190
$ export TORAX_COMPILATION_ENABLED=<True/False>
193191
```
194192

193+
The following implements the JAX persistent cache and will cause jax to store
194+
compiled programs to the filesystem, reducing recompilation time in some cases:
195+
196+
```shell
197+
$ export JAX_COMPILATION_CACHE_DIR=<path of your choice, such as ~/jax_cache>
198+
$ export JAX_PERSISTENT_CACHE_MIN_ENTRY_SIZE_BYTES=-1
199+
$ export JAX_PERSISTENT_CACHE_MIN_COMPILE_TIME_SECS=0.0
200+
```
195201

196202
### Set flags
197203
Output simulation time, dt, and number of stepper iterations (dt backtracking with nonlinear solver) carried out at each timestep.

docs/configuration.rst

+50-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ geometry
356356
--------
357357

358358
``geometry_type`` (str = 'chease')
359-
Geometry model used. There are currently two options:
359+
Geometry model used. There are currently three options:
360360

361361
* ``'circular'``
362362
An ad-hoc circular geometry model. Includes elongation corrections.
@@ -365,7 +365,8 @@ geometry
365365
* ``'chease'``
366366
Loads a CHEASE geometry file.
367367

368-
Time dependent geometry is not currently supported, but is on the immediate-term roadmap.
368+
* ``'fbt'``
369+
Loads FBT geometry files.
369370

370371
``nrho`` (int = 25)
371372
Number of radial grid points
@@ -374,6 +375,15 @@ Time dependent geometry is not currently supported, but is on the immediate-term
374375
Only used for ``geometry_type='chease'``. Sets the geometry file loaded.
375376
The geometry directory is set with the ``TORAX_GEOMETRY_DIR`` environment variable. If none is set, then the default is ``torax/data/third_party/geo``.
376377

378+
``LY_file`` (str = None)
379+
Only used for ``geometry_type='fbt'``. Sets the FBT LY geometry file loaded.
380+
381+
``L_file`` (str = None)
382+
Only used for ``geometry_type='fbt'``. Sets the FBT L geometry file loaded.
383+
384+
``geometry_dir`` (str = None)
385+
Optionally overrides the``TORAX_GEOMETRY_DIR`` environment variable.
386+
377387
``Ip_from_parameters`` (bool = True)
378388
Only used for ``geometry_type='chease'``.Toggles whether total plasma current is read from the configuration file,
379389
or from the geometry file. If True, then the :math:`\psi` calculated from the geometry file is scaled to match the desired :math:`I_p`.
@@ -394,6 +404,44 @@ Time dependent geometry is not currently supported, but is on the immediate-term
394404
Only used when the initial condition ``psi`` is from plasma current. Sets up a higher resolution mesh
395405
with ``nrho_hires = nrho * hi_res_fac``, used for ``j`` to ``psi`` conversions.
396406

407+
For setting up time-dependent geometry, a subset of varying geometry parameters
408+
and input files are defined in a ``geometry_configs`` dict, which is a
409+
time-series of {time: {configs}} pairs. For example, a time-dependent geometry
410+
input with 3 time-slices of FBT geometries can be set up as:
411+
412+
.. code-block:: python
413+
414+
'geometry': {
415+
'geometry_type': 'fbt',
416+
'Ip_from_parameters': True,
417+
'geometry_configs': {
418+
20.0: {
419+
'LY_file': 'LY_early_rampup.mat',
420+
'L_file': 'L_early_rampup.mat',
421+
'Rmaj': 6.2,
422+
'Rmin': 2.0,
423+
'B0': 5,3,
424+
},
425+
50.0: {
426+
'LY_file': 'LY_mid_rampup.mat',
427+
'L_file': 'L_mid_rampup.mat',
428+
'Rmaj': 6.2,
429+
'Rmin': 2.0,
430+
'B0': 5,3,
431+
},
432+
100.0: {
433+
'LY_file': 'LY_endof_rampup.mat',
434+
'L_file': 'L_endof_rampup.mat',
435+
'Rmaj': 6.2,
436+
'Rmin': 2.0,
437+
'B0': 5,3,
438+
},
439+
},
440+
},
441+
442+
All file loading and geometry processing is done upon simulation initialization.
443+
The geometry inputs into the TORAX PDE coefficients are then time-interpolated
444+
on-the-fly onto the TORAX time slices where the PDE calculations are done.
397445

398446
transport
399447
---------

docs/overview.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TORAX's physics and solver feature set includes the following:
3232
* Time dependent boundary conditions and sources
3333
* Coupling to the QLKNN10D `[van de Plassche et al, Phys. Plasmas 2020] <https://doi.org/10.1063/1.5134126>`_
3434
QuaLiKiz-neural-network surrogate for physics-based turbulent transport
35-
* General geometry, provided via CHEASE equilibrium files
35+
* General geometry, provided via CHEASE or FBT equilibrium files
3636

3737
* For testing and demonstration purposes, a single CHEASE equilibrium file is available in the
3838
data/geo directory. It corresponds to an ITER hybrid scenario equilibrium based on simulations

docs/physics_models.rst

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ geometry variables required for the transport equations.
1515
- **CHEASE:** This model utilizes equilibrium data from the `CHEASE <https://doi.org/10.1016/0010-4655(96)00046-X>`_ fixed boundary
1616
Grad-Shafranov equilibrium code. Users provide a CHEASE output file, and TORAX extracts the relevant geometric quantities.
1717

18+
- **FBT:** This model utilizes equilibrium data from the `FBT <https://www.sciencedirect.com/science/article/pii/0010465588900410>`_ free boundary
19+
Grad-Shafranov equilibrium code. Users provide FBT output files, and TORAX extracts the relevant geometric quantities.
20+
1821
- **Circular:** For testing and demonstration purposes, TORAX includes a simplified circular geometry model.
1922
This model assumes a circular plasma cross-section and corrects for elongation to approximate the metric coefficients.
2023

docs/roadmap.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ Development Roadmap
55

66
Short term development plans include:
77

8-
* Time dependent geometry
9-
* More flexible functional forms for initial and prescribed conditions
8+
* Extension of and more flexible datastructures for prescribed input data
109
* Implementation of forward sensitivity calculations w.r.t. control inputs and parameters
11-
* Implementation of persistent compilation cache for CPU
10+
* More extensive documentation and tutorials
1211
* Extended visualisation
1312

1413
Longer term desired features include:

torax/core_profile_setters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,9 @@ def initial_core_profiles(
624624
isinstance(geo, geometry.StandardGeometry)
625625
and not dynamic_runtime_params_slice.profile_conditions.initial_psi_from_j
626626
):
627-
# psi is already provided from the CHEASE equilibrium, so no need to first
628-
# calculate currents. However, non-inductive currents are still calculated
629-
# and used in current diffusion equation.
627+
# psi is already provided from a numerical equilibrium, so no need to
628+
# first calculate currents. However, non-inductive currents are still
629+
# calculated and used in current diffusion equation.
630630
psi_grad_constraint = _calculate_psi_grad_constraint(
631631
dynamic_runtime_params_slice,
632632
geo,

torax/geometry.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class GeometryType(enum.Enum):
115115
"""
116116

117117
CIRCULAR = 0
118-
CHEASE = 1
118+
NUMERICAL = 1
119119

120120

121121
# pylint: disable=invalid-name
@@ -891,8 +891,8 @@ def build_standard_geometry(
891891
g2g3_over_rhon = g2[1:] * g3[1:] / rho_norm_intermediate[1:]
892892
g2g3_over_rhon = np.concatenate((np.zeros(1), g2g3_over_rhon))
893893

894-
# make an alternative initial psi, self-consistent with CHEASE Ip profile
895-
# needed because CHEASE psi profile has noisy second derivatives
894+
# make an alternative initial psi, self-consistent with numerical geometry
895+
# Ip profile. Needed since input psi profile may have noisy second derivatives
896896
dpsidrhon = (
897897
intermediate.Ip_profile[1:]
898898
* (16 * constants.CONSTANTS.mu0 * np.pi**3 * intermediate.Phi[-1])
@@ -1012,7 +1012,7 @@ def build_standard_geometry(
10121012
area = rhon_interpolation_func(rho_norm, intermediate.area)
10131013

10141014
return StandardGeometry(
1015-
geometry_type=GeometryType.CHEASE.value,
1015+
geometry_type=GeometryType.NUMERICAL.value,
10161016
drho_norm=np.asarray(drho_norm),
10171017
torax_mesh=mesh,
10181018
Phi=Phi,

0 commit comments

Comments
 (0)