gs2_diagnostics Module

A module for calculating and writing the main GS2 outputs.



Contents


Variables

Type Visibility Attributes Name Initial
real, private :: omegatinst
real, public :: omegatol
logical, private :: print_line
logical, private :: print_flux_line
logical, private :: print_summary
logical, private :: write_line
logical, private :: write_flux_line
logical, private :: write_omega
logical, private :: write_omavg
logical, private :: write_ascii
logical, private :: write_gs
logical, private :: write_ql_metric
logical, private :: write_g
logical, private :: write_gyx
logical, private :: write_eigenfunc
logical, private :: write_fields
logical, private :: write_final_fields
logical, private :: write_final_antot
logical, private :: write_final_moments
logical, private :: write_avg_moments
logical, private :: write_parity
logical, private :: write_moments
logical, private :: ob_midplane
logical, private :: write_final_db
logical, private :: write_full_moments_notgc
logical, private :: write_cross_phase
logical, private :: write_final_epar
logical, private :: write_kpar
logical, private :: write_heating
logical, private :: write_lorentzian
logical, public :: write_fluxes
logical, private :: write_fluxes_by_mode
logical, private :: write_kinetic_energy_transfer
logical, private :: write_verr
logical, private :: write_cerr
logical, private :: write_max_verr
logical, public :: exit_when_converged
logical, private :: use_nonlin_convergence
logical, private :: dump_check1
logical, private :: dump_check2
logical, public :: dump_fields_periodically
logical, public :: make_movie
logical, public :: save_for_restart
logical, public :: save_distfn
logical, public :: save_glo_info_and_grids
logical, public :: save_velocities
logical, private :: write_symmetry
logical, private :: write_correlation_extend
logical, private :: write_correlation
logical, private :: write_nl_flux_dist
logical, private :: file_safety_check
logical, private :: append_old
logical, private :: write_phi_over_time
logical, private :: write_apar_over_time
logical, private :: write_bpar_over_time
logical, private :: write_jext
integer, public :: nwrite
integer, public :: nmovie
integer, public :: navg
integer, public :: nsave
integer, private :: igomega
integer, private :: nwrite_mult
integer, private :: nc_sync_freq
integer, private :: trin_istep = 0

Variables for convergence condition testing

integer, private :: conv_isteps_converged = 0
real, private, allocatable, dimension(:) :: conv_heat
real, private :: heat_sum_av = 0
real, private :: heat_av = 0
real, private :: heat_av_test = 0
logical, private :: write_any
logical, private :: write_any_fluxes
logical, private :: dump_any
logical, private :: initialized = .false.
complex, private, allocatable, dimension (:,:,:) :: domega
complex, private, dimension (:, :), allocatable :: omega

Complex frequency, and time-averaged complex frequency

complex, public, dimension (:, :), allocatable :: omegaavg

Complex frequency, and time-averaged complex frequency

integer, private :: out_unit
integer, private :: heat_unit
integer, private :: heat_unit2
integer, private :: lpc_unit
integer, private :: jext_unit
integer, private :: phase_unit
integer, private :: dist_unit
integer, private :: yxdist_unit
integer, private :: dump_check1_unit
integer, private :: dump_check2_unit
integer, private :: res_unit
integer, private :: res_unit2
integer, private :: parity_unit
integer, private :: cres_unit
integer, private :: conv_nstep_av
integer, private :: conv_min_step
integer, private :: conv_max_step
integer, private :: conv_nsteps_converged
complex, private, dimension (:,:,:), allocatable :: omegahist

Frequency time history, size (navg, ntheta0, naky)

type(heating_diagnostics), private :: h

Heating diagnostics summed over space at the current timestep

type(heating_diagnostics), private, dimension(:), save, allocatable :: h_hist

Heating diagnostics summed over space over the last navg timesteps

type(heating_diagnostics), private, dimension(:,:), save, allocatable :: hk

Heating diagnostics as a function of at the current timestep

type(heating_diagnostics), private, dimension(:,:,:), save, allocatable :: hk_hist

Heating diagnostics as a function of over the last navg timesteps

