Staff/HighSchoolStudents/20MatPok/NICE/index

Introduction

Theory

NICE—Newton direct and Inverse Computation for Equilibrium—is a relatively modern C++ numerical code dealing with plasma magnetohydrodynamic (MHD) equilibrium (for its detailed description, see official paper). It offers three computation modes:

  • plasma boundary only reconstruction from magnetic field measurements

  • full MHD equilibrium reconstruction from magnetic field and other measurements (similar to, e.g., EFIT)

  • direct and inverse equilibrium computation (similar to, e.g., Fiesta)

So far, we worked on putting into operation the mode. Direct simulations compute the plasma MHD equilibrium based on given currents in poloidal field coils (PF coils) and inverse simulations based on given plasma position. Simulations in both direct and inverse regime output not only 2D poloidal magnetic flux profile, but also information on plasma geometry and various 1D and 2D profiles of, e.g., magnetic field, current density, safety factor, plasma beta etc.

Carried out work

In order to put into operation the inverse and direct computation regimes, a virtual model of GOLEM had to be created (see Figure [fig:virtual-model]). The model includes a toroidally symmetrical model of GOLEM’s iron core, proposed by Markovič et al.

GOLEM virtual model.

The model also includes a virtual central solenoid approximating GOLEM’s primary transformer coils. We determined the solenoid’s optimal parameters by achieving best possible match between measured and simulated values of plasma position in total current in PF coils / virtual solenoid. Determined solenoid parameters are shown in the following table:

Solenoid parameter Optimal value
Height 35,0 cm
Width 1,5 cm
Center \(R\) coord. 21,0 cm
Center \(Z\) coord. 3,0 cm
Number of loops 2

We very briefly verified that inverse simulations without plasma stabilization (i.e., without PF coils) usually produce MHD equilibrium configurations typical for GOLEM. Direct simulations enable slight modifications of MHD equilibria computed inversely (by varying central solenoid current). Simulations with PF coils currently do not produce usable results, as NICE assumes 8 independent PF coils instead of 2 quadrupoles of 4 PF coils.

An attempt at putting into operation the full MHD equilibrium reconstruction computation mode was made, as it would allow for precise plasma boundary computations based on Mirnov coils data. Unfortunately, the iron core does not seem to be compatible with the computation mode.

Suggestions for future work

  • Turning the 8 independent PF coils of the virtual model into 2 quadrupoles of 4 coils (as is the case of GOLEM).

  • Linking NICE with METIS (NICE simulations require radial profile estimates of \(p', ff'\) functions).

  • Contacting NICE authors about possible solutions the the iron core incompatibility with the full MHD reconstruction regime.

  • Using MHD equilibria computed with the direct / inverse regimes as input for GBS.

  • Creating a database containing NICE computed MHD equilibria for every past GOLEM discharge with active Mirnov coils / fast cameras (for plasma boundary input).

NICE at GOLEM

Folders structure

At GOLEM, NICE is compiled on the Abacus server. There you can find two parent folders: nice-src and nice-golem. The nice-src folder contains NICE source code and related useful resources. Important folders in nice-src are:

src

NICE source code

data/testCases

exemplary input files for various tokamaks

nice-workspace

MATLAB interface for various tokamaks (including GOLEM)

doc

brief NICE tutorial and Doxygen info and configuration

The nice-golem folder contains all the necessary folders and files for running NICE for the case of GOLEM. Conserving its folder structure is necessary for successfully performing NICE simulations. It contains 4 folders and 1 file. The file, called nice, is the compiled NICE executable. The 4 folders are:

input

input files for simulations

output

files outputted by simulations

util

files for mainly plotting output data

PythonGUI

Python graphical user interface for NICE usage at GOLEM

In the following sections, we discuss the nice-golem folder only.

Input and output data

Input / data are provided to / outputted by NICE in the form of text files in the input and output folders. Each file, namely in the input folder, has a pre-defined structure that has to be respected for for successfully performing NICE simulations. The input folder also contains a param.xml file used for fine-tuning NICE simulations.

