params_feature_selection_m.f90 Source File


Contents


Source Code

module params_feature_selection_m
    !! Paramete related with selection of features
    use error_handling_grillix_m, only: handle_error
    use status_codes_grillix_m, only : GRILLIX_ERR_NAMELIST
    use screen_io_m, only : get_stdout
    implicit none
    
    logical, protected :: stop_after_init = .false.
    !! Indicates if code stops after establishing initial state 
    !! before entering time-stepping pahse
    logical, protected :: mms_on = .false.
    !! Switch for MMS analysis
    logical, protected :: mms_potvort_solve_on = .true.
    !! Switch for numerical solve of potential/vorticity 
    !! if set false, potential/vorticity will be set to MMS solution
    logical, protected :: mms_aparjpar_solve_on = .true.
    !! Switch for numerical solve of apar and jpar 
    !! if set false, apar/jpar will be set to MMS solution
    logical, protected :: mms_neutrals_temp_coeff = .false.
    !! DEBUGGING FEATURE: whether to use mms solution of neutrals_temp as implicit solve coefficient
    logical, protected :: checksum_on = .false.
    !! Switch for performing checksums on plasma state 
    !! no physical meaning, but can be used e.g. for CI/CD 
    !! to ensure integrity of code
    logical, protected :: neutrals_on = .false.
    !! Switch for neutrals module
    logical, protected :: iol_on = .false.
    !! Switch for Ion-orbit loss module 
    !! (If on needs to be compiled with -DENABLE_IOL=ON)
    logical, protected :: scalar_diagnostics_on = .false.
    !! Switch for enabling scalar diagnostics
    logical, protected :: zonal_diagnostics_on = .false.
    !! Switch for enabling zonal diagnostics
    logical, protected :: lineout_diagnostics_on = .false.
    !! Switch for enabling lineout diagnostics
    logical, protected :: field_diagnostics_on = .false.
    !! Switch for enabling full field diagnostics
    logical, protected :: analyse_snapshots_on = .false.
    !! Switch for analysising snapshots (without timestepping)
    integer, protected :: analyse_snapshots_start = 1
    !! Snapshot number where snapshot analysis starts
    integer, protected :: analyse_snapshots_end = 99999
    !! Snapshot number where snapshot analysis ends 
    logical, protected :: evol_apar_shift_on = .false.
    !! Switch for evolving background shift of apar

    public :: read_params_feature_selection
    public :: write_params_feature_selection
         
    namelist / feature_selection / &
        stop_after_init, &
        mms_on, &
        mms_potvort_solve_on, &
        mms_aparjpar_solve_on, &
        mms_neutrals_temp_coeff, &
        checksum_on, &
        neutrals_on, &
        iol_on, &
        scalar_diagnostics_on, &
        zonal_diagnostics_on, &
        lineout_diagnostics_on, &
        field_diagnostics_on, &
        analyse_snapshots_on, &
        analyse_snapshots_start, &
        analyse_snapshots_end, &
        evol_apar_shift_on
    private feature_selection
    
contains
       
    subroutine read_params_feature_selection(filename)
        !! Reads parameters related with feature_selection
        character(len=*), intent(in) :: filename
        !! Filename, to read from 
        
        integer :: io_unit, io_error
        character(len=256) :: io_errmsg 
         
        open(newunit=io_unit, file=filename, status='old', action='read', &
            iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif
  
        read(io_unit, nml=feature_selection, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif

        close(io_unit)

    end subroutine

    subroutine write_params_feature_selection(filename)
        !! Reads parameters related with feature_selection
        character(len=*), intent(in), optional :: filename
        !! If present, filename where params are written to, 
        !! if not present, writes to screen 
        
        integer :: io_unit, io_error
        character(len=256) :: io_errmsg 
         
        if (present(filename)) then
            open(newunit=io_unit, file=filename, status='unknown', &
                access='append', action='write', &
                iostat=io_error, iomsg=io_errmsg )
            if (io_error /= 0) then
                call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                                  __LINE__, __FILE__)
            endif
        else
            io_unit = get_stdout()
        endif

        write(io_unit, nml=feature_selection, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif

        if (present(filename)) then
            close(io_unit)
        endif

    end subroutine
end module