Example #1
0
https://github.com/landreman/stellopt_scenarios/tree/master/7DOF_varyAxisAndElongation_targetIotaAndQuasisymmetry
See that website for a detailed description of the problem.
"""

# This next line turns on detailed logging. It can be commented out if
# you do not want such verbose output.
log()

mpi = MpiPartition()
vmec = Vmec(
    os.path.join(os.path.dirname(__file__), 'inputs',
                 'input.stellopt_scenarios_7dof'), mpi)

# We will optimize in the space of Garabedian coefficients:
surf = vmec.boundary.to_Garabedian()
vmec.boundary = surf

# Define parameter space:
surf.all_fixed()
surf.fixed_range(mmin=0, mmax=2, nmin=-1, nmax=1, fixed=False)
surf.set_fixed("Delta(1,0)")  # toroidally-averaged major radius
surf.set_fixed("Delta(0,0)")  # toroidally-averaged minor radius

# Define objective function:
boozer = Boozer(vmec, mpol=32, ntor=16)
qs = Quasisymmetry(
    boozer,
    1.0,  # Radius to target
    1,
    0,  # (M, N) you want in |B|
    normalization="symmetric",
# In the next line, we can adjust how many groups the pool of MPI
# processes is split into.
mpi = MpiPartition(ngroups=1)
mpi.write()

# Start with a default surface, which is axisymmetric with major
# radius 1 and minor radius 0.1.
equil = Vmec(os.path.join(os.path.dirname(__file__), 'inputs',
                          'input.1DOF_Garabedian'),
             mpi=mpi)

# We will optimize in the space of Garabedian coefficients rather than
# RBC/ZBS coefficients. To do this, we convert the boundary to the
# Garabedian representation:
surf = equil.boundary.to_Garabedian()
equil.boundary = surf

# VMEC parameters are all fixed by default, while surface parameters
# are all non-fixed by default.  You can choose which parameters are
# optimized by setting their 'fixed' attributes.
surf.all_fixed()
surf.set_fixed('Delta(1,-1)', False)

# Each function we want in the objective function is then equipped
# with a shift and weight, to become a term in a least-squares
# objective function.  A list of terms are combined to form a
# nonlinear-least-squares problem.
desired_iota = -0.41
prob = LeastSquaresProblem([(equil.iota_axis, desired_iota, 1)])

# Solve the minimization problem. We can choose whether to use a