XGC1
Functions/Subroutines | Variables
ptb_3db_module Module Reference

The module "ptb_3db" contains the framework for handling perturbed 3D magnetic fields in XGCa and XGC1. More...

Functions/Subroutines

subroutine read_3db_test (As_vac, explicit_em_int)
 Sets up an analytical magnetic field perturbation with fixed toroidal mode number and (currently) 2 poloidal mode numbers. The number of poloidal mode numbers can be adjusted with few code changes. The most important parameters are the value of the poloidal mode numbers, the centers of the Gaussian envelopes of each mode number, the width of the Gaussian, and the amplitude. More...
 
subroutine read_3db_m3dc1_mesh ()
 Allocates memory for and reads perturbed field data from M3D-C1 file. For M3D-C1 input, the fusion-io library by N. Ferraro is used. The interpolation used in the fusion-io library keeps the field divergence free. More...
 
subroutine read_3db_m3dc1_rz ()
 Allocates memory for and reads perturbed field data from M3D-C1 file. This version of the routine reads the vector potential A on an (R,Z) grid. The perturbed field on the XGC mesh can be evaluated in a separate subroutine. Eventually, the perturbed magnetic field is to be calculated directy from A using spline interpolation. For M3D-C1 input, the fusion-io library by N. Ferraro is used. More...
 
subroutine extract_resonant_vector_potential_from_m3dc1 (itor, As_vac)
 Extension of RZ reader for EM Use RZ reader to read the full vector potential from M3D-C1. For EM, proeceed to extract the (near) resonant components of \(A_\parallel\) (A_parallel) on the XGC mesh. Interpolate those back to the RZ grid and subtract from the raw vector potential from M3D-C1. Then re-initialize the spline interpolation for A. This enables pushing particles with the full M3D-C1 field while still calculating the plasma response to the near resonant modes. As a stop-gap measure, the such filtered vector potential is used to calculate the perturbed field on the XGC mesh because the spline interpolation of the vector potential on the RZ grid is not available in C++ yet. This currently works only for single toroidal mode number input. Extending it to multiple mode numbers seems straightforward. More...
 
subroutine extract_resonant_vector_potential_from_m3dc1_p2 (itor, As_vac, As_vac_full)
 
subroutine read_3db_m3dc1_eem (As_vac)
 Allocates memory for and reads perturbed field data from M3D-C1 file for use with the explicit EM method. This reader reads only the parallel component of the perturbed vacuum vector potential for a single toroidal mode number. More...
 
real(kind=8) function ptb_3db_screening_factor (r, z, psi)
 Evaluates the screening factor for artificial exponential damping of the vacuum perturbed field towards the magnetic axis. The screening shape function is simply exp((psi-psi0)/w). Since psi decreases towards the magnetic axis, psi-psi0 becomes negative at some point. More...
 
subroutine ptb_3db_calc_db (grid, dA_phi, dB_re, dB_im)
 Evaluates the perturbed field from the perturbed vector potential on the XGC grid. More...
 
subroutine update_3db (rampup_fac, gstep, time)
 Updates the ramp-up factor of the vacuum RMP field. The external (or vacuum) RMP field can be ramped up linearly instead of a hard switch from off to on. The ramp-up factor ptb_3db_rampup_fac determines the amplitude of the external RMP field throughout XGC. This routine is used only in electrostatic simulations. In electromagnetic simulations, push_As updates the ramp-up factor. More...
 
subroutine ptb_3db_damping_factor_em (Apar, dApar, rampup_fac, time)
 Calculates an adaptive damping factor to limit the time rate of change of the perturbed vector potential The routine calculates the poloidal Fourier spectrum of the current increment of the vector potential (dApar --> effectively the Hamiltonian vector potential Ah) and the vector potential itself (Apar). Then it compares the amplitude of the increment and the current value and computes a damping factor for each poloidal mode number such that the increment is limited to be a fraction of the current value. Using this damping factor, the increment is transformed back to real space and returned to the calling routine. More...
 

Variables