As input data, the user has to provide a virtual model of the GOLEM tokamak, estimates of certain radial profiles and info specific to the inverse / direct computation regime. Input data that does not need to be altered by the user is comprised of the shape and location of the following tokamak components (in parentheses additional required info):

  • PF coils (numbers of loops)

  • iron core segments (magnetic permeabilities)

  • chamber (conductivity)

  • limiter

  • passive structures, i.e., arbitrary iron objects (magnetic permeability; has to be included even if a tokamak doesn’t have one)

  • estimates of \(p'\) and \(ff'\) (functions present in the Grad-Shafranov equation) radial profiles with respect to \(\psi/\psi_\mathrm{LCFS}\) and \(\psi/\psi_\mathrm{LCFS}\) profile from 0 to 1 (all need to have the same dimension)

At the moment, we only dispose of the \(p'\) and \(ff'\) radial profiles of discharge #27466, so we use them for every simulation.

For each new simulation, the user has to provide the following parameters:

  • plasma current \(I_p\) and toroidal magnetic field \(B_\phi\) (file Ip_B0.txt)

  • plasma boundary (file plasma_bnd.txt; only for inverse simulations)

  • currents in PF coils (file Icoils.txt; only for direct simulations)

The input folder also contains a param.xml file. This file defines the simulation settings. Important tags in the file are:

<verbose>

amount of logs

<algoMode>

simulation regime (31 for inverse, 11 for direct)

<vacuumTriangleArea>

area of meshgrid triangles in vacuum region (other regions on lines 70-75)

  • modifying meshgrid density significantly alters simulation results (lowering it often assures convergence)

<r0>

magnetic axis \(R\) coord. (has to be specified for inverse simulations)

<n_coil_group_index>

number of PF coils groups (settings of PF coils on lines 285-297; PF coils can be grouped, but we are sure how)

The output data are stored in the output folder in text files. Important files in the output folder are:

mesh_coord.txt

coordinates of generated meshgrid

psi.txt

\(\psi\) value on each meshgrid point

Ip_B0.txt

\(I_p\) and \(B_\phi\) for which NICE found a solution

plasma_bnd.txt

calculated plasma boundary (in case of inverse regime, closest possible boundary to the inputted one)

dataEqui_currents_inverse.txt

calculated currents in PF coils (inverse only)

profiles_1d_psiN.txt

\(\psi/\psi_\mathrm{LCFS}\) profile (x-axis for all outputted 1D profiles)

Other files contain various 1D or 2D profiles of, e.g., \(p'\) and \(ff'\) functions, safety factor, toroidal current density, magnetic field etc.

Interfaces

Two interfaces exist that make running NICE easier: a MATLAB interface and a graphical Python interface. It is possible to use NICE without no interface, running the nice executable directly. To do so, it is necessary that the folders structure described in 2.1 is respected and that all the necessary input files are present and filled out. It then suffices to run the nice executable and if the simulation runs successfully, output text files appear in the output folder.

MATLAB

The MATLAB interface allows the user to run NICE and visualize simulation results via MATLAB only. The interface is located in nice/matlab-runs/nice-golem. To run NICE, open the TestNiceGOLEM.m file; write desired \(I_p, B_\phi\) and plasma boundary / currents in PF coils to variables in the upper section of the file; run the inverse mode / direct mode section of the file. The simulation results will be loaded into the equi_out_inv or equi_out_dir variable depending on chosen simulation regime.

For the MATLAB interface, input data are specified in a .h5 (Hierarchical Data Format) file. The file can be generated and the data plotted with functions located in the python folder.

Python

We’ve also created a graphical user interface (GUI) written with Python and the Streamlit library. It is located in the PythonGUI folder. To run the Python GUI, the Streamlit library must be installed, as well as the standard Numpy, Pandas, Matplotlib etc. It then suffices to run the command streamlit run main.py from the PythonGUI folder. The folder contains 6 Python files:

main.py

defines general GUI structure and calls the GUI_ENG.py / GUI_CZ.py file

GlobalData.py

data class with GOLEM geometry info

GUI_ENG.py

frontend of English GUI version

GUI_CZ.py

frontend of Czech GUI version

functions_NICE.py

functions for altering text input files, modyfing XML file, running NICE, parsing output text files

functions_plotting.py

functions for plotting plasma boundary (for input visualization) and \(\psi\)

GUI_backup.py

old GUI frontend

Usage

to be written