real, private, dimension(:,:,:), allocatable :: j_ext_hist
real, private, dimension (:,:,:), allocatable :: pflux_tormom
real, public :: start_time = 0.0
real, public, dimension (:), allocatable :: pflux_avg
real, public, dimension (:), allocatable :: qflux_avg
real, public, dimension (:), allocatable :: heat_avg
real, public, dimension (:), allocatable :: vflux_avg
real, private :: conv_test_multiplier
integer, private :: ntg_extend
integer, private :: nth0_extend
integer, private :: nout = 1
integer, private :: nout_movie = 1
integer, private :: nout_big = 1
complex, private :: wtmp_old = 0.

Interfaces

private interface get_vol_average

  • private subroutine get_vol_average_one(a, b, axb, axb_by_mode)

    FIXME : Add documentation

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension (:,:) :: a
    complex, intent(in), dimension (:,:) :: b
    real, intent(out) :: axb
    real, intent(out), dimension (:,:) :: axb_by_mode
  • private subroutine get_vol_average_all(a, b, axb, axb_by_mode)

    FIXME : Add documentation

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension (-ntgrid:,:,:) :: a
    complex, intent(in), dimension (-ntgrid:,:,:) :: b
    real, intent(out) :: axb
    real, intent(out), dimension (:,:) :: axb_by_mode

private interface get_vol_int

  • private subroutine get_vol_int_one(a, b, axb, axb_by_mode)

    FIXME : Add documentation

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension (:,:) :: a
    complex, intent(in), dimension (:,:) :: b
    complex, intent(out) :: axb
    complex, intent(out), dimension (:,:) :: axb_by_mode
  • private subroutine get_vol_int_all(a, b, axb, axb_by_mode)

    FIXME : Add documentation

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension (-ntgrid:,:,:) :: a
    complex, intent(in), dimension (-ntgrid:,:,:) :: b
    complex, intent(out) :: axb
    complex, intent(out), dimension (:,:) :: axb_by_mode

private interface get_fldline_avg

Calculate the field-line average

  • private subroutine get_fldline_avg_r(fld_in, fld_out)

    Calculate the field-line average (real values)

    Arguments

    Type IntentOptional Attributes Name
    real, intent(in), dimension (-ntgrid:) :: fld_in
    real, intent(out) :: fld_out
  • private subroutine get_fldline_avg_c(fld_in, fld_out)

    Calculate the field-line average (complex values)

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(in), dimension (-ntgrid:) :: fld_in
    complex, intent(out) :: fld_out

Functions

public function diffusivity()

A linear estimate of the diffusivity, used for Trinity testing

Arguments

None

Return Value real

private function get_field_weighted_average_kperp2(field) result(average)

Calculates <|field|2 kperp2>_theta / <|field|2>_theta. Useful for simple quasilinear metric

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension(-ntgrid:ntgrid, ntheta0, naky) :: field

Return Value real, dimension(ntheta0, naky)

public function calculate_simple_quasilinear_flux_metric_by_k(growth_rates) result(ql_metric)

Calculates a simple gamma/kperp2 QL flux metric

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension(ntheta0, naky) :: growth_rates

Return Value real, dimension(ntheta0, naky)

public pure function calculate_instantaneous_omega(ig, tolerance) result(omega_inst)

Calculates the instantaneous omega from chinew = chi * exp(-i * omega * dt) with chi = phi + apar + bpar. This gives omega = log(chinew/chi) * i / dt.

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: ig
real, intent(in), optional :: tolerance

Return Value complex, dimension(ntheta0, naky)


Subroutines

public subroutine wnml_gs2_diagnostics(unit)

Write the diagnostics namelist to file

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

Unit of an open file to write to

public subroutine check_gs2_diagnostics(report_unit)

Perform some basic checking of the diagnostic input parameters, and write the results to file

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: report_unit

Unit of an open file to write to

public subroutine init_gs2_diagnostics(list, nstep, gs2_diagnostics_config_in, header)

Initialise this module and all its dependencies, including defining NetCDF vars, call real_init, which calls read_parameters; broadcast all the different write flags.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: list

If true, this is a "list-mode run" and so turn off print_flux_line and print_line if set

integer, intent(in) :: nstep

Maximum number of steps to take

type(diagnostics_config_type), intent(in), optional :: gs2_diagnostics_config_in

Input parameters for this module

type(standard_header_type), intent(in), optional :: header