integer ptb_3db_mode =0
 Mode of operation: (0) static RMP field (ES), or fully self-consistent RMP field (EM version) (2) self-consistent RMP field with time-averaged field-equations (EM version) More...
 
character(len=250) ptb_3db_filename ='C1.h5'
 File containing the perturbed field data. More...
 
logical ptb_3db_single_mode_input =.true.
 For M3D-C1 input; If .true., M3D-C1 file contains only one toroidal mode number. More...
 
integer ptb_3db_single_mode_ntor =3
 The mode number in the M3D-C1 file in case of single mode input. More...
 
real(kind=8) ptb_3db_mult_factor =1D0
 Factor for scaling the perturbed field. More...
 
integer ptb_3db_m3dc1_timeslice =1
 Time slice that is to be read from M3D-C1 file. More...
 
integer ptb_3db_mstep_es =0
 Number of ES time steps in RMP penetration calculation with ptb_3db_mode==2. More...
 
integer ptb_3db_mstep_em =1
 Number of EM time steps in RMP penetration calculation with ptb_3db_mode==2. More...
 
integer ptb_3db_es_to_em_dt_ratio =1
 Ratio of ES to EM time step size in RMP penetration calculation with ptb_3db_mode==2 (also: the number of time steps over which the perturbed current is averaged) More...
 
real(kind=8) ptb_3db_update_alpha =1.0D0
 Damping factor for update of the perturbed field. More...
 
integer ptb_3db_start_time =1
 Time step in which perturbed field is switched on. More...
 
logical ptb_3db_rampup_vac =.true.
 (.true.) Ramp up perturbed field slowly, (.false.) turn on perturbed field abruptly More...
 
integer ptb_3db_rampup_time =1000
 Number of time steps over which the perturbed field is ramped up. More...
 
logical ptb_3db_screening_on =.false.
 Artificial screening for static RMP field: (.false.) no screening, (.true.) exponential damping towards the axis. More...
 
real(kind=8) ptb_3db_screening_width1 =0.02D0
 Decay length of the exponential damping function in units of normalized poloidal flux. More...
 
real(kind=8) ptb_3db_screening_width2 =0.02D0
 Width of tanh for damping in the core in units of normalized poloidal flux. More...
 
real(kind=8) ptb_3db_screening_psi1 =0.975D0
 Center of the tanh function for screening in the core (<1) More...
 
real(kind=8) ptb_3db_screening_fac1 =0.9D0
 Reduction of deltaB at the separatrix (<=1) More...
 
real(kind=8) ptb_3db_screening_fac2 =0.8D0
 Fraction of vacuum RMP in the core (<=1) More...
 
integer ptb_3db_num_ntor =1
 Number of toroidal mode numbers (<= sml_nphi_total) More...
 
integer, dimension(:), allocatable, target ptb_3db_ntor
 Array to store the toroidal mode numbers. More...
 
integer ptb_3db_ntor_min =3
 smallest toroidal mode number More...
 
integer ptb_3db_num_mpol =30
 Number of poloidal mode numbers. More...
 
integer, dimension(:), allocatable ptb_3db_mpol
 Array to store the poloidal mode numbers. More...
 
integer ptb_3db_nr =1000
 (R,Z) grid size in R-direction More...
 
integer ptb_3db_nz =1000
 (R,Z) grid size in Z-direction More...
 
real(kind=8) ptb_3db_r_min
 
real(kind=8) ptb_3db_r_max
 Range of R in (R,Z) grid. More...
 
real(kind=8) ptb_3db_z_min
 
real(kind=8) ptb_3db_z_max
 Range of Z in (R,Z) grid. More...
 
real(kind=8) ptb_3db_dr
 
real(kind=8) ptb_3db_dz
 grid spacing of (R,Z) grid More...
 
real(kind=8), dimension(:,:,:), allocatable, target ptb_3db_bfield_re_vac
 perturbed vacuum field on XGC mesh, real part, dimensions: (grid vertex, R-Z-phi components, tor. mode number) More...
 
