Preprocessing Inputs

Preprocessing Inputs

Create FIDASIM input files using PREFIDA

FIDASIM requires inputs to be in a specific format. PREFIDA(IDL,Python) is an routine that takes the required inputs, checks their validity, and transforms them into a form FIDASIM understands.

PREFIDA is called as follows

IDL> prefida, inputs, grid, nbi, plasma, fields, dist, spec=spec, npa=npa

or using Python

>>> import preprocessing
>>> preprocessing.prefida(inputs, grid, nbi, plasma, fields, dist, spec=spec, npa=npa)

where arguments are defined as follows. Click the argument description for extreme detail.

PREFIDA will create the following files

  • Namelist File
  • Geometry File
  • Equilibrium File
  • Distribution File

Most devices may have already setup helper routines to make running FIDASIM and Prefida easy. Click here to find out if someone has done your work for you.

Making Grids

PREFIDA uses two types of grids**: the Interpolation Grid and the Beam Grid. By default, axisymmetry is assumed and the Interpolation Grid is a 2D grid in the R-Z plane that is used for interpolating the plasma parameters and the electromagnetic fields. A 3D cylindrical grid in R, Z and Phi can be created if the user inputs phi variable information. The routine rz_grid(IDL,Python) accomplishes the task and creates the grid structure. For example, the command below will create a 2D grid,

IDL> grid = rz_grid(rmin,rmax,nr,zmin,zmax,nz)

whereas the following command will create a 3D grid,

IDL> grid = rz_grid(rmin,rmax,nr,zmin,zmax,nz,phimin=phimin,phimax=phimax,nphi=nphi)

In Python, the 2D grid can be created with,

>>> from fidasim.utils import rz_grid
>>> grid = rz_grid(rmin,rmax,nr,zmin,zmax,nz)

and the 3D grid with,

>>> from fidasim.utils import rz_grid
>>> grid = rz_grid(rmin,rmax,nr,zmin,zmax,nz,phimin=phimin,phimax=phimax,nphi=nphi)

The output 2D grid structure will have Phi = 0.0 and nphi = 1, but the 3D grid structure will have values based on what the user input.

The beam grid is a 3D grid used for most of the calculations in FIDASIM. It represents the 3D volume where the neutral beam lives and interacts with the plasma. To maximize the resolution of this grid it is useful to align the beam grid with the beam centerline. The routine beam_grid(IDL,Python) calculates from the neutral beam geometry the optimal beam grid settings that would align the grid with the beam sightline.

IDL> bgrid = beam_grid(nbi,rstart)

or in Python

>>> from fidasim.utils import beam_grid
>>> bgrid = beam_grid(nbi,rstart)

FIDASIM creates a third grid for passive calculations.

Reading GEQDSK files

Most tokamaks use EFIT to reconstruct the MHD equilibrium. To make things easy we provide the IDL routine read_geqdsk.pro to calculate the fields structure from EFITs GEQDSK file.

IDL> fields = read_geqdsk('g159243.00300',grid,rho=rho,btipsign=btipsign)

or in Python

>>> from fidasim.utils import read_geqdsk
>>> fields, rho, btipsign = read_geqdsk('g159243.00300',grid)

where grid is the interpolation grid, rho keyword is a named variable that recieves the sqrt(normalized torodial flux) upon executation, and btipsign is a named variable that recieves the Bt-Ip sign (-1 for anti-parallel, 1 for parallel).

Extracting GEQDSK file and Plasma Parameters from TRANSP

It is convenient to grab FIDASIM inputs from previously calculated TRANSP runs.

The python script, extract_transp_geqdsk, can be used to extract the MHD equilibrium from TRANSP's .DATA* files. For example:

extract_transp_geqdsk /p/transparch/result/NSTX/14 159243H06 

will create a GEQDSK file for every .DATA* file in the 159243H06 TRANSP run. Run extract_transp_geqdsk -h for the full documentation.

The IDL routine extract_transp_plasma.pro or the equivalent Python function creates the plasma structure at a given time.

IDL> plasma = extract_transp_plasma("159243H06.CDF",1.02,grid,rho)

or in Python

>>> from fidasim.utils import extract_transp_plasma
>>> plasma = extract_transp_plasma("159243H06.CDF",1.02,grid,rho)

where grid is the interpolation grid and rho is the sqrt(normalized torodial flux).

Translating NUBEAM Neutral Beam Geometry

The IDL routine nubeam_geometry.pro can be used to translate the NUBEAM neutral beam geometry definition into the correct format.

IDL> nbi = nubeam_geometry(nubeam)

or in Python

>>> from fidasim.utils import nubeam_geometry
>>> nbi = nubeam_geometry(nubeam)

where nubeam is a structure/dictionary containing the NUBEAM geometry variables taken from the TRANSP namelist.

Extracting the Fast-ion Distribution Function from TRANSP/NUBEAM

The python script, extract_transp_fbm, provides a easy way to extract the fast-ion distribution. For example:

extract_transp_fbm /p/transparch/result/NSTX/14 159243H06

extracts a distribution function for every .DATA* file in the 159243H06 TRANSP run. Run extract_transp_fbm -h for the full documentation.

Reading NUBEAM/SPIRAL Fast-ion Distributions

Out of the box, FIDASIM provides IDL and Python routines for reading different fast-ion distributions. We provide routines for:

IDL> f = read_nubeam(nubeam_distribution_file,grid,btipsign = -1) 
IDL> mcf = read_mc_nubeam(mc_nubeam_distribution_file,Ntotal=1e19,btipsign=-1)
IDL> s = read_spiral(spiral_file,Ntotal=1e19,btipsign=-1)

or in Python

>>> from fidasim.utils import read_nubeam
>>> f = read_nubeam(nubeam_distribution_file, grid, btipsign=-1)

Visualization: Inputs

Visualizing your inputs can be done by executing plot_inputs found in lib/scripts/

Depending on what you wish to plot, your inputs, geometry, equilibrium and/or distribution files will need to be located in the same folder. Below are brief descriptions and examples of what the script can currently handle:

To plot all of your inputs, simply indicate the directory and run ID.

plot_inputs /p/fida/lstagner/TEST/ test_1a

To plot only the beam and diagnostic geometry, append the optional argument -g

plot_inputs /p/fida/lstagner/TEST/ test_1a -g

In a similar fashion, append -p, -f and/or -d to plot the plasma, fields and/or distribution function inputs, respectively.

If you are plotting many FIDA or NPA line of sights, then it might be beneficial for you to append -l to remove the legend from the 3D plot.

If you wish to plot lineouts on your figures, simply indicate the value and dimension you want to cut through. For example, if you are interested in seeing what the plasma lineout looks like at R = 170 cm along the z axis, execute the following command

plot_inputs /p/fida/lstagner/TEST/ test_1a -p -rz 170

There are many more possible lineouts that can be viewed, so run plot_inputs -h to look at the help documentation.