params_neut_floors_m.f90 Source File


Contents


Source Code

module params_neut_floors_m
    !! Parameters for the neutrals model related with floors
    use precision_grillix_m, only : GP, GP_EPS, GP_LARGEST
    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
    
    real(GP), protected :: floor_dens = GP_EPS
    !! Floor value for neutrals density
    real(GP), protected :: floor_temp = GP_EPS
    !! Minimal neutrals temperature in neutrals model
    real(GP), protected :: rho_min_for_parmom_advection = -GP_LARGEST
    !! Flux surface below which no parallel advection is applied for neutrals parallel momentum
    !! to avoid numerical problems due to divisions by small numbers (neutrals_dens is near zero).

    public :: read_params_neut_floors
    public :: write_params_neut_floors
    
    namelist / neut_floors / &
        floor_dens, &
        floor_temp, &
        rho_min_for_parmom_advection
    private neut_floors

contains

   subroutine read_params_neut_floors(filename)
        !! Reads parameters related with neut_floors
        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=neut_floors, 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_neut_floors(filename)
        !! Reads parameters related with neut_floors
        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=neut_floors, 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