real(kind=8), dimension(:,:,:), allocatable, target ptb_3db_bfield_im_vac
 perturbed vacuum field on XGC mesh, imaginary part More...
 
real(kind=8), dimension(:,:,:,:), allocatable ptb_3db_vecpot_re_vac_rz
 perturbed vacuum vector potential on (R,Z) mesh, real part More...
 
real(kind=8), dimension(:,:,:,:), allocatable ptb_3db_vecpot_im_vac_rz
 perturbed vacuum vector potential on (R,Z) mesh, imaginary part More...
 
real(kind=8), dimension(:), allocatable ptb_3db_rgrid
 
real(kind=8), dimension(:), allocatable ptb_3db_zgrid
 R and Z grid in case of (R,Z) input data. More...
 
type(ezspline2_r8), dimension(:,:), allocatable ptb_3db_vecpot_spl_rz_re
 Spline for interpolation of the real part of (R,Z) data to XGC mesh. More...
 
type(ezspline2_r8), dimension(:,:), allocatable ptb_3db_vecpot_spl_rz_im
 Spline for interpolation of the imaginary part of (R,Z) data to XGC mesh. More...
 
type(ezspline2_r8) ptb_3db_spl_tmp
 Dummy 2D spline used for setting up the 2D interpolations with bicub_mod. More...
 
type(bicub_type), dimension(:,:,:), allocatable ptb_3db_bicub_da
 Spline for interpolation of the perturbed vector potential with bicub_mod. More...
 

Detailed Description

The module "ptb_3db" contains the framework for handling perturbed 3D magnetic fields in XGCa and XGC1.

Function/Subroutine Documentation

◆ extract_resonant_vector_potential_from_m3dc1()

subroutine ptb_3db_module::extract_resonant_vector_potential_from_m3dc1 ( integer, intent(in), value  itor,
real (kind=8), dimension(grid%nnode), intent(inout)  As_vac 
)

Extension of RZ reader for EM Use RZ reader to read the full vector potential from M3D-C1. For EM, proeceed to extract the (near) resonant components of \(A_\parallel\) (A_parallel) on the XGC mesh. Interpolate those back to the RZ grid and subtract from the raw vector potential from M3D-C1. Then re-initialize the spline interpolation for A. This enables pushing particles with the full M3D-C1 field while still calculating the plasma response to the near resonant modes. As a stop-gap measure, the such filtered vector potential is used to calculate the perturbed field on the XGC mesh because the spline interpolation of the vector potential on the RZ grid is not available in C++ yet. This currently works only for single toroidal mode number input. Extending it to multiple mode numbers seems straightforward.

Parameters
[in]gridXGC mesh object, type(grid_type)
[in,out]psnXGC field object, type(psn_type)
[in]itorIndex of targeted mode number, integer
Here is the call graph for this function:

◆ extract_resonant_vector_potential_from_m3dc1_p2()

subroutine ptb_3db_module::extract_resonant_vector_potential_from_m3dc1_p2 ( integer, intent(in), value  itor,
real(8), dimension(grid%nnode,2), intent(in)  As_vac,
real(8), dimension(grid%nnode), intent(in)  As_vac_full 
)
Here is the call graph for this function:

◆ ptb_3db_calc_db()

subroutine ptb_3db_module::ptb_3db_calc_db ( type(grid_type), intent(in)  grid,
real (kind=8), dimension(grid%nnode,2,ptb_3db_num_ntor), intent(in)  dA_phi,
real (kind=8), dimension(3,grid%nnode,ptb_3db_num_ntor), intent(out)  dB_re,
real (kind=8), dimension(3,grid%nnode,ptb_3db_num_ntor), intent(out)  dB_im 
)

Evaluates the perturbed field from the perturbed vector potential on the XGC grid.

Parameters
grid(in) type(grid_type), grid data
dA_phi(in) real(8), perturbed vector potential (dA_phi, covariant phi-component)
dB_re(out) real(8), real (cos) part of the perturbed mag. field
dB_im(out) real(8), imaginary (sin) part of the perturbed mag. field
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ptb_3db_damping_factor_em()

