params_brag_buffer_m.f90 Source File


Contents


Source Code

module params_brag_buffer_m
    !! Parameters for the BRAGINSKII model related with buffer
    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
    use technical_constants_m, only : PATHLEN_MAX
    implicit none
         
    character(len=64), protected :: buffer_select = 'NONE'
    !! Type of buffer zone
    character(len=PATHLEN_MAX), protected :: buffer_path = 'params_braginskii.in'
    !! Name of file where parameters for buffer zone are read
    logical, protected :: buffer_dbgout = .true.
    !! Indicates if buffer function written out as netcdf file
    real(GP), protected :: buffer_coeff_ne = 0.0_GP
    !! Diffusion coefficient for density inside the buffer zone 
    real(GP), protected :: buffer_coeff_te = 0.0_GP
    !! Diffusion coefficient for electron temperature inside the buffer zone 
    real(GP), protected :: buffer_coeff_ti = 0.0_GP
    !! Diffusion coefficient for ion temperature inside the buffer zone
    real(GP), protected :: buffer_coeff_pe = 0.0_GP
    !! Diffusion coefficient for electron pressure inside the buffer zone 
    real(GP), protected :: buffer_coeff_pi = 0.0_GP
    !! Diffusion coefficient for ion pressure inside the buffer zone
    real(GP), protected :: buffer_coeff_vort = 0.0_GP
    !! Diffusion coefficient for vorticity inside the buffer zone
    real(GP), protected :: buffer_coeff_upar = 0.0_GP
    !! Diffusion coefficient for parallel velocity inside the buffer zone
    real(GP), protected :: buffer_coeff_ohm = 0.0_GP
    !! Diffusion coefficient for generalised electromagnetic potential 
    !! inside the buffer zone      

    public :: read_params_brag_buffer
    public :: write_params_brag_buffer

    namelist / brag_buffer / &
        buffer_select, &
        buffer_path, &
        buffer_dbgout, &
        buffer_coeff_ne, &
        buffer_coeff_te, &
        buffer_coeff_ti, &
        buffer_coeff_pe, &
        buffer_coeff_pi, &
        buffer_coeff_vort, &
        buffer_coeff_upar, &
        buffer_coeff_ohm
    private brag_buffer
    
contains

    subroutine read_params_brag_buffer(filename)
        !! Reads parameters related with brag_buffer
        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=brag_buffer, 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_brag_buffer(filename)
        !! Reads parameters related with brag_buffer
        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=brag_buffer, 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