Header for files with build and run information

public subroutine check_restart_file_writeable(check_writable, need_restart, extra_files)

Check if we can write the restart files

Read more…

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: check_writable

Has the user requested this check

logical, intent(in) :: need_restart

Has the user requested restart files

logical, intent(inout) :: extra_files

Has the user requested distribution function to be written

private subroutine real_init(is_list_run, gs2_diagnostics_config_in, header)

Read the input parameters; open the various text output files according to the relevant input flags; allocate and zero the module-level flux arrays, gs2_diagnostics_knobs and gs2_diagnostics_knobs

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: is_list_run

If true, this is a "list-mode run" and so turn off print_flux_line and print_line if set

type(diagnostics_config_type), intent(in), optional :: gs2_diagnostics_config_in

Input parameters for this module

type(standard_header_type), intent(in), optional :: header

Header for files with build and run information

public subroutine read_parameters(is_list_run, gs2_diagnostics_config_in, warn_nonfunctional)

Read the input parameters for the diagnostics module

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: is_list_run

If true, this is a "list-mode run" and so turn off print_flux_line and print_line if set

type(diagnostics_config_type), intent(in), optional :: gs2_diagnostics_config_in

Configuration for this module, can be used to set new default values or avoid reading the input file

logical, intent(in), optional :: warn_nonfunctional

public subroutine finish_gs2_diagnostics()

Finalise the diagnostics module, writing final timestep diagnostics and closing any open files

Arguments

None

public subroutine save_restart_dist_fn(save_for_restart, save_distfn, save_glo_info_and_grids, save_velocities, user_time, fileopt_base)

Save some extra information in final restart files

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: save_for_restart

See save_for_restart

logical, intent(in) :: save_distfn

See save_distfn

logical, intent(in) :: save_glo_info_and_grids

See save_glo_info_and_grids

logical, intent(in) :: save_velocities

See save_velocities

real, intent(in) :: user_time

Current simulation time

character(len=*), intent(in), optional :: fileopt_base

Optional string to add to file name

private subroutine deallocate_arrays()

Deallocate the gs2_diagnostics module-level arrays

Arguments

None

private subroutine close_files()

Close various text output files

Arguments

None

public subroutine loop_diagnostics(istep, exit, debopt, force)

Calculate and write the various diagnostic quantities.

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep

Current timestep

logical, intent(out) :: exit

If true, simulation should stop (for example, because it has converged)

logical, intent(in), optional :: debopt

If true, turn on some debug prints

logical, intent(in), optional :: force

private subroutine do_get_omega(istep, debug, exit)

Calculate gs2_diagnostics_knobs for linear simulations or if run_parameters_knobs is on; otherwise set gs2_diagnostics_knobs and gs2_diagnostics_knobs to zero

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep

The current timestep

logical, intent(in) :: debug

Turn on some debug messages

logical, intent(inout) :: exit

Returns true if the simulation has converged (see omegatol) or if a numerical instability has occurred (see gs2_diagnostics_knobs).

private subroutine do_write_ncloop(time, istep, phi2, apar2, bpar2, phitot)

Compute volume averages of the fields and write the fields, field averages, heating and frequency to the netCDF files

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Simulation time

integer, intent(in) :: istep

Current timestep

real, intent(out) :: phi2

Fields squared

real, intent(out) :: apar2

Fields squared

real, intent(out) :: bpar2

Fields squared

real, intent(out), dimension (:, :) :: phitot

FIXME: add documentation. Needs phinorm documenting

private subroutine do_write_eigenfunc(file_id, write_text, phi0)

Write normalised to the value of at the outboard midplane

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

logical, intent(in) :: write_text

If true, write text file

complex, intent(inout), dimension (:,:) :: phi0

The normalising factor for the fields that is actually used. See write_eigenfunc for more details

public subroutine do_write_geom()

Write some geometry information to text file <runname>.g

Arguments

None

private subroutine do_write_movie(time)

Transform to real space, then write to netCDF

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Current simulation time

private subroutine do_print_line(phitot)

Print estimated frequencies and growth rates to screen/stdout

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension (:, :) :: phitot

Total magnitude of all the fields

private subroutine do_write_jext(time, istep)

