# EFIT¶

Contacts: Orso Meneghini, Sterling Smith, Lang Lao, Brian Grierson, Steve Sabbagh

## Short Description¶

Run the EFIT equilibrium solver

## Long Description¶

EFIT (Equilibrium Fitting) is a computer code developed to translate measurements from plasma diagnostics into useful information like plasma geometry, stored energy, and current profiles. The measurements are obtained from diagnostics such as external magnetic probes, external poloidal flux loops, and the Motional Stark Effect (MSE), which measures the direction of the magnetic field lines inside the plasma. The Grad-Shafranov equilibrium equation, which describes the force balance in a plasma, is solved using the available measurements as constraints on the toroidal current density. Since the current also depends on the solution of the equation, the poloidal flux function, this is a nonlinear optimization problem. The equilibrium constraint allows the two-dimensional current density to be represented by two one-dimensional stream functions (functions only of flux), which significantly reduces the complexity of the problem.

EFIT can be run in either the fitting mode or the equilibrium mode.

- equilibrium mode: EFIT solves the 2D equilibrium Grad-Shafranov equation.
- reconstruction mode: EFIT solves a non-linear optimization problem, trying to minimize a cost function that depends on a series of constraints derived from either experimental measurements (magnetic probes, flux loops, MSE, kinetic pressure, ECE, CER) or models (q-on axis, bootstrap-current). Kinetic-EFIT refers to the ability of EFIT to include internal constraints (namely pressure and the current). EFIT efficiency derives from it’s numerical scheme which transforms the original non-linear optimization problem into a sequence of linearized minimizations interleaved with the equilibrium iterations.

EFIT can be run as a free or fixed boundary equilibrium solver. In the latter case the location of the last closed flux surface is externally specified (in practice EFIT works by enforcing constant poloidal flux at those points). EFIT can also be run with a mixed free and fixed boundary constraints.

EFIT is computationally not expensive, requiring only few seconds on a single CPU (few minutes at highest resolutions 513x513). For plasma control applications, there is a real-time C++ EFIT version RT-EFIT available with algorithms designed to allow real-time equilibrium reconstructions. A MPI version is also available to support parallelized multi-timeslice equilibrium reconstructions. There has also been an effort aimed at using GPU acceleration: parallelized-EFIT (P-EFIT) on EAST and DIII-D. Calculation of the Green’s function tables is computationally intensive but are pre-comnputed (with the EFUND code) and stored as look-up tables.

EFIT expects an interactive input for setting it’s main mode of operation; after that the input parameters are passed through a namelist file: k-file or snap file. When in reconstruction mode, EFIT can take as an input a snap file to generate a k-file with the experimental data (this feature is obviously machine dependent). When run with a snap file, the experimental data are looked up directly from experimental databases. When in equilibrium mode, the k-file is referred to as the r-file. The three most important EFIT output are two ASCII files g-file, a-file, and a NetCDF file m-file (when operating in reconstruction mode). Other diagnostics and plotting files are also generated.

## Typical workflows¶

- Generate equilibrium from experimental data
- Free-bondary a/g-files from k-file
- Closed-bondary a/g-files from r-file
- Free-bondary g-files from snap-file
- Modify k-file with constraints
- Fetch an existing g-file

- Modify existing equilibrium
- Current, magnetic field, plasma position, and shape
- Reduce resolution of existing g-file

- Generate equilibria from kinetic file (see kineticEFIT and kineticEFITtime modules)
- Magnetics, pressure, current, MSE, boundary, on-axis q constraints
- E_r correction of MSE signal from measurement (e.g. GAprofiles) or model (e.g. NEO)
- Auto-knotting of P’ and FF’ spline basis functions

**Monte-Carlo uncertainty quantification analysis**- Plotting
- Equilibrium
- Flux surface and flux surface averaged quantities
- Constraints
- Quality of reconstruction metrics

- DIII-D specific goodies:
- Query DIII-D SQL database for available SNAP files and retrieve them from DIII-D MDS+
- Save run to DIII-D MDS+

