overrides.f90 Source File


Contents

Source Code


Source Code

! DO NOT EDIT THIS FILE
! This file has been automatically generated using generate_overrides.py

!> A module which defines the override types. These types
!> are used within the init object (which itself is contained
!> within the gs2_program_state object) to override values
!> of the specified parameters (i.e. modify their values from
!> what is specified in the input file). The appropriate "prepare_..."
!> function from gs2_main must always be called before setting overrides.
!>
!> In the future it would be nice to replace this code with something which
!> uses the config types directly.
module overrides
  implicit none

public :: profiles_overrides_type
public :: miller_geometry_overrides_type
public :: optimisations_overrides_type
public :: timestep_overrides_type
public :: kt_grids_overrides_type
public :: initial_values_overrides_type

!> A type for storing overrides of the intial
!> values of the fields and distribution function.
!> This override is different to all the others,
!> because in order to minimise memory usage and disk writes,
!> this override is used internally during the simulation, and
!> its values can thus change over the course of the simulation.
!> In contrast, no other overrides are modified by running gs2.
!> Also, depending on the value of in_memory, the override
!> values will either be taken from the the arrays within
!> the object, or from the restart files. If you want
!> to externally modify the initial field and dist fn values,
!> you need to use in_memory = .true. If you just want to
!> use this override to allow you to reinitialise the equations
!> and start from the same values, you can use either memory
!> or restart files. If you want to want to change the number
!> of processors and then reinitialise and then use this override
!> you must use in_memory = .false., because currently the memory
!> is allocated on a processor by processor basis. Changing
!> grid sizes and then using this override is not supported.
!> This one is too complicated to generate
!> automatically
type initial_values_overrides_type
  !> True if the object has been initialized.
  logical, private :: init = .false.
  !> If true, override values are read from the
  !> arrays in this object. If not, they are read
  !> from the restart files. The value of in_memory
  !> should not be changed without reinitializing this
  !> object (doing so is an excellent way of generating
  !> segmentation faults).
  logical :: in_memory = .true.
  !> Whether to override initial values or not,
  !> i.e., whether or not this override is switched on.
  !> If it is switched on, initial values will be determined
  !> by the values in the arrays or the restart files,
  !> depending on the value of in_memory. If false,
  !> initial values will be determined by the gs2 input file
  !> (note that of course, this can result in initial values
  !> being taken from the input files).
  logical :: override = .false.
  ! The force_maxwell_reinit component has been removed to avoid problems in gs2_init. See comments there and in gs2_main for details.
  complex, dimension (:,:,:), allocatable :: phi
  complex, dimension (:,:,:), allocatable :: apar
  complex, dimension (:,:,:), allocatable :: bpar
  complex, dimension (:,:,:), allocatable :: g
  complex, dimension (:,:,:), allocatable :: gexp_1, gexp_2, gexp_3
  real, dimension(2) :: vnmult
 contains
  procedure :: initialise => init_initial_values_overrides
  procedure :: finish => finish_initial_values_overrides
  procedure :: is_initialised => is_initialised_initial_values_overrides
end type initial_values_overrides_type

!> An object for overriding all or selected
!> profile parameters, for example species
!> temps, densities or gradients or the flow gradient or mach
!> number. Note that all species parameters are arrays of
!> size nspec and you must set the override switches
!> individually for each species.
type profiles_overrides_type
  logical, private :: init = .false.
logical, dimension (:), allocatable :: override_dens
real, dimension (:), allocatable :: dens
logical, dimension (:), allocatable :: override_temp
real, dimension (:), allocatable :: temp
logical, dimension (:), allocatable :: override_tprim
real, dimension (:), allocatable :: tprim
logical, dimension (:), allocatable :: override_fprim
real, dimension (:), allocatable :: fprim
logical, dimension (:), allocatable :: override_vnewk
real, dimension (:), allocatable :: vnewk
logical :: override_g_exb = .false.
real :: g_exb
logical :: override_mach = .false.
real :: mach
 contains
  procedure :: initialise => init_profiles_overrides
  procedure :: finish => finish_profiles_overrides
  procedure :: is_initialised => is_initialised_profiles_overrides
end type profiles_overrides_type

!> An object for overriding all or selected
!> Miller geometry parameters.
type miller_geometry_overrides_type
  logical, private :: init = .false.
