torus_solver.optimize¶
- class torus_solver.optimize.SourceParams(theta_src, phi_src, currents_raw)[source]¶
Bases:
objectElectrode locations and injected currents (unconstrained).
- Parameters:
theta_src (Array)
phi_src (Array)
currents_raw (Array)
- currents_raw: Array¶
- phi_src: Array¶
- theta_src: Array¶
- torus_solver.optimize.enforce_net_zero(currents_raw)[source]¶
Project currents onto the Σ I_i = 0 subspace.
- Return type:
Array- Parameters:
currents_raw (Array)
- torus_solver.optimize.forward_B(surface, params, *, eval_points, sigma_theta, sigma_phi, sigma_s=1.0, current_scale=1.0, tol=1e-10, maxiter=2000, biot_savart_eps=1e-09)[source]¶
Compute B at eval_points from electrode params on the torus surface.
- Return type:
Array- Parameters:
surface (TorusSurface)
params (SourceParams)
eval_points (Array)
sigma_theta (float)
sigma_phi (float)
sigma_s (float)
current_scale (float)
tol (float)
maxiter (int)
biot_savart_eps (float)
- torus_solver.optimize.make_helical_axis_points(*, R_axis, n_points, dtype=<class 'jax.numpy.float64'>)[source]¶
Convenience: points on the torus magnetic axis (major circle) + basis.
- Return type:
Tuple[Array,Array,Array,Array]- Parameters:
R_axis (float)
n_points (int)
- torus_solver.optimize.optimize_sources(surface, *, init, eval_points, B_target, B_scale=1.0, sigma_theta, sigma_phi, n_steps, lr, reg_currents=1e-06, reg_positions=0.0, callback=None, return_history=False)[source]¶
Optimize electrode params to match a target B field at given points.
- Return type:
SourceParams|tuple[SourceParams,Dict[str,list[float]]]- Parameters:
surface (TorusSurface)
init (SourceParams)
eval_points (Array)
B_target (Array)
B_scale (float)
sigma_theta (float)
sigma_phi (float)
n_steps (int)
lr (float)
reg_currents (float)
reg_positions (float)
callback (Callable[[int, Dict[str, float]], None] | None)
return_history (bool)
- torus_solver.optimize.optimize_sources_lbfgs(surface, *, init, eval_points, B_target, B_scale=1.0, sigma_theta, sigma_phi, maxiter, tol=1e-09, reg_currents=1e-06, reg_positions=0.0, callback=None, return_history=False)[source]¶
Optimize electrode params using L-BFGS (often faster than Adam for small problems).
- Return type:
SourceParams|tuple[SourceParams,Dict[str,list[float]]]- Parameters:
surface (TorusSurface)
init (SourceParams)
eval_points (Array)
B_target (Array)
B_scale (float)
sigma_theta (float)
sigma_phi (float)
maxiter (int)
tol (float)
reg_currents (float)
reg_positions (float)
callback (Callable[[int, Dict[str, float]], None] | None)
return_history (bool)
- torus_solver.optimize.surface_solution(surface, params, *, sigma_theta, sigma_phi, sigma_s=1.0, current_scale=1.0, tol=1e-10, maxiter=2000, use_preconditioner=False)[source]¶
Return (currents, source_density, potential, surface_current).
- Return type:
tuple[Array,Array,Array,Array]- Parameters:
surface (TorusSurface)
params (SourceParams)
sigma_theta (float)
sigma_phi (float)
sigma_s (float)
current_scale (float)
tol (float)
maxiter (int)
use_preconditioner (bool)