diagnostics_kinetic_energy_transfer Module

A module which writes out the electrostatic drive of zonal flows. The code is based on a Python3 post-processing tool from Stephen Biggs-Fox which can be found at [gitlab.com/stephen-biggs-fox/zonal-transfer-functions]

The code calculates the Reynolds stress drive through a bispectra-like transfer function by directly performing three-wave-coupling calculations. The couplings take place between a "target mode", a "source modes", and a "mediator mode", the latter being determined by a selection rule.

The total electrostatic zonal flow drive is resolved over the poloidal angle in the output "kinetic_energy_transfer_theta". Additional insight into the poloidal distributions of contributions from different source and target scales are provided by "kinetic_energy_transfer_theta_kxsource", "kinetic_energy_transfer_theta_kxtarget", and "kinetic_energy_transfer_theta_kysource".


Contents


Variables

Type Visibility Attributes Name Initial
real, private, dimension(:), allocatable :: kxnew_array
real, private, dimension(:), allocatable :: kynew_array
logical, private, dimension(:,:,:), allocatable :: valid_mediator_lookup
real, private, dimension(:,:,:), allocatable :: z_factor
integer, private :: ikx0
integer, private :: iky0
integer, private :: nkynew
real, private, dimension(:), allocatable :: T_result_theta
real, private, dimension(:,:), allocatable :: T_result_theta_kxsource
real, private, dimension(:,:), allocatable :: T_result_theta_kxtarget
real, private, dimension(:,:), allocatable :: T_result_theta_kysource
logical, private, parameter :: distribute_work = .true.

If true then distribute theta grid points over processors. This requires some additional global communication so at scale (and with small ntheta) it might be more efficient to do all the calculation on proc0 and avoid the associated communcations.


Interfaces

private interface fftshift

  • private subroutine fftshift1D_real(array)

    similar to numpy.fft.fftshift in Python shift data such that the element for kx=0 or ky=0 is in the center of the array

    Arguments

    Type IntentOptional Attributes Name
    real, intent(inout), dimension(:) :: array
  • private subroutine fftshift2D_complex(array)

    similar to numpy.fft.fftshift in Python shift data such that the element for kx=0 and ky=0 is in the center of the matrix

    Arguments

    Type IntentOptional Attributes Name
    complex, intent(inout), dimension(:,:) :: array

Functions

private elemental function is_responsible_for_any_theta_grid_point(iproc, ntgrid) result(any_responsible)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iproc
integer, intent(in) :: ntgrid

Return Value logical

private elemental function is_responsible_for_this_theta_grid_index(iproc, theta_index, nproc, ntgrid) result(responsible)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iproc
integer, intent(in) :: theta_index
integer, intent(in) :: nproc
integer, intent(in) :: ntgrid

Return Value logical

private elemental function get_ikm(ikt, iks, ik0) result(ikm)

return the mediator index for either kx or ky

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ikt
integer, intent(in) :: iks
integer, intent(in) :: ik0

Return Value integer

private elemental function valid_mediator(ikxt, ikxs, ikx0, ikyt, ikys, iky0, nkx, nky)

return bolean whether a source-mode and target-mode combination yields a valid mediator

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: ikxt
integer, intent(in) :: ikxs
integer, intent(in) :: ikx0
integer, intent(in) :: ikyt
integer, intent(in) :: ikys
integer, intent(in) :: iky0
integer, intent(in) :: nkx
integer, intent(in) :: nky

Return Value logical


Subroutines

Arguments

None

private subroutine define_kinetic_energy_transfer_dims(file_id)

Arguments

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

Arguments

None

private subroutine extend_ky(kynew)

extend ky to negative values and return in "shifted" format. due to reality condition only ky >= 0 is used in GS2.

Arguments

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

private subroutine get_z_factor(kx_array, ky_array, result_array)

where the second term, , is unique for kinetic energy transfer and does not appear for internal energy transfer or entropy transfer

Arguments

Type IntentOptional Attributes Name
real, intent(in), dimension(:) :: kx_array
real, intent(in), dimension(:) :: ky_array
real, intent(out), dimension(:,:,:) :: result_array

private subroutine get_full(field_arr, result_array)

extend a 2D data array to negative ky-values with the original "unshifted" order

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension(:,:) :: field_arr
complex, intent(out), dimension(:,:) :: result_array

private subroutine fftshift1D_real(array)

similar to numpy.fft.fftshift in Python shift data such that the element for kx=0 or ky=0 is in the center of the array

Arguments

Type IntentOptional Attributes Name
real, intent(inout), dimension(:) :: array

private subroutine fftshift2D_complex(array)

similar to numpy.fft.fftshift in Python shift data such that the element for kx=0 and ky=0 is in the center of the matrix

Arguments

Type IntentOptional Attributes Name
complex, intent(inout), dimension(:,:) :: array

private subroutine get_mediator_helpers(valid_mediator_lookup)

create a boolean lookup for the valid mediator attribute of a pair of target wavevector and source wavevector

Arguments

Type IntentOptional Attributes Name
logical, intent(out), dimension(:,:,:) :: valid_mediator_lookup

private subroutine get_phi_mediator(phi_source, result_array)

calculate the mediator mode for all possible pairs of source and target wavevectors

Arguments

Type IntentOptional Attributes Name
complex, intent(in), dimension(:, :) :: phi_source
complex, intent(out), dimension(:, :, :) :: result_array

private subroutine real_calculate_kinetic_energy_transfer(B_factor, z_factor, phi_target, phi_mediator, phi_source, result_array)

compute the three-wave couplings

Arguments

Type IntentOptional Attributes Name
real, intent(in) :: B_factor
real, intent(in), dimension(:, :, :) :: z_factor
complex, intent(in), dimension(:) :: phi_target
complex, intent(in), dimension(:, :, :) :: phi_mediator
complex, intent(in), dimension(:, :) :: phi_source
real, intent(out), dimension(:,:,:) :: result_array

public subroutine write_kinetic_energy_transfer(file_id, nout)

Arguments

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

private subroutine calculate_kinetic_energy_transfer_this_theta(theta_index, T_result_3D)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: theta_index
real, intent(out), dimension(:, :, :) :: T_result_3D

Arguments

None