subroutine ptb_3db_module::ptb_3db_damping_factor_em ( real(kind=8), dimension(grid%nnode), intent(in)  Apar,
real(kind=8), dimension(grid%nnode), intent(inout)  dApar,
real(kind=8), intent(in), value  rampup_fac,
real(8), intent(in), value  time 
)

Calculates an adaptive damping factor to limit the time rate of change of the perturbed vector potential The routine calculates the poloidal Fourier spectrum of the current increment of the vector potential (dApar --> effectively the Hamiltonian vector potential Ah) and the vector potential itself (Apar). Then it compares the amplitude of the increment and the current value and computes a damping factor for each poloidal mode number such that the increment is limited to be a fraction of the current value. Using this damping factor, the increment is transformed back to real space and returned to the calling routine.

Parameters
[in]AparCurrent symplectic vector potential As, double
[in,out]dAparIncrement of the vector potential (=Ah), double
Here is the call graph for this function:

◆ ptb_3db_screening_factor()

real (kind=8) function ptb_3db_module::ptb_3db_screening_factor ( real (kind=8), intent(in)  r,
real (kind=8), intent(in)  z,
real (kind=8), intent(in)  psi 
)

Evaluates the screening factor for artificial exponential damping of the vacuum perturbed field towards the magnetic axis. The screening shape function is simply exp((psi-psi0)/w). Since psi decreases towards the magnetic axis, psi-psi0 becomes negative at some point.

Parameters
r(in) real(8), major radius
z(in) real(8), Z coordinate
psi(in) real(8), normalized poloidal flux corresponding to r and z
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_3db_m3dc1_eem()

subroutine ptb_3db_module::read_3db_m3dc1_eem ( real(kind=8), dimension(grid%nnode), intent(inout)  As_vac)

Allocates memory for and reads perturbed field data from M3D-C1 file for use with the explicit EM method. This reader reads only the parallel component of the perturbed vacuum vector potential for a single toroidal mode number.

Parameters
[in]gridtype(grid_type), XGC grid information
[in,out]psnXGC field data object, type(psn_type)
Here is the call graph for this function:

◆ read_3db_m3dc1_mesh()

subroutine ptb_3db_module::read_3db_m3dc1_mesh

Allocates memory for and reads perturbed field data from M3D-C1 file. For M3D-C1 input, the fusion-io library by N. Ferraro is used. The interpolation used in the fusion-io library keeps the field divergence free.

Parameters
grid(in) type(grid_type), XGC grid information
Here is the call graph for this function:

◆ read_3db_m3dc1_rz()

subroutine ptb_3db_module::read_3db_m3dc1_rz

Allocates memory for and reads perturbed field data from M3D-C1 file. This version of the routine reads the vector potential A on an (R,Z) grid. The perturbed field on the XGC mesh can be evaluated in a separate subroutine. Eventually, the perturbed magnetic field is to be calculated directy from A using spline interpolation. For M3D-C1 input, the fusion-io library by N. Ferraro is used.

Parameters
grid(in) type(grid_type), XGC grid information
Here is the call graph for this function:

◆ read_3db_test()

subroutine ptb_3db_module::read_3db_test ( real(kind=8), dimension(grid%nnode), intent(inout)  As_vac,
integer, intent(in), value  explicit_em_int 
)

Sets up an analytical magnetic field perturbation with fixed toroidal mode number and (currently) 2 poloidal mode numbers. The number of poloidal mode numbers can be adjusted with few code changes. The most important parameters are the value of the poloidal mode numbers, the centers of the Gaussian envelopes of each mode number, the width of the Gaussian, and the amplitude.

Parameters
[in]gridXGC grid data object, type(grid_type)
[in,out]psnXGC field data object, type(psn_type)
Here is the call graph for this function:

◆ update_3db()

subroutine ptb_3db_module::update_3db ( real(8), intent(in), value  rampup_fac,
integer, intent(in), value  gstep,
real(8), intent(in), value  time 
)

