![]() |
The Open FUSION Toolkit 26.6
An open-source framework for fusion and plasma science and engineering
|
TokaMaker + TORAX Coupled Pulse Simulation Code.
Public Member Functions | |
| __init__ (self, t_init, t_final, eqtimes, g_eqdsk_arr, tokamaker_obj, tx_dt=0.1, tm_times=None, last_surface_factor=0.99, truncate_eq=False) | |
| Initialize the Coupled TokaMaker + TORAX object. | |
| configure_redirect_to_log (self) | |
| Step 3/3 of setup to divert noisy outputs to log file. | |
| fly (self, run_name='tmp', convergence_threshold=-1.0, max_loop=3, output_mode=False, skip_bad_init_eqdsks=False, initial_relax=True, relax=False, relax_kinetics=False, relax_duration=0.1, t_ave_toggle='off', t_ave_window=0.5, t_ave_causal=True, t_ave_ignore_start=0.25, loop0=False, steady_state_mode=False) | |
| Run TokaMaker_TORAX coupled pulse design loop. | |
| get_final_timepoint_results (self, eqdsk_save_dir=None) | |
| Profiles and scalars at the last TokaMaker timepoint of the last completed coupling loop. | |
| load_pedestal_config (self, pedestal_config) | |
| Load pedestal config dict and fully replace 'pedestal' in TORAX config. | |
| load_TORAX_config (self, config) | |
| Load a TORAX config dict. | |
| make_movie (self, save_path=None, **kwargs) | |
| Generate pulse movie from stored psi snapshots. | |
| plot_coils (self, save_path=None, display=True, **kwargs) | |
| Plot coil current traces over the pulse. | |
| plot_lcfs_evolution (self, save_path=None, display=True, one_plot=False, **kwargs) | |
| Plot time evolution of the LCFS for each pulse phase (rampup, flattop, rampdown). | |
| plot_profile_evolution (self, save_path=None, display=True, one_plot=False, **kwargs) | |
| Plot profile evolution over time. | |
| plot_profiles (self, **kwargs) | |
| Interactive profile viewer (ipywidgets slider in Jupyter, static otherwise). | |
| plot_scalars (self, save_path=None, display=True, **kwargs) | |
| Plot scalar time traces (Ip, Q, Te, ne, power channels, etc.). | |
| save_res (self) | |
| Save simulation results to JSON. | |
| save_state (self, fname) | |
| Save intermediate simulation state to JSON. | |
| set_evolve (self, density=True, Ti=True, Te=True, current=True) | |
| Set variables as either prescribed (False) or evolved (True) for TORAX. | |
| set_fueling (self, gas_puff_S_total=None, gas_puff_decay_length=None, pellet_deposition_location=None, pellet_width=None, pellet_S_total=None, generic_particle_location=None, generic_particle_width=None, generic_particle_S_total=None) | |
| Set gas puff and pellet fueling particle sources for TORAX. | |
| set_heating (self, generic_heat=None, generic_heat_loc=None, generic_heat_width=0.25, nbi_current=False, ecrh=None, ecrh_loc=None, ecrh_width=0.1, ohmic=None, fusion=True, ei_exchange=True) | |
| Set TORAX heating and source toggles. | |
| set_Ip (self, Ip) | |
| Set plasma current (Amps), used for both codes and not evolved by either. | |
| set_ne (self, n_e, right_bc=None) | |
| Set electron density profiles and optional right boundary condition. | |
| set_pedestal (self, set_pedestal=False, T_i_ped=None, T_e_ped=None, n_e_ped=None, ped_top=0.90) | |
| Set pedestals for ion/electron temperatures and density (legacy API). | |
| set_plasma_composition (self, Zeff=None, main_ion=None, impurity=None) | |
| Set plasma effective charge and composition. | |
| set_Te (self, T_e, right_bc=None) | |
| Set electron temperature profiles and optional right boundary condition. | |
| set_Ti (self, T_i, right_bc=None) | |
| Set ion temperature profiles and optional right boundary condition. | |
| set_TokaMaker_coil_reg (self, coil_bounds=None, updownsym=False, default_weight=1.0E-1, disable_coils=None, disable_weight=1.0E4, symmetry_weight=1.0E3, disable_virtual_vsc=True, vsc_weight=1.0E4) | |
| Set coil regularization using the dict-based TokaMaker reg_terms API. | |
| set_TORAX_grid (self, grid_type, grid) | |
| Set TORAX grid type and grid points. | |
| set_transport_coefs (self, chi_min=None, chi_max=None, De_min=None, De_max=None, Ve_min=None, Ve_max=None) | |
| Set transport coefficient bounds for TORAX. | |
| set_x_points (self, diverted_times=None, x_point_targets=None, x_point_weight=100.0, strike_point_targets=None) | |
| Configure diverted window, X-point targets, and optional strike points. | |
| summary (self, **kwargs) | |
| Print/display a physics summary of the simulation. | |
Public Attributes | |
| lcfs = lcfs | |
| results = None | |
| Access simulation results dict. | |
| state = None | |
| Access simulation state dict. | |
Protected Member Functions | |
| _apply_tm_coil_reg (self, targets=None) | |
| Internal: build and apply reg_terms from stored config plus per-timestep targets. | |
| _apply_tx_set_overrides (self, myconfig) | |
| Apply user set_*() overrides to a TORAX config dict (in place). | |
| _calc_tx_ffp_ni (self, i) | |
| Calculate non-inductive FF' profile from TORAX current densities. | |
| _capture_relax_tx_profiles_from_datatree (self, data_tree, time_val=None) | |
| Store psi, n_e, T_e, T_i at time_val for debug relax figures / history. | |
| _capture_steady_state_tx_seed (self, data_tree) | |
| Store psi, n_e, T_e, T_i at t_final for steady_state_mode next coupling loop. | |
| _coupling_iteration_is_first (self) | |
| True on the first TokaMaker_TORAX loop (TORAX uses the seed gEQDSK map). | |
| _extract_tx_profile (self, data_tree, var_name, time, load_into_state='state', normalize=False, profile_type='linterp') | |
| Extract a TORAX profile onto self._psi_N with optional time-averaging. | |
| _extract_tx_scalar (self, data_tree, var_name, time, source='scalars', scale=1.0) | |
| Extract a scalar value from TORAX with optional time-averaging. | |
| _extract_tx_scalar_at_rho (self, data_tree, var_name, time, rho_val, rho_coord='rho_norm', scale=1.0) | |
| Extract a profile value at a specific rho location as a scalar, with time-averaging. | |
| _extract_tx_scalar_at_rho_timeseries (self, data_tree, var_name, rho_val, rho_coord='rho_norm', scale=1.0) | |
| Extract a profile-at-fixed-rho time-series with time-averaging. | |
| _extract_tx_scalar_timeseries (self, data_tree, var_name, source='scalars', scale=1.0) | |
| Extract a full time-series scalar from TORAX with time-averaging applied at each point. | |
| _get_time_window (self, time, tx_times) | |
| Return the (t_start, t_end) averaging window for a given timepoint. | |
| _get_tx_config (self) | |
| Generate config object for Torax simulation. | |
| _interp_tx_profile_onto_psi (self, data_tree, var_name, time, profile_type='linterp') | |
| Interpolate a single TORAX profile snapshot onto self._psi_N. | |
| _log (self, msg) | |
| Write message to log file only. | |
| _loop0_coarse_tx_main_scope (self) | |
| Apply loop-0 coarse TORAX grid for main _run_tx; restore after. | |
| _loop0_coarse_tx_relax_scope (self, stage) | |
| Apply loop-0 coarse TORAX grid during initial relax only; restore after. | |
| _pop_tx_grid (self) | |
| Restore TORAX grid from _push_tx_grid stack. | |
| _print (self, msg) | |
| Write message to both stdout and log file. | |
| _push_tx_grid (self) | |
| Save current TORAX grid onto stack for later _pop_tx_grid. | |
| _quiet_tm (self) | |
| Context manager: redirect C/Fortran-level stdout+stderr to /dev/null. | |
| _res_update (self, data_tree) | |
| Populate self._results from TORAX data with time-averaging. | |
| _run_tm (self) | |
| Run the GS solve across n timesteps using TokaMaker. | |
| _run_tx (self) | |
| Run the TORAX transport simulation. | |
| _run_tx_relax (self, *, stage, eqdsk_path, prescribed_profiles) | |
| Short TORAX relax: initial run on the seed EQDSK, or inter-loop on TM i=0 EQDSK. | |
| _test_eqdsk_tx_config (self, eqdsk, *, quiet=False) | |
| Return whether TORAX accepts eqdsk as ToraxConfig geometry. | |
| _tm_prof_input_ped_smooth (self, ffp_prof, pp_prof, p_prof, transition_psi_N=0.6, gauss_sigma=8, blend_width=0.02, sav_window=41, sav_order=3) | |
| Edge smoothing with Gaussian filter: smooth p profile and take derivative for pp_prof. | |
| _tm_prof_input_power_flux (self, ffp_prof, pp_prof) | |
| Generic power-flux shape. | |
| _tm_prof_input_raw (self, ffp_prof, pp_prof) | |
| Raw TORAX profiles passed through unchanged. | |
| _tm_prof_input_sign_flip (self, ffp_prof, pp_prof) | |
| Sign-flip clipping: clip each profile to its dominant sign. | |
| _tm_update (self, i) | |
| Update internal state and coil current results based on results of GS solver. | |
| _tx_update (self, i, data_tree) | |
| Update the simulation state from TORAX results at timestep i. | |
| _zz_doxygen_dummy (self) | |
Static Protected Member Functions | |
| _flatten_time_dependent (config) | |
| Recursively flatten time-dependent config values to their initial value only. | |
| _loop0_tm_solve_indices (n_tm, stride) | |
| TokaMaker timestep indices for coupling loop 0 subsampling: endpoints plus every stride-th. | |
| _numpy_to_plain_python (obj) | |
| Recursively convert numpy scalars/arrays to plain Python types. | |
| _relax_flat_profile_to_rho_y (profile_val) | |
| (rho_norm, y) from a profile_conditions value after merge + flatten. | |
| _tx_config_merge (base, override) | |
| Recursively merge override into base TORAX config (in-place). | |
| __init__ | ( | self, | |
| t_init, | |||
| t_final, | |||
| eqtimes, | |||
| g_eqdsk_arr, | |||
| tokamaker_obj, | |||
| tx_dt = 0.1, | |||
| tm_times = None, | |||
| last_surface_factor = 0.99, | |||
| truncate_eq = False ) |
Initialize the Coupled TokaMaker + TORAX object.
| t_init | Start time (s). |
| t_final | End time (s). |
| eqtimes | Time points of each gEQDSK file. |
| g_eqdsk_arr | Filenames of each gEQDSK file. |
| tokamaker_obj | Preconfigured TokaMaker object. |
| tx_dt | Time step (s) of TORAX simulation. |
| tm_times | Time points where TokaMaker solves equilibrium. |
| last_surface_factor | Last surface factor for Torax. |
| truncate_eq | Whether to truncate equilibrium when saving TokaMaker output to EQDSK. |
Coupling fly() option loop0: if True, the first coupling pass uses a coarse TORAX grid and subsampled TokaMaker times; if False, that pass is skipped (see fly()).
|
protected |
Internal: build and apply reg_terms from stored config plus per-timestep targets.
| targets | Dict of {coil_name: current [A/turn]} to use as soft targets, or None for zeros. |
|
protected |
Apply user set_*() overrides to a TORAX config dict (in place).
Only applied when the corresponding attribute is not None (i.e. the user called the setter explicitly; None means fall through to the loaded/base config). Used by both _get_tx_config (coupling loop 0+) and _run_tx_relax so each relax simulation sees the same plasma conditions as the main sim.
Does NOT touch geometry, numerics.{t_initial, t_final, fixed_dt}, or profile_conditions.{psi, initial_psi_mode, initial_psi_from_j} — those are loop-specific and set by the calling method.
| myconfig | Config dict (modified in place). |
|
protected |
Calculate non-inductive FF' profile from TORAX current densities.
The full GS relation is: FF'_total = 2 * mu_0 * (j_tor + p' * <R>) / <1/R>
To avoid double-counting p' when decomposing into inductive/non-inductive: FF'_NI = 2 * mu_0 * j_NI / <1/R> FF'_I = 2 * mu_0 * (j_I + p' * <R>) / <1/R>
| i | Time index |
|
protected |
Store psi, n_e, T_e, T_i at time_val for debug relax figures / history.
Updates _relax_profiles_snapshot temporarily so the caller can append a copy to _relax_mainrun_profile_history. Not used to seed inter-loop relax runs (those profiles come from the user config each time).
|
protected |
Store psi, n_e, T_e, T_i at t_final for steady_state_mode next coupling loop.
Profile tuples use t_init as the time key (TORAX profile_conditions convention), matching _psi_init / relax snapshots.
|
protected |
True on the first TokaMaker_TORAX loop (TORAX uses the seed gEQDSK map).
|
protected |
Extract a TORAX profile onto self._psi_N with optional time-averaging.
Replaces the former _pull_tx_onto_psi. When time-averaging is active the profile is interpolated at every TORAX timestep inside the window and the results are averaged pointwise on the psi_N grid.
| data_tree | TORAX output data tree. |
| var_name | Name of variable (e.g., 'T_i', 'j_ohmic', 'FFprime'). |
| time | Target time value. |
| load_into_state | 'state' → return dict; else return plain array. |
| normalize | If True, normalize profile by the core value. |
| profile_type | 'linterp' or 'jphi-linterp'. |
|
protected |
Extract a scalar value from TORAX with optional time-averaging.
| data_tree | TORAX output data tree. |
| var_name | Attribute name on data_tree.scalars (or .profiles). |
| time | Target time (seconds). |
| source | 'scalars' or 'profiles' — which subtree to read from. |
| scale | Multiplicative factor applied after extraction. |
|
protected |
Extract a profile value at a specific rho location as a scalar, with time-averaging.
| data_tree | TORAX output data tree. |
| var_name | Attribute name on data_tree.profiles. |
| time | Target time (seconds). |
| rho_val | Radial coordinate value to select. |
| rho_coord | Name of the rho coordinate ('rho_norm', 'rho_face_norm', etc.). |
| scale | Multiplicative factor applied after extraction. |
|
protected |
Extract a profile-at-fixed-rho time-series with time-averaging.
Returns dict {'x': times_list, 'y': values_array}.
|
protected |
Extract a full time-series scalar from TORAX with time-averaging applied at each point.
Returns dict {'x': times_list, 'y': values_array} suitable for self._results.
| data_tree | TORAX output data tree. |
| var_name | Attribute name on data_tree.scalars (or .profiles). |
| source | 'scalars' or 'profiles'. |
| scale | Multiplicative factor applied after extraction. |
|
staticprotected |
Recursively flatten time-dependent config values to their initial value only.
A dict whose keys are ALL numeric (int/float) is treated as time-dependent: only the entry with the smallest key is retained. Structural dicts (with any string keys) are recursed into. Tuples of form (times_array, values_array) are flattened to the first entry.
|
protected |
Return the (t_start, t_end) averaging window for a given timepoint.
Respects self._t_ave_toggle, self._t_ave_window, self._t_ave_causal, and self._t_ave_ignore_start. If averaging is disabled for this timepoint the returned window collapses to (time, time).
| time | The target timepoint (seconds). |
| tx_times | Sorted numpy array of all available TORAX times. |
|
protected |
Generate config object for Torax simulation.
|
protected |
Interpolate a single TORAX profile snapshot onto self._psi_N.
No averaging, just one timeslice. Returns a plain numpy array on self._psi_N.
|
protected |
Write message to log file only.
|
protected |
Apply loop-0 coarse TORAX grid for main _run_tx; restore after.
|
protected |
Apply loop-0 coarse TORAX grid during initial relax only; restore after.
|
staticprotected |
TokaMaker timestep indices for coupling loop 0 subsampling: endpoints plus every stride-th.
|
staticprotected |
Recursively convert numpy scalars/arrays to plain Python types.
Used before pformat-saving config dicts so the saved .py files are loadable without numpy (no array([...]) references).
|
protected |
Restore TORAX grid from _push_tx_grid stack.
Used for reducing grid in loop0.
|
protected |
Write message to both stdout and log file.
|
protected |
Save current TORAX grid onto stack for later _pop_tx_grid.
Used for reducing grid in loop0.
|
protected |
Context manager: redirect C/Fortran-level stdout+stderr to /dev/null.
|
staticprotected |
(rho_norm, y) from a profile_conditions value after merge + flatten.
Handles:
|
protected |
Populate self._results from TORAX data with time-averaging.
|
protected |
Run the GS solve across n timesteps using TokaMaker.
|
protected |
Run the TORAX transport simulation.
|
protected |
Short TORAX relax: initial run on the seed EQDSK, or inter-loop on TM i=0 EQDSK.
Uses flattened user inputs (_apply_tx_set_overrides + _flatten_time_dependent). If prescribed_profiles is None, psi follows EQDSK initial_psi_mode='geometry' and n_e, T_e, T_i stay as already merged from base / loaded config and _apply_tx_set_overrides (user inputs). If a dict is passed, it must supply psi, n_e, T_e, T_i tuples (advanced; loop N relax uses None so kinetics are always user-specified).
| stage | 'initial' or 'interloop' (logging / output names only). |
| eqdsk_path | Path to gEQDSK for geometry_configs at t_initial. |
| prescribed_profiles | None, or dict with keys psi, n_e, T_e, T_i (3-tuples). |
|
protected |
Return whether TORAX accepts eqdsk as ToraxConfig geometry.
| quiet | If True, do not print or append to the coupling log on failure (used for intermediate-resolution retries in _run_tm). If False, failure is only reported when output_mode is 'debug'. |
|
protected |
Edge smoothing with Gaussian filter: smooth p profile and take derivative for pp_prof.
|
protected |
Generic power-flux shape.
|
protected |
Raw TORAX profiles passed through unchanged.
|
protected |
Sign-flip clipping: clip each profile to its dominant sign.
|
protected |
Update internal state and coil current results based on results of GS solver.
| i | Timestep of the solve. |
|
staticprotected |
Recursively merge override into base TORAX config (in-place).
For every key in override:
| base | Dict to merge into (modified in-place). |
| override | Dict whose keys take precedence. |
|
protected |
Update the simulation state from TORAX results at timestep i.
If sawtooth averaging is enabled, all profile and scalar extractions use time-averaged methods to smooth sawtooth oscillations.
| i | Timestep index. |
| data_tree | Result object from Torax. |
|
protected |
| configure_redirect_to_log | ( | self | ) |
Step 3/3 of setup to divert noisy outputs to log file.
Captures INFO-level and above.
| fly | ( | self, | |
| run_name = 'tmp', | |||
| convergence_threshold = -1.0, | |||
| max_loop = 3, | |||
| output_mode = False, | |||
| skip_bad_init_eqdsks = False, | |||
| initial_relax = True, | |||
| relax = False, | |||
| relax_kinetics = False, | |||
| relax_duration = 0.1, | |||
| t_ave_toggle = 'off', | |||
| t_ave_window = 0.5, | |||
| t_ave_causal = True, | |||
| t_ave_ignore_start = 0.25, | |||
| loop0 = False, | |||
| steady_state_mode = False ) |
Run TokaMaker_TORAX coupled pulse design loop.
| convergence_threshold | Max fractional change in consumed flux between loops for convergence. |
| max_loop | Highest counted coupling index to run (inclusive): full-resolution passes use indices 1 … max_loop. The optional cheap pass at index 0 (when loop0=True) is always attempted first and does not count toward this limit. Example: max_loop=3 runs loop 0 (if enabled) then loops 1, 2, and 3 before stopping unless convergence ends earlier. |
| run_name | Name for this run (used in output directory and log file). |
| output_mode | Output level selector: False (or None), 'minimal', 'normal', or 'debug'. |
| skip_bad_init_eqdsks | If True, skip broken initial gEQDSK files instead of raising. |
| initial_relax | If True (default), run a short TORAX relax on the seed EQDSK before the first coupling TM-TORAX pass (flattened user inputs; psi from geometry unless an inter-loop relax already set psi). If False, skip and start from EQDSK psi / loaded config. When relax is True, this is forced True so initial relax establishes psi before later coupling iterations. |
| relax | If True, run an additional short TORAX relax before each coupling iteration with index ≥1, on TM-solved EQDSK (previous_loop).000.eqdsk (fallback: seed), with user n_e, T_e, T_i from loaded config and set_*() and psi from geometry on that EQDSK— avoiding drift from previous TORAX outputs between loops. Default False (backward compatible). Implies initial_relax=True. |
| relax_kinetics | If False (default), each relax only evolves current; density and ion/electron heat stay fixed at the profiles present before that relax. If True, relax uses the same evolve_* flags as set_evolve() / loaded config. When True, relaxed n_e, T_e, T_i are injected into main TORAX after set_*() like psi. |
| relax_duration | Duration (s) of each relax simulation; timestep is fixed at 0.01 s. |
| t_ave_toggle | Time-averaging mode: 'off' (no averaging), 'flattop' (average only during flat-top), or 'pulse' (average over the whole pulse). |
| t_ave_window | Averaging window size in seconds. Default 0.5 s. |
| t_ave_causal | If True, window is entirely behind the timepoint (backward-looking). If False, window is centred on the timepoint. |
| t_ave_ignore_start | Ignore the first N seconds of the pulse when building the averaging window (avoids numerical transients). Default 0.25 s. |
| loop0 | If True, run a first coupling pass at index 0 with reduced cost: coarse TORAX radial grid (face_centers linspace, DEFAULT_LOOP0_TX_FACE_POINTS), the same coarse grid on the optional initial relax, and subsampled TokaMaker times (stride 2). If False (default), skip that pass and start coupling at index 1 at full resolution (initial relax is unchanged and controlled only by initial_relax / relax). |
| steady_state_mode | If False (default), each coupling loop after the first reuses the time-dependent TokaMaker EQDSK sequence from the previous loop (existing behavior). If True, after each completed loop the next loop seeds TORAX with psi and kinetics from the previous main run at t_final, uses the final TokaMaker EQDSK from the previous loop for all TORAX geometry times (flat equilibrium shape in time), warm-starts TokaMaker at i=0 from the previous loop's final psi grid, and runs inter-loop relax on that final EQDSK when relax is True. |
| get_final_timepoint_results | ( | self, | |
| eqdsk_save_dir = None ) |
Profiles and scalars at the last TokaMaker timepoint of the last completed coupling loop.
Call after fly() when TokaMaker has populated state['equil'] at every timestep index.
Profiles use the usual TokaMaker_TORAX flux-surface dict form {'x', 'y', 'type'} (x = normalized poloidal flux when applicable). TokaMaker p_prime and FF_prime are P' and F F' from get_profiles(npsi=...) on the same grid as stored in state. Kinetic profiles and eta come from the TORAX-updated state at that timestep; current densities j_* are TORAX flux-surface profiles (sources for the GS solve).
Scalars: fusion Q from TORAX (last save or live data tree); q95 and q0 from TokaMaker get_q (l_i likewise from get_stats); V_loop from TORAX v_loop_lcfs; Ip is the TokaMaker equilibrium value.
| eqdsk_save_dir | If set (non-empty str or path-like), write the final TokaMaker equilibrium gEQDSK with save_eqdsk into this directory (created if needed). If None (default), no file is written. |
| load_pedestal_config | ( | self, | |
| pedestal_config ) |
Load pedestal config dict and fully replace 'pedestal' in TORAX config.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#pedestal If provided, this dict is copied to 'myconfig['pedestal']' directly, replacing the full pedestal section from BASE_CONFIG and load_TORAX_config().
| pedestal_config | Dictionary in TORAX pedestal config format, or None to clear and fall back to set_pedestal(). |
| load_TORAX_config | ( | self, | |
| config ) |
Load a TORAX config dict.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html The loaded config is deep-merged on top of BASE_CONFIG when the simulation config is built. Any key present in the loaded config will override the corresponding BASE_CONFIG key; keys only in BASE_CONFIG are kept as-is. Geometry is always overwritten (eqdsk-based).
Explicit set_*() calls made AFTER load_TORAX_config() will override both the base and the loaded config.
| config | Dictionary (TORAX config format). |
| make_movie | ( | self, | |
| save_path = None, | |||
| ** | kwargs ) |
Generate pulse movie from stored psi snapshots.
| save_path | Path to save MP4 file. If None, does not save. |
| plot_coils | ( | self, | |
| save_path = None, | |||
| display = True, | |||
| ** | kwargs ) |
Plot coil current traces over the pulse.
| save_path | Path to save figure. If None, does not save. |
| display | Whether to show the plot. |
| plot_lcfs_evolution | ( | self, | |
| save_path = None, | |||
| display = True, | |||
| one_plot = False, | |||
| ** | kwargs ) |
Plot time evolution of the LCFS for each pulse phase (rampup, flattop, rampdown).
| save_path | Path prefix to save figures. If None, does not save. |
| display | Whether to show the plots. |
| one_plot | If True, combine all pulse phases into one figure. |
| plot_profile_evolution | ( | self, | |
| save_path = None, | |||
| display = True, | |||
| one_plot = False, | |||
| ** | kwargs ) |
Plot profile evolution over time.
| save_path | Path to save figure. If None, does not save. |
| display | Whether to show the plot. |
| one_plot | If True, combine all pulse phases into one figure. |
| plot_profiles | ( | self, | |
| ** | kwargs ) |
Interactive profile viewer (ipywidgets slider in Jupyter, static otherwise).
| plot_scalars | ( | self, | |
| save_path = None, | |||
| display = True, | |||
| ** | kwargs ) |
Plot scalar time traces (Ip, Q, Te, ne, power channels, etc.).
| save_path | Path to save figure. If None, does not save. |
| display | Whether to show the plot. |
| save_res | ( | self | ) |
Save simulation results to JSON.
| save_state | ( | self, | |
| fname ) |
Save intermediate simulation state to JSON.
| fname | Filename to save to. |
| set_evolve | ( | self, | |
| density = True, | |||
| Ti = True, | |||
| Te = True, | |||
| current = True ) |
Set variables as either prescribed (False) or evolved (True) for TORAX.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#numerics
| density | Evolve density. |
| Ti | Evolve ion temperature. |
| Te | Evolve electron temperature. |
| current | Evolve current. |
| set_fueling | ( | self, | |
| gas_puff_S_total = None, | |||
| gas_puff_decay_length = None, | |||
| pellet_deposition_location = None, | |||
| pellet_width = None, | |||
| pellet_S_total = None, | |||
| generic_particle_location = None, | |||
| generic_particle_width = None, | |||
| generic_particle_S_total = None ) |
Set gas puff and pellet fueling particle sources for TORAX.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#sources
| gas_puff_S_total | Gas puff particle source (particles/s). |
| gas_puff_decay_length | Gas puff decay length from edge (normalized rho). |
| pellet_deposition_location | Pellet deposition location (normalized rho). |
| pellet_width | Pellet deposition width (normalized rho). |
| pellet_S_total | Pellet particle source (particles/s). |
| generic_particle_location | Generic particle source location (normalized rho). |
| generic_particle_width | Generic particle source width (normalized rho). |
| generic_particle_width | Generic particle source amount (particles/s). |
| set_heating | ( | self, | |
| generic_heat = None, | |||
| generic_heat_loc = None, | |||
| generic_heat_width = 0.25, | |||
| nbi_current = False, | |||
| ecrh = None, | |||
| ecrh_loc = None, | |||
| ecrh_width = 0.1, | |||
| ohmic = None, | |||
| fusion = True, | |||
| ei_exchange = True ) |
Set TORAX heating and source toggles.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#sources
| generic_heat | Generic heating ({time: power_W}). |
| generic_heat_loc | Generic heating deposition location (normalized rho). |
| generic_heat_width | Generic heating deposition width (normalized rho). |
| nbi_current | Enable NBI current drive estimate from generic heating. |
| ecrh | ECRH heating ({time: power_W}). |
| ecrh_loc | ECRH deposition location (normalized rho). |
| ecrh_width | ECRH deposition width (normalized rho). |
| ohmic | Optional explicit ohmic power ({time: power_W}). |
| fusion | Enable fusion alpha heating source. |
| ei_exchange | Enable electron-ion energy exchange source. |
| set_Ip | ( | self, | |
| Ip ) |
Set plasma current (Amps), used for both codes and not evolved by either.
| ip | Plasma current. |
| set_ne | ( | self, | |
| n_e, | |||
| right_bc = None ) |
Set electron density profiles and optional right boundary condition.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#profile-conditions
| n_e | Electron density (m^-3). |
| right_bc | Right boundary value at rho=1 (m^-3), scalar or time-varying map. |
| set_pedestal | ( | self, | |
| set_pedestal = False, | |||
| T_i_ped = None, | |||
| T_e_ped = None, | |||
| n_e_ped = None, | |||
| ped_top = 0.90 ) |
Set pedestals for ion/electron temperatures and density (legacy API).
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#pedestal This preserves the original behavior:
| set_pedestal | Toggle pedestal model on/off. |
| T_i_ped | Ion temperature pedestal (time-varying scalar allowed). |
| T_e_ped | Electron temperature pedestal (time-varying scalar allowed). |
| n_e_ped | Electron density pedestal (time-varying scalar allowed). |
| ped_top | Pedestal-top location rho_norm_ped_top. |
| set_plasma_composition | ( | self, | |
| Zeff = None, | |||
| main_ion = None, | |||
| impurity = None ) |
Set plasma effective charge and composition.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#profile-conditions
| Zeff | Effective charge target. |
| main_ion | Main ion species dict, e.g. {'D': 0.5, 'T': 0.5}. |
| impurity | Impurity species string, e.g. 'Ne', 'Ar', 'W'. |
| set_Te | ( | self, | |
| T_e, | |||
| right_bc = None ) |
Set electron temperature profiles and optional right boundary condition.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#profile-conditions
| T_e | Electron temperature (keV). |
| right_bc | Right boundary value at rho=1 (keV), scalar or time-varying map. |
| set_Ti | ( | self, | |
| T_i, | |||
| right_bc = None ) |
Set ion temperature profiles and optional right boundary condition.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#profile-conditions
| T_i | Ion temperature (keV). |
| right_bc | Right boundary value at rho=1 (keV), scalar or time-varying map. |
| set_TokaMaker_coil_reg | ( | self, | |
| coil_bounds = None, | |||
| updownsym = False, | |||
| default_weight = 1.0E-1, | |||
| disable_coils = None, | |||
| disable_weight = 1.0E4, | |||
| symmetry_weight = 1.0E3, | |||
| disable_virtual_vsc = True, | |||
| vsc_weight = 1.0E4 ) |
Set coil regularization using the dict-based TokaMaker reg_terms API.
Coil bounds are hard current limits in Amperes per turn (A/turn). The total current in a coil region is I_coil [A/turn] * n_turns, where n_turns comes from the mesh file coil definition.
During the pulse, coil current targets are set automatically: the initial equilibrium currents seed i=0, and each subsequent timestep uses the previous timestep's solved currents as loose targets.
| coil_bounds | Dict of {coil_name: [min, max]} hard current bounds [A/turn]. Default ±5 MA/turn. |
| updownsym | Enforce up-down symmetry for coil pairs (U/L naming convention). |
| default_weight | Regularization weight for normal coils (default 0.1). |
| disable_coils | List of coil name prefixes to disable (e.g. ['DV1', 'DV2']). |
| disable_weight | Regularization weight for disabled coils (default 1e4). |
| symmetry_weight | Regularization weight for symmetry constraints (default 1e3). |
| disable_virtual_vsc | Disable the virtual VSC coil (default True). |
| vsc_weight | Regularization weight for disabled VSC (default 1e4). |
| set_TORAX_grid | ( | self, | |
| grid_type, | |||
| grid ) |
Set TORAX grid type and grid points.
TORAX grid documentation: https://torax.readthedocs.io/en/latest/configuration.html#geometry
| grid_type | Grid type ('n_rho' or 'face_centers'). |
| grid | Grid points (integer or np.array). |
| set_transport_coefs | ( | self, | |
| chi_min = None, | |||
| chi_max = None, | |||
| De_min = None, | |||
| De_max = None, | |||
| Ve_min = None, | |||
| Ve_max = None ) |
Set transport coefficient bounds for TORAX.
TORAX input config documentation: https://torax.readthedocs.io/en/latest/configuration.html#transport
| chi_min | Minimum ion thermal diffusivity (m^2/s). |
| chi_max | Maximum ion thermal diffusivity (m^2/s). |
| De_min | Minimum electron diffusion coefficient (m^2/s). |
| De_max | Maximum electron diffusion coefficient (m^2/s). |
| Ve_min | Minimum electron thermal velocity (m/s). |
| Ve_max | Maximum electron thermal velocity (m/s). |
| set_x_points | ( | self, | |
| diverted_times = None, | |||
| x_point_targets = None, | |||
| x_point_weight = 100.0, | |||
| strike_point_targets = None ) |
Configure diverted window, X-point targets, and optional strike points.
| diverted_times | Tuple (t_start, t_end) defining the diverted plasma window. |
| x_point_targets | X-point target locations, shape (n_xpoints, 2) with [R, Z] pairs. |
| x_point_weight | Weight for saddle-point constraints. |
| strike_point_targets | Strike point locations, shape (n_points, 2) with [R, Z] pairs, or None to disable. |
| summary | ( | self, | |
| ** | kwargs ) |
Print/display a physics summary of the simulation.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| lcfs = lcfs |
| results = None |
Access simulation results dict.
| state = None |
Access simulation state dict.