PlasmaControl / DESC

Stellarator Equilibrium and Optimization Suite
MIT License
87 stars 22 forks source link

Add Functionality to `FixBoundaryR` and `FixBoundaryZ` to fix modes within certain modenumber ranges in M and N #1117

Open dpanici opened 2 months ago

dpanici commented 2 months ago

Currently to restrict which modes of a boundary are in the optimization space, we have to do this slightly clunky procedure of defining the modes externally then passing them into the constraint.

# as opposed to SIMSOPT and STELLOPT where variables are assumed fixed, in DESC
    # we assume variables are free. Here we decide which ones to fix, starting with
    # the major radius (R mode = [0,0,0]) and all modes with m,n > k
    R_modes = np.vstack(
        (
            [0, 0, 0],
            eq.surface.R_basis.modes[
                np.max(np.abs(eq.surface.R_basis.modes), 1) > k, :
            ],
        )
    )
    Z_modes = eq.surface.Z_basis.modes[
        np.max(np.abs(eq.surface.Z_basis.modes), 1) > k, :
    ]
    # next we create the constraints, using the mode number arrays just created
    # if we didn't pass those in, it would fix all the modes (like for the profiles)
    constraints = (
        ForceBalance(eq=eq),
        FixBoundaryR(eq=eq, modes=R_modes),
        FixBoundaryZ(eq=eq, modes=Z_modes),
        FixPressure(eq=eq),
        FixCurrent(eq=eq),
        FixPsi(eq=eq),)

We could possibly add logic to FixBoundaryR and FixBoundaryZ to fix all modes within a certain M,N range, like something below

FixBoundaryR(eq=eq, fix_M = (k,eq.M), fix_N = (k,eq.N))
kianorr commented 2 weeks ago

Assigned myself because I should learn more about R, Z modes stuff