ASCOT5
Loading...
Searching...
No Matches
Macros | Functions
hdf5_bfield.c File Reference

Module for reading magnetic field data from HDF5 file. More...

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <hdf5.h>
#include <hdf5_hl.h>
#include "../ascot5.h"
#include "../print.h"
#include "../consts.h"
#include "../B_field.h"
#include "../Bfield/B_2DS.h"
#include "../Bfield/B_3DS.h"
#include "../Bfield/B_STS.h"
#include "../Bfield/B_TC.h"
#include "../Bfield/B_GS.h"
#include "hdf5_helpers.h"
#include "hdf5_bfield.h"

Go to the source code of this file.

Macros

#define BPATH
 
#define BPATH   "/bfield/B_2DS_XXXXXXXXXX/"
 
#define BPATH   "/bfield/B_3DS_XXXXXXXXXX/"
 
#define BPATH   "/bfield/B_STS_XXXXXXXXXX/"
 
#define BPATH   "/bfield/B_TC_XXXXXXXXXX/"
 
#define BPATH   "/bfield/B_GS_XXXXXXXXXX/"
 

Functions

int hdf5_bfield_read_2DS (hid_t f, B_2DS_offload_data *offload_data, real **offload_array, char *qid)
 Read magnetic field data of type B_2DS.
 
int hdf5_bfield_read_3DS (hid_t f, B_3DS_offload_data *offload_data, real **offload_array, char *qid)
 Read magnetic field data of type B_3DS.
 
int hdf5_bfield_read_STS (hid_t f, B_STS_offload_data *offload_data, real **offload_array, char *qid)
 Read magnetic field data of type B_STS.
 
int hdf5_bfield_read_TC (hid_t f, B_TC_offload_data *offload_data, real **offload_array, char *qid)
 Read magnetic field data of type B_TC.
 
int hdf5_bfield_read_GS (hid_t f, B_GS_offload_data *offload_data, real **offload_array, char *qid)
 Read magnetic field data of type B_GS.
 
int hdf5_bfield_init_offload (hid_t f, B_field_offload_data *offload_data, real **offload_array, char *qid)
 Initialize magnetic field offload data from HDF5 file.
 

Detailed Description

Module for reading magnetic field data from HDF5 file.

This module contains routines to read magnetic field data from ASCOT5 HDF5 file. The reading is done by calling hdf5_bfield_init_offload() which reads the data and uses that to initialize the offload data.

Note: the routines within this module that read the data from HDF5 file may use the offload data struct and offload arrays as (temporary) storage. However, the actual initialization is done at the specific B_field_init_offload() function the magnetic field data corresponds to. Check from that function what the offload data and the offload array are expected to contain. As a rule of thumb, the reading routines here should only read the data and maybe do some trivial computations but nothing complicated.

Definition in file hdf5_bfield.c.

Macro Definition Documentation

◆ BPATH [1/6]

#define BPATH

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

◆ BPATH [2/6]

#define BPATH   "/bfield/B_2DS_XXXXXXXXXX/"

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

◆ BPATH [3/6]

#define BPATH   "/bfield/B_3DS_XXXXXXXXXX/"

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

◆ BPATH [4/6]

#define BPATH   "/bfield/B_STS_XXXXXXXXXX/"

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

◆ BPATH [5/6]

#define BPATH   "/bfield/B_TC_XXXXXXXXXX/"

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

◆ BPATH [6/6]

#define BPATH   "/bfield/B_GS_XXXXXXXXXX/"

Macro that is used to store paths to data groups

Definition at line 35 of file hdf5_bfield.c.

Function Documentation

◆ hdf5_bfield_read_2DS()

int hdf5_bfield_read_2DS ( hid_t f,
B_2DS_offload_data * offload_data,
real ** offload_array,
char * qid )

Read magnetic field data of type B_2DS.

The B_2DS data is stored in HDF5 file under the group /bfield/B_2DS_XXXXXXXXXX/ where X's mark the QID.

This function assumes the group holds the following datasets:

  • int nr Number of R grid points in the magnetic field grid
  • int nz Number of z grid points in the magnetic field grid
  • double rmin Minimum value in R grid [m]
  • double rmax Maximum value in R grid [m]
  • double zmin Minimum value in z grid [m]
  • double zmax Maximum value in z grid [m]
  • double axisr Magnetic axis R coordinate [m]
  • double axisz Magnetic axis z coordinate [m]
  • double psi0 Poloidal magnetic flux value on magnetic axis [V*s*m^-1]
  • double psi1 Poloidal magnetic flux value on separatrix [V*s*m^-1]
  • double psi Poloidal magnetic flux on the Rz-grid as a {nz, nR} matrix [V*s*m^-1]
  • double br Magnetic field R component on the Rz-grid as a {nz, nR} matrix [T]
  • double bphi Magnetic field R component on the Rz-grid as a {nz, nR} matrix [T]
  • double bz Magnetic field R component on the Rz-grid as a {nz, nR} matrix [T]
Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is allocated here
offload_arraypointer to offload array which is allocated here and used to store psi, B_R, B_phi, and B_z values as required by B_2DS_init_offload()
qidQID of the B_2DS field that is to be read
Returns
zero if reading succeeded