Calculate and write the time-averaged antenna current to jext_unit

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Current simulation time

integer, intent(in) :: istep

Current timestep

private subroutine do_write_moments()

Write various moments to netCDF

Arguments

None

private subroutine do_write_crossphase(time)

Calculate the cross-phase (see get_cross_phase) and write to the phase_unit file

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Current simulation time

private subroutine do_write_line(time, it, ik, phitot)

Write estimated frequency and growth rates to out_unit for an individual point

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: time

Simulation time

integer, intent(in) :: it

- and -indices

integer, intent(in) :: ik

- and -indices

real, intent(in) :: phitot

Simulation time

private subroutine do_write_omega(it, ik)

Write instantaneous growth rate and frequency to out_unit for an individual point

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: it

- and -indices

integer, intent(in) :: ik

- and -indices

private subroutine do_write_omavg(it, ik)

Write time-averaged growth rate and frequency to out_unit for an individual point

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: it
integer, intent(in) :: ik

private subroutine do_write_verr()

Write some error estimates.

Read more…

Arguments

None

public subroutine do_write_heating(t, file_unit, file_unit2, h)

Write the (total) heating diagnostics to heat_unit and heat_unit2 (per-species)

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: t
integer, intent(in) :: file_unit
integer, intent(in) :: file_unit2
type(heating_diagnostics), intent(in) :: h

Heating diagnostics

public subroutine do_write_symmetry(file_id, nout)

Calculate the momentum flux as a function of and write to netCDF

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

integer, intent(in) :: nout

Current timestep

private subroutine do_write_kinetic_energy_transfer(file_id, nout)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

integer, intent(in) :: nout

Current timestep

public subroutine do_write_nl_flux_dist(file_id, nout)

Calculate the poloidal distributions of the fluxes of particles, parallel momentum, perpendicular momentum, and energy (see section 3.1 and appendix A of Ball et al. PPCF 58 (2016) 045023 as well as section 5 of "GS2 analytic geometry specification")

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

integer, intent(in) :: nout

Current timestep

public subroutine do_write_correlation(file_id, nout)

Calculate the correlation function over the physical domain and write to netCDF

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

integer, intent(in) :: nout

Current timestep

public subroutine do_write_correlation_extend(file_id, time, time_old)

Calculate the correlation function over the extended domain and write to netCDF

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: file_id

NetCDF ID of the file to write to

real, intent(in) :: time

Current and previous simulation times

real, intent(in) :: time_old

Current and previous simulation times

public subroutine do_write_parity(t, file_unit, write_text)

Calculate average parity of distribution function under , and write to parity_unit

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: t
integer, intent(in) :: file_unit

Open formatted file to write text to

logical, intent(in) :: write_text

If false, don't calculate or write parity

private subroutine do_write_avg_moments()

Calculate flux surfgace averaged low-order moments of and write to netCDF

Arguments

None

private subroutine do_write_full_moments_notgc()

Calculate moments (density, parallel flow, and parallel and perpendicular temperatures) in non-guiding centre coordinates and write to netCDF

Arguments

None

private subroutine do_write_dump_1(t)

Calculate the field-line average of and write to dump_check1_unit

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: t

private subroutine do_write_dump_2(t)

Calculate at igomega and write to dump_check2_unit

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: t

public subroutine do_dump_fields_periodically(t)

Write out to text file

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: t

private subroutine flush_files()

Flush text files (only out_unit, res_unit, lpc_unit, and parity_unit)

Arguments

None

private subroutine check_nonlin_convergence(istep, heat_flux, exit)

Trinity convergence condition - simple and experimental look for the averaged differential of the summed averaged heat flux to drop below a threshold

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep
real, intent(in) :: heat_flux
logical, intent(inout) :: exit

public subroutine heating(istep, navg, h, hk)

Calculate some heating diagnostics, and update their time history

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep
integer, intent(in) :: navg
type(heating_diagnostics), intent(inout) :: h

Heating diagnostics summed over space at the current timestep

type(heating_diagnostics), intent(inout), dimension(:,:) :: hk

Heating diagnostics as a function of at the current timestep

private subroutine calc_jext(istep, j_ext)

Calculate the time-averaged antenna current

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep

Current simulation timestep

real, intent(inout), dimension(:,:) :: j_ext

