simsopt
simsopt copied to clipboard
[Enhancement]: angle constraint for QFMsurface
The QfmSurface class is extremely useful for generating surfaces for magnetic fields, but it stumbles on moderately shaped surfaces.
I believe this is due to the lack of enforcement of an angle constraint in the optimization, leading to surfaces with non-monotonically varying poloidal angle.
MWE for attempting to generate a QFM surface for W7X in the region of closed flux surfaces:
from simsopt.field import BiotSavart
from simsopt.geo import SurfaceRZFourier
from simsopt.geo.qfmsurface import QfmSurface
from simsopt.geo.surfaceobjectives import QfmResidual, Volume
from simsopt.configs import get_w7x_data
from simsopt.field import coils_via_symmetries
NFP=5
s = SurfaceRZFourier.from_nphi_ntheta(mpol=8, ntor=8, stellsym=True, nfp=NFP, range='half period')
curves, currents, ma = get_w7x_data()
coils = coils_via_symmetries(curves, currents, NFP, True)
s.fit_to_curve(ma, 0.15, flip_theta=True)
bfield = BiotSavart(coils)
bfield.set_points(s.gamma().reshape(-1, 3))
qfm = QfmResidual(s, bfield)
qfm.J()
label = Volume(s)
vol_target = 10
qfm_surface = QfmSurface(bfield, s, label, vol_target)
constraint_weight = 1e-3
qfm_surface.minimize_qfm_penalty_constraints_LBFGS(tol=1e-20, maxiter=50,
constraint_weight=constraint_weight)
# repeat the optimization for further convergence
qfm_surface.minimize_qfm_penalty_constraints_LBFGS(tol=1e-20, maxiter=200,
constraint_weight=constraint_weight)
s.plot(engine='mayavi')
resulting in the following surface:
I believe that a simple angle constraint would prevent the optimiser from trying to bunch the quadpoints in places of low error, causing this overlap.
Happy to take this issue in the upcoming hackathon