ASCOT5
Loading...
Searching...
No Matches
Functions
mhd.c File Reference

MHD module interface. More...

#include <stdlib.h>
#include "ascot5.h"
#include "error.h"
#include "print.h"
#include "mhd.h"
#include "B_field.h"
#include "boozer.h"
#include "mhd/mhd_stat.h"
#include "mhd/mhd_nonstat.h"

Go to the source code of this file.

Functions

int mhd_init_offload (mhd_offload_data *offload_data, real **offload_array)
 Load MHD data and prepare parameters.
 
void mhd_free_offload (mhd_offload_data *offload_data, real **offload_array)
 Free offload array and reset parameters.
 
int mhd_init (mhd_data *mhddata, mhd_offload_data *offload_data, real *offload_array)
 Initialize MHD data struct on target.
 
a5err mhd_eval (real mhd_dmhd[10], real r, real phi, real z, real t, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
 Evaluate the needed quantities from MHD mode for orbit following.
 
a5err mhd_perturbations (real pert_field[7], real r, real phi, real z, real t, int pertonly, int includemode, boozer_data *boozerdata, mhd_data *mhddata, B_field_data *Bdata)
 Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.
 
int mhd_get_n_modes (mhd_data *mhddata)
 Return number of modes.
 
const int * mhd_get_nmode (mhd_data *mhddata)
 Return mode toroidal numbers.
 
const int * mhd_get_mmode (mhd_data *mhddata)
 Return mode poloidal numbers.
 
const realmhd_get_amplitude (mhd_data *mhddata)
 Return mode amplitudes.
 
const realmhd_get_frequency (mhd_data *mhddata)
 Return mode frequencies.
 
const realmhd_get_phase (mhd_data *mhddata)
 Return mode phases.
 

Detailed Description

MHD module interface.

This is an interface through which MHD data is initialized and accessed. Reading e.g. from disk is done elsewhere. The MHD module produces helical EM perturbations in to the EM field using the boozer module in making the coordinate transformations between cylindrical and straight-field-line coordinates.

To add a new MHD instance, make sure these functions are implemented and called from this interface, and that mhd.h contains enum type for the new instance.

The interface checks which instance given data corresponds to from mhd_offload_data.type and mhd_data.type from the struct that is given as an argument, and calls the relevant function for that instance.

Definition in file mhd.c.

Function Documentation

◆ mhd_init_offload()

int mhd_init_offload ( mhd_offload_data * offload_data,
real ** offload_array )

Load MHD data and prepare parameters.

This function fills the relevant MHD offload struct with parameters and allocates and fills the offload array.

The offload data has to have a type when this function is called as it should be set when the offload data is constructed from inputs.

This function is host only.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to pointer to offload array
Returns
zero if initialization succeeded

Definition at line 45 of file mhd.c.

◆ mhd_free_offload()

void mhd_free_offload ( mhd_offload_data * offload_data,
real ** offload_array )

Free offload array and reset parameters.

This function deallocates the offload_array.

This function is host only.

Parameters
offload_datapointer to offload data struct
offload_arraypointer to pointer to offload array

Definition at line 90 of file mhd.c.

◆ mhd_init()

int mhd_init ( mhd_data * mhddata,
mhd_offload_data * offload_data,
real * offload_array )

Initialize MHD data struct on target.

This function copies the electric field parameters from the offload struct to the struct on target and sets the MHD data pointers to correct offsets in the offload array.

This function returns error if the offload data has not been initialized. The instances themselves should not return an error since all they do is assign pointers and values.

Parameters
mhddatapointer to data struct on target
offload_datapointer to offload data struct
offload_arraythe offload array
Returns
Non-zero integer if offload was not initialized beforehand

Definition at line 121 of file mhd.c.

◆ mhd_eval()

a5err mhd_eval ( real mhd_dmhd[10],
real r,
real phi,
real z,
real t,
int includemode,
boozer_data * boozerdata,
mhd_data * mhddata,
B_field_data * Bdata )

Evaluate the needed quantities from MHD mode for orbit following.

The quantities to be evaluated are alpha, phi, grad alpha, grad phi, partial t alpha, partial t phi

The values are stored in the given array as:

  • mhd_dmhd[0] = alpha
  • mhd_dmhd[1] = dalpha/dt
  • mhd_dmhd[2] = grad alpha, r component
  • mhd_dmhd[3] = grad alpha, phi component
  • mhd_dmhd[4] = grad alpha, z component
  • mhd_dmhd[5] = phi
  • mhd_dmhd[6] = dphi/dt
  • mhd_dmhd[7] = grad phi, r component
  • mhd_dmhd[8] = grad phi, phi component
  • mhd_dmhd[9] = grad phi, z component
Parameters
mhd_dmhd
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
ttime coordinate [s]
includemodemode number to be included or MHD_INCLUDE_ALL
boozerdatapointer to boozer data
mhddatapointer to mhd data
Bdatapointer to magnetic field data
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 178 of file mhd.c.

◆ mhd_perturbations()

a5err mhd_perturbations ( real pert_field[7],
real r,
real phi,
real z,
real t,
int pertonly,
int includemode,
boozer_data * boozerdata,
mhd_data * mhddata,
B_field_data * Bdata )

Evaluate perturbed fields Btilde, Etilde and potential Phi explicitly.

The values are stored in the given array as

  • pert_field[0] = BtildeR
  • pert_field[1] = BtildePhi
  • pert_field[2] = BtildeZ
  • pert_field[3] = EtildeR
  • pert_field[4] = EtildePhi
  • pert_field[5] = EtildeZ
  • pert_field[6] = Phi

Only the perturbation values for the magnetic field are returned if pertonly=1, otherwise, the total perturbed field is returned. This is done to avoid double evaluation of the magnetic field e.g. in field line tracing. For electric field only the perturbation component is returned always.

Parameters
pert_fieldperturbation field components
rR coordinate [m]
phiphi coordinate [rad]
zz coordinate [m]
ttime coordinate [s]
pertonlyflag whether to return the whole field or only perturbation
includemodemode number to be included or MHD_INCLUDE_ALL
boozerdatapointer to boozer data
mhddatapointer to mhd data
Bdatapointer to magnetic field data
Returns
Non-zero a5err value if evaluation failed, zero otherwise

Definition at line 234 of file mhd.c.

◆ mhd_get_n_modes()

int mhd_get_n_modes ( mhd_data * mhddata)

Return number of modes.

Parameters
mhddatapointer to mhd data
Returns
number of modes

Definition at line 270 of file mhd.c.

◆ mhd_get_nmode()

const int * mhd_get_nmode ( mhd_data * mhddata)

Return mode toroidal numbers.

Parameters
mhddatapointer to mhd data
Returns
mode n numbers

Definition at line 290 of file mhd.c.

◆ mhd_get_mmode()

const int * mhd_get_mmode ( mhd_data * mhddata)

Return mode poloidal numbers.

Parameters
mhddatapointer to mhd data
Returns
mode m numbers

Definition at line 310 of file mhd.c.

◆ mhd_get_amplitude()

const real * mhd_get_amplitude ( mhd_data * mhddata)

Return mode amplitudes.

Parameters
mhddatapointer to mhd data
Returns
mode amplitudes

Definition at line 330 of file mhd.c.

◆ mhd_get_frequency()

const real * mhd_get_frequency ( mhd_data * mhddata)

Return mode frequencies.

Parameters
mhddatapointer to mhd data
Returns
mode omega

Definition at line 350 of file mhd.c.

◆ mhd_get_phase()

const real * mhd_get_phase ( mhd_data * mhddata)

Return mode phases.

Parameters
mhddatapointer to mhd data
Returns
mode phases

Definition at line 370 of file mhd.c.