private subroutine get_omegaavg(istep, exit, omegaavg, debopt)

Calculate the time-averaged complex frequency, check convergence criterion, and numerical instability criterion.

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: istep

The current timestep

logical, intent(inout) :: exit

Should the simulation exit? FIXME: This could be intent(out) only

complex, intent(out), dimension (:,:) :: omegaavg

The time-averaged complex frequency

logical, intent(in), optional :: debopt

If true, write some debug messages

private subroutine phinorm(phitot)

Summed magnitude of all the fields

Arguments

Type IntentOptional Attributes Name
real, intent(out), dimension (:,:) :: phitot

private subroutine get_vol_average_all(a, b, axb, axb_by_mode)

FIXME : Add documentation

Read more…

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (-ntgrid:,:,:) :: a
complex, intent(in), dimension (-ntgrid:,:,:) :: b
real, intent(out) :: axb
real, intent(out), dimension (:,:) :: axb_by_mode

private subroutine get_vol_average_one(a, b, axb, axb_by_mode)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (:,:) :: a
complex, intent(in), dimension (:,:) :: b
real, intent(out) :: axb
real, intent(out), dimension (:,:) :: axb_by_mode

public subroutine get_volume_average(f, favg)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension (:,:) :: f
real, intent(out) :: favg

private subroutine get_surf_average(f, favg)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension (:,:) :: f
real, intent(out), dimension (:) :: favg

public subroutine reset_init()

FIXME : Add documentation

Arguments

None

public subroutine ensemble_average(nensembles, time_int)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nensembles
real, intent(out) :: time_int

private subroutine get_fldline_avg_r(fld_in, fld_out)

Calculate the field-line average (real values)

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension (-ntgrid:) :: fld_in
real, intent(out) :: fld_out

private subroutine get_fldline_avg_c(fld_in, fld_out)

Calculate the field-line average (complex values)

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (-ntgrid:) :: fld_in
complex, intent(out) :: fld_out

private subroutine get_cross_phase(phase_tot, phase_theta)

This is a highly simplified synthetic diagnostic which calculates the cross phase between the electron density and the perpendicular electron temperature for comparisons with DIII-D.
Returns the value of the cross-phase at the outboard midplane and integrated over all v and x. We can generalize this routine to other fields at some point, but for now this is just a skeleton for a more realistic synthetic diagnostic.

Arguments

Type IntentOptional Attributes Name
real, intent(out) :: phase_tot
real, intent(out) :: phase_theta

private subroutine get_vol_int_all(a, b, axb, axb_by_mode)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (-ntgrid:,:,:) :: a
complex, intent(in), dimension (-ntgrid:,:,:) :: b
complex, intent(out) :: axb
complex, intent(out), dimension (:,:) :: axb_by_mode

private subroutine get_vol_int_one(a, b, axb, axb_by_mode)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (:,:) :: a
complex, intent(in), dimension (:,:) :: b
complex, intent(out) :: axb
complex, intent(out), dimension (:,:) :: axb_by_mode

private subroutine get_volume_int(f, favg)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (:,:) :: f
complex, intent(out) :: favg

private subroutine correlation_extend(cfnc, phi2extend)

Calculate the correlation function over the extended domain

Arguments

Type IntentOptional Attributes Name
complex, intent(out), dimension (:,:,:) :: cfnc
real, intent(out), dimension (:,:,:) :: phi2extend

private subroutine correlation(cfnc_2pi)

Calculate the correlation function on the physical domain

Arguments

Type IntentOptional Attributes Name
complex, intent(out), dimension (-ntgrid:,:) :: cfnc_2pi

public subroutine do_write_f(unit)

Write at ik=it=is=1, ig=0 to text file <runname>.dist

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

public subroutine do_write_fyx(unit, phi, bpar)

Write distribution function ( or possibly ?) in real space to text file ".yxdist"

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
complex, intent(in), dimension (-ntgrid:,:,:) :: phi

Electrostatic potential and parallel magnetic field

complex, intent(in), dimension (-ntgrid:,:,:) :: bpar

Electrostatic potential and parallel magnetic field

private subroutine reorder_kx(unord, ord)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension (:) :: unord
complex, intent(out), dimension (:) :: ord