params_brag_switches_m.f90 Source File


Contents


Source Code

module params_brag_switches_m
    !! Parameters for the Braiginskii model related 
    !! with switches for individual terms
    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
    implicit none

    real(GP), protected :: swb_flutter_main = 1.0_GP
    !! Main switch for all flutter terms

    ! Continuity equation 
    real(GP), protected :: swb_cont_exb = 1.0_GP
    !! Switch for ExB Advection term in continuity equation
    real(GP), protected :: swb_cont_curv_pot = 1.0_GP
    !! Switch for ne*C(pot) term in continuity equation
    real(GP), protected :: swb_cont_curv_te = 1.0_GP
    !! Switch for -ne*C(te) term in continuity equation
    real(GP), protected :: swb_cont_curv_ne = 1.0_GP
    !! Switch for -te*C(ne) term in continuity equation     
    real(GP), protected :: swb_cont_divjpar = 1.0_GP
    !! Switch for div(jpar) term in continuity equation
    real(GP), protected :: swb_cont_paradv    = 1.0_GP
    !! Switch for parallel advection in continuity equation
    real(GP), protected :: swb_cont_divupar = 1.0_GP
    !! Switch for div(upar) term in continuity equation
    real(GP), protected :: swb_cont_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in continuity equation
    real(GP), protected :: swb_cont_dissparallel = 1.0_GP
    !! Switch for parallel dissipation term in continuity equation
    real(GP), protected :: swb_cont_source = 1.0_GP
    !! Switch for source term in continuity equation
    real(GP), protected :: swb_cont_flutter_paradv    = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection in continuity equation
    real(GP), protected :: swb_cont_flutter_divjpar = 1.0_GP
    !! Switch for magnetic-flutter-caused div(jpar) term in continuity equation
    real(GP), protected :: swb_cont_flutter_divupar = 1.0_GP
    !! Switch for magnetic-flutter-caused div(upar) term in continuity equation
    
    ! Electron temperature equation
    real(GP), protected :: swb_etemp_exb = 1.0_GP
    !! Switch for ExB Advection term in electron temperature equation
    real(GP), protected :: swb_etemp_paradv    = 1.0_GP
    !! Switch for parallel advection in electron temperature equation
    real(GP), protected :: swb_etemp_curv_pot = 1.0_GP
    !! Switch for C(pot) term in electron temperature equation
    real(GP), protected :: swb_etemp_curv_ne = 1.0_GP
    !! Switch for C(ne) term in electron temperature equation
    real(GP), protected :: swb_etemp_curv_te = 1.0_GP
    !! Switch for C(Te) term in electron temperature equation
    real(GP), protected :: swb_etemp_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in electron temperature equation
    real(GP), protected :: swb_etemp_divvpar = 1.0_GP
    !! Switch for divergence of parallel electron velocity in electron temperature equation
    real(GP), protected :: swb_etemp_divjpar = 1.0_GP
    !! Switch for divergence of parallel current in electron temperature equation
    real(GP), protected :: swb_etemp_resist = 1.0_GP
    !! Switch for parallel resistivity in electron temperature equation
    real(GP), protected :: swb_etemp_equipart = 1.0_GP
    !! Switch for equipartition term in electron temperature equation
    real(GP), protected :: swb_etemp_pardiff = 1.0_GP
    !! Switch for parallel heat diffusion in electron temperature equation
    real(GP), protected :: swb_etemp_source = 1.0_GP
    !! Switch for source term in electron temperature equation
    real(GP), protected :: swb_etemp_flutter_paradv = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection term in electron temperature equation
    real(GP), protected :: swb_etemp_flutter_divvpar = 1.0_GP
    !! Switch for magnetic-flutter-caused divvpar term in electron temperature equation
    real(GP), protected :: swb_etemp_flutter_divjpar = 1.0_GP
    !! Switch for magnetic-flutter-caused divjpar term in electron temperature equation
    real(GP), protected :: swb_etemp_flutter_pardiff_div = 1.0_GP
    !! Switch for magnetic-flutter-caused divergence of heat flux in etemp_pardiff term
    real(GP), protected :: swb_etemp_flutter_pardiff_grad = 1.0_GP
    !! Switch for magnetic-flutter-caused gradient of electron temperature in etemp_pardiff term

    ! Ion temperature equation
    real(GP), protected :: swb_itemp_exb = 1.0_GP
    !! Switch for ExB Advection term in ion temperature equation
    real(GP), protected :: swb_itemp_curv_pot = 1.0_GP
    !! Switch for C(pot) term in ion temperature equation
    real(GP), protected :: swb_itemp_curv_ne = 1.0_GP
    !! Switch for C(ne) term in ion temperature equation
    real(GP), protected :: swb_itemp_curv_te = 1.0_GP
    !! Switch for C(Te) term in ion temperature equation
    real(GP), protected :: swb_itemp_curv_ti = 1.0_GP
    !! Switch for C(Te) term in ion temperature equation
    real(GP), protected :: swb_itemp_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in ion temperature equation
    real(GP), protected :: swb_itemp_paradv = 1.0_GP
    !! Switch for parallel advection in ion temperature equation
    real(GP), protected :: swb_itemp_pardiff = 1.0_GP
    !! Switch for parallel heat diffusion in ion temperature equation
    real(GP), protected :: swb_itemp_divupar = 1.0_GP
    !! Switch for div(upar) term in ion temperature equation
    real(GP), protected :: swb_itemp_divjpar = 1.0_GP
    !! Switch for div(jpar) term in ion temperature equation
    real(GP), protected :: swb_itemp_equipart = 1.0_GP
    !! Switch for equipartition term in ion temperature equation
    real(GP), protected :: swb_itemp_vischeat = 1.0_GP
    !! Switch for ion viscous heating in ion temperature equation
    real(GP), protected :: swb_itemp_source = 1.0_GP
    !! Switch for source term in ion temperature equation
    real(GP), protected :: swb_itemp_flutter_paradv = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection term in ion temperature equation
    real(GP), protected :: swb_itemp_flutter_divupar = 1.0_GP
    !! Switch for magnetic-flutter-caused divvpar term in ion temperature equation
    real(GP), protected :: swb_itemp_flutter_divjpar = 1.0_GP
    !! Switch for magnetic-flutter-caused divjpar term in ion temperature equation
    real(GP), protected :: swb_itemp_flutter_pardiff_div = 1.0_GP
    !! Switch for magnetic-flutter-caused divergence of heat flux in itemp_pardiff term
    real(GP), protected :: swb_itemp_flutter_pardiff_grad = 1.0_GP
    !! Switch for magnetic-flutter-caused gradient of ion temperature in itemp_pardiff term
    
    ! Parallel momentum equation
    real(GP), protected :: swb_upar_exb = 1.0_GP
    !! Switch for ExB Advection term in parallel momentum equation
    real(GP), protected :: swb_upar_paradv = 1.0_GP
    !! Switch for parallel advection term in parallel momentum equation
    real(GP), protected :: swb_upar_curv = 1.0_GP
    !! Switch for curvature term in parallel momentum equation
    real(GP), protected :: swb_upar_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in parallel momentum equation
    real(GP), protected :: swb_upar_gradpar_n = 1.0_GP
    !! Switch for parallel density gradient in parallel momentum equation
    real(GP), protected :: swb_upar_gradparTe = 1.0_GP
    !! Switch for parallel electron temperature gradient in parallel momentum equation
    real(GP), protected :: swb_upar_gradparTi = 1.0_GP
    !! Switch for parallel ion temperature gradient in parallel momentum equation
    real(GP), protected :: swb_upar_viscion = 1.0_GP
    !! Switch for ion gyroviscous dissipation in parallel momentum equation
    real(GP), protected :: swb_upar_source = 1.0_GP
    !! Switch for source term in parallel momentum equation
    real(GP), protected :: swb_upar_flutter_paradv = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection term in parallel momentum equation
    real(GP), protected :: swb_upar_flutter_gradne = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_ne term in parallel momentum equation
    real(GP), protected :: swb_upar_flutter_gradte = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_te term in parallel momentum equation
    real(GP), protected :: swb_upar_flutter_gradti = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_ti term in parallel momentum equation
    real(GP), protected :: swb_upar_flutter_viscion_grad = 1.0_GP
    !! Switch for magnetic-flutter-caused gradient ion gyroviscous dissipation
    
    real(GP), protected :: swb_flutter_visc = 1.0_GP
    !! Switch for magnetic-flutter corrections of Braginskii's ion viscosity (flutter divergence)
    real(GP), protected :: swb_neocl_visc = 0.0_GP
    !! Switch for neoclassical corrections of Braginskii's ion viscosity
   
    ! Vorticity equation
    real(GP), protected :: swb_vort_dia = 1.0_GP
    !! Switch for diamagnetic polarisation term in vorticity equation
    real(GP), protected :: swb_vort_exb = 1.0_GP
    !! Switch for ExB Advection term in vorticity equation
    real(GP), protected :: swb_vort_paradv = 1.0_GP
    !! Switch for parallel advection term in vorticity equation
    real(GP), protected :: swb_vort_necurvte = 1.0_GP
    !! Switch for ne*C(te) term in vorticity equation
    real(GP), protected :: swb_vort_tecurvne = 1.0_GP
    !! Switch for te*C(ne) term in vorticity equation
    real(GP), protected :: swb_vort_necurvti = 1.0_GP
    !! Switch for ne*C(ti) term in vorticity equation
    real(GP), protected :: swb_vort_ticurvne = 1.0_GP
    !! Switch for ti*C(ne) term in vorticity equation
    real(GP), protected :: swb_vort_divjpar = 1.0_GP
    !! Switch for divjpar term in vorticity equation
    real(GP), protected :: swb_vort_viscion = 1.0_GP
    !! Switch for ion gyroviscous dissipation in vorticity equation 
    real(GP), protected :: swb_vort_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in vorticity equation
    real(GP), protected :: swb_vort_dissparallel = 1.0_GP
    !! Switch for parallel dissipation term in vorticity equation
    real(GP), protected :: swb_vort_source = 1.0_GP
    !! Switch for source term in vorticity equation
    real(GP), protected :: swb_vort_flutter_divjpar = 1.0_GP
    !! Switch for magnetic-flutter-caused divjpar term in vorticity equation
    real(GP), protected :: swb_vort_flutter_paradv = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection term in vorticity equation

    ! Ohm's law 
    real(GP), protected :: swb_ohm_exb = 1.0_GP
    !! Switch for ExB Advection term in Ohm's law
    real(GP), protected :: swb_ohm_paradv = 1.0_GP
    !! Switch for parallel advection in Ohm's law
    real(GP), protected :: swb_ohm_physdiss = 1.0_GP
    !! Switch for physical dissipation in Ohm's law
    real(GP), protected :: swb_ohm_gradpar_pot = 1.0_GP
    !! Switch for parallel gradient on electrostatic potential in Ohm's law
    real(GP), protected :: swb_ohm_gradpar_ne = 1.0_GP
    !! Switch for parallel gradient on density in Ohm's law
    real(GP), protected :: swb_ohm_gradpar_te = 1.0_GP
    !! Switch for parallel gradient on electrom temperature in Ohm's law
    real(GP), protected :: swb_ohm_dissperp = 1.0_GP
    !! Switch for perpendicular dissipation term in Ohm's law
    real(GP), protected :: swb_ohm_dissparallel = 1.0_GP
    !! Switch for parallel dissipation term in Ohm's law
    real(GP), protected :: swb_ohm_flutter_paradv = 1.0_GP
    !! Switch for magnetic-flutter-caused parallel advection term in Ohm's law
    real(GP), protected :: swb_ohm_flutter_gradpot = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_pot term in Ohm's law
    real(GP), protected :: swb_ohm_flutter_gradne = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_ne term in Ohm's law
    real(GP), protected :: swb_ohm_flutter_gradte = 1.0_GP
    !! Switch for magnetic-flutter-caused gradpar_te term in Ohm's law
        
    public :: read_params_brag_switches
    public :: write_params_brag_switches
    
    namelist / brag_switches / &
        swb_flutter_main, &
        swb_cont_exb, &
        swb_cont_curv_pot, &
        swb_cont_curv_te, &
        swb_cont_curv_ne, &
        swb_cont_divjpar, &
        swb_cont_paradv   , &
        swb_cont_divupar, &
        swb_cont_dissperp, &
        swb_cont_dissparallel, &
        swb_cont_source, &
        swb_cont_flutter_paradv   , &
        swb_cont_flutter_divjpar, &
        swb_cont_flutter_divupar, &

        swb_etemp_exb, &
        swb_etemp_paradv   , &
        swb_etemp_curv_pot, &
        swb_etemp_curv_ne, &
        swb_etemp_curv_te, &
        swb_etemp_dissperp, &
        swb_etemp_divvpar, &
        swb_etemp_divjpar, &
        swb_etemp_resist, &
        swb_etemp_equipart, &
        swb_etemp_pardiff, &
        swb_etemp_source, &
        swb_etemp_flutter_paradv, &
        swb_etemp_flutter_divvpar, &
        swb_etemp_flutter_divjpar, &
        swb_etemp_flutter_pardiff_div, &
        swb_etemp_flutter_pardiff_grad, &
        
        swb_itemp_exb, &
        swb_itemp_curv_pot, &
        swb_itemp_curv_ne, &
        swb_itemp_curv_te, &
        swb_itemp_curv_ti, &
        swb_itemp_dissperp, &
        swb_itemp_paradv, &
        swb_itemp_pardiff, &
        swb_itemp_divupar, &
        swb_itemp_divjpar, &
        swb_itemp_equipart, &
        swb_itemp_vischeat, &
        swb_itemp_source, &
        swb_itemp_flutter_paradv, &
        swb_itemp_flutter_divupar, &
        swb_itemp_flutter_divjpar, &
        swb_itemp_flutter_pardiff_div, &
        swb_itemp_flutter_pardiff_grad, &

        swb_upar_exb, &
        swb_upar_paradv, &
        swb_upar_curv, &
        swb_upar_dissperp, &
        swb_upar_gradpar_n, &
        swb_upar_gradparTe, &
        swb_upar_gradparTi, &
        swb_upar_viscion, &
        swb_upar_source, &
        swb_upar_flutter_paradv, &
        swb_upar_flutter_gradne, &
        swb_upar_flutter_gradte, &
        swb_upar_flutter_gradti, &
        swb_upar_flutter_viscion_grad, &
        
        swb_flutter_visc, &
        swb_neocl_visc, &

        swb_vort_dia, &
        swb_vort_exb, &
        swb_vort_paradv, &
        swb_vort_necurvte, &
        swb_vort_tecurvne, &
        swb_vort_necurvti, &
        swb_vort_ticurvne, &
        swb_vort_divjpar, &
        swb_vort_viscion, &
        swb_vort_dissperp, &
        swb_vort_dissparallel, &
        swb_vort_source, &
        swb_vort_flutter_divjpar, &
        swb_vort_flutter_paradv, &

        swb_ohm_exb, &
        swb_ohm_paradv, &
        swb_ohm_physdiss, &
        swb_ohm_gradpar_pot, &
        swb_ohm_gradpar_ne, &
        swb_ohm_gradpar_te, &
        swb_ohm_dissperp, &
        swb_ohm_dissparallel, &
        swb_ohm_flutter_paradv, &
        swb_ohm_flutter_gradpot, &
        swb_ohm_flutter_gradne, &
        swb_ohm_flutter_gradte
        
    private brag_switches
    
contains

   subroutine read_params_brag_switches(filename)
        !! Reads parameters related with brag_switches
        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_switches, 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_switches(filename)
        !! Reads parameters related with switches
        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_switches, 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