params_diffusion_boundaries_perp_m.f90 Source File


Contents


Source Code

module params_diffusion_boundaries_perp_m
    !! Parameters for the DIFFUSION model related with perpendicular boundaries
    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 descriptors_m, only : convert_descriptor_char_int, BND_TYPE_DIRICHLET_ZERO
    implicit none
    
    integer, protected :: bnd_descr_core = BND_TYPE_DIRICHLET_ZERO
    !! Boundary descriptor for core
    real(GP), protected :: bnd_val_core = 0.0_GP
    !! Value for boundary condition at core
    integer, protected :: bnd_descr_wall= BND_TYPE_DIRICHLET_ZERO
    !! Boundary descriptor for wall
    real(GP), protected :: bnd_val_wall = 0.0_GP        
    !! Value for boundary condition at wall
    integer, protected :: bnd_descr_dome= BND_TYPE_DIRICHLET_ZERO
    !! Boundary descriptor for dome
    real(GP), protected :: bnd_val_dome = 0.0_GP
    !! Value for boundary condition at dome
    integer, protected :: bnd_descr_out= BND_TYPE_DIRICHLET_ZERO
    !! Boundary descriptor for shadow region
    real(GP), protected :: bnd_val_out = 0.0_GP
    !! Value for boundary condition at shadow region
        
    public :: read_params_boundaries_perp
    public :: write_params_boundaries_perp
        
    ! The bnd_type variables are introduced for human 
    ! readable format in parameter files
    character(len=32), private :: &
           bnd_type_core = 'BND_TYPE_DIRICHLET_ZERO', &
           bnd_type_wall = 'BND_TYPE_DIRICHLET_ZERO', &
           bnd_type_dome = 'BND_TYPE_DIRICHLET_ZERO', &
           bnd_type_out = 'BND_TYPE_DIRICHLET_ZERO'
           
    namelist / boundaries_perp / &
            bnd_type_core, bnd_type_wall, bnd_type_dome, bnd_type_out,  &
            bnd_val_core, bnd_val_wall, bnd_val_dome, bnd_val_out
    private boundaries_perp
        
contains

   subroutine read_params_boundaries_perp(filename)
        !! Reads parameters related with boundaries_perp
        character(len=*), intent(in) :: filename
        !! Filename, to read boundary parameters
     
        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=boundaries_perp, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif
        
        ! Convert character to descriptor (integer parameter) 
        call convert_descriptor_char_int(trim(adjustl(bnd_type_core)), &
            bnd_descr_core)
        call convert_descriptor_char_int(trim(adjustl(bnd_type_wall)), &
            bnd_descr_wall)
        call convert_descriptor_char_int(trim(adjustl(bnd_type_dome)), &
            bnd_descr_dome)
        call convert_descriptor_char_int(trim(adjustl(bnd_type_out)),  &
            bnd_descr_out)

        close(io_unit)

    end subroutine
    
    subroutine write_params_boundaries_perp(filename)
        !! Writes parameters related with boundaries_perp
        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=boundaries_perp, 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