logical :: override_rhoc = .false.
real :: rhoc
logical :: override_qinp = .false.
real :: qinp
logical :: override_shat = .false.
real :: shat
logical :: override_rgeo_lcfs = .false.
real :: rgeo_lcfs
logical :: override_rgeo_local = .false.
real :: rgeo_local
logical :: override_geoType = .false.
integer :: geoType
logical :: override_aSurf = .false.
real :: aSurf
logical :: override_shift = .false.
real :: shift
logical :: override_shiftVert = .false.
real :: shiftVert
logical :: override_mMode = .false.
integer :: mMode
logical :: override_nMode = .false.
integer :: nMode
logical :: override_deltam = .false.
real :: deltam
logical :: override_deltan = .false.
real :: deltan
logical :: override_deltampri = .false.
real :: deltampri
logical :: override_deltanpri = .false.
real :: deltanpri
logical :: override_thetam = .false.
real :: thetam
logical :: override_thetan = .false.
real :: thetan
logical :: override_betaprim = .false.
real :: betaprim
logical :: override_akappa = .false.
real :: akappa
logical :: override_akappri = .false.
real :: akappri
logical :: override_tri = .false.
real :: tri
logical :: override_tripri = .false.
real :: tripri
 contains
  procedure :: initialise => init_miller_geometry_overrides
  procedure :: finish => finish_miller_geometry_overrides
  procedure :: is_initialised => is_initialised_miller_geometry_overrides
end type miller_geometry_overrides_type

!> A type for containing overrides to the processor layout
!> and optimisation flags for gs2.
type optimisations_overrides_type
  logical, private :: init = .false.
logical :: override_nproc = .false.
integer :: nproc
logical :: override_opt_redist_nbk = .false.
logical :: opt_redist_nbk
logical :: override_opt_redist_persist = .false.
logical :: opt_redist_persist
logical :: override_opt_redist_persist_overlap = .false.
logical :: opt_redist_persist_overlap
logical :: override_intmom_sub = .false.
logical :: intmom_sub
logical :: override_intspec_sub = .false.
logical :: intspec_sub
logical :: override_local_field_solve = .false.
logical :: local_field_solve
logical :: override_layout = .false.
character(len=5) :: layout
logical :: override_field_option = .false.
character(len=8) :: field_option
logical :: override_gf_lo_integrate = .false.
logical :: gf_lo_integrate
logical :: override_gf_local_fields = .false.
logical :: gf_local_fields
logical :: override_simple_gf_decomposition = .false.
logical :: simple_gf_decomposition
logical :: override_field_subgath = .false.
logical :: field_subgath
logical :: override_do_smart_update = .false.
logical :: do_smart_update
logical :: override_field_local_allreduce = .false.
logical :: field_local_allreduce
logical :: override_field_local_allreduce_sub = .false.
logical :: field_local_allreduce_sub
logical :: override_opt_source = .false.
logical :: opt_source
logical :: override_minnrow = .false.
integer :: minnrow
logical :: override_old_comm = .false.
integer :: old_comm
 contains
  procedure :: initialise => init_optimisations_overrides
  procedure :: finish => finish_optimisations_overrides
  procedure :: is_initialised => is_initialised_optimisations_overrides
end type optimisations_overrides_type

!> A type for containing overrides to the timestep and the cfl parameters
type timestep_overrides_type
  logical, private :: init = .false.
logical :: override_immediate_reset = .false.
logical :: immediate_reset
 contains
  procedure :: initialise => init_timestep_overrides
  procedure :: finish => finish_timestep_overrides
  procedure :: is_initialised => is_initialised_timestep_overrides
end type timestep_overrides_type

!> A type for containing overrides to the perpendicular grids (x and y).
type kt_grids_overrides_type
  logical, private :: init = .false.
logical :: override_ny = .false.
integer :: ny
logical :: override_naky = .false.
integer :: naky
logical :: override_nx = .false.
integer :: nx
logical :: override_ntheta0 = .false.
integer :: ntheta0
logical :: override_y0 = .false.
real :: y0
logical :: override_x0 = .false.
real :: x0
logical :: override_jtwist = .false.
integer :: jtwist
 contains
  procedure :: initialise => init_kt_grids_overrides
  procedure :: finish => finish_kt_grids_overrides
  procedure :: is_initialised => is_initialised_kt_grids_overrides
end type kt_grids_overrides_type

contains

subroutine init_profiles_overrides(self, nspec)
  class(profiles_overrides_type), intent(in out) :: self
  integer, intent(in) :: nspec
  if (self%init) return
  self%init = .true.
allocate(self%override_dens(nspec), self%dens(nspec))
self%override_dens = .false.
allocate(self%override_temp(nspec), self%temp(nspec))
self%override_temp = .false.
allocate(self%override_tprim(nspec), self%tprim(nspec))
self%override_tprim = .false.
allocate(self%override_fprim(nspec), self%fprim(nspec))
self%override_fprim = .false.
allocate(self%override_vnewk(nspec), self%vnewk(nspec))
self%override_vnewk = .false.
end subroutine init_profiles_overrides

