params_tstep_m.f90 Source File


Contents

Source Code


Source Code

module params_tstep_m
    !! Parameters for the Braginskii model related with time-stepping
    use precision_grillix_m, only : GP
    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
    
    integer, protected :: tstep_order = 2
    !! Order of time-stepping scheme
    real(GP), protected :: dtau = 1.0E-2_GP
    !! Size of time-step
    real(GP), protected :: tau_fin = 20.0_GP
    !! End timepoint of simulation            
    real(GP), protected:: tau_snaps = 1.0_GP
    !! Time interval for snapshot output 
    real(GP), protected:: tau_diags = 1.0_GP
    !! Time interval for diagnostic snapshot output 
    logical, protected:: tstep_dbgout =.false.
    !! Switch if debug output shall be written
      
    public :: read_params_tstep
    public :: write_params_tstep
      
    namelist / tstep / &
        tstep_order, dtau, tau_fin, tau_snaps, &
        tau_diags, tstep_dbgout
    private tstep
         
contains

    subroutine read_params_tstep(filename)
        !! Reads parameters related with timestepping in Braginskii model
        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=tstep, 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_tstep(filename)
        !! Reads parameters related with timestepping in Braginskii model
        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=tstep, 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