read_parameters Subroutine

private subroutine read_parameters(knobs_config_in)

FIXME : Add documentation
Identify if we need to warn about removal of parameters If we have zero beta then disable apar and bpar fields as these contribute nothing to result but slow down calculation. If we have non-zero beta then alert the user that they have some of the perturbed magnetic fields disabled. This may be intended behaviour, so we throw a warning. However, if both are disabled, we set beta=0. This will make the simulation electrostatic, as probably intended if both apar and bpar are set to zero.

Arguments

Type IntentOptional Attributes Name
type(knobs_config_type), intent(in), optional :: knobs_config_in

Contents

Source Code


Source Code

  subroutine read_parameters(knobs_config_in)
    use file_utils, only: input_unit, error_unit, input_unit_exist
    use mp, only: proc0, broadcast
    use text_options, only: text_option, get_option_value
    use kt_grids, only: gryfx
    use ran, only: set_seed_from_single_integer
    implicit none
    type(knobs_config_type), intent(in), optional :: knobs_config_in
    
    type (text_option), dimension (4), parameter :: eqzipopts = &
         (/ text_option('none', eqzip_option_none), &
            text_option('secondary', eqzip_option_secondary), &
            text_option('tertiary', eqzip_option_tertiary), &
            text_option('equilibrium', eqzip_option_equilibrium) /)
    character (len=20) :: eqzip_option
    type (text_option), dimension (3), parameter :: deltopts = &
         (/ text_option('default', delt_option_hand), &
            text_option('set_by_hand', delt_option_hand), &
            text_option('check_restart', delt_option_auto) /)
    character(20) :: delt_option
    integer :: ierr, in_file
    logical :: rpexist
    !> Identify if we need to warn about removal of parameters
    if (proc0) then
       in_file = input_unit_exist('parameters', rpexist)
       if (rpexist) write(*, '("Warning: Input file contains namelist ",A," but this has been removed. Inputs have been migrated to ",A)') "'parameters'", "'knobs'"
    end if
    
    if (present(knobs_config_in)) knobs_config = knobs_config_in
    call knobs_config%init(name = 'knobs', requires_index = .false.)

    ! Copy out internal values into module level parameters
    avail_cpu_time = knobs_config%avail_cpu_time
    beta = knobs_config%beta
    delt = knobs_config%delt
    delt_option = knobs_config%delt_option
    do_eigsolve = knobs_config%do_eigsolve
    eqzip_option = knobs_config%eqzip_option
    fapar = knobs_config%fapar
    fbpar = knobs_config%fbpar
    fphi = knobs_config%fphi
    immediate_reset = knobs_config%immediate_reset
    k0 = knobs_config%k0
    margin_cpu_time = knobs_config%margin_cpu_time
    max_sim_time = knobs_config%max_sim_time
    ncheck_stop = knobs_config%ncheck_stop
    neo_test = knobs_config%neo_test
    nstep = knobs_config%nstep
    rhostar = knobs_config%rhostar
    save_init_times = knobs_config%save_init_times
    save_timer_statistics = knobs_config%save_timer_statistics
    seed = knobs_config%seed
    tite = knobs_config%tite
    trinity_linear_fluxes = knobs_config%trinity_linear_fluxes
    trinity_ql_fluxes = knobs_config%trinity_ql_fluxes
    use_old_diagnostics = knobs_config%use_old_diagnostics
    user_comments = knobs_config%user_comments
    wstar_units = knobs_config%wstar_units
    zeff = knobs_config%zeff
  
    knexist = knobs_config%exist

    ! Now handle inputs to calculate derived quantities

    ! Override fapar, fbpar and beta if set inconsistently:
    
    !> If we have zero beta then disable apar and bpar fields
    !! as these contribute nothing to result but slow down calculation.
    if(beta.eq.0) then
       if(((fapar.ne.0) .or. (fbpar.ne.0)).and. proc0) then
          ierr = error_unit()
          write(ierr,'("Warning: Disabling apar and bpar as beta = 0.")')
       endif
       fapar = 0.
       fbpar = 0.
    endif

    has_phi = fphi > epsilon(0.0)
    has_apar = fapar > epsilon(0.0)
    has_bpar = fbpar > epsilon(0.0)

    !> If we have non-zero beta then alert the user that they have some
    !! of the perturbed magnetic fields disabled. This may be intended
    !! behaviour, so we throw a warning. However, if both are disabled,
    !! we set beta=0. This will make the simulation electrostatic, as 
    !! probably intended if both apar and bpar are set to zero.
    if( beta /= 0.0 .and. .not. (has_apar .or. has_bpar)) then
       if(proc0) then
          ierr = error_unit()
          write(ierr,'("Warning: Both fapar and fbpar are zero: setting beta = 0.")')
       endif
       beta = 0.0
    endif
    if((beta.ne.0).and.proc0) then
       ierr = error_unit()
       if(.not. has_apar) write(ierr,'("Warning: Running with finite beta but fapar=0.")')
       if(.not. has_bpar) write(ierr,'("Warning: Running with finite beta but fbpar=0.")')
    endif

    ierr = error_unit()
    call get_option_value &
         (delt_option, deltopts, delt_option_switch, ierr, &
         "delt_option in knobs",.true.)
    
    call get_option_value ( &
         eqzip_option, eqzipopts, eqzip_option_switch, error_unit(), &
         "eqzip_option in knobs",.true.)

    ! FOR GRYFX
    if (gryfx()) then
       delt = delt/sqrt(2.0)
       max_sim_time = max_sim_time / sqrt(2.0)
       nstep = nstep*2
    end if

    if (seed .ne. 0 ) call set_seed_from_single_integer(seed)
  end subroutine read_parameters