elemental logical function is_initialised_profiles_overrides(self) result(init)
  class(profiles_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_profiles_overrides

subroutine finish_profiles_overrides(self)
  use file_utils, only: error_unit
  class(profiles_overrides_type), intent(in out) :: self
  if (.not. self%init) then
    write (error_unit(), *) "ERROR: Called finish_profiles_overrides on an uninitialized object."
    return
  end if
if ( allocated(self%override_dens)) deallocate(self%override_dens, self%dens)
if ( allocated(self%override_temp)) deallocate(self%override_temp, self%temp)
if ( allocated(self%override_tprim)) deallocate(self%override_tprim, self%tprim)
if ( allocated(self%override_fprim)) deallocate(self%override_fprim, self%fprim)
if ( allocated(self%override_vnewk)) deallocate(self%override_vnewk, self%vnewk)
self%override_g_exb = .false.
self%override_mach = .false.
end subroutine finish_profiles_overrides

subroutine init_miller_geometry_overrides(self)
  class(miller_geometry_overrides_type), intent(in out) :: self
  
  if (self%init) return
  self%init = .true.

end subroutine init_miller_geometry_overrides

elemental logical function is_initialised_miller_geometry_overrides(self) result(init)
  class(miller_geometry_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_miller_geometry_overrides

subroutine finish_miller_geometry_overrides(self)
  use file_utils, only: error_unit
  class(miller_geometry_overrides_type), intent(in out) :: self
  if (.not. self%init) then
    write (error_unit(), *) "ERROR: Called finish_miller_geometry_overrides on an uninitialized object."
    return
  end if
self%override_rhoc = .false.
self%override_qinp = .false.
self%override_shat = .false.
self%override_rgeo_lcfs = .false.
self%override_rgeo_local = .false.
self%override_geoType = .false.
self%override_aSurf = .false.
self%override_shift = .false.
self%override_shiftVert = .false.
self%override_mMode = .false.
self%override_nMode = .false.
self%override_deltam = .false.
self%override_deltan = .false.
self%override_deltampri = .false.
self%override_deltanpri = .false.
self%override_thetam = .false.
self%override_thetan = .false.
self%override_betaprim = .false.
self%override_akappa = .false.
self%override_akappri = .false.
self%override_tri = .false.
self%override_tripri = .false.
end subroutine finish_miller_geometry_overrides

subroutine init_optimisations_overrides(self)
  class(optimisations_overrides_type), intent(in out) :: self
  
  if (self%init) return
  self%init = .true.

end subroutine init_optimisations_overrides

elemental logical function is_initialised_optimisations_overrides(self) result(init)
  class(optimisations_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_optimisations_overrides

subroutine finish_optimisations_overrides(self)
  use file_utils, only: error_unit
  class(optimisations_overrides_type), intent(in out) :: self
  if (.not. self%init) then
    write (error_unit(), *) "ERROR: Called finish_optimisations_overrides on an uninitialized object."
    return
  end if
self%override_nproc = .false.
self%override_opt_redist_nbk = .false.
self%override_opt_redist_persist = .false.
self%override_opt_redist_persist_overlap = .false.
self%override_intmom_sub = .false.
self%override_intspec_sub = .false.
self%override_local_field_solve = .false.
self%override_layout = .false.
self%override_field_option = .false.
self%override_gf_lo_integrate = .false.
self%override_gf_local_fields = .false.
self%override_simple_gf_decomposition = .false.
self%override_field_subgath = .false.
self%override_do_smart_update = .false.
self%override_field_local_allreduce = .false.
self%override_field_local_allreduce_sub = .false.
self%override_opt_source = .false.
self%override_minnrow = .false.
self%override_old_comm = .false.
end subroutine finish_optimisations_overrides

subroutine init_timestep_overrides(self)
  class(timestep_overrides_type), intent(in out) :: self
  
  if (self%init) return
  self%init = .true.

end subroutine init_timestep_overrides

elemental logical function is_initialised_timestep_overrides(self) result(init)
  class(timestep_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_timestep_overrides

subroutine finish_timestep_overrides(self)
  use file_utils, only: error_unit
  class(timestep_overrides_type), intent(in out) :: self
  if (.not. self%init) then
    write (error_unit(), *) "ERROR: Called finish_timestep_overrides on an uninitialized object."
    return
  end if
self%override_immediate_reset = .false.
end subroutine finish_timestep_overrides

subroutine init_kt_grids_overrides(self)
  class(kt_grids_overrides_type), intent(in out) :: self
  
  if (self%init) return
  self%init = .true.

end subroutine init_kt_grids_overrides

elemental logical function is_initialised_kt_grids_overrides(self) result(init)
  class(kt_grids_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_kt_grids_overrides

subroutine finish_kt_grids_overrides(self)
  use file_utils, only: error_unit
  class(kt_grids_overrides_type), intent(in out) :: self
  if (.not. self%init) then
    write (error_unit(), *) "ERROR: Called finish_kt_grids_overrides on an uninitialized object."
    return
  end if
self%override_ny = .false.
self%override_naky = .false.
self%override_nx = .false.
self%override_ntheta0 = .false.
self%override_y0 = .false.
self%override_x0 = .false.
self%override_jtwist = .false.
end subroutine finish_kt_grids_overrides

!> Warning: You can't change the value of
!> overrides%in_memory after calling this function
subroutine init_initial_values_overrides(overrides_obj, ntgrid, ntheta0, naky, &
   g_llim, g_ulim, force_maxwell_reinit, in_memory, has_explicit_terms)
  use file_utils, only: error_unit
  use mp, only: proc0
  implicit none
  class(initial_values_overrides_type), intent(in out) :: overrides_obj
  integer, intent(in) :: ntgrid, ntheta0, naky, g_llim, g_ulim
  logical, intent(in) :: force_maxwell_reinit, in_memory, has_explicit_terms
  integer :: iostat
  if (overrides_obj%init) return
  overrides_obj%init = .true.
  overrides_obj%override = .false.
  overrides_obj%in_memory = in_memory
  overrides_obj%vnmult = 0.0

  if (proc0) write (error_unit(), *) "INFO: changing in_memory &
    & after calling initial_values_overrides_type will almost certainly cause &
    & segmentation faults."
  if (overrides_obj%in_memory) then
     allocate(overrides_obj%g(-ntgrid:ntgrid,2,g_llim:g_ulim), stat=iostat)
     if (has_explicit_terms) then
        if (iostat.eq.0) allocate(overrides_obj%gexp_1(-ntgrid:ntgrid,2,g_llim:g_ulim), stat=iostat)
        if (iostat.eq.0) allocate(overrides_obj%gexp_2(-ntgrid:ntgrid,2,g_llim:g_ulim), stat=iostat)
        if (iostat.eq.0) allocate(overrides_obj%gexp_3(-ntgrid:ntgrid,2,g_llim:g_ulim), stat=iostat)
     end if

     if (.not. force_maxwell_reinit) then
        if (iostat.eq.0) allocate(overrides_obj%phi(-ntgrid:ntgrid,ntheta0,naky), stat=iostat)
        if (iostat.eq.0) allocate(overrides_obj%apar(-ntgrid:ntgrid,ntheta0,naky), stat=iostat)
        if (iostat.eq.0) allocate(overrides_obj%bpar(-ntgrid:ntgrid,ntheta0,naky), stat=iostat)
     end if

     if (iostat.ne.0) then
        overrides_obj%in_memory = .false.
        if (proc0) write(error_unit(), '(A," ",I0)') "WARNING: could not allocate memory for initial_values_overrides. Only restart from file possible (manual setting of initial values not possible). Error code",iostat
        if (allocated(overrides_obj%g)) deallocate(overrides_obj%g)
        if (allocated(overrides_obj%gexp_1)) deallocate(overrides_obj%gexp_1)
        if (allocated(overrides_obj%gexp_2)) deallocate(overrides_obj%gexp_2)
        if (allocated(overrides_obj%gexp_3)) deallocate(overrides_obj%gexp_3)
        if (allocated(overrides_obj%phi)) deallocate(overrides_obj%phi)
        if (allocated(overrides_obj%apar)) deallocate(overrides_obj%apar)
        if (allocated(overrides_obj%bpar)) deallocate(overrides_obj%bpar)
     end if
  end if
end subroutine init_initial_values_overrides
elemental logical function is_initialised_initial_values_overrides(self) result(init)
  class(initial_values_overrides_type), intent(in) :: self
  init = self%init
end function is_initialised_initial_values_overrides
subroutine finish_initial_values_overrides(overrides_obj)
  use file_utils, only: error_unit
  use mp, only: proc0
  implicit none
  class(initial_values_overrides_type), intent(in out) :: overrides_obj
  if (.not. overrides_obj%init) then
    if (proc0) write (error_unit(), *) "WARNING: Called finish_initial_values_overrides on an uninitialized object"
    return
  end if
  overrides_obj%init = .false.
  overrides_obj%override = .false.
  overrides_obj%vnmult = 0.0
  if (allocated(overrides_obj%g)) deallocate(overrides_obj%g)
  if (allocated(overrides_obj%gexp_1)) deallocate(overrides_obj%gexp_1)
  if (allocated(overrides_obj%gexp_2)) deallocate(overrides_obj%gexp_2)
  if (allocated(overrides_obj%gexp_3)) deallocate(overrides_obj%gexp_3)
  if (allocated(overrides_obj%phi)) deallocate(overrides_obj%phi)
  if (allocated(overrides_obj%apar)) deallocate(overrides_obj%apar)
  if (allocated(overrides_obj%bpar)) deallocate(overrides_obj%bpar)
end subroutine finish_initial_values_overrides

end module overrides