Example: Static inverse free-boundary equilibrium calculations (in ITER)


Here we will generate an equilibrium (find coil currents with the inverse solver) in an ITER-like tokamak.

The machine description comes from files located here.

The equilbirium\profile parameters are completely made up - please experiment on your own and change them to more realistic values as you please!

Import packages

import matplotlib.pyplot as plt
import numpy as np

Create the machine object

# build machine
from freegsnke import build_machine
tokamak = build_machine.tokamak(
    active_coils_path=f"../machine_configs/ITER/ITER_active_coils.pickle",
    passive_coils_path=f"../machine_configs/ITER/ITER_passive_coils.pickle",
    limiter_path=f"../machine_configs/ITER/ITER_limiter.pickle",
    wall_path=f"../machine_configs/ITER/ITER_wall.pickle",
)
Active coils --> built from pickle file.
Passive structures --> built from pickle file.
Limiter --> built from pickle file.
Wall --> built from pickle file.
Magnetic probes --> none provided.
Resistance (R) and inductance (M) matrices --> built using actives (and passives if present).
Tokamak built.
# plot the machine
fig1, ax1 = plt.subplots(1, 1, figsize=(7, 15), dpi=80)
plt.tight_layout()

tokamak.plot(axis=ax1, show=False)
ax1.plot(tokamak.limiter.R, tokamak.limiter.Z, color='k', linewidth=1.2, linestyle="--")
# ax1.plot(tokamak.wall.R, tokamak.wall.Z, color='k', linewidth=1.2, linestyle="-")

ax1.grid(alpha=0.5)
ax1.set_aspect('equal')
ax1.set_xlim(1.1, 12.4)
ax1.set_ylim(-8.3, 8.3)
ax1.set_xlabel(r'Major radius, $R$ [m]')
ax1.set_ylabel(r'Height, $Z$ [m]')
Text(40.02777777777778, 0.5, 'Height, $Z$ [m]')
../_images/5fd8b9286b44fed283a52f308bfa9f1ff23035a0371976be71e5ea872d664927.png

Instantiate an equilibrium

from freegsnke import equilibrium_update

eq = equilibrium_update.Equilibrium(
    tokamak=tokamak,       # provide tokamak object
    Rmin=3.2, Rmax=8.8,   # radial range
    Zmin=-5, Zmax=5,   # vertical range
    nx=129,                # number of grid points in the radial direction (needs to be of the form (2**n + 1) with n being an integer)
    ny=129,                # number of grid points in the vertical direction (needs to be of the form (2**n + 1) with n being an integer)
    # psi=plasma_psi
)

Instantiate a profile object

# initialise the profiles
from freegsnke.jtor_update import ConstrainBetapIp
profiles = ConstrainBetapIp(
    eq=eq,        # equilibrium object
    betap=0.15,   # poloidal beta
    Ip=11e6,      # plasma current
    fvac=0.5,     # fvac = rB_{tor}
    alpha_m=2.0,  # profile function parameter
    alpha_n=1.0   # profile function parameter
)

Load the static nonlinear solver

from freegsnke import GSstaticsolver
GSStaticSolver = GSstaticsolver.NKGSsolver(eq)    

Constraints

Rx = 5.02      # X-point radius
Zx = -3.23      # X-point height

Ro = 6.34      # X-point radius
Zo = 0.66      # X-point height

# set desired null_points locations
# this can include X-point and O-point locations
null_points = [[Rx, Ro], [Zx, Zo]]

# set desired isoflux constraints with format 
# isoflux_set = [isoflux_0, isoflux_1 ... ] 
# with each isoflux_i = [R_coords, Z_coords]
isoflux_set = np.array([[
    [4.25455147,
 4.1881875,
 4.2625,
 4.45683769,
 4.78746942,
 5.31835938,
 5.91875,
 6.44275166,
 6.92285156,
 7.35441013,
 7.73027344,
 8.03046875,
 8.19517497,
 8.05673414,
 7.75308013,
 7.37358451,
 6.94355469,
 6.47773438,
 5.99121094,
 5.49433594,
 Rx,
 4.79042969,
 4.56269531,
 4.36038615], 
[0.0,
 1.13554688,
 2.2565134,
 3.16757813,
 3.80507812,
 4.0499021,
 3.93089003,
 3.665625,
 3.31076604,
 2.86875,
 2.3199601,
 1.62832118,
 0.657421875,
 -0.35859375,
 -1.05585937,
 -1.59375,
 -2.03492727,
 -2.41356403,
 -2.75622016,
 -3.08699278,
 Zx,
 -2.40548044,
 -1.55982142,
 -0.67734375]
    ]])
           

# instantiate the freegsnke constrain object
from freegsnke.inverse import Inverse_optimizer
constrain = Inverse_optimizer(null_points=null_points,
                              isoflux_set=isoflux_set)


# remove from the coils available for control the radial field coil 
# eq.tokamak['VS3'].control = False

The inverse solve

