params_diffusion_boundaries_parpen_m.f90 Source File


Contents


Source Code

module params_diffusion_boundaries_parpen_m
    !! Parameters for the DIFFUSION model related with 
    !! parallel penalisation 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_par = BND_TYPE_DIRICHLET_ZERO
    !! Descriptor for parallel boundary condition
    real(GP), protected :: bnd_val_par = 0.0_GP
    !! Value that solution shall be damped to
    real(GP), protected :: epsinv = 0.0_GP
    !! Strength of penalisation source (Inverse of epsilon)
    logical, protected :: bnd_par_odd = .false.
    !! Switch if boundaries are applied in odd or even signs
    
    public :: read_params_boundaries_parpen
    public :: write_params_boundaries_parpen
        
    ! The bnd_type variables are introduced for human 
    ! readable format in parameter files
    character(len=32), private :: &
           bnd_type_par = 'BND_TYPE_DIRICHLET_ZERO'
    namelist / boundaries_parpen / &
            bnd_type_par, bnd_val_par, bnd_par_odd, epsinv
    private boundaries_parpen

contains

   subroutine read_params_boundaries_parpen(filename)
        !! Reads parameters related with boundaries_parpen
        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_parpen, 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_par)), &
            bnd_descr_par)

        close(io_unit)

    end subroutine
    
    subroutine write_params_boundaries_parpen(filename)
        !! Writes parameters related with boundaries_parpen
        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_parpen, 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