params_brag_boundaries_parpen_m.f90 Source File


Contents


Source Code

module params_brag_boundaries_parpen_m
    !! Parameters for the BRAGINSKII model related with boundaries_parpen
    use precision_grillix_m, only : GP, GP_NAN
    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_braginskii_m, only : &
        convert_descriptor_char_int, &
        BND_TYPE_NEUMANN, BND_TYPE_DIRICHLET_ZERO, BND_BRAGTYPE_JPAR_SMOOTHPENZERO
    implicit none
         
       
    real(GP), protected :: pen_epsinv = GP_NAN
    !! Inverse of penalisation epsilon

    ! For density
    integer, protected :: bnddescr_ne_pen = BND_TYPE_NEUMANN
    !! Type of boundary condition of density for penalisation
    real(GP), protected :: bndval_ne_pen = 1.0_GP
    !! Value for penalisation boundary of density

    ! For electron temperature
    integer, protected :: bnddescr_te_pen = BND_TYPE_NEUMANN
    !! Type of boundary condition of electron temperature for penalisation
    real(GP), protected :: bndval_te_pen = 1.0_GP
    !! Value for penalisation boundary of electron temperature 
    real(GP), protected :: sheath_heattransfac_e = 2.5_GP
    !! Anomalous electron sheath heat-transmission factor,
    !! used with BND_BRAGTYPE_PARALLEL_HEAT_TRANSMISSION boundary condition

    ! For ion temperature
    integer, protected :: bnddescr_ti_pen = BND_TYPE_NEUMANN
    !! Type of boundary condition of ion temperature for penalisation
    real(GP), protected :: bndval_ti_pen = 1.0_GP
    !! Value for penalisation boundary of ion temperature
    real(GP), protected :: sheath_heattransfac_i = 0.1_GP
    !! Anomalous ion sheath heat-transmission factor,
    !! used with BND_BRAGTYPE_PARALLEL_HEAT_TRANSMISSION boundary condition

    ! For parallel ion velocity
    integer, protected :: bnddescr_upar_pen = BND_TYPE_NEUMANN
    !! Type of boundary condition of parallel ion velocity for penalisation
    real(GP), protected :: bohm_frac_ti = 1.0_GP
    !! Fraction/switch of the ion temperature included in the calculation 
    !! of the sound speed at the Bohm boundary conditions (for upar)

    ! For generalised vorticity
    integer, protected :: bnddescr_vort_pen = BND_TYPE_NEUMANN
    !! Type of boundary condition of vorticity for penalisation
    real(GP), protected :: bndval_vort_pen = 0.0_GP
    !! Value for penalisation boundary of vorticity

    ! For electrostatic potential
    integer, protected :: bnddescr_pot_pen = BND_TYPE_DIRICHLET_ZERO
    !! Type of boundary condition of electrostatic potential 
    !! for penalisation
    real(GP), protected :: sheath_potential_lambda_sh = 2.69_GP
    !! Potential drop across the sheath, usually \approx 2.69

    ! For parallel current (Ohm's law)
    integer, protected :: bnddescr_ohm_pen = BND_BRAGTYPE_JPAR_SMOOTHPENZERO
    !! Type of boundary condition for parallel current
    !! (intricate in Ohm's law)
       
    public :: read_params_brag_boundaries_parpen
    public :: write_params_brag_boundaries_parpen
    
    
    ! The bndtype variables are introduced for human 
    ! readable format in parameter files
    character(len=64), private :: &
        bndtype_ne_pen = 'BND_TYPE_NEUMANN', &
        bndtype_te_pen = 'BND_TYPE_NEUMANN', &
        bndtype_ti_pen = 'BND_TYPE_NEUMANN', &
        bndtype_upar_pen = 'BND_TYPE_NEUMANN', & 
        bndtype_vort_pen = 'BND_TYPE_DIRICHLET_ZERO', & 
        bndtype_pot_pen = 'BND_TYPE_DIRICHLET_ZERO', & 
        bndtype_ohm_pen = 'BND_BRAGTYPE_JPAR_SMOOTHPENZERO'        
        
    namelist / brag_boundaries_parpen / &
        pen_epsinv, &
        bndtype_ne_pen, &
        bndval_ne_pen, &
        bndtype_te_pen, &
        bndval_te_pen, &
        sheath_heattransfac_e, &
        bndtype_ti_pen, &
        bndval_ti_pen, &
        sheath_heattransfac_i, &
        bndtype_upar_pen, &
        bohm_frac_ti, &
        bndtype_vort_pen, &
        bndval_vort_pen, &
        bndtype_pot_pen, &
        sheath_potential_lambda_sh, &
        bndtype_ohm_pen
     private brag_boundaries_parpen
        
contains

   subroutine read_params_brag_boundaries_parpen(filename)
        !! Reads parameters related with brag_boundaries_parpen
        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_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 to descriptors
        call convert_descriptor_char_int(bndtype_ne_pen, bnddescr_ne_pen)
        call convert_descriptor_char_int(bndtype_te_pen, bnddescr_te_pen)
        call convert_descriptor_char_int(bndtype_ti_pen, bnddescr_ti_pen)
        call convert_descriptor_char_int(bndtype_upar_pen, bnddescr_upar_pen)
        call convert_descriptor_char_int(bndtype_vort_pen, bnddescr_vort_pen)
        call convert_descriptor_char_int(bndtype_pot_pen, bnddescr_pot_pen)        
        call convert_descriptor_char_int(bndtype_ohm_pen, bnddescr_ohm_pen)
        
        close(io_unit)

    end subroutine

    subroutine write_params_brag_boundaries_parpen(filename)
        !! Reads parameters related with brag_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=brag_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