![]() |
The Open FUSION Toolkit 26.9
An open-source framework for fusion and plasma science and engineering
|
In this example we show how to perform an equilibrium reconstruction in ITER from a simple with L-mode case. This example demonstrates the new reconstruction method, which leverages a multi-step approach where: 1) An EFIT-like quasi-linear reconstruction is performed by fitting to linearly-related DoF and constraints during the standard nonlinear solve 2) The reconstruction is refined using a fully general nonlinear approach that utilizes scipy.optimize.least_squares and thus supports many other optimization methods
This example utilizes the mesh built in TokaMaker Meshing Example: Building a mesh for ITER.
To load the TokaMaker python module we need to tell python where to the module is located. This can be done either through the PYTHONPATH environment variable or using within a script using sys.path.append() as below, where we look for the environement variable OFT_ROOTPATH to provide the path to where the OpenFUSIONToolkit is installed (/Applications/OFT on macOS).
For meshing we will use the gs_Domain class to build a 2D triangular grid suitable for Grad-Shafranov equilibria. This class uses the triangle code through a python wrapper.
We now create a OFT_env instance for execution using two threads and a TokaMaker instance to use for equilibrium calculations. Note at present only a single TokaMaker instance can be used per python kernel, so this command should only be called once in a given Jupyter notebook or python script. In the future this restriction may be relaxed.
#----------------------------------------------
____ ____________
/ __ \/ ____/_ __/
/ / / / /_ / /
/ /_/ / __/ / /
\____/_/ /_/
Base release: v1.0.0-beta7
Development branch: release_26_06
Revision id: 978c4b9f
Parallelization Info:
Not compiled with MPI
# of OpenMP threads = 2
Linear Algebra backend: native
#----------------------------------------------
Now we load the mesh generated in TokaMaker Meshing Example: Building a mesh for ITER using load_gs_mesh() and setup_mesh. Then we use setup_regions(), passing the conductor and coil dictionaries for the mesh, to define the different region types. Finally, we call setup() to setup the required solver objects. During this call we can specify the desired element order (min=2, max=4) and the toroidal field through F0 = B0*R0, where B0 is the toroidal field at a reference location R0.
**** Loading OFT surface mesh
**** Generating surface grid level 1
Generating boundary domain linkage
Mesh statistics:
Area = 2.859E+02
# of points = 4757
# of edges = 14156
# of cells = 9400
# of boundary points = 112
# of boundary edges = 112
# of boundary cells = 112
Resolution statistics:
hmin = 9.924E-03
hrms = 2.826E-01
hmax = 8.466E-01
Surface grounded at vertex 870
**** Creating Lagrange FE space
Order = 2
Minlev = -1
Computing flux BC matrix
Inverting real matrix
Time = 9.3599999999999998E-004
Like many elongated equilibria, the equilibrium we seek to compute below is vertically unstable. In this case we use the actual ITER Vertical Stability Coil (VSC) in order to help with convergence using the set_coil_vsc() method.
Hard limits on coil currents can be set using set_coil_bounds(). In this case we just the simple and approximate bi-directional limit of 50 MA in each coil.
Bounds are specified using a dictionary of 2 element lists, containing the minimum and maximum bound, where the dictionary key corresponds to the coil names, which are available in mygs.coil_sets
For the inverse case we define a target for the plasma current and the peak plasma pressure, which occurs on the magnetic axis.
In order to constrain the shape of the plasma we can utilize two types of constraints:
Here we define a handful of isoflux points that we want to lie on the LCFS of the target equilibrium. Additionally, we define a single X-point and set it as a saddle constraint as well as adding it to the list of isoflux points.
In general, for a given coil set a given plasma shape cannot be exactly reproduced, which generally yields large amplitude coil currents if no constraint on the coil currents is applied. As a result, it is useful to include regularization terms for the coils to balance minimization of the shape error with the amplitude of current in the coils. In TokaMaker these regularization terms have the general form, where each term corresponds to a set of coil coefficients, target value, and weight. The coil_reg_term() method is provided to aid in defining these terms.
In this case, one regularization term is added for each coil with a single unit coefficient for that coil and target of zero with modest weights. This regularization acts to penalize the amplitude of current in each coil, acting to balance coil current with error in the shape targets. Note that the weight on the VSC virtual coil (#VSC) defined above is set high to prevent interaction with the real VS coil set (see below for further information).
Although TokaMaker has a "default" profile for the F*F' and P' terms this should almost never be used and one should instead choose an appropriate flux function for their application. In this case we use an L-mode-like profile of the form \(((1-\hat{\psi})^{\alpha})^{\gamma}\), using create_power_flux_fun(), where \(\alpha\) and \(\gamma\) are set differently for F*F' and P' to provide peaked and broad profiles respectively. Within TokaMaker this profile is represented as a piecewise linear function, which can be set up using the dictionary approach shown below.
We can now compute a free-boundary equilibrium using these constraints. Note that before running a calculation for the first time we must initialize the flux function \(\psi\), which can be done using init_psi(). This subroutine initializes the flux using the specified Ip_target from above, which is evenly distributed over the entire plasma region or only with a boundary defined using a center point (R,Z), minor radius (a), and elongation and triangularity. Coil currents are also initialized at this point using the constraints above and this uniform plasma current initialization.
solve() is then called to compute a self-consitent Grad-Shafranov equilibrium. If the result variable (err_flag) is zero then the solution has converged to the desired tolerance ( \(10^{-6}\) by default).
Starting non-linear GS solver
1 8.2775E+00 4.5346E-02 2.5053E-01 6.3670E+00 5.2517E-01 5.1278E+00
2 9.2818E+00 4.3811E-02 1.2032E-01 6.3542E+00 5.2850E-01 -1.0532E-01
3 9.8332E+00 4.4199E-02 4.8727E-02 6.3488E+00 5.3104E-01 -1.6270E+00
4 1.0088E+01 4.4362E-02 2.2631E-02 6.3463E+00 5.3295E-01 -2.2306E+00
5 1.0205E+01 4.4440E-02 1.1259E-02 6.3452E+00 5.3436E-01 -2.4918E+00
6 1.0260E+01 4.4473E-02 5.5355E-03 6.3448E+00 5.3537E-01 -2.6162E+00
7 1.0285E+01 4.4488E-02 2.8275E-03 6.3445E+00 5.3609E-01 -2.6794E+00
8 1.0297E+01 4.4495E-02 1.3839E-03 6.3444E+00 5.3660E-01 -2.7080E+00
9 1.0302E+01 4.4499E-02 6.8286E-04 6.3444E+00 5.3695E-01 -2.7236E+00
10 1.0305E+01 4.4501E-02 3.4760E-04 6.3444E+00 5.3719E-01 -2.7305E+00
11 1.0306E+01 4.4502E-02 1.9076E-04 6.3443E+00 5.3736E-01 -2.7339E+00
12 1.0307E+01 4.4502E-02 1.0669E-04 6.3443E+00 5.3748E-01 -2.7358E+00
13 1.0307E+01 4.4502E-02 6.4925E-05 6.3443E+00 5.3756E-01 -2.7368E+00
14 1.0307E+01 4.4502E-02 4.1959E-05 6.3443E+00 5.3762E-01 -2.7373E+00
15 1.0307E+01 4.4502E-02 2.8095E-05 6.3443E+00 5.3765E-01 -2.7376E+00
16 1.0307E+01 4.4502E-02 1.9155E-05 6.3443E+00 5.3768E-01 -2.7378E+00
17 1.0307E+01 4.4502E-02 1.3169E-05 6.3443E+00 5.3770E-01 -2.7379E+00
18 1.0307E+01 4.4502E-02 9.0850E-06 6.3443E+00 5.3771E-01 -2.7380E+00
19 1.0307E+01 4.4502E-02 6.2759E-06 6.3443E+00 5.3772E-01 -2.7380E+00
20 1.0307E+01 4.4502E-02 4.3368E-06 6.3443E+00 5.3773E-01 -2.7381E+00
21 1.0307E+01 4.4502E-02 2.9967E-06 6.3443E+00 5.3773E-01 -2.7381E+00
22 1.0307E+01 4.4502E-02 2.0704E-06 6.3443E+00 5.3773E-01 -2.7381E+00
23 1.0307E+01 4.4502E-02 1.4303E-06 6.3443E+00 5.3774E-01 -2.7381E+00
24 1.0307E+01 4.4502E-02 9.8787E-07 6.3443E+00 5.3774E-01 -2.7381E+00
Timing: 0.21146899997256696
Source: 0.13136300002224743
Solve: 3.8474000233691186E-002
Boundary: 4.4809998362325132E-003
Other: 3.7150999880395830E-002
Flux surfaces of the computed equilibrium can be plotted using the plot_psi() method. The additional plotting methods plot_machine() and plot_constraints() are also used to show context and other information. Each method has a large number of optional arguments for formatting and other options.
Basic parameters can be displayed using the print_info() method. For access to these quantities as variables instead the get_stats() can be used.
The final coil currents can also be retrieved using the get_coil_currents() method, which are all within the approximate coil limits imposed above.
Equilibrium Statistics: Topology = Diverted Toroidal Current [A] = 1.5600E+07 Current Centroid [m] = 6.162 0.515 Magnetic Axis [m] = 6.344 0.538 Elongation = 1.863 (U: 1.721, L: 2.006) Triangularity = 0.453 (U: 0.356, L: 0.551) Plasma Volume [m^3] = 810.854 q_0, q_95 = -0.594 -2.812 Plasma Pressure [Pa] = Axis: 4.2936E+05, Peak: 4.2936E+05 Stored Energy [J] = 1.9992E+08 <Beta_pol> [%] = 34.7667 <Beta_tor> [%] = 1.4813 <Beta_n> [%] = 0.9915 Diamagnetic flux [Wb] = -1.6343E+00 Toroidal flux [Wb] = -1.2036E+02 l_i = 1.0618 Coil Currents [MA]: CS3U: 14.01 CS2U: 9.33 CS1U: -9.12 CS1L: -7.42 CS2L: 8.57 CS3L: 16.83 PF1: 10.78 PF2: -1.49 PF3: -6.16 PF4: -3.97 PF5: -8.45 PF6: 24.57 VS: -0.00
We now create the reconstruction object to reconstruct the equilibrium above from only diagnostic information.
For this example we define a simple set of flux loops and Mirnov sensors that lie on the inner vaccum vessel. The signal in these sensors will be used to constrain the reconstruction along with coil currents and global plasma quantities (eg. \(I_p\)).
We also define a helper function to add Gaussian noise to signals based on a relative and absolute error.
First we define a constraint on the plasma current with 2% relative and 100 kA absolute Gaussian noise added to the signal and corresponding error. This constraint is equivalent to the measurement of a synthetic Rigowskii coil and can be set using set_Ip().
Next we define a constraint on the diamagnetic flux with 5% relative and 100 mWb absolute Gaussian noise added to the signal and corresponding error. This constraint is equivalent to the measurement of a synthetic Diamagnetic flux loop and can be set using set_DFlux().
Next we define constraints on the plasma pressure corresponding to the Thomson chords constructed above. Each point has a 10% relative and 3 kPa absolute Gaussian noise added to the signal and corresponding error. This constraint is equivalent to the measurement of synthetic Thomson points and can be set using add_pressure().
Next we sample the poloidal flux at each of the locations defined above with 2% relative and 1 Wb absolute Gaussian noise added to each signal. Flux loop constraints are defined using add_flux_loop().
Next we sample the radial and vertical magnetic field at each of the locations defined above with 2% relative and 50 mT absolute Gaussian noise added to each signal. Local B-field constraints are defined using add_Mirnov().
Finally we add 1% relative and 100 kA-turn absolute noise to each coil current and define reconstruction constraints using set_coil_currents().
Starting non-linear GS solver
1 8.5568E+00 1.7700E-01 5.1892E-02 6.4059E+00 9.7376E-02 6.2213E+02
2 1.9530E+01 6.9838E-02 1.2827E-02 6.3734E+00 1.4878E-01 6.7783E+02
3 1.7959E+01 8.5337E-02 1.0039E-02 6.3757E+00 1.9599E-01 6.6627E+02
4 1.9416E+01 7.1018E-02 8.2304E-03 6.3668E+00 2.3504E-01 6.1913E+02
5 1.8407E+01 7.8374E-02 7.6746E-03 6.3689E+00 2.7066E-01 5.7732E+02
6 1.9023E+01 7.1181E-02 6.6159E-03 6.3645E+00 3.0166E-01 5.3130E+02
7 1.8464E+01 7.4648E-02 6.0222E-03 6.3651E+00 3.3046E-01 4.9440E+02
8 1.8726E+01 7.0910E-02 5.3076E-03 6.3623E+00 3.5542E-01 4.5814E+02
9 1.8392E+01 7.2647E-02 4.7453E-03 6.3623E+00 3.7801E-01 4.2858E+02
10 1.8485E+01 7.0699E-02 4.1659E-03 6.3605E+00 3.9797E-01 4.0039E+02
11 1.8278E+01 7.1572E-02 3.7033E-03 6.3603E+00 4.1574E-01 3.7674E+02
12 1.8293E+01 7.0556E-02 3.2279E-03 6.3592E+00 4.3150E-01 3.5509E+02
13 1.8164E+01 7.0935E-02 2.8485E-03 6.3589E+00 4.4548E-01 3.3670E+02
14 1.8144E+01 7.0430E-02 2.5073E-03 6.3582E+00 4.5770E-01 3.2012E+02
15 1.8058E+01 7.0604E-02 2.1974E-03 6.3579E+00 4.6846E-01 3.0588E+02
16 1.8025E+01 7.0370E-02 1.9256E-03 6.3575E+00 4.7791E-01 2.9316E+02
17 1.7965E+01 7.0442E-02 1.7021E-03 6.3572E+00 4.8625E-01 2.8222E+02
18 1.7932E+01 7.0325E-02 1.4870E-03 6.3568E+00 4.9367E-01 2.7254E+02
19 1.7890E+01 7.0345E-02 1.3002E-03 6.3566E+00 5.0017E-01 2.6412E+02
20 1.7861E+01 7.0292E-02 1.1309E-03 6.3563E+00 5.0588E-01 2.5675E+02
21 1.7831E+01 7.0291E-02 9.8845E-04 6.3561E+00 5.1087E-01 2.5038E+02
22 1.7806E+01 7.0275E-02 8.6361E-04 6.3560E+00 5.1523E-01 2.4477E+02
23 1.7782E+01 7.0278E-02 7.4916E-04 6.3558E+00 5.1904E-01 2.3987E+02
24 1.7762E+01 7.0273E-02 6.5034E-04 6.3557E+00 5.2236E-01 2.3560E+02
25 1.7744E+01 7.0278E-02 5.6762E-04 6.3556E+00 5.2526E-01 2.3189E+02
26 1.7728E+01 7.0278E-02 4.9519E-04 6.3555E+00 5.2778E-01 2.2866E+02
27 1.7714E+01 7.0283E-02 4.3231E-04 6.3554E+00 5.2997E-01 2.2584E+02
28 1.7702E+01 7.0286E-02 3.7690E-04 6.3554E+00 5.3188E-01 2.2339E+02
29 1.7692E+01 7.0289E-02 3.2924E-04 6.3553E+00 5.3354E-01 2.2124E+02
30 1.7682E+01 7.0292E-02 2.8669E-04 6.3552E+00 5.3499E-01 2.1937E+02
31 1.7675E+01 7.0292E-02 2.4907E-04 6.3552E+00 5.3625E-01 2.1774E+02
32 1.7667E+01 7.0296E-02 2.1655E-04 6.3552E+00 5.3735E-01 2.1634E+02
33 1.7661E+01 7.0300E-02 1.8784E-04 6.3551E+00 5.3831E-01 2.1510E+02
34 1.7656E+01 7.0300E-02 1.6373E-04 6.3551E+00 5.3914E-01 2.1404E+02
35 1.7651E+01 7.0303E-02 1.4279E-04 6.3551E+00 5.3986E-01 2.1312E+02
36 1.7647E+01 7.0304E-02 1.2394E-04 6.3550E+00 5.4049E-01 2.1232E+02
37 1.7643E+01 7.0305E-02 1.0796E-04 6.3550E+00 5.4104E-01 2.1163E+02
38 1.7640E+01 7.0307E-02 9.3781E-05 6.3550E+00 5.4152E-01 2.1102E+02
39 1.7638E+01 7.0307E-02 8.1327E-05 6.3550E+00 5.4193E-01 2.1049E+02
40 1.7635E+01 7.0309E-02 7.1060E-05 6.3550E+00 5.4229E-01 2.1004E+02
41 1.7633E+01 7.0309E-02 6.1759E-05 6.3550E+00 5.4261E-01 2.0964E+02
42 1.7632E+01 7.0310E-02 5.3894E-05 6.3550E+00 5.4288E-01 2.0929E+02
43 1.7630E+01 7.0311E-02 4.6674E-05 6.3550E+00 5.4312E-01 2.0899E+02
44 1.7629E+01 7.0312E-02 4.0519E-05 6.3550E+00 5.4332E-01 2.0873E+02
45 1.7628E+01 7.0312E-02 3.5006E-05 6.3549E+00 5.4350E-01 2.0850E+02
46 1.7627E+01 7.0312E-02 3.0441E-05 6.3549E+00 5.4366E-01 2.0830E+02
47 1.7626E+01 7.0313E-02 2.6570E-05 6.3549E+00 5.4380E-01 2.0813E+02
48 1.7625E+01 7.0313E-02 2.2985E-05 6.3549E+00 5.4391E-01 2.0798E+02
49 1.7624E+01 7.0313E-02 2.0099E-05 6.3549E+00 5.4401E-01 2.0786E+02
50 1.7624E+01 7.0314E-02 1.7289E-05 6.3549E+00 5.4410E-01 2.0774E+02
51 1.7623E+01 7.0314E-02 1.5098E-05 6.3549E+00 5.4418E-01 2.0765E+02
52 1.7623E+01 7.0314E-02 1.3164E-05 6.3549E+00 5.4425E-01 2.0756E+02
53 1.7622E+01 7.0314E-02 1.1330E-05 6.3549E+00 5.4430E-01 2.0749E+02
54 1.7622E+01 7.0314E-02 9.8614E-06 6.3549E+00 5.4435E-01 2.0742E+02
55 1.7622E+01 7.0315E-02 8.5061E-06 6.3549E+00 5.4440E-01 2.0737E+02
56 1.7621E+01 7.0315E-02 7.3721E-06 6.3549E+00 5.4444E-01 2.0732E+02
57 1.7621E+01 7.0315E-02 6.3880E-06 6.3549E+00 5.4447E-01 2.0728E+02
58 1.7621E+01 7.0315E-02 5.5350E-06 6.3549E+00 5.4450E-01 2.0724E+02
59 1.7621E+01 7.0315E-02 4.7960E-06 6.3549E+00 5.4452E-01 2.0721E+02
60 1.7621E+01 7.0315E-02 4.1553E-06 6.3549E+00 5.4454E-01 2.0718E+02
61 1.7621E+01 7.0315E-02 4.0560E-06 6.3549E+00 5.4456E-01 2.0716E+02
62 1.7621E+01 7.0315E-02 3.1418E-06 6.3549E+00 5.4458E-01 2.0714E+02
63 1.7620E+01 7.0315E-02 2.7213E-06 6.3549E+00 5.4459E-01 2.0712E+02
64 1.7620E+01 7.0315E-02 2.3584E-06 6.3549E+00 5.4460E-01 2.0711E+02
65 1.7620E+01 7.0315E-02 2.0434E-06 6.3549E+00 5.4461E-01 2.0709E+02
66 1.7620E+01 7.0315E-02 1.7710E-06 6.3549E+00 5.4462E-01 2.0708E+02
67 1.7620E+01 7.0315E-02 1.5346E-06 6.3549E+00 5.4463E-01 2.0707E+02
68 1.7620E+01 7.0315E-02 1.3299E-06 6.3549E+00 5.4464E-01 2.0706E+02
69 1.7620E+01 7.0315E-02 1.1524E-06 6.3549E+00 5.4464E-01 2.0706E+02
70 1.7620E+01 7.0315E-02 9.9868E-07 6.3549E+00 5.4465E-01 2.0705E+02
Timing: 0.65148900001076981
Source: 0.37720599991735071
Solve: 0.11065999988932163
Boundary: 1.2524000077974051E-002
Other: 0.15109900012612343
Equilibrium Statistics: Topology = Diverted Toroidal Current [A] = 1.5927E+07 Current Centroid [m] = 6.146 0.529 Magnetic Axis [m] = 6.355 0.545 Elongation = 1.888 (U: 1.750, L: 2.026) Triangularity = 0.461 (U: 0.371, L: 0.551) Plasma Volume [m^3] = 821.036 q_0, q_95 = -0.856 -2.761 Plasma Pressure [Pa] = Axis: 5.3701E+05, Peak: 5.3701E+05 Stored Energy [J] = 2.3366E+08 <Beta_pol> [%] = 39.1600 <Beta_tor> [%] = 1.7091 <Beta_n> [%] = 1.1139 Diamagnetic flux [Wb] = -1.5602E+00 Toroidal flux [Wb] = -1.2202E+02 l_i = 0.9273 Coil Currents [MA]: CS3U: 14.55 CS2U: 9.79 CS1U: -9.62 CS1L: -7.63 CS2L: 8.06 CS3L: 16.74 PF1: 10.35 PF2: -1.75 PF3: -6.01 PF4: -3.94 PF5: -8.79 PF6: 25.08 VS: 0.00
We now refine the reconstruction by applying a general nonlinear optimization approach over the inner diagnostic-constrained nonlinear solve. The TokaMaker reconstruction object has several helper functions to support this for optimization approaches that use callable error and Jacobian functions as shown below for the scipy.optimize.least_squares method, which uses both callable functions with a Levenberg–Marquardt algorithm.
chi_rms = 1.0521E+00; chi_max = 4.1317E+00
chi_rms = 8.5389E-01; chi_max = 3.4197E+00
chi_rms = 5.8139E-01; chi_max = 4.5249E+00
chi_rms = 5.2645E-01; chi_max = 3.8078E+00
chi_rms = 5.2468E-01; chi_max = 3.8389E+00
chi_rms = 5.2465E-01; chi_max = 3.8233E+00
message: `ftol` termination condition is satisfied.
success: True
status: 2
fun: [-3.246e-01 -3.450e-01 ... 1.864e-01 4.209e-01]
x: [ 4.280e-02 1.920e+00 2.204e+00]
cost: 36.74649712857145
jac: [[ 8.190e+00 -2.660e-02 6.123e-02]
[ 9.480e+00 -1.645e-02 7.830e-02]
...
[-4.179e+00 2.074e-03 -3.679e-02]
[-9.482e+01 1.829e-02 -5.502e-01]]
grad: [ 1.391e+00 1.605e-01 -1.180e-01]
optimality: 1.390849360620803
active_mask: [0 0 0]
nfev: 5
njev: 4
Equilibrium Statistics: Topology = Diverted Toroidal Current [A] = 1.5924E+07 Current Centroid [m] = 6.161 0.533 Magnetic Axis [m] = 6.347 0.556 Elongation = 1.862 (U: 1.719, L: 2.006) Triangularity = 0.455 (U: 0.365, L: 0.545) Plasma Volume [m^3] = 820.243 q_0, q_95 = -0.587 -2.799 Plasma Pressure [Pa] = Axis: 4.2561E+05, Peak: 4.2561E+05 Stored Energy [J] = 2.0355E+08 <Beta_pol> [%] = 33.9731 <Beta_tor> [%] = 1.4921 <Beta_n> [%] = 0.9838 Diamagnetic flux [Wb] = -1.7164E+00 Toroidal flux [Wb] = -1.2187E+02 l_i = 1.0575 Coil Currents [MA]: Name Reconstructed Target Ground Truth % Error from target CS3U: 14.62 14.05 14.01 4.36 CS2U: 9.85 9.38 9.33 5.61 CS1U: -9.81 -9.08 -9.12 -7.60 CS1L: -7.67 -7.28 -7.42 -3.27 CS2L: 8.18 8.43 8.57 -4.55 CS3L: 16.86 16.83 16.83 0.16 PF1: 10.29 10.80 10.78 -4.57 PF2: -1.55 -1.50 -1.49 -4.02 PF3: -6.24 -6.21 -6.16 -1.30 PF4: -3.97 -4.00 -3.97 -0.04 PF5: -8.61 -8.55 -8.45 -1.88 PF6: 24.92 24.66 24.57 1.42 VS: 0.10 -0.01 -0.01 1886.98