Updates the ramp-up factor of the vacuum RMP field. The external (or vacuum) RMP field can be ramped up linearly instead of a hard switch from off to on. The ramp-up factor ptb_3db_rampup_fac determines the amplitude of the external RMP field throughout XGC. This routine is used only in electrostatic simulations. In electromagnetic simulations, push_As updates the ramp-up factor.

Variable Documentation

◆ ptb_3db_bfield_im_vac

real (kind=8), dimension(:,:,:), allocatable, target ptb_3db_module::ptb_3db_bfield_im_vac

perturbed vacuum field on XGC mesh, imaginary part

◆ ptb_3db_bfield_re_vac

real (kind=8), dimension(:,:,:), allocatable, target ptb_3db_module::ptb_3db_bfield_re_vac

perturbed vacuum field on XGC mesh, real part, dimensions: (grid vertex, R-Z-phi components, tor. mode number)

◆ ptb_3db_bicub_da

type (bicub_type), dimension(:,:,:), allocatable ptb_3db_module::ptb_3db_bicub_da

Spline for interpolation of the perturbed vector potential with bicub_mod.

◆ ptb_3db_dr

real (kind=8) ptb_3db_module::ptb_3db_dr

◆ ptb_3db_dz

real (kind=8) ptb_3db_module::ptb_3db_dz

grid spacing of (R,Z) grid

◆ ptb_3db_es_to_em_dt_ratio

integer ptb_3db_module::ptb_3db_es_to_em_dt_ratio =1

Ratio of ES to EM time step size in RMP penetration calculation with ptb_3db_mode==2 (also: the number of time steps over which the perturbed current is averaged)

◆ ptb_3db_filename

character(len=250) ptb_3db_module::ptb_3db_filename ='C1.h5'

File containing the perturbed field data.

◆ ptb_3db_m3dc1_timeslice

integer ptb_3db_module::ptb_3db_m3dc1_timeslice =1

Time slice that is to be read from M3D-C1 file.

◆ ptb_3db_mode

integer ptb_3db_module::ptb_3db_mode =0

Mode of operation: (0) static RMP field (ES), or fully self-consistent RMP field (EM version) (2) self-consistent RMP field with time-averaged field-equations (EM version)

◆ ptb_3db_mpol

integer, dimension(:), allocatable ptb_3db_module::ptb_3db_mpol

Array to store the poloidal mode numbers.

◆ ptb_3db_mstep_em

integer ptb_3db_module::ptb_3db_mstep_em =1

Number of EM time steps in RMP penetration calculation with ptb_3db_mode==2.

◆ ptb_3db_mstep_es

integer ptb_3db_module::ptb_3db_mstep_es =0

Number of ES time steps in RMP penetration calculation with ptb_3db_mode==2.

◆ ptb_3db_mult_factor

real (kind=8) ptb_3db_module::ptb_3db_mult_factor =1D0

Factor for scaling the perturbed field.

◆ ptb_3db_nr

integer ptb_3db_module::ptb_3db_nr =1000

(R,Z) grid size in R-direction

◆ ptb_3db_ntor

integer, dimension(:), allocatable, target ptb_3db_module::ptb_3db_ntor

Array to store the toroidal mode numbers.

◆ ptb_3db_ntor_min

integer ptb_3db_module::ptb_3db_ntor_min =3

smallest toroidal mode number

◆ ptb_3db_num_mpol

integer ptb_3db_module::ptb_3db_num_mpol =30

Number of poloidal mode numbers.

◆ ptb_3db_num_ntor

integer ptb_3db_module::ptb_3db_num_ntor =1

Number of toroidal mode numbers (<= sml_nphi_total)

◆ ptb_3db_nz

integer ptb_3db_module::ptb_3db_nz =1000

(R,Z) grid size in Z-direction

◆ ptb_3db_r_max

real (kind=8) ptb_3db_module::ptb_3db_r_max

Range of R in (R,Z) grid.

◆ ptb_3db_r_min

real (kind=8) ptb_3db_module::ptb_3db_r_min

