!> Provides a defined type that contains all possible config objects. !> This can be used to represent the configuration used for a particular !> run etc. module config_collection use ballstab, only: ballstab_config_type use collisions, only: collisions_config_type use diagnostics_configuration, only: diagnostics_config_type use dist_fn, only: dist_fn_config_type use dist_fn, only: dist_fn_species_config_type use antenna, only: driver_config_type use eigval, only: eigval_config_type use fields, only: fields_config_type use hyper, only: hyper_config_type use ingen_mod, only: ingen_config_type use init_g, only: init_g_config_type use run_parameters, only: knobs_config_type use kt_grids, only: kt_grids_config_type use kt_grids_box, only: kt_grids_box_config_type use kt_grids_range, only: kt_grids_range_config_type use kt_grids_single, only: kt_grids_single_config_type use kt_grids_specified, only: kt_grids_specified_config_type use kt_grids_specified, only: kt_grids_specified_element_config_type use gs2_layouts, only: layouts_config_type use le_grids, only: le_grids_config_type use nonlinear_terms, only: nonlinear_terms_config_type use normalisations, only: normalisations_config_type use optimisation_configuration, only: optimisation_config_type use gs2_reinit, only: reinit_config_type use dist_fn, only: source_config_type use species, only: species_config_type use species, only: species_element_config_type use split_nonlinear_terms, only: split_nonlinear_terms_config_type use antenna, only: stir_config_type use theta_grid, only: theta_grid_config_type use theta_grid_eik, only: theta_grid_eik_config_type use theta_grid_file, only: theta_grid_file_config_type use theta_grid_gridgen, only: theta_grid_gridgen_config_type use theta_grid_params, only: theta_grid_parameters_config_type use theta_grid_salpha, only: theta_grid_salpha_config_type implicit none private public :: gs2_config_type type :: gs2_config_type type(ballstab_config_type) :: ballstab_config type(collisions_config_type) :: collisions_config type(diagnostics_config_type) :: diagnostics_config type(dist_fn_config_type) :: dist_fn_config type(dist_fn_species_config_type), dimension(:), allocatable :: dist_fn_species_config type(driver_config_type) :: driver_config type(eigval_config_type) :: eigval_config type(fields_config_type) :: fields_config type(hyper_config_type) :: hyper_config type(ingen_config_type) :: ingen_config type(init_g_config_type) :: init_g_config type(knobs_config_type) :: knobs_config type(kt_grids_config_type) :: kt_grids_config type(kt_grids_box_config_type) :: kt_grids_box_config type(kt_grids_range_config_type) :: kt_grids_range_config type(kt_grids_single_config_type) :: kt_grids_single_config type(kt_grids_specified_config_type) :: kt_grids_specified_config type(kt_grids_specified_element_config_type), dimension(:), allocatable :: kt_grids_specified_element_config type(layouts_config_type) :: layouts_config type(le_grids_config_type) :: le_grids_config type(nonlinear_terms_config_type) :: nonlinear_terms_config type(normalisations_config_type) :: normalisations_config type(optimisation_config_type) :: optimisation_config type(reinit_config_type) :: reinit_config type(source_config_type) :: source_config type(species_config_type) :: species_config type(species_element_config_type), dimension(:), allocatable :: species_element_config type(split_nonlinear_terms_config_type) :: split_nonlinear_terms_config type(stir_config_type), dimension(:), allocatable :: stir_config type(theta_grid_config_type) :: theta_grid_config type(theta_grid_eik_config_type) :: theta_grid_eik_config type(theta_grid_file_config_type) :: theta_grid_file_config type(theta_grid_gridgen_config_type) :: theta_grid_gridgen_config type(theta_grid_parameters_config_type) :: theta_grid_parameters_config type(theta_grid_salpha_config_type) :: theta_grid_salpha_config contains !> See [[write_to_unit]] for details. procedure :: write_to_unit !> See [[get_configs]] for details procedure :: get_configs !> See [[set_configs]] for details procedure :: set_configs !> See [[populate_from_file]] for details procedure :: populate_from_file end type gs2_config_type contains !> Writes out the current configuration state to an optionally provided unit. !> If no unit is provided then we write to `output_unit`. subroutine write_to_unit(self, unit) use iso_fortran_env, only: output_unit use optionals, only: get_option_with_default implicit none ! Note we have to make this intent out as we may want/need to allocate ! some components that have not been allocated. If so we do deallocate ! so self should be unchanged on exit. class(gs2_config_type), intent(in out) :: self ! The unit to write to, if not given then will use output_unit. Note we ! assume this unit has been opened ready for writing. integer, intent(in), optional :: unit integer :: local_output_unit, i logical :: allocated_flag ! Handle optional argument local_output_unit = get_option_with_default(unit, output_unit) ! Take care of writing call self%ballstab_config%write(local_output_unit) call self%collisions_config%write(local_output_unit) call self%diagnostics_config%write(local_output_unit) call self%dist_fn_config%write(local_output_unit) allocated_flag = allocated(self%dist_fn_species_config) if (.not. allocated_flag) then allocate(self%dist_fn_species_config(self%species_config%nspec)) do i = 1, size(self%dist_fn_species_config) self%dist_fn_species_config(i)%index = i end do end if do i = 1, size(self%dist_fn_species_config) call self%dist_fn_species_config(i)%write(local_output_unit) end do if (.not. allocated_flag) deallocate(self%dist_fn_species_config) call self%driver_config%write(local_output_unit) call self%eigval_config%write(local_output_unit) call self%fields_config%write(local_output_unit) call self%hyper_config%write(local_output_unit) call self%ingen_config%write(local_output_unit) call self%init_g_config%write(local_output_unit) call self%knobs_config%write(local_output_unit) call self%kt_grids_config%write(local_output_unit) call self%kt_grids_box_config%write(local_output_unit) call self%kt_grids_range_config%write(local_output_unit) call self%kt_grids_single_config%write(local_output_unit) call self%kt_grids_specified_config%write(local_output_unit) allocated_flag = allocated(self%kt_grids_specified_element_config) if (.not. allocated_flag) then allocate(self%kt_grids_specified_element_config(self%kt_grids_specified_config%nmodes)) do i = 1, size(self%kt_grids_specified_element_config) self%kt_grids_specified_element_config(i)%index = i end do end if do i = 1, size(self%kt_grids_specified_element_config) call self%kt_grids_specified_element_config(i)%write(local_output_unit) end do if (.not. allocated_flag) deallocate(self%kt_grids_specified_element_config) call self%layouts_config%write(local_output_unit) call self%le_grids_config%write(local_output_unit) call self%nonlinear_terms_config%write(local_output_unit) call self%normalisations_config%write(local_output_unit) call self%optimisation_config%write(local_output_unit) call self%reinit_config%write(local_output_unit) call self%source_config%write(local_output_unit) call self%species_config%write(local_output_unit) allocated_flag = allocated(self%species_element_config) if (.not. allocated_flag) then allocate(self%species_element_config(self%species_config%nspec)) do i = 1, size(self%species_element_config) self%species_element_config(i)%index = i end do end if do i = 1, size(self%species_element_config) call self%species_element_config(i)%write(local_output_unit) end do if (.not. allocated_flag) deallocate(self%species_element_config) call self%split_nonlinear_terms_config%write(local_output_unit) allocated_flag = allocated(self%stir_config) if (.not. allocated_flag) then allocate(self%stir_config(self%driver_config%nk_stir)) do i = 1, size(self%stir_config) self%stir_config(i)%index = i end do end if do i = 1, size(self%stir_config) call self%stir_config(i)%write(local_output_unit) end do if (.not. allocated_flag) deallocate(self%stir_config) call self%theta_grid_config%write(local_output_unit) call self%theta_grid_eik_config%write(local_output_unit) call self%theta_grid_file_config%write(local_output_unit) call self%theta_grid_gridgen_config%write(local_output_unit) call self%theta_grid_parameters_config%write(local_output_unit) call self%theta_grid_salpha_config%write(local_output_unit) end subroutine write_to_unit !> Copy all the module-level configs into `self`. !> !> Can be used to get a "snapshot" of the current state of all !> module's configs. subroutine get_configs(self) use ballstab, only: get_ballstab_config use collisions, only: get_collisions_config use diagnostics_configuration, only: get_diagnostics_config use dist_fn, only: get_dist_fn_config use dist_fn, only: get_dist_fn_species_config use antenna, only: get_driver_config use eigval, only: get_eigval_config use fields, only: get_fields_config use hyper, only: get_hyper_config use ingen_mod, only: get_ingen_config use init_g, only: get_init_g_config use run_parameters, only: get_knobs_config use kt_grids, only: get_kt_grids_config use kt_grids_box, only: get_kt_grids_box_config use kt_grids_range, only: get_kt_grids_range_config use kt_grids_single, only: get_kt_grids_single_config use kt_grids_specified, only: get_kt_grids_specified_config use kt_grids_specified, only: get_kt_grids_specified_element_config use gs2_layouts, only: get_layouts_config use le_grids, only: get_le_grids_config use nonlinear_terms, only: get_nonlinear_terms_config use normalisations, only: get_normalisations_config use optimisation_configuration, only: get_optimisation_config use gs2_reinit, only: get_reinit_config use dist_fn, only: get_source_config use species, only: get_species_config use species, only: get_species_element_config use split_nonlinear_terms, only: get_split_nonlinear_terms_config use antenna, only: get_stir_config use theta_grid, only: get_theta_grid_config use theta_grid_eik, only: get_theta_grid_eik_config use theta_grid_file, only: get_theta_grid_file_config use theta_grid_gridgen, only: get_theta_grid_gridgen_config use theta_grid_params, only: get_theta_grid_parameters_config use theta_grid_salpha, only: get_theta_grid_salpha_config class(gs2_config_type), intent(in out) :: self self%ballstab_config = get_ballstab_config() self%collisions_config = get_collisions_config() self%diagnostics_config = get_diagnostics_config() self%dist_fn_config = get_dist_fn_config() self%dist_fn_species_config = get_dist_fn_species_config() self%driver_config = get_driver_config() self%eigval_config = get_eigval_config() self%fields_config = get_fields_config() self%hyper_config = get_hyper_config() self%ingen_config = get_ingen_config() self%init_g_config = get_init_g_config() self%knobs_config = get_knobs_config() self%kt_grids_config = get_kt_grids_config() self%kt_grids_box_config = get_kt_grids_box_config() self%kt_grids_range_config = get_kt_grids_range_config() self%kt_grids_single_config = get_kt_grids_single_config() self%kt_grids_specified_config = get_kt_grids_specified_config() self%kt_grids_specified_element_config = get_kt_grids_specified_element_config() self%layouts_config = get_layouts_config() self%le_grids_config = get_le_grids_config() self%nonlinear_terms_config = get_nonlinear_terms_config() self%normalisations_config = get_normalisations_config() self%optimisation_config = get_optimisation_config() self%reinit_config = get_reinit_config() self%source_config = get_source_config() self%species_config = get_species_config() self%species_element_config = get_species_element_config() self%split_nonlinear_terms_config = get_split_nonlinear_terms_config() self%stir_config = get_stir_config() self%theta_grid_config = get_theta_grid_config() self%theta_grid_eik_config = get_theta_grid_eik_config() self%theta_grid_file_config = get_theta_grid_file_config() self%theta_grid_gridgen_config = get_theta_grid_gridgen_config() self%theta_grid_parameters_config = get_theta_grid_parameters_config() self%theta_grid_salpha_config = get_theta_grid_salpha_config() end subroutine get_configs !> Copy all the `self` configs into module level ones. subroutine set_configs(self) use ballstab, only: set_ballstab_config use collisions, only: set_collisions_config use diagnostics_configuration, only: set_diagnostics_config use dist_fn, only: set_dist_fn_config use dist_fn, only: set_dist_fn_species_config use antenna, only: set_driver_config use eigval, only: set_eigval_config use fields, only: set_fields_config use hyper, only: set_hyper_config use ingen_mod, only: set_ingen_config use init_g, only: set_init_g_config use run_parameters, only: set_knobs_config use kt_grids, only: set_kt_grids_config use kt_grids_box, only: set_kt_grids_box_config use kt_grids_range, only: set_kt_grids_range_config use kt_grids_single, only: set_kt_grids_single_config use kt_grids_specified, only: set_kt_grids_specified_config use kt_grids_specified, only: set_kt_grids_specified_element_config use gs2_layouts, only: set_layouts_config use le_grids, only: set_le_grids_config use nonlinear_terms, only: set_nonlinear_terms_config use normalisations, only: set_normalisations_config use optimisation_configuration, only: set_optimisation_config use gs2_reinit, only: set_reinit_config use dist_fn, only: set_source_config use species, only: set_species_config use species, only: set_species_element_config use split_nonlinear_terms, only: set_split_nonlinear_terms_config use antenna, only: set_stir_config use theta_grid, only: set_theta_grid_config use theta_grid_eik, only: set_theta_grid_eik_config use theta_grid_file, only: set_theta_grid_file_config use theta_grid_gridgen, only: set_theta_grid_gridgen_config use theta_grid_params, only: set_theta_grid_parameters_config use theta_grid_salpha, only: set_theta_grid_salpha_config class(gs2_config_type), intent(in) :: self call set_ballstab_config(self%ballstab_config) call set_collisions_config(self%collisions_config) call set_diagnostics_config(self%diagnostics_config) call set_dist_fn_config(self%dist_fn_config) call set_dist_fn_species_config(self%dist_fn_species_config) call set_driver_config(self%driver_config) call set_eigval_config(self%eigval_config) call set_fields_config(self%fields_config) call set_hyper_config(self%hyper_config) call set_ingen_config(self%ingen_config) call set_init_g_config(self%init_g_config) call set_knobs_config(self%knobs_config) call set_kt_grids_config(self%kt_grids_config) call set_kt_grids_box_config(self%kt_grids_box_config) call set_kt_grids_range_config(self%kt_grids_range_config) call set_kt_grids_single_config(self%kt_grids_single_config) call set_kt_grids_specified_config(self%kt_grids_specified_config) call set_kt_grids_specified_element_config(self%kt_grids_specified_element_config) call set_layouts_config(self%layouts_config) call set_le_grids_config(self%le_grids_config) call set_nonlinear_terms_config(self%nonlinear_terms_config) call set_normalisations_config(self%normalisations_config) call set_optimisation_config(self%optimisation_config) call set_reinit_config(self%reinit_config) call set_source_config(self%source_config) call set_species_config(self%species_config) call set_species_element_config(self%species_element_config) call set_split_nonlinear_terms_config(self%split_nonlinear_terms_config) call set_stir_config(self%stir_config) call set_theta_grid_config(self%theta_grid_config) call set_theta_grid_eik_config(self%theta_grid_eik_config) call set_theta_grid_file_config(self%theta_grid_file_config) call set_theta_grid_gridgen_config(self%theta_grid_gridgen_config) call set_theta_grid_parameters_config(self%theta_grid_parameters_config) call set_theta_grid_salpha_config(self%theta_grid_salpha_config) end subroutine set_configs !> Attempts to populate the configs from file (basically call their init methods). !> There's no attempt currently to enforce any order here so smart defaults are !> unlikely correct, but it at least checks we can parse all namelists. subroutine populate_from_file(self) class(gs2_config_type), intent(in out) :: self integer :: i logical :: allocated_flag call self%ballstab_config%init(name = 'ballstab_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%collisions_config%init(name = 'collisions_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%diagnostics_config%init(name = 'gs2_diagnostics_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%dist_fn_config%init(name = 'dist_fn_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%driver_config%init(name = 'driver',requires_index = .false., skip_smart_defaults = .true.) call self%eigval_config%init(name = 'eigval_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%fields_config%init(name = 'fields_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%hyper_config%init(name = 'hyper_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%ingen_config%init(name = 'ingen_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%init_g_config%init(name = 'init_g_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%knobs_config%init(name = 'knobs',requires_index = .false., skip_smart_defaults = .true.) call self%kt_grids_config%init(name = 'kt_grids_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%kt_grids_box_config%init(name = 'kt_grids_box_parameters',requires_index = .false., skip_smart_defaults = .true.) call self%kt_grids_range_config%init(name = 'kt_grids_range_parameters',requires_index = .false., skip_smart_defaults = .true.) call self%kt_grids_single_config%init(name = 'kt_grids_single_parameters',requires_index = .false., skip_smart_defaults = .true.) call self%kt_grids_specified_config%init(name = 'kt_grids_specified_parameters',requires_index = .false., skip_smart_defaults = .true.) call self%layouts_config%init(name = 'layouts_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%le_grids_config%init(name = 'le_grids_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%nonlinear_terms_config%init(name = 'nonlinear_terms_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%normalisations_config%init(name = 'normalisations_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%optimisation_config%init(name = 'optimisation_config',requires_index = .false., skip_smart_defaults = .true.) call self%reinit_config%init(name = 'reinit_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%source_config%init(name = 'source_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%species_config%init(name = 'species_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%split_nonlinear_terms_config%init(name = 'split_nonlinear_terms_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_config%init(name = 'theta_grid_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_eik_config%init(name = 'theta_grid_eik_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_file_config%init(name = 'theta_grid_file_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_gridgen_config%init(name = 'theta_grid_gridgen_knobs',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_parameters_config%init(name = 'theta_grid_parameters',requires_index = .false., skip_smart_defaults = .true.) call self%theta_grid_salpha_config%init(name = 'theta_grid_salpha_knobs',requires_index = .false., skip_smart_defaults = .true.) allocated_flag = allocated(self%dist_fn_species_config) if (.not. allocated_flag) then allocate(self%dist_fn_species_config(self%species_config%nspec)) do i = 1, size(self%dist_fn_species_config) self%dist_fn_species_config(i)%index = i end do end if do i = 1, size(self%dist_fn_species_config) call self%dist_fn_species_config(i)%init(name = 'dist_fn_species_knobs', requires_index = .true., index = i, skip_smart_defaults = .true.) end do allocated_flag = allocated(self%kt_grids_specified_element_config) if (.not. allocated_flag) then allocate(self%kt_grids_specified_element_config(self%kt_grids_specified_config%nmodes)) do i = 1, size(self%kt_grids_specified_element_config) self%kt_grids_specified_element_config(i)%index = i end do end if do i = 1, size(self%kt_grids_specified_element_config) call self%kt_grids_specified_element_config(i)%init(name = 'kt_grids_specified_element', requires_index = .true., index = i, skip_smart_defaults = .true.) end do allocated_flag = allocated(self%species_element_config) if (.not. allocated_flag) then allocate(self%species_element_config(self%species_config%nspec)) do i = 1, size(self%species_element_config) self%species_element_config(i)%index = i end do end if do i = 1, size(self%species_element_config) call self%species_element_config(i)%init(name = 'species_parameters', requires_index = .true., index = i, skip_smart_defaults = .true.) end do allocated_flag = allocated(self%stir_config) if (.not. allocated_flag) then allocate(self%stir_config(self%driver_config%nk_stir)) do i = 1, size(self%stir_config) self%stir_config(i)%index = i end do end if do i = 1, size(self%stir_config) call self%stir_config(i)%init(name = 'stir', requires_index = .true., index = i, skip_smart_defaults = .true.) end do end subroutine populate_from_file end module config_collection