## Supported devices¶

- DIII-D, NSTX, C-Mod, EAST

## Relevant publications¶

- Lao, L.; John, H. S.; Stambaugh, R.; Kellman, A. & Pfeiffer, W.; Reconstruction of current profile parameters and plasma shapes in tokamaks; Nuclear Fusion, 1985, 25, 1611
- Lao, L. L., Ferron, J.R., Groebner, R.J., Howl, W., St. John, Strait E.J., Taylor, T.S. Equilibrium Analysis of Current Profiles in tokamaks. Nuclear Fusion, 30 , 1035 (1990)
- Lao, L. L., St. John, H. E., Peng, Q., Ferron, J. R., Strait, E. J., Taylor, T. S., Meyer, W. H., Zhang, C., & You, K. I. MHD equilibrium reconstruction in the DIII-D tokamak. Fusion Science and Technology 48, 968 (2005)

## External resources¶

- Official webpage: https://fusion.gat.com/theory/Efit
- Overview presentation: https://fusion.gat.com/theory-wiki/images/8/80/Lao_2013_EFIT_V4B.pdf
- Tutorial for optimization of EFIT runs with eliminating negative j_t, optimizing edge j_t and minimizing chi^2=sum of (chi_flux_loop^2, chi_mag_probe^2, chi_MSE^2): https://docs.google.com/document/d/1BrT7bMyqm-fbYVEeelmXXSihXH-j6sGW_csxqCvXfFM/edit?usp=sharing

## Classes¶

`classes.omfit_base.OMFITcollection()`

`classes.omfit_base.OMFITmcTree()`

`classes.omfit_eqdsk.OMFITaeqdsk()`

`classes.omfit_eqdsk.OMFITgeqdsk()`

`classes.omfit_eqdsk.OMFITkeqdsk()`

`classes.omfit_eqdsk.OMFITmeqdsk()`

`classes.omfit_json.OMFITjson()`

`classes.omfit_mds.OMFITmdsValue()`

`classes.omfit_mds.OMFITmds()`

`classes.omfit_namelist.OMFITnamelist()`

`classes.omfit_osborne.OMFITpFile()`

## Contributors¶

List of contributors sorted by number of lines authored:

```
3240 Orso Meneghini
217 Sterling Smith
165 Brian Grierson
149 Gregorio L. Trevisan
87 Siye Ding
52 Brendan Lyons
46 David Eldon
44 Nikolas Logan
35 Brian Victor
34 Joseph McClenaghan
4 Zhixuan Wang
1 Christopher Holland
```

## Submodules¶

None

## Users¶

