params_neut_boundaries_parpen_m.f90 Source File


Contents


Source Code

module params_neut_boundaries_parpen_m
    !! Parameters for the neutrals model related with parallel boundary conditions
    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

    ! Neutrals density
    integer, protected :: bnddescr_neut_dens_pen = BND_TYPE_DIRICHLET_ZERO
    !! Type of boundary condition of neutrals density for penalisation
    real(GP), protected :: bndval_neut_dens_peninto = 1.0_GP
    !! Value for penalisation boundary of neutrals density where magnetic field is directed towards target
    real(GP), protected :: bndval_neut_dens_penout = 1.0_GP
    !! Value for penalisation boundary of neutrals density where magnetic field is directed out of target
    real(GP), protected :: bndval_neut_dens_peninto_second = 1.0_GP
    !! Value for secondary penalisation boundary (with y>y0) of neutrals density
    real(GP), protected :: bndval_neut_dens_penout_second = 1.0_GP
    !! Value for secondary penalisation boundary (with y>y0) of neutrals density

    ! Neutrals parallel momentum
    integer, protected :: bnddescr_neut_parmom_pen = BND_TYPE_DIRICHLET_ZERO
    !! Type of boundary condition of neutrals parallel momentum for penalisation
    real(GP), protected :: bndval_neut_parmom_peninto = 0.0_GP
    !! Value for penalisation boundary of neutrals parallel momentum where magnetic field is directed towards target
    real(GP), protected :: bndval_neut_parmom_penout = 0.0_GP
    !! Value for penalisation boundary of neutrals parallel momentum where magnetic field is directed out of target
    real(GP), protected :: bndval_neut_parmom_peninto_second = 0.0_GP
    !! Value for secondary penalisation boundary (with y>y0) of neutrals parallel momentum
    real(GP), protected :: bndval_neut_parmom_penout_second = 0.0_GP
    !! Value for secondary penalisation boundary (with y>y0) of neutrals parallel momentum

    ! Neutrals pressure
    integer, protected :: bnddescr_neut_pressure_pen = BND_TYPE_DIRICHLET_ZERO
    !! Type of boundary condition of neutrals pressure for penalisation
    real(GP), protected :: bndval_neut_pressure_peninto = 1.0_GP
    !! Value for penalisation boundary of neutrals pressure where magnetic field is directed towards target
    real(GP), protected :: bndval_neut_pressure_penout = 1.0_GP
    !! Value for penalisation boundary of neutrals pressure where magnetic field is directed out of target
    real(GP), protected :: bndval_neut_pressure_peninto_second = 1.0_GP
    !! Value for penalisation boundary (with y>y0) of neutrals pressure
    real(GP), protected :: bndval_neut_pressure_penout_second = 1.0_GP
    !! Value for penalisation boundary (with y>y0) of neutrals pressure
    integer, protected :: second_pen_flag = 0
    !! = 0, do not distinguish the second penalisation boundary
    !! = 1, distinguish the second penalisation boundary by y-y0 > 0, where y0 is the y value of magnetic axis
    !! = -1, distinguish the second penalisation boundary by y-y0 < 0, where y0 is the y value of magnetic axis

    logical, protected :: on_neutrals_temp = .false.
    !! Whether or not to apply boundary condition on temperature instead of pressure. Default: false

    public :: read_params_neut_boundaries_parpen
    public :: write_params_neut_boundaries_parpen

    ! The bndtype variables are introduced for human
    ! readable format in parameter files
    character(len=64), private :: &
        bndtype_neut_dens_pen = 'BND_TYPE_DIRICHLET_ZERO', &
        bndtype_neut_parmom_pen = 'BND_TYPE_DIRICHLET_ZERO', &
        bndtype_neut_pressure_pen = 'BND_TYPE_DIRICHLET_ZERO'

    namelist / neut_boundaries_parpen / &
        bndtype_neut_dens_pen, bndval_neut_dens_peninto, bndval_neut_dens_penout, &
        bndval_neut_dens_peninto_second, bndval_neut_dens_penout_second, &
        bndtype_neut_parmom_pen, bndval_neut_parmom_peninto, bndval_neut_parmom_penout, &
        bndval_neut_parmom_peninto_second, bndval_neut_parmom_penout_second, &
        bndtype_neut_pressure_pen, bndval_neut_pressure_peninto, bndval_neut_pressure_penout, &
        bndval_neut_pressure_peninto_second, bndval_neut_pressure_penout_second, second_pen_flag, &
        on_neutrals_temp
    private neut_boundaries_parpen

contains

   subroutine read_params_neut_boundaries_parpen(filename)
        !! Reads parameters related with neut_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=neut_boundaries_parpen, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif

        call convert_descriptor_char_int(bndtype_neut_dens_pen, bnddescr_neut_dens_pen)
        call convert_descriptor_char_int(bndtype_neut_parmom_pen, bnddescr_neut_parmom_pen)
        call convert_descriptor_char_int(bndtype_neut_pressure_pen, bnddescr_neut_pressure_pen)

        close(io_unit)

    end subroutine

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