Definition at line 157 of file hdf5_bfield.c.

◆ hdf5_bfield_read_3DS()

int hdf5_bfield_read_3DS ( hid_t f,
B_3DS_offload_data * offload_data,
real ** offload_array,
char * qid )

Read magnetic field data of type B_3DS.

The B_3DS data is stored in HDF5 file under the group /bfield/B_3DS-XXXXXXXXXX/ where X's mark the QID.

This function assumes the group holds the following datasets: (B data refers to $B_R$, $B_phi$, and $B_z$ and psi data to $\psi$.)

  • int nr Number of R grid points in the B data grid
  • int nphi Number of phi grid points in the B data grid
  • int nz Number of z grid points in the B data grid
  • double b_rmin Minimum value in B data R grid [m]
  • double b_rmax Maximum value in B data R grid [m]
  • double b_phimin Minimum value in B data phi grid [deg]
  • double b_phimax Maximum value in B data phi grid [deg]
  • double b_zmin Minimum value in B data z grid [m]
  • double b_zmax Maximum value in B data z grid [m]
  • int b_nr Number of R grid points in the psi data grid
  • int psi_nz Number of z grid points in the psi data grid
  • double ps_rmin Minimum value in psi data R grid [m]
  • double psi_rmax Maximum value in psi data R grid [m]
  • double psi_zmin Minimum value in psi data z grid [m]
  • double psi_zmax Maximum value in psi data z grid [m]
  • double axisr Magnetic axis R coordinate [m]
  • double axisz Magnetic axis z coordinate [m]
  • double psi0 Poloidal magnetic flux value on magnetic axis [V*s*m^-1]
  • double psi1 Poloidal magnetic flux value on separatrix [V*s*m^-1]
  • double psi Poloidal magnetic flux on the Rz-grid as a {psi_nz, psi_nr} matrix [V*s*m^-1]
  • double br Magnetic field R component on the Rz-grid as a {b_nz, b_nphi, b_nr} matrix [T]
  • double bphi Magnetic field R component on the Rz-grid as a {b_nz, b_nphi, b_nr} matrix [T]
  • double bz Magnetic field R component on the Rz-grid as a {b_nz, b_nphi, b_nr} matrix [T]
Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is allocated here
offload_arraypointer to offload array which is allocated here and used to store psi, B_R, B_phi, and B_z values as required by B_3DS_init_offload()
qidQID of the B_3DS field that is to be read
Returns
zero if reading succeeded

Definition at line 256 of file hdf5_bfield.c.

◆ hdf5_bfield_read_STS()

int hdf5_bfield_read_STS ( hid_t f,
B_STS_offload_data * offload_data,
real ** offload_array,
char * qid )

Read magnetic field data of type B_STS.

The B_STS data is stored in HDF5 file under the group /bfield/B_STS_XXXXXXXXXX/ where X's mark the QID.

This function assumes the group holds the following datasets: (B data refers to $B_R$, $B_phi$, and $B_z$ and psi data to $\psi$.)

  • int nr Number of R grid points in the B data grid
  • int nphi Number of phi grid points in the B data grid
  • int nz Number of z grid points in the B data grid
  • double b_rmin Minimum value in B data R grid [m]
  • double b_rmax Maximum value in B data R grid [m]
  • double b_phimin Minimum value in B data phi grid [deg]
  • double b_phimax Maximum value in B data phi grid [deg]
  • double b_zmin Minimum value in B data z grid [m]
  • double b_zmax Maximum value in B data z grid [m]
  • int psi_nr Number of R grid points in the psi data grid
  • int psi_nphi Number of phi grid points in the psi data grid
  • int psi_nz Number of z grid points in the psi data grid
  • double psi_rmin Minimum value in psi data R grid [m]
  • double psi_rmax Maximum value in psi data R grid [m]
  • double psi_phimin Minimum value in psi data phi grid [deg]
  • double psi_phimax Maximum value in psi data phi grid [deg]
  • double psi_zmin Minimum value in psi data z grid [m]
  • double psi_zmax Maximum value in psi data z grid [m]
  • int n_axis Number of phi grid points in the magnetic axis data grid
  • double axis_min Minimum value in magnetic axis data phi grid [deg]
  • double axis_max Maximum value in magnetic axis data phi grid [deg]
  • double psi0 Poloidal magnetic flux value on magnetic axis [V*s*m^-1]
  • double psi1 Poloidal magnetic flux value on separatrix [V*s*m^-1]
  • double psi Poloidal magnetic flux on the Rpz-grid as a {psi_nphi, psi_nz, psi_nr} matrix [V*s*m^-1]
  • double br Magnetic field R component on the Rpz-grid as a {b_nphi, b_nz, b_nr} matrix [T]
  • double bphi Magnetic field R component on the Rpz-grid as a {b_nphi, b_nz, b_nr} matrix [T]
  • double bz Magnetic field R component on the Rpz-grid as a {b_nphi, b_nz, b_nr} matrix [T]
  • double axis_R Magnetic axis R location as a {n_axis} vector [m]
  • double axis_z Magnetic axis R location as a {n_axis} vector [m]
  • int toroidalPeriods Fraction of the device the data represents.
Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is allocated here
offload_arraypointer to offload array which is allocated here and used to store psi, B_R, B_phi, B_z, axis_r, and axis_z values as required by B_STS_init_offload()
qidQID of the B_STS field that is to be read
Returns
zero if reading succeeded

