The Open FUSION Toolkit 26.9
An open-source framework for fusion and plasma science and engineering
Loading...
Searching...
No Matches
pulse_design.py File Reference

Classes

class  MyEncoder
 JSON Encoder Object to store simulation results. More...
class  TokaMaker_TORAX
 TokaMaker + TORAX Coupled Pulse Simulation Code. More...

Namespaces

namespace  OpenFUSIONToolkit
 Python interface for Open FUSION Toolkit.
namespace  OpenFUSIONToolkit.TokaMaker
 Python interface for TokaMaker Grad-Shafranov functionality.
namespace  OpenFUSIONToolkit.TokaMaker.pulse_design
 TokaMaker + TORAX Coupled Pulse Design and Simulation Workflow (TokaMaker_TORAX/tmtx).

Functions

 _apply_coil_config (tmtx, tm_inputs)
 Apply the unified tm_inputs coil settings to a TokaMaker_TORAX object.
 _apply_tm_weight_config (tmtx, tm_inputs)
 Apply the tm_inputs GS constraint weights that hold at every timepoint.
 _bc_at (right_bc, t)
 Evaluate an edge (rho=1) BC at time t: a scalar as-is, or a {time: value} map linearly interpolated in time (constant-extrapolated past the ends).
 _coil_aturn_clim (tt)
 Return (min, max) colormap limits in A-turns from _coil_bounds (stored in A-turns).
 _coil_net_turns (tt, cname)
 Return net_turns for a coil set name, defaulting to 1.
 _core_transition_profile (rhos, ped_rho, ped, core, exp_a=2.0, exp_b=2.0)
 Smooth CORE-only H-mode-like profile over [0, ped_rho] that joins the pedestal top WITHOUT its own edge roll-off (so it doesn't create a second pedestal):
 _create_seed_eqdsks (tmtx_config, mygs, save_dir=None)
 Create the seed gEQDSK files that seed the TokaMaker_TORAX coupling.
 _draw_equil_from_dir (ax, tt, loop, idx, t_now, equil_dir)
 Draw equilibrium from pre-rendered PNG in equil_dir.
 _draw_info (ax, tt, loop, run_name)
 _draw_profiles_movie (axes, tt, idx)
 Draw the 6 radial profile panels for a movie frame.
 _draw_scalars_movie (axes, tt, times, t_now, flux_con_tm)
 Draw the 6 scalar time-series panels for a movie frame.
 _embed_video_jupyter (video_path)
 Embed an MP4 video in a Jupyter notebook.
 _encode_video_from_dir (frame_dir, out_path, fps=2, frame_times=None)
 Encode frames from a directory into an MP4 file.
 _eqdsk_shape_stats (rz)
 Geometric shape parameters (R_geo, a_geo, kappa, delta) from an LCFS contour [:,2].
 _eval_ibc_at_time (spec, t)
 Evaluate a single-field IBC SparseTimeVaryingArray spec at time t -> (rhos, values), linearly interpolating each rho's value in time between listed times (matching TORAX).
 _fmt_saved_artifact_link (path)
 Absolute path as a file:// URI when possible (terminal / IDE hyperlink), else abs path.
 _in_jupyter ()
 Return True if running inside a Jupyter notebook.
 _init_TM_object (tmtx_config)
 Initialize a TokaMaker object from a TMTX config dict.
 _init_TMTX_from_configs (tmtx_config, torax_config, mygs)
 Build a TokaMaker_TORAX object from the TMTX and TORAX config dicts.
 _interp_traj (traj, t)
 Linear interpolation of a {time: value} trajectory dict at time t.
 _last_solve_eqdsk_stats (tt, i)
 Scalars read back from the gEQDSK the previous loop's TM solve wrote at timestep i.
 _lcfs_shape_rms (targets, contour)
 RMS over each target point of its minimum distance to the achieved LCFS contour (treated as a polyline of segments).
 _load_config_file (config_file)
 Load tmtx_dict and torax_dict from a saved reproduction .py file.
 _make_temp_dir_viz ()
 Create temp directory for visualization temporary files: RAM-backed on Linux, OS default elsewhere.
 _merge_ibc_specs (spec_a, spec_b)
 Merge two single-field IBC SparseTimeVaryingArrays that use DIFFERENT band locations (e.g.
 _mtanh_pedestal (rho, ped_top, foot, core_slope, knee, hwid, blend)
 Linear core gradient smoothly blended into a tanh pedestal.
 _output_mode_is_debug (output_mode)
 Whether a fly() output_mode value selects debug mode, using the same normalization as TokaMaker_TORAX.fly() (True -> 'normal'; strings stripped/lowercased).
 _ped_top_slope_at (shape_by_time, t, default)
 Interpolate (ped_top, slope) in time from a {tm_time: (ped_top, slope)} dict (constant-extrapolated past the ends).
 _pedestal_ibc (ped_rho, right_bc, shape_by_time, default_shape, transition, windows, knee, hwid, blend)
 Build a TORAX internal-boundary-condition SparseTimeVaryingArray for one field: {time: {(ped_rho, 1.0): {rho: value}}}.
 _prof (state_dict, idx)
 Return (x, y) arrays from a profile state dict, or (None, None).
 _render_equil_frames (tt, loop, equil_dir)
 Render equilibrium plots from stored equilibrium snapshots to PNG files.
 _render_frame (tt, loop, idx, t_now, times, flux_con_tm, out_path, run_name, equil_dir)
 Create a single movie frame.
 _rms_prof_diff (prof_a, prof_b)
 RMS of (prof_a - prof_b) after interpolating prof_b onto prof_a's x grid.
 _saddle_targets (tt)
 Every point given a saddle constraint: primary nulls plus any secondary nulls.
 _save_or_display (fig, save_path=None, display=True)
 Save figure and/or display it, then close.
 _seed_tm_profiles_for_failure_profile_plot (tt, i)
 Fill TM comparison fields for profile_plot from seed EQDSK/GS inputs when TM has not run at index i.
 _style (ax)
 Apply consistent styling to a matplotlib Axes.
 _tm_diag_coil_panel (tt, ax, i)
 Solved coil currents against the bounds enforced on this solve, in MA-turns.
 _tm_diag_equil_targets (tt, ax, i, equil)
 Draw the constraint targets this timestep's solve was given, plus what it achieved.
 _tm_diag_tm_column (tt, i, gs_ok, solve_succeeded, succeeded_profile)
 TokaMaker column values for the diagnostic table at timestep i.
 _trace_lcfs_for_evolution_plot (equil)
 Try successive normalized psi surfaces until tracing returns a non-empty contour.
 _transition_ibc (loc, lmode_profile, hmode_target, lh, transition)
 Build a CORE (rho 0 -> ped_rho) internal-boundary-condition SparseTimeVaryingArray for one field, active ONLY across the L->H transition window [lh, lh+transition]: {time: {loc: {rho: value}}} where loc = (0.0, ped_rho).
 _tx_profile_at_rho (tt, var_name, rho_val, rho_coord='rho_norm', scale=1.0)
 Return (times, values) for a profile variable at a fixed rho, full resolution.
 _tx_scalar (tt, var_name, scale=1.0)
 Return (times, values) arrays from data_tree.scalars at full TORAX resolution.
 _x_points_active (tt, i, t=None)
 Return True when X-point targets should be applied at timestep index i.
 _xpt_rms (targets, achieved)
 RMS over each target X-point of its distance to the nearest achieved X-point.
 IBC_debug (tt, i, t, save_path=None)
 Debug figure for the internal_manual IBC technique (debug mode, one per TM solve).
 log_redirect_setup ()
 Step 1/3 of setup to redirect noisy outputs to log file.
 make_movie (tt, save_path=None, display=True, speed_factor=5.0, loop=None, notebook_mode=None)
 Create pulse movie from simulation data.
 plot_coil_current_tunnel (tt, save_path=None, display=True)
 Per-coil current vs time inside the rate-limited bounds "tunnel".
 plot_coils (tt, save_path=None, display=True)
 Plot coil current traces in MA-turns with limit bands (data stored in A-turns).
 plot_coupling_convergence (tt, save_path=None, display=True)
 Plot the flavor-2 coupling-convergence cost vs coupling loop — the loop-over-loop trend that is the whole point of the aggregate metric.
 plot_equil_interactive (tt, loop=None, notebook_mode=None, save_path=None)
 Equilibrium viewer — widget slider in notebook, saved PNGs otherwise.
 plot_errors (tt, save_path=None, display=True)
 Plot per-timestep TokaMaker-vs-TORAX coupling error metrics, one panel per channel in a 4-column grid (layout mirrors plot_scalars).
 plot_lcfs_evolution (tt, save_path=None, display=True, one_plot=False)
 Plot time evolution of the last closed flux surface for each phase.
 plot_PLH_components (tt, save_path=None, display=True)
 Decompose the L->H transition power into every ingredient, for the current loop's TORAX run.
 plot_profile_evolution (tt, save_path=None, display=True, one_plot=False)
 Plot profile evolution by pulse phase by default, or as one figure when one_plot=True.
 plot_profiles_interactive (tt)
 Interactive profile viewer with ipywidgets slider to scrub through timesteps.
 plot_scalars (tt, save_path=None, display=True)
 Plot 4x3 grid of time-series scalars plus a bottom row: power channels, sources, P_LH.
 plot_tx_relax_profiles (tt, data_tree, *, stage, t_final_relax, user_ref_curves=None, save_path=None, display=False)
 Plot psi, n_e, T_e, T_i vs rho_norm after a short TORAX relax.
 profile_plot (tt, i, t, save_path=None, display=True)
 Detailed profile comparison at a single timestep.
 redirect_outputs_to_log (filename)
 Step 2/3 of setup to redirect noisy outputs to log file.
 run_tmtx_from_config (tmtx_config=None, torax_config=None, config_file=None, save_dir=None)
 Full TokaMaker_TORAX run from config dicts: seed eqdsk creation, object initialization, and simulation.
 summary (tt)
 Print and return key physics figures of merit from the simulation.
 tm_diagnostic_plot (tt, i, t, level_attempts, solve_succeeded, save_path=None, display=True, tm_gs_ok=None, step_error=None)
 TokaMaker input/output diagnostic plot for a single timestep.
 tm_loop_summary_plot (tt, loop_level_log, save_path=None, display=True)
 Summary figure showing per-timestep GS solve outcomes.

Variables

dict _COIL_RATE_KEY_MAP
dict _COIL_REG_KEY_MAP
dict _COUPLING_COST_FLOORS
tuple _COUPLING_COST_SPEC
dict _COUPLING_COST_WEIGHTS
list _ERROR_KEYS = [spec[0] for spec in _ERROR_SPECS]
list _ERROR_SPECS
tuple _LCFS_EVO_PSI_TRY = (1.0, 0.99, 0.98, 0.97)
int _NBI_W_TO_MA = 1/16e6
dict _TM_WEIGHT_KEY_MAP
dict BASE_CONFIG
str COLOR_TM = 'steelblue'
str COLOR_TX = 'crimson'
list COLORS_MULTI
int DEFAULT_LOOP0_TX_FACE_POINTS = 51
int DIAG_FS = 13
tuple EQDSK_SAVE_NR_NZ_SEQUENCE = (300, 900)
float GRID_ALPHA = 0.2
int INFO_FS = 13
int LABEL_FS = 11
float LCFS_WEIGHT = 100.0
int LEGEND_FS = 9
str LS_PRI = '-'
str LS_SEC = '--'
float LW = 1.6
int MK_SZ = 3
str MK_TM = '.'
int MOVIE_DPI = 300
int MOVIE_EQUIL_PSI_PLASMA_NLEVELS = 8
 MOVIE_FIG_H
 MOVIE_FIG_W
float mu_0 = 4.0 * np.pi * 1e-7
int N_PSI = 1000
float PED_GRAD_WINDOW = 0.1
int PED_N_SAMPLE = 24
float PSI_LCFS_WEIGHT = 1000.0
int TICK_FS = 10
int TITLE_FS = 13
str VLINE_COLOR = 'black'
str VLINE_LS = ':'
float VLINE_LW = 1.0