regcoil

A regularized current potential method for fast and reliable computation of the shapes of stellarator coils, described in Landreman, Nuclear Fusion 57, 046003 (2017).

import regcoil

ds = regcoil.examples("W7-X")  # Or "NCSX"
# ds then provides paths to a vmec wout file, simsopt virtual casing file,
# stellopt bnorm file, and coil winding surface in nescin format.

# Define the plasma boundary surface (from_wout accepts a filename or simsopt.mhd.Vmec object):
plasma = regcoil.PlasmaSurface.from_wout(ds.wout, ntheta=64, nzeta=64)
# Assign B_normal data associated with the plasma current:
plasma.set_bnormal_from_virtual_casing(ds.vcasing)

# Define a coil winding surface:
coil = regcoil.CoilSurface.from_uniform_offset(
    plasma, separation=0.3, ntheta=64, nzeta=64, mpol=12, ntor=12
)

# Visualize the plasma and coil winding surfaces before solving:
regcoil.plot.cross_sections(plasma, coil)
regcoil.plot.plot_3d(plasma=plasma, winding_surface=coil)

problem = regcoil.Regcoil(plasma, coil, mpol_potential=12, ntor_potential=12)
# You can solve the system with a specific value of the regularization parameter
# lambda, or scan over a range of lambdas, or search for the lambda that achieves
# a desired value of a metric such as f_B, f_K, max_K, or avg_Bnormal_over_B:
solution = problem.solve_for_target("avg_Bnormal_over_B", 0.005)
print(f"f_B = {solution.f_B:.1e}, f_K = {solution.f_K:.1e}")
# f_B = 5.0e-02, f_K = 1.1e+15

# Save the plasma and coil surfaces along with the solution:
solution.save("regcoil_out.nc")

# Cut discrete coils from the current potential and plot them:
cut_coils = solution.cut(coils_per_half_period=5)
regcoil.plot.plot_3d(plasma=plasma, coils=cut_coils)

See Installation to set up the package, or jump straight to the fuller Quickstart.

Reference

Indices and tables