◆ ptb_3db_rampup_time

integer ptb_3db_module::ptb_3db_rampup_time =1000

Number of time steps over which the perturbed field is ramped up.

◆ ptb_3db_rampup_vac

logical ptb_3db_module::ptb_3db_rampup_vac =.true.

(.true.) Ramp up perturbed field slowly, (.false.) turn on perturbed field abruptly

◆ ptb_3db_rgrid

real (kind=8), dimension(:), allocatable ptb_3db_module::ptb_3db_rgrid

◆ ptb_3db_screening_fac1

real (kind=8) ptb_3db_module::ptb_3db_screening_fac1 =0.9D0

Reduction of deltaB at the separatrix (<=1)

◆ ptb_3db_screening_fac2

real (kind=8) ptb_3db_module::ptb_3db_screening_fac2 =0.8D0

Fraction of vacuum RMP in the core (<=1)

◆ ptb_3db_screening_on

logical ptb_3db_module::ptb_3db_screening_on =.false.

Artificial screening for static RMP field: (.false.) no screening, (.true.) exponential damping towards the axis.

◆ ptb_3db_screening_psi1

real (kind=8) ptb_3db_module::ptb_3db_screening_psi1 =0.975D0

Center of the tanh function for screening in the core (<1)

◆ ptb_3db_screening_width1

real (kind=8) ptb_3db_module::ptb_3db_screening_width1 =0.02D0

Decay length of the exponential damping function in units of normalized poloidal flux.

◆ ptb_3db_screening_width2

real (kind=8) ptb_3db_module::ptb_3db_screening_width2 =0.02D0

Width of tanh for damping in the core in units of normalized poloidal flux.

◆ ptb_3db_single_mode_input

logical ptb_3db_module::ptb_3db_single_mode_input =.true.

For M3D-C1 input; If .true., M3D-C1 file contains only one toroidal mode number.

◆ ptb_3db_single_mode_ntor

integer ptb_3db_module::ptb_3db_single_mode_ntor =3

The mode number in the M3D-C1 file in case of single mode input.

◆ ptb_3db_spl_tmp

type (ezspline2_r8) ptb_3db_module::ptb_3db_spl_tmp

Dummy 2D spline used for setting up the 2D interpolations with bicub_mod.

◆ ptb_3db_start_time

integer ptb_3db_module::ptb_3db_start_time =1

Time step in which perturbed field is switched on.

◆ ptb_3db_update_alpha

real (kind=8) ptb_3db_module::ptb_3db_update_alpha =1.0D0

Damping factor for update of the perturbed field.

◆ ptb_3db_vecpot_im_vac_rz

real (kind=8), dimension(:,:,:,:), allocatable ptb_3db_module::ptb_3db_vecpot_im_vac_rz

perturbed vacuum vector potential on (R,Z) mesh, imaginary part

◆ ptb_3db_vecpot_re_vac_rz

real (kind=8), dimension(:,:,:,:), allocatable ptb_3db_module::ptb_3db_vecpot_re_vac_rz

perturbed vacuum vector potential on (R,Z) mesh, real part

◆ ptb_3db_vecpot_spl_rz_im

type (ezspline2_r8), dimension(:,:), allocatable ptb_3db_module::ptb_3db_vecpot_spl_rz_im

Spline for interpolation of the imaginary part of (R,Z) data to XGC mesh.

◆ ptb_3db_vecpot_spl_rz_re

type (ezspline2_r8), dimension(:,:), allocatable ptb_3db_module::ptb_3db_vecpot_spl_rz_re

Spline for interpolation of the real part of (R,Z) data to XGC mesh.

◆ ptb_3db_z_max

real (kind=8) ptb_3db_module::ptb_3db_z_max

Range of Z in (R,Z) grid.

◆ ptb_3db_z_min

real (kind=8) ptb_3db_module::ptb_3db_z_min

◆ ptb_3db_zgrid

real (kind=8), dimension(:), allocatable ptb_3db_module::ptb_3db_zgrid

R and Z grid in case of (R,Z) input data.