Definition at line 395 of file hdf5_bfield.c.

◆ hdf5_bfield_read_TC()

int hdf5_bfield_read_TC ( hid_t f,
B_TC_offload_data * offload_data,
real ** offload_array,
char * qid )

Read magnetic field data of type B_TC.

The B_TC data is stored in HDF5 file under the group /bfield/B_TC_XXXXXXXXXX/ where X's mark the QID.

This function assumes the group holds the following datasets:

  • double axisr A value that is returned when magnetic axis R coordinate is requested [m]
  • double axisz A value that is returned when magnetic axis z coordinate is requested [m]
  • double psival A value that is returned when poloidal magnetic flux value is requested [V*s*m^-1]
  • double rhoval A value that is returned when normalized poloidal flux value is requested
  • double Bxyz Magnetic field values at origo: [B_x, B_y, B_z] [T]
  • double jacobian Magnetic field Jacobian [dB_x/dx, dB_x/dy, dB_x/dz, dB_y/dx, dB_y/dy, dB_y/dz, dB_z/dx, dB_z/dy, dB_z/dz] [T/m]
Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is allocated here
offload_arraypointer to offload array but no data is stored there so it is not allocated and NULL pointer is returned instead
qidQID of the B_TC field that is to be read
Returns
zero if reading succeeded

Definition at line 533 of file hdf5_bfield.c.

◆ hdf5_bfield_read_GS()

int hdf5_bfield_read_GS ( hid_t f,
B_GS_offload_data * offload_data,
real ** offload_array,
char * qid )

Read magnetic field data of type B_GS.

The B_GS data is stored in HDF5 file under the group /bfield/B_GS_XXXXXXXXXX/ where X's mark the QID.

This function assumes the group holds the following datasets:

  • double r0 Magnetic axis R coordinate [m]
  • double z0 Magnetic axis z coordinate [m]
  • double bphi0 Toroidal magnetic field value at magnetic axis [T]
  • double psi0 Poloidal flux value at magnetic axis [V*s*m^-1]
  • double psi1 Poloidal flux value at separatrix [V*s*m^-1]
  • double psi_mult Scaling factor for psi
  • double coefficients Coefficients for evaluating psi [c_1, c_2, ..., c_12, A]
  • double delta0 Ripple strength
  • double alpha0 Ripple penetration
  • double a0 Minor radius [m]
  • int nripple Number of toroidal field coils
Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is allocated here
offload_arraypointer to offload array but no data is stored there so it is not allocated and NULL pointer is returned instead
qidQID of the B_GS field that is to be read
Returns
zero if reading succeeded

Definition at line 584 of file hdf5_bfield.c.

◆ hdf5_bfield_init_offload()

int hdf5_bfield_init_offload ( hid_t f,
B_field_offload_data * offload_data,
real ** offload_array,
char * qid )

Initialize magnetic field offload data from HDF5 file.

This function determines to which type of magnetic field the given QID corresponds to, and calls the corresponding reading routine. The read data is then used to initialize the offload data by calling B_field_init_offload().

The magnetic field data is stored under /bfield/ group in ASCOT5 HDF5 file. Several magnetic fields of same or different type maybe stored there in their respective groups as long as the group name contains QID as an identifier.

Parameters
fHDF5 file identifier for a file which is opened and closed outside of this function
offload_datapointer to offload data struct which is initialized here
offload_arraypointer to offload array which is allocated and initialized here
qidQID of the data that is to be read
Returns
zero if reading and initialization succeeded

Definition at line 69 of file hdf5_bfield.c.