GSStaticSolver.inverse_solve(eq=eq, 
                     profiles=profiles, 
                     constrain=constrain, 
                     target_relative_tolerance=1e-4,
                     target_relative_psit_update=1e-3,
                    #  max_solving_iterations=150,
                    #  max_iter_per_update=10,
                    #  max_rel_update_size=0.075,
                    #  damping_factor=.99,
                    #  max_rel_psit=.05,
                     verbose=True, # print output
                     l2_reg=1e-14,
                     )
-----
Inverse static solve starting...
Initial guess for plasma_psi successful, residual found.
Initial relative error = 2.46e+01
-----
Iteration: 0
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.04e+07', '1.04e+07', '1.35e+07', '7.63e+01', '3.28e+06', '3.26e+05', '2.53e+05', '2.81e+05', '1.15e+05', '3.05e+06']
Constraint losses = 7.48e-01
Relative update of tokamak psi (in plasma core): 1.12e+09
Handing off to forward solve (with updated currents).
Relative error =  1.05e+02
-----
Iteration: 1
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.93e+06', '2.03e+06', '1.78e+06', '-9.34e+02', '7.38e+05', '8.22e+04', '-6.64e+04', '-8.69e+04', '1.72e+05', '4.90e+05']
Constraint losses = 2.22e+00
Relative update of tokamak psi (in plasma core): 1.11e-01
Handing off to forward solve (with updated currents).
Relative error =  4.45e+01
-----
Iteration: 2
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.54e+06', '-2.54e+06', '-3.42e+06', '-7.31e+02', '-7.99e+05', '-2.20e+04', '-2.01e+05', '-2.16e+05', '1.10e+05', '-8.97e+05']
Constraint losses = 2.60e+00
Relative update of tokamak psi (in plasma core): 1.58e-01
Handing off to forward solve (with updated currents).
Relative error =  2.65e+01
-----
Iteration: 3
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.56e+06', '-7.86e+06', '-8.57e+06', '7.71e+02', '-2.82e+06', '-5.58e+04', '-3.85e+05', '-3.86e+05', '1.25e+05', '-2.71e+06']
Constraint losses = 3.19e+00
Relative update of tokamak psi (in plasma core): 5.68e-01
Handing off to forward solve (with updated currents).
Relative error =  1.85e+01
-----
Iteration: 4
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['6.76e+06', '6.97e+06', '7.68e+06', '-1.51e+03', '2.60e+06', '4.73e+04', '5.54e+04', '9.52e+04', '-2.25e+05', '2.55e+06']
Constraint losses = 3.89e+00
Relative update of tokamak psi (in plasma core): 2.13e+00
Handing off to forward solve (with updated currents).
Relative error =  1.29e+01
-----
Iteration: 5
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.04e+07', '-1.08e+07', '-1.17e+07', '1.34e+03', '-3.90e+06', '-5.98e+04', '-5.69e+05', '-5.60e+05', '1.63e+05', '-3.68e+06']
Constraint losses = 5.09e+00
Relative update of tokamak psi (in plasma core): 9.68e-01
Handing off to forward solve (with updated currents).
Relative error =  8.84e+00
-----
Iteration: 6
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.62e+07', '-1.69e+07', '-1.72e+07', '2.14e+03', '-6.24e+06', '-1.20e+05', '-7.88e+05', '-7.47e+05', '1.23e+05', '-5.73e+06']
Constraint losses = 6.14e+00
Relative update of tokamak psi (in plasma core): 3.75e+00
Handing off to forward solve (with updated currents).
Relative error =  5.79e+00
-----
Iteration: 7
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-8.52e+05', '-1.08e+06', '4.14e+04', '-1.59e+03', '-2.19e+05', '-3.82e+05', '-2.36e+05', '-7.56e+04', '-1.07e+06', '6.48e+05']
Constraint losses = 9.01e+00
Relative update of tokamak psi (in plasma core): 5.38e-02
Handing off to forward solve (with updated currents).
Relative error =  4.17e+00
-----
Iteration: 8
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.33e+07', '-1.38e+07', '-1.44e+07', '1.95e+02', '-4.97e+06', '8.84e+03', '-9.36e+05', '-9.05e+05', '3.34e+05', '-4.66e+06']
Constraint losses = 1.02e+01
Relative update of tokamak psi (in plasma core): 4.44e-01
Handing off to forward solve (with updated currents).
Relative error =  2.74e+00
-----
Iteration: 9
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.45e+07', '-1.48e+07', '-1.55e+07', '-9.41e+02', '-5.17e+06', '-1.82e+04', '-1.09e+06', '-1.03e+06', '2.83e+05', '-4.71e+06']
Constraint losses = 1.27e+01
Relative update of tokamak psi (in plasma core): 2.93e-01
Handing off to forward solve (with updated currents).
Relative error =  1.71e+00
-----
Iteration: 10
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-9.62e+06', '-9.54e+06', '-9.84e+06', '-2.82e+03', '-3.09e+06', '8.65e+04', '-1.11e+06', '-1.04e+06', '3.00e+05', '-2.63e+06']
Constraint losses = 1.58e+01
Relative update of tokamak psi (in plasma core): 1.42e-01
Handing off to forward solve (with updated currents).
Relative error =  9.47e-01
-----
Iteration: 11
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.62e+06', '2.59e+06', '3.02e+06', '-5.76e+03', '1.57e+06', '2.63e+05', '-9.56e+05', '-8.67e+05', '2.30e+05', '2.04e+06']
Constraint losses = 1.92e+01
Relative update of tokamak psi (in plasma core): 1.20e-02
Handing off to forward solve (with updated currents).
Relative error =  3.95e-01
-----
Iteration: 12
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.38e+07', '2.64e+07', '2.87e+07', '-9.99e+03', '1.07e+07', '4.84e+05', '-4.03e+05', '-2.53e+05', '-2.08e+05', '1.14e+07']
Constraint losses = 2.18e+01
Relative update of tokamak psi (in plasma core): 2.70e-01
Handing off to forward solve (with updated currents).
Relative error =  9.31e-02
-----
Iteration: 13
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.39e+06', '-9.88e+05', '1.25e+06', '-3.95e+04', '3.81e+06', '-1.51e+06', '-3.85e+05', '3.20e+04', '-2.93e+06', '7.11e+06']
Constraint losses = 1.80e+01
Relative update of tokamak psi (in plasma core): 4.42e-02
Handing off to forward solve (with updated currents).
Relative error =  2.39e-02
-----
Iteration: 14
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.03e+07', '5.28e+06', '2.13e+06', '1.70e+04', '1.26e+06', '-1.24e+06', '2.89e+06', '2.91e+06', '-5.14e+06', '7.66e+06']
Constraint losses = 5.50e+01
Relative update of tokamak psi (in plasma core): 4.20e-02
Handing off to forward solve (with updated currents).
Relative error =  1.58e-01
-----
Iteration: 15
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.01e+07', '-1.10e+06', '-3.16e+06', '1.99e+05', '-7.76e+06', '3.06e+06', '-5.66e+05', '-1.33e+07', '1.34e+07', '-1.31e+07']
Constraint losses = 1.02e+02
Relative update of tokamak psi (in plasma core): 1.28e-01
Handing off to forward solve (with updated currents).
Relative error =  1.06e-01
-----
Iteration: 16
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.30e+07', '1.22e+06', '5.11e+06', '-9.78e+04', '3.21e+06', '-2.77e+06', '1.80e+05', '1.43e+07', '-1.49e+07', '1.52e+07']
Constraint losses = 1.13e+02
Relative update of tokamak psi (in plasma core): 5.25e-02
Handing off to forward solve (with updated currents).
Relative error =  2.07e-01
-----
Iteration: 17
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-5.03e+08', '-5.26e+08', '-6.17e+08', '-7.96e+03', '-1.66e+08', '-1.73e+07', '-1.08e+07', '-2.36e+07', '-3.25e+06', '-1.59e+08']
Constraint losses = 1.06e+02
Relative update of tokamak psi (in plasma core): 8.34e+00
Handing off to forward solve (with updated currents).
Relative error =  2.04e-01
-----
Iteration: 18
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.59e+08', '2.66e+08', '3.01e+08', '-8.64e+04', '9.26e+07', '6.92e+06', '4.18e+06', '1.52e+07', '-2.34e+06', '8.70e+07']
Constraint losses = 5.50e+01
Relative update of tokamak psi (in plasma core): 2.66e-01
Handing off to forward solve (with updated currents).
Relative error =  9.48e-02
-----
Iteration: 19
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.51e+05', '-1.88e+06', '-9.34e+05', '-1.54e+05', '7.01e+06', '-3.69e+06', '3.26e+06', '3.87e+06', '-5.56e+06', '6.71e+06']
Constraint losses = 4.54e+01
Relative update of tokamak psi (in plasma core): 5.30e-03
Handing off to forward solve (with updated currents).
Relative error =  1.59e-01
-----
Iteration: 20
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.54e+06', '8.69e+06', '-7.50e+05', '3.59e+05', '-1.36e+07', '4.88e+06', '2.26e+06', '-1.90e+07', '1.92e+07', '-2.04e+07']
Constraint losses = 1.07e+02
Relative update of tokamak psi (in plasma core): 1.55e-02
Handing off to forward solve (with updated currents).
Relative error =  1.37e-01
-----
Iteration: 21
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-8.07e+06', '-2.29e+06', '5.36e+06', '-2.71e+05', '7.30e+06', '-1.78e+06', '-4.00e+06', '1.92e+07', '-1.48e+07', '9.54e+06']
Constraint losses = 1.17e+02
Relative update of tokamak psi (in plasma core): 7.63e-03
Handing off to forward solve (with updated currents).
Relative error =  2.12e-01
-----
Iteration: 22
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.09e+07', '-3.90e+06', '1.43e+07', '1.65e+05', '-1.16e+07', '3.93e+06', '7.71e+05', '-1.59e+07', '1.61e+07', '-1.63e+07']
Constraint losses = 1.07e+02
Relative update of tokamak psi (in plasma core): 1.46e-02
Handing off to forward solve (with updated currents).
Relative error =  2.22e-01
-----
Iteration: 23
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.12e+08', '2.19e+08', '2.41e+08', '-1.08e+05', '7.89e+07', '5.31e+06', '2.34e+06', '1.56e+07', '-6.37e+06', '7.82e+07']
Constraint losses = 5.49e+01
Relative update of tokamak psi (in plasma core): 4.33e-01
Handing off to forward solve (with updated currents).
Relative error =  1.10e-01
-----
Iteration: 24
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-4.14e+05', '-2.97e+06', '-4.88e+05', '-1.49e+05', '8.90e+06', '-3.85e+06', '1.68e+06', '6.32e+06', '-7.92e+06', '8.30e+06']
Constraint losses = 4.89e+01
Relative update of tokamak psi (in plasma core): 1.95e-02
Handing off to forward solve (with updated currents).
Relative error =  1.87e-01
-----
Iteration: 25
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-6.84e+07', '-7.05e+07', '-6.43e+07', '3.07e+05', '-4.44e+07', '3.44e+06', '1.57e+06', '-2.21e+07', '2.11e+07', '-4.94e+07']
Constraint losses = 1.03e+02
Relative update of tokamak psi (in plasma core): 6.42e-01
Handing off to forward solve (with updated currents).
Relative error =  2.44e-01
-----
Iteration: 26
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.12e+08', '2.18e+08', '2.38e+08', '-1.68e+05', '7.97e+07', '6.31e+06', '2.24e+05', '1.78e+07', '-7.20e+06', '7.83e+07']
Constraint losses = 5.76e+01
Relative update of tokamak psi (in plasma core): 8.46e-01
Handing off to forward solve (with updated currents).
Relative error =  1.15e-01
-----
Iteration: 27
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.93e+06', '-1.67e+06', '6.19e+05', '-1.57e+05', '7.41e+06', '-1.44e+06', '1.43e+05', '6.47e+06', '-7.47e+06', '6.06e+06']
Constraint losses = 4.77e+01
Relative update of tokamak psi (in plasma core): 1.99e-02
Handing off to forward solve (with updated currents).
Relative error =  1.58e-01
-----
Iteration: 28
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['3.47e+06', '6.40e+06', '-5.93e+05', '4.19e+05', '-1.53e+07', '2.90e+06', '4.55e+06', '-2.06e+07', '1.94e+07', '-1.86e+07']
Constraint losses = 1.07e+02
Relative update of tokamak psi (in plasma core): 6.64e-02
Handing off to forward solve (with updated currents).
Relative error =  1.74e-01
-----
Iteration: 29
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.52e+06', '-3.56e+06', '5.53e+06', '-2.82e+05', '7.23e+06', '-1.89e+06', '-4.14e+06', '1.91e+07', '-1.49e+07', '1.05e+07']
Constraint losses = 1.17e+02
Relative update of tokamak psi (in plasma core): 3.35e-02
Handing off to forward solve (with updated currents).
Relative error =  1.94e-01
-----
Iteration: 30
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.67e+08', '-1.79e+08', '-2.07e+08', '8.48e+04', '-6.18e+07', '-3.85e+06', '-3.28e+06', '-1.74e+07', '7.89e+06', '-5.99e+07']
Constraint losses = 9.86e+01
Relative update of tokamak psi (in plasma core): 1.64e+00
Handing off to forward solve (with updated currents).
Relative error =  2.18e-01
-----
Iteration: 31
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.14e+08', '1.19e+08', '1.29e+08', '-5.60e+04', '4.52e+07', '1.61e+06', '1.01e+06', '1.21e+07', '-8.21e+06', '4.83e+07']
Constraint losses = 5.09e+01
Relative update of tokamak psi (in plasma core): 6.31e-01
Handing off to forward solve (with updated currents).
Relative error =  9.46e-02
-----
Iteration: 32
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-6.94e+05', '-2.51e+06', '2.42e+05', '-1.17e+05', '6.84e+06', '-2.76e+06', '1.30e+06', '5.20e+06', '-6.58e+06', '6.10e+06']
Constraint losses = 4.22e+01
Relative update of tokamak psi (in plasma core): 1.25e-01
Handing off to forward solve (with updated currents).
Relative error =  1.37e-01
-----
Iteration: 33
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.62e+06', '7.40e+06', '1.10e+05', '3.68e+05', '-1.50e+07', '4.23e+06', '3.20e+06', '-1.87e+07', '1.86e+07', '-1.92e+07']
Constraint losses = 1.04e+02
Relative update of tokamak psi (in plasma core): 3.94e-01
Handing off to forward solve (with updated currents).
Relative error =  1.52e-01
-----
Iteration: 34
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-6.80e+06', '-3.93e+06', '5.50e+06', '-2.51e+05', '6.44e+06', '-1.92e+06', '-3.50e+06', '1.76e+07', '-1.42e+07', '9.96e+06']
Constraint losses = 1.10e+02
Relative update of tokamak psi (in plasma core): 1.93e-01
Handing off to forward solve (with updated currents).
Relative error =  1.88e-01
-----
Iteration: 35
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.75e+08', '-1.87e+08', '-2.15e+08', '6.43e+04', '-6.43e+07', '-3.75e+06', '-3.71e+06', '-1.75e+07', '8.52e+06', '-6.37e+07']
Constraint losses = 9.85e+01
Relative update of tokamak psi (in plasma core): 1.13e+01
Handing off to forward solve (with updated currents).
Relative error =  2.13e-01
-----
Iteration: 36
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.35e+08', '1.39e+08', '1.53e+08', '-6.25e+04', '5.18e+07', '2.32e+06', '1.70e+06', '1.26e+07', '-8.10e+06', '5.46e+07']
Constraint losses = 5.19e+01
Relative update of tokamak psi (in plasma core): 4.61e-01
Handing off to forward solve (with updated currents).
Relative error =  1.02e-01
-----
Iteration: 37
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.85e+05', '-3.17e+06', '1.92e+04', '-1.25e+05', '7.66e+06', '-3.61e+06', '1.81e+06', '5.73e+06', '-7.41e+06', '7.56e+06']
Constraint losses = 4.82e+01
Relative update of tokamak psi (in plasma core): 3.56e-02
Handing off to forward solve (with updated currents).
Relative error =  1.77e-01
-----
Iteration: 38
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.70e+06', '7.69e+06', '-9.61e+05', '3.18e+05', '-1.30e+07', '4.27e+06', '2.86e+06', '-1.82e+07', '1.81e+07', '-1.76e+07']
Constraint losses = 1.02e+02
Relative update of tokamak psi (in plasma core): 1.09e-01
Handing off to forward solve (with updated currents).
Discarding 'primary' Xpoint! Please check final result
Discarding 'primary' Xpoint! Please check final result
Relative error =  1.67e-01
-----
Iteration: 39
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['6.12e+05', '-7.20e+06', '2.70e+06', '-2.84e+05', '7.91e+06', '-2.25e+06', '-3.46e+06', '1.49e+07', '-1.18e+07', '6.86e+06']
Constraint losses = 8.14e+01
Relative update of tokamak psi (in plasma core): 4.07e-02
Handing off to forward solve (with updated currents).
Relative error =  7.87e-02
-----
Iteration: 40
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.24e+06', '1.60e+06', '1.93e+06', '-4.98e+04', '-7.96e+03', '1.67e+06', '-9.28e+05', '2.01e+06', '-3.80e+06', '1.30e+06']
Constraint losses = 2.64e+01
Relative update of tokamak psi (in plasma core): 1.56e-02
Handing off to forward solve (with updated currents).
Discarding 'primary' Xpoint! Please check final result
Relative error =  1.27e-01
-----
Iteration: 41
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['4.81e+05', '4.52e+06', '-3.22e+06', '3.79e+03', '5.53e+05', '-1.45e+04', '2.58e+06', '-7.32e+06', '7.05e+06', '-2.26e+06']
Constraint losses = 3.58e+01
Relative update of tokamak psi (in plasma core): 2.33e-02
Handing off to forward solve (with updated currents).
Relative error =  2.12e-01
-----
Iteration: 42
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.55e+08', '2.53e+08', '3.02e+08', '1.40e+05', '8.06e+07', '7.51e+06', '3.55e+06', '1.19e+07', '4.99e+05', '8.10e+07']
Constraint losses = 4.33e+01
Relative update of tokamak psi (in plasma core): 3.50e+00
Handing off to forward solve (with updated currents).
Relative error =  1.22e-01
-----
Iteration: 43
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.78e+06', '-5.47e+05', '-3.45e+05', '-1.40e+03', '-9.61e+05', '1.22e+06', '-5.63e+05', '-2.40e+06', '2.25e+06', '-2.07e+06']
Constraint losses = 2.50e+01
Relative update of tokamak psi (in plasma core): 5.02e-03
Handing off to forward solve (with updated currents).
Relative error =  4.94e-04
-----
Iteration: 44
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-5.63e+06', '6.94e+06', '7.78e+05', '-1.23e+05', '1.46e+06', '1.01e+06', '1.84e+06', '-1.04e+06', '3.57e+06', '-7.50e+06']
Constraint losses = 3.85e+01
Relative update of tokamak psi (in plasma core): 3.68e-03
Handing off to forward solve (with updated currents).
Relative error =  2.17e-01
-----
Iteration: 45
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['1.30e+08', '1.24e+08', '1.39e+08', '7.74e+04', '4.06e+07', '4.55e+06', '2.88e+05', '3.78e+05', '4.11e+06', '4.07e+07']
Constraint losses = 4.96e+01
Relative update of tokamak psi (in plasma core): 3.26e-01
Handing off to forward solve (with updated currents).
Relative error =  1.57e-01
-----
Iteration: 46
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.54e+06', '-1.20e+06', '2.14e+06', '5.99e+04', '-1.23e+06', '-8.91e+05', '3.18e+05', '2.12e+06', '-1.19e+06', '1.24e+06']
Constraint losses = 3.05e+01
Relative update of tokamak psi (in plasma core): 2.56e-03
Handing off to forward solve (with updated currents).
Relative error =  1.62e-03
-----
Iteration: 47
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-4.71e+06', '1.84e+06', '2.90e+06', '-4.96e+04', '8.43e+04', '2.47e+05', '1.44e+06', '1.20e+06', '-7.10e+05', '-1.88e+06']
Constraint losses = 3.62e+01
Relative update of tokamak psi (in plasma core): 2.31e-03
Handing off to forward solve (with updated currents).
Relative error =  1.78e-01
-----
Iteration: 48
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['5.36e+06', '-4.27e+06', '-4.72e+05', '1.53e+05', '-3.81e+06', '2.95e+05', '-2.83e+06', '-2.29e+06', '1.84e+06', '4.22e+05']
Constraint losses = 6.13e+01
Relative update of tokamak psi (in plasma core): 7.69e-03
Handing off to forward solve (with updated currents).
Discarding 'primary' Xpoint! Please check final result
Relative error =  4.32e-02
-----
Iteration: 49
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-9.46e+06', '3.17e+06', '3.95e+06', '-2.20e+04', '-7.91e+05', '-1.68e+05', '2.48e+06', '2.43e+06', '-2.94e+06', '3.84e+06']
Constraint losses = 5.98e+01
Relative update of tokamak psi (in plasma core): 4.05e-03
Handing off to forward solve (with updated currents).
Discarding 'primary' Xpoint! Please check final result
Relative error =  1.51e-01
-----
Iteration: 50
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['8.97e+06', '-4.78e+06', '-3.95e+06', '3.67e+04', '2.46e+06', '-3.11e+06', '2.80e+06', '-6.01e+06', '3.36e+06', '-2.18e+06']
Constraint losses = 5.15e+01
Relative update of tokamak psi (in plasma core): 6.22e-03
Handing off to forward solve (with updated currents).
Relative error =  9.12e-02
-----
Iteration: 51
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.61e+06', '6.37e+06', '2.59e+06', '-8.40e+04', '-2.42e+06', '1.18e+06', '2.24e+06', '3.14e+05', '-5.02e+05', '-4.83e+06']
Constraint losses = 4.75e+01
Relative update of tokamak psi (in plasma core): 1.82e-03
Handing off to forward solve (with updated currents).
Relative error =  2.32e-01
-----
Iteration: 52
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.12e+06', '-1.73e+07', '-3.11e+07', '-1.10e+05', '4.49e+06', '2.38e+05', '-6.31e+06', '4.69e+06', '-4.97e+06', '6.59e+06']
Constraint losses = 3.11e+01
Relative update of tokamak psi (in plasma core): 2.71e-02
Handing off to forward solve (with updated currents).
Relative error =  9.32e-02
-----
Iteration: 53
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-8.08e+06', '4.48e+06', '6.18e+06', '5.07e+04', '-5.83e+06', '2.91e+06', '9.71e+05', '3.21e+05', '1.51e+06', '-7.67e+06']
Constraint losses = 4.98e+01
Relative update of tokamak psi (in plasma core): 2.72e-03
Handing off to forward solve (with updated currents).
Relative error =  2.13e-01
-----
Iteration: 54
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.79e+08', '-1.95e+08', '-2.19e+08', '-2.57e+04', '-6.06e+07', '-7.23e+06', '-5.53e+06', '-7.73e+06', '-2.12e+06', '-5.48e+07']
Constraint losses = 6.01e+01
Relative update of tokamak psi (in plasma core): 3.36e-01
Handing off to forward solve (with updated currents).
Relative error =  1.72e-01
-----
Iteration: 55
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-1.65e+06', '-9.69e+05', '1.49e+06', '3.26e+04', '5.67e+05', '-1.60e+06', '2.75e+05', '2.84e+06', '-1.79e+06', '2.33e+06']
Constraint losses = 3.52e+01
Relative update of tokamak psi (in plasma core): 7.05e-03
Handing off to forward solve (with updated currents).
Relative error =  5.56e-04
-----
Iteration: 56
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-4.93e+06', '2.54e+06', '2.12e+06', '-4.47e+04', '8.08e+05', '-2.28e+05', '1.60e+06', '1.74e+06', '-1.18e+06', '-5.63e+05']
Constraint losses = 4.08e+01
Relative update of tokamak psi (in plasma core): 7.72e-03
Handing off to forward solve (with updated currents).
Discarding 'primary' Xpoint! Please check final result
Discarding 'primary' Xpoint! Please check final result
Discarding 'primary' Xpoint! Please check final result
Discarding 'primary' Xpoint! Please check final result
Relative error =  1.43e-01
-----
Iteration: 57
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.35e+06', '4.88e+06', '7.61e+05', '-9.79e+04', '1.28e+06', '1.32e+06', '2.32e+05', '1.50e+06', '-6.26e+04', '-6.49e+06']
Constraint losses = 4.18e+01
Relative update of tokamak psi (in plasma core): 4.51e-03
Handing off to forward solve (with updated currents).
Relative error =  2.23e-01
-----
Iteration: 58
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['5.84e+07', '4.01e+07', '7.93e+07', '2.48e+05', '-1.52e+06', '4.88e+06', '3.59e+06', '-1.64e+07', '1.85e+07', '-4.88e+06']
Constraint losses = 1.03e+02
Relative update of tokamak psi (in plasma core): 1.74e-01
Handing off to forward solve (with updated currents).
Relative error =  2.89e-01
-----
Iteration: 59
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['3.33e+07', '3.77e+07', '2.73e+07', '-1.14e+05', '2.20e+07', '-1.10e+06', '-3.42e+06', '1.31e+07', '-1.12e+07', '2.87e+07']
Constraint losses = 5.87e+01
Relative update of tokamak psi (in plasma core): 1.15e-01
Handing off to forward solve (with updated currents).
Relative error =  1.31e-01
-----
Iteration: 60
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.60e+06', '6.13e+06', '5.66e+05', '-1.37e+05', '5.82e+05', '2.24e+06', '2.06e+06', '-3.28e+06', '4.35e+06', '-9.79e+06']
Constraint losses = 5.45e+01
Relative update of tokamak psi (in plasma core): 3.46e-03
Handing off to forward solve (with updated currents).
Relative error =  2.85e-01
-----
Iteration: 61
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['4.50e+08', '4.41e+08', '5.44e+08', '1.28e+05', '1.39e+08', '1.46e+07', '7.55e+06', '1.72e+07', '3.47e+06', '1.35e+08']
Constraint losses = 4.05e+01
Relative update of tokamak psi (in plasma core): 1.10e+00
Handing off to forward solve (with updated currents).
Relative error =  2.21e-01
-----
Iteration: 62
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.51e+08', '-2.54e+08', '-3.09e+08', '3.88e+04', '-7.74e+07', '-1.09e+07', '-5.39e+06', '-7.06e+06', '-5.47e+06', '-6.62e+07']
Constraint losses = 3.42e+01
Relative update of tokamak psi (in plasma core): 2.26e-01
Handing off to forward solve (with updated currents).
Relative error =  3.89e-02
-----
Iteration: 63
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.22e+06', '3.67e+06', '5.36e+04', '-7.92e+04', '-5.15e+05', '2.13e+06', '9.19e+05', '-2.75e+06', '2.39e+06', '-4.46e+06']
Constraint losses = 3.76e+01
Relative update of tokamak psi (in plasma core): 1.91e-03
Handing off to forward solve (with updated currents).
Relative error =  2.31e-01
-----
Iteration: 64
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.05e+06', '-8.89e+06', '-1.03e+07', '5.70e+04', '2.70e+05', '-2.84e+06', '-7.84e+05', '3.95e+06', '-5.96e+06', '5.16e+06']
Constraint losses = 2.55e+01
Relative update of tokamak psi (in plasma core): 7.76e-03
Handing off to forward solve (with updated currents).
Relative error =  6.73e-02
-----
Iteration: 65
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.02e+06', '3.56e+06', '2.99e+05', '-8.09e+04', '-1.00e+06', '2.04e+06', '1.13e+06', '-3.07e+06', '4.10e+06', '-5.05e+06']
Constraint losses = 2.81e+01
Relative update of tokamak psi (in plasma core): 1.05e-03
Handing off to forward solve (with updated currents).
Relative error =  2.31e-01
-----
Iteration: 66
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['9.60e+07', '9.22e+07', '1.07e+08', '4.54e+04', '3.21e+07', '1.68e+06', '8.74e+05', '3.85e+06', '-4.29e+05', '3.23e+07']
Constraint losses = 1.92e+01
Relative update of tokamak psi (in plasma core): 1.35e-01
Handing off to forward solve (with updated currents).
Relative error =  9.88e-02
-----
Iteration: 67
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.93e+06', '3.02e+06', '2.29e+06', '-2.81e+04', '-3.74e+06', '2.62e+06', '2.79e+06', '-4.59e+06', '6.04e+06', '-6.94e+06']
Constraint losses = 3.65e+01
Relative update of tokamak psi (in plasma core): 1.34e-03
Handing off to forward solve (with updated currents).
Relative error =  2.77e-01
-----
Iteration: 68
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.63e+06', '-8.60e+06', '-2.94e+07', '-4.02e+04', '6.74e+06', '-3.50e+06', '-2.85e+06', '3.92e+06', '-7.82e+06', '1.11e+07']
Constraint losses = 2.97e+01
Relative update of tokamak psi (in plasma core): 1.38e-02
Handing off to forward solve (with updated currents).
Relative error =  1.60e-01
-----
Iteration: 69
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-7.87e+05', '-2.02e+05', '1.93e+06', '1.28e+05', '-2.75e+06', '-3.19e+05', '-1.59e+05', '-2.83e+05', '2.73e+06', '-3.14e+06']
Constraint losses = 2.62e+01
Relative update of tokamak psi (in plasma core): 1.03e-03
Handing off to forward solve (with updated currents).
Relative error =  1.52e-04
-----
Iteration: 70
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.84e+06', '4.40e+06', '1.50e+06', '-1.08e+05', '1.52e+04', '1.37e+06', '1.70e+06', '-2.01e+06', '3.15e+06', '-7.62e+06']
Constraint losses = 3.93e+01
Relative update of tokamak psi (in plasma core): 1.11e-03
Handing off to forward solve (with updated currents).
Relative error =  2.28e-01
-----
Iteration: 71
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['5.52e+07', '4.10e+07', '7.43e+07', '6.74e+04', '1.13e+07', '1.48e+06', '-5.02e+05', '3.50e+06', '-1.99e+06', '1.55e+07']
Constraint losses = 1.87e+01
Relative update of tokamak psi (in plasma core): 5.84e-02
Handing off to forward solve (with updated currents).
Relative error =  9.22e-02
-----
Iteration: 72
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-2.07e+06', '2.71e+06', '9.29e+05', '-9.30e+04', '-1.58e+06', '1.92e+06', '2.66e+06', '-4.02e+06', '4.51e+06', '-4.57e+06']
Constraint losses = 3.53e+01
Relative update of tokamak psi (in plasma core): 9.15e-04
Handing off to forward solve (with updated currents).
Relative error =  3.01e-01
-----
Iteration: 73
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.94e+07', '2.87e+07', '2.05e+07', '3.12e+04', '1.58e+07', '-1.93e+06', '-1.67e+06', '5.19e+06', '-6.14e+06', '1.96e+07']
Constraint losses = 2.72e+01
Relative update of tokamak psi (in plasma core): 2.92e-02
Handing off to forward solve (with updated currents).
Relative error =  9.40e-02
-----
Iteration: 74
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.28e+06', '3.95e+06', '2.71e+06', '-2.87e+04', '-4.75e+06', '3.79e+06', '1.52e+06', '-4.09e+06', '6.33e+06', '-9.40e+06']
Constraint losses = 3.96e+01
Relative update of tokamak psi (in plasma core): 8.20e-04
Handing off to forward solve (with updated currents).
Relative error =  3.01e-01
-----
Iteration: 75
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['2.37e+06', '-3.38e+06', '-5.11e+06', '1.18e+04', '4.62e+06', '-2.93e+06', '-2.15e+06', '3.51e+06', '-5.60e+06', '8.60e+06']
Constraint losses = 3.05e+01
Relative update of tokamak psi (in plasma core): 2.51e-03
Handing off to forward solve (with updated currents).
Relative error =  1.68e-01
-----
Iteration: 76
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-4.01e+05', '-5.52e+05', '1.60e+06', '1.24e+05', '-2.50e+06', '-3.83e+05', '-3.53e+04', '-5.46e+05', '2.64e+06', '-2.19e+06']
Constraint losses = 2.63e+01
Relative update of tokamak psi (in plasma core): 8.57e-04
Handing off to forward solve (with updated currents).
Relative error =  3.50e-04
-----
Iteration: 77
Using simplified Green's Jacobian (of constraints wrt coil currents) to optimise the currents.
Change in coil currents (being controlled): ['-3.42e+06', '4.60e+06', '8.05e+05', '-1.29e+05', '8.64e+05', '1.18e+06', '2.22e+06', '-2.48e+06', '3.09e+06', '-7.41e+06']
Constraint losses = 4.60e+01
Relative update of tokamak psi (in plasma core): 1.10e-03
Handing off to forward solve (with updated currents).
/Users/george.holt/miniforge3/envs/freegsnke/lib/python3.10/site-packages/freegs4e/jtor.py:361: RuntimeWarning: divide by zero encountered in scalar divide
  L = self.Ip / I_R - LBeta0 * (IR / I_R - 1)
/Users/george.holt/miniforge3/envs/freegsnke/lib/python3.10/site-packages/freegs4e/jtor.py:361: RuntimeWarning: invalid value encountered in scalar divide
  L = self.Ip / I_R - LBeta0 * (IR / I_R - 1)
fig1, ax1 = plt.subplots(1, 1, figsize=(7, 15), dpi=80)

ax1.grid(zorder=0, alpha=0.75)
ax1.set_aspect('equal')
eq.tokamak.plot(axis=ax1,show=False)                                                          # plots the active coils and passive structures
ax1.fill(tokamak.wall.R, tokamak.wall.Z, color='k', linewidth=1.2, facecolor='w', zorder=0)   # plots the limiter
eq.plot(axis=ax1,show=False)                                                                  # plots the equilibrium
constrain.plot(axis=ax1, show=False)                                                          # plots the contraints
ax1.set_xlim(1.1, 12.4)
ax1.set_ylim(-8.3, 8.3)
eq.tokamak.getCurrents()

# # save coil currents to file
# import pickle
# with open('simple_diverted_currents_PaxisIp.pk', 'wb') as f:
#     pickle.dump(obj=inverse_current_values, file=f)