params_brag_model_m.f90 Source File


Contents


Source Code

module params_brag_model_m
    !! Parameters for the BRAGINSKII model related with model, i.e.
    !! physics parameters
    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
    implicit none
         
    real(GP), protected :: rhos = GP_NAN
    !! Reference rho_s in inits of [R0] 
    !! --> used to normalise  perpendicular grid spacing
    real(GP), protected :: delta = GP_NAN
    !! Delta = R_0/rho_s, parameter in front of ExB advection terms
    real(GP), protected :: etapar0 = GP_NAN
    !! Normalized parallel resistivity
    real(GP), protected :: eta_i0 = GP_NAN
    !! Normalised ion resistivity
    real(GP), protected :: heat_fac = 0.0_GP
    !! Neoclassical heat viscosity coefficient (recommended: 0.75_GP / 0.96_GP )
    real(GP), protected :: tratio = GP_NAN
    !! Ion / electron temperature ratio  at reference T_i0 / T_e0 
    real(GP), protected :: beta = GP_NAN
    !! Normalized plasma beta at reference
    real(GP), protected :: mass_ratio_ei = GP_NAN
    !! Electron to ion mass ratio
    real(GP), protected :: nu_e0 = GP_NAN
    !! Normalised electron collision frequency at reference
    real(GP), protected :: thermal_force_coeff = 0.71_GP
    !! Thermal force coefficient
    logical, protected :: boussinesq_on = .false.
    !! Switch for Boussinesq approximation
   
    public :: read_params_brag_model
    public :: write_params_brag_model
   
    namelist / brag_model / &
        rhos, &
        delta, &
        etapar0, &
        eta_i0, &
        heat_fac, &
        tratio, &
        beta, &
        mass_ratio_ei, &
        nu_e0, &
        thermal_force_coeff, &
        boussinesq_on 
    private brag_model
        
contains

   subroutine read_params_brag_model(filename)
        !! Reads parameters related with brag_model
        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_model, 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_brag_model(filename)
        !! Reads parameters related with brag_model
        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_model, 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