List of usernames sorted by number of module imports: **meneghini**, **dorr**, **mcclenaghanj**, **victorb**, **roelofsm**, **renq**, **panck**, **wangy**, **marinoni**, **smithsp**, **grierson**, **nelsonand**, **guowf**, **lyonsbc**, **snoepg**, **dingsiye**, **lijx**, **fernandezp**, **jacksona**, **lindan**, **pankin**, **wanghuiqian**, **knolkerm**, **Trevisan**, **barrj**, **chenj**, **bgrierson**, **wilkstm**, **eldond**, **thomek**, **hinsone**, **trevisan**, **xiangjian**, **bykovi**, **lizj**, **wangqi**, **xuemiao**, **pablorf**, **ulbl_p**, **logannc**, **xugl**, **duhl**, **liud**, **luoc**, **merlog**, **taylornz**, **churchillr**, **cuil**, **huqiming**, **jsachdev**, **stephanet**, **ashourvana**, **ryoneda**, **adwiteey**, **chenxi**, **jayesh**, **kinsey**, **lizeyu**, **rkalling**, **schmitzl**, **wangyuanzhen**, **beidlerm**, **francisco**, **holcomb**, **johnsonc**, **laggnerf**, **lib**, **nlogan**, **ramanr**, **kostukm**, **lig**, **paz-soldan**, **pipern**, **shoushar**, **teklua**, **tomas**, **zyli**, **clau**, **duxiaodi**, **howardnt**, **jlchen**, **lfluo**, **lupinl**, **vanzee**, **xugs**, **anetepen**, **atom**, **chenji**, **chenm**, **fila**, **holland**, **likai**, **lvovskiya**, **mortonl**, **munarettos**, **odstrcilt**, **qinx**, **wangjun**, **yuguanying**, **zhaodeng**, **zywickib**, **blyons**, **evans**, **houshman**, **jianx**, **krietedm**, **kripner**, **luxin**, **masliner**, **nanshi**, **samuellc**, **shenders**, **turcof**, **wmq**, **xug**, **zhuyiren**, **zhuzj**, **abramst**, **boedo**, **brookmanmw**, **chenjia**, **flaggner**, **gibsons**, **haskeysr**, **izzov**, **prattq**, **rchurchi**, **rosenthala**, **saarelmas**, **sciortinof**, **waij**, **weisbergd**, **wilcoxr**, **yonedar**, **zeng**, **zhangjie**, **zhangp**, **Morton**, **abbatej**, **austinm**, **capitainetema**, **chrystal**, **delcastilloc**, **glassf**, **groebner**, **halfmoon**, **halfmoonm**, **halpernf**, **inyong**, **kongd**, **nave**, **nornbergm**, **ohtaniy**, **orso**, **pandyam**, **snyder**, **ssmith**, **sweeneyrm**, **truongd**, **turnbull**, **vailp**, **wuyifan**, **yfwang**, **zhhwang**, **aashourv**, **asperdut**, **callahank**, **carbinj**, **casalil**, **choiwilkie**, **collinscs**, **degrandchampg**, **eidietis**, **fscotti**, **glassera**, **goodmana**, **gpaganin**, **gugliadav**, **guterlj**, **hengl**, **herfindalj**, **huxing**, **izacardo**, **kleijwegtk**, **lao**, **majorm**, **makowski**, **margomw**, **mboyer**, **pacedc**, **pbonofig**, **peter**, **psinha**, **qianjp**, **root**, **shisy**, **soukhan**, **suzukiy**, **tang31**, **tobiasb**, **unterbee**, **vancompernolle**, **wangzw**, **willensdorferm**, **zamperinis**, **zhangx**, **zhuyilun**, **zyunpeng**, **DarkConscript**, **MHalfmoon**, **afil**, **amaan**, **anyanetui**, **baradakk**, **binchen**, **bortolon**, **briesemeister**, **buttj**, **bzhu**, **candy**, **carpanesef**, **chabanr**, **chenwj**, **cianciosa**, **clementm**, **crocker**, **curtis**, **david**, **dboyle**, **degrassi**, **diems**, **dingrui**, **epaul**, **fenster**, **fyang**, **gagek**, **garofalo**, **hhwang**, **howelle**, **hughesjw**, **hyueheng**, **jeon**, **jgchen**, **jorge**, **josephi**, **kessel**, **kimkyungjin**, **kkirov**, **lammersj**, **lanctot**, **leem**, **lgarzot**, **liua**, **lmorton**, **maxinxing**, **mordijck**, **mroelofs**, **neisert**, **nfil**, **nicholsj**, **nthoward**, **oasunta**, **okabay**, **orlov**, **petty**, **qianzh**, **rea**, **reac**, **renyang**, **rraman**, **sangcf**, **schaeferc**, **sfreethy**, **shaskey**, **shibatay**, **shin**, **shiyf**, **tangs**, **tema**, **u10198**, **vaezip**, **vallar**, **wangzhirui**, **wchoi**, **wdp504**, **wukitchj**, **wumuq**, **wwehner**, **xier**, **xuelei**, **xzhang**, **yangchen**, **yanz**, **yfu**, **yjeon**, **yoshidam**, **zhangjiayuan**, **zhangxx**, **zhaol**, **zhwang**