
! Copyright (C) 2002 - Observatoire de Paris/Meudon
!                      Universite Paris 7
!                      CNRS (France)
!                      Contact : Jacques.Lebourlot@obspm.fr
!
! This program is free software; you can redistribute it and/or
! modify it under the terms of the GNU General Public License version 2
! as published by the Free Software Foundation.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

! 20 mai 2008 - JLB

MODULE PXDR_CHEM_DATA

! Chemistry related quantities
! Introduced 30 aug 2002 - JLB

  USE PXDR_CONSTANTES

! Different type of chemical reactions
  INTEGER, PUBLIC                                   :: nchemfil ! number of lines in input chemistry file (for hdf5 output files)

  INTEGER, PUBLIC                                   :: nh2for   ! type 0 : H2 and HD formation on grains
                                                                ! Obsolete old style ! DON'T USE ANY MORE !
  INTEGER, PUBLIC                                   :: ncrion   ! type 1 : Cosmic rays processes
  INTEGER, PUBLIC                                   :: npsion   ! type 2 : Secondary photons processes
  INTEGER, PUBLIC                                   :: nasrad   ! type 3 : Radiative association
  INTEGER, PUBLIC                                   :: nrest    ! type 4 : Ordinary gas phase reactions
  INTEGER, PUBLIC                                   :: nh2endo  ! type 6 : Endothermal reactions with H2 (NEW!)
  INTEGER, PUBLIC                                   :: nphot_f  ! type 5 : Photoreactions (external fit)
  INTEGER, PUBLIC                                   :: nphot_i  ! type 7 : Photoreactions (direct integration)
  INTEGER, PUBLIC                                   :: i_mandat ! type 7 : Photoreactions (mandatory rxns -> not in sections)
  INTEGER, PUBLIC                                   :: kdeph0   ! type 7 : index of first mandatory photorxn
  INTEGER, PUBLIC                                   :: n3body   ! type 8 : 3 body reactions

  INTEGER, PUBLIC                                   :: ncpart   ! type 101, ... : Exceptions and special cases

  INTEGER, PUBLIC                                   :: ngsurf   ! type 11 : Reactions on grain surface
  INTEGER, PUBLIC                                   :: ngphot   ! type 12 : Photoreactions on grain surface
  INTEGER, PUBLIC                                   :: ngads    ! type 13 : Adsorption on to grains
  INTEGER, PUBLIC                                   :: ngneut   ! type 14 : Neutralization
  INTEGER, PUBLIC                                   :: nggdes   ! type 15 : Explosive desorption from grains
  INTEGER, PUBLIC                                   :: ncrdes   ! type 16 : Cosmic rays induced desorption
  INTEGER, PUBLIC                                   :: nphdes   ! type 17 : Photodesorption from grains
  INTEGER, PUBLIC                                   :: ngevap   ! type 18 : Evaporation from grains
  INTEGER, PUBLIC                                   :: ngchs    ! type 19 : Chemisorption on grains
  INTEGER, PUBLIC                                   :: ngelri   ! type 20 : Eley-Rideal process
  INTEGER, PUBLIC                                   :: nxray    ! type 30 : xray ionization
  INTEGER, PUBLIC                                   :: nelsec   ! type 31 : ionization by secondary electrons
  INTEGER, PUBLIC                                   :: nglass   ! type 40 : radiative and dielec. recomb. of atomic ions

  INTEGER, PUBLIC                                   :: iphot_i  ! index of the first type 7  reaction
  INTEGER, PUBLIC                                   :: ixray_i  ! index of the first type 30 reaction

  INTEGER, PUBLIC                                   :: nsp_ne   ! Number of neutral species
  INTEGER, PUBLIC                                   :: nsp_ip   ! Number of ionised species
  INTEGER, PUBLIC                                   :: nsp_im   ! Number of negatively charged species
  INTEGER, PUBLIC                                   :: nsp_gm   ! Number of species on grains (multi layers)
  INTEGER, PUBLIC                                   :: nsp_cs   ! Number of chemisorbed species on grains (mono layer)
  INTEGER, PUBLIC                                   :: nsp_g1   ! Number of species on grains (mono layer)
  INTEGER, PUBLIC                                   :: nsp_n1   ! = nsp_ne + nsp_ip + nsp_im + nsp_gm + nsp_cs
  INTEGER, PUBLIC                                   :: nspec    ! Number chemical species (total)
  INTEGER, PUBLIC                                   :: n_var    ! Number of variables in NR system
  INTEGER, PUBLIC                                   :: neqt     ! Number of chemical equations
  INTEGER, PUBLIC, PARAMETER                        :: nbrm = 3 ! Max number of reactants
  INTEGER, PUBLIC, PARAMETER                        :: nbpm = 4 ! Max number of products
  INTEGER, PUBLIC, PARAMETER                        :: nbsm = 7 ! Max number of species in a reaction

  REAL (KIND=dp), PUBLIC, DIMENSION (0:nes+npart)   :: enth     ! Reaction enthalpies
  INTEGER, PUBLIC, DIMENSION(nqm,0:nbsm)            :: react    ! Chemical reactions
  REAL (KIND=dp), PUBLIC, DIMENSION(:,:), ALLOCATABLE :: pr_rej ! Probability of rejection

  REAL (KIND=dp), PUBLIC, DIMENSION (0:nes,0:noptm) :: rxigr  ! Recombination rate of ions on grains
  REAL (KIND=dp), PUBLIC, DIMENSION(:), ALLOCATABLE :: abions ! ions / electrons abundances of the ngneut reactions during the previous subiteration (itenua)
  REAL (KIND=dp), PUBLIC, DIMENSION (2,0:noptm)     :: relgr  ! Production and destruction rates of electrons by grains

  ! ----------------------------------------------------------------
  TYPE (RREC_DREC), DIMENSION (:), ALLOCATABLE      :: rdrec       ! radiative and dielectric recombination table...
                                                                   ! defined as a RREC_DREC TYPE variable (PXDR_CONTANTES)
  ! ----------------------------------------------------------------

! 12 Feb 2008 - Change the way to compute reaction rates and Jacobian
  TYPE (SPDF), DIMENSION (:), ALLOCATABLE           :: xmatk       ! New full reaction rates
  REAL (KIND=dp), PUBLIC, DIMENSION(:), ALLOCATABLE :: creat       ! Creation rate of species
  INTEGER, PUBLIC                                   :: k_fco_c_oh  ! index of reaction C + OH -> CO + H
  REAL (KIND=dp), PUBLIC                            :: t_fco_c_oh  ! exothermicity in K
  REAL (KIND=dp), PUBLIC, DIMENSION(:), ALLOCATABLE :: bfact_co    ! Boltzman factor for CO formation-excitation
  REAL (KIND=dp), PUBLIC                            :: e_int_co    ! Internal energy in each CO formation (eV)
  REAL (KIND=dp), PUBLIC                            :: T2_stick_ER ! Critical gas temperature for stick of H = 0.5
  REAL (KIND=dp), PUBLIC                            :: ex_stick_ER ! Temperature exponent for sticking coefficient
  INTEGER, PUBLIC                                   :: k_fh3p_h2p_h2  ! index of reaction H2+ + H2 -> H3+ + H
  REAL (KIND=dp), PUBLIC                            :: t_fh3p_h2p_h2  ! exothermicity in K of H2+ + H2 -> H3+ + H
  REAL (KIND=dp), PUBLIC                            :: e_int_h3p      ! Internal energy in each H3+ formation (eV)
  INTEGER, PUBLIC                                   :: k_foat_oh_phot ! index of reaction OH + photon -> O + H
  REAL (KIND=dp), PUBLIC                            :: T_eff_H2    ! Effective excitation energy of H2, used for new type (6) reactions

  ! Data from report_4105.pdf - Collisional destruction of H2 by H
  ! Janev, Reiter & Samm, 2008, "Collision and Radiative Processes in Hydrogen Plasmas", Springer
  REAL (KIND=dp), PUBLIC, DIMENSION (0:14)          :: a1h2v, a2h2v, a3h2v, a4h2v, a5h2v
  DATA a1h2v / 20.6964_dp   , 20.5788_dp   , 20.5183_dp   , 20.4460_dp   , 20.3608_dp     &
             , 20.2426_dp   , 20.0161_dp   , 19.8954_dp   , 19.7543_dp   , 19.7464_dp     &
             , 19.5900_dp   , 19.4937_dp   , 19.0708_dp   , 18.9718_dp   , 18.7530_dp     /
  DATA a2h2v /  7.32149e7_dp,  4.32679e7_dp,  5.15169e7_dp,  1.87116e8_dp,  4.93688e8_dp  &
             ,  1.80194e8_dp,  2.96945e5_dp,  4.53104e5_dp,  5.13174e5_dp,  9.47230e4_dp  &
             ,  6.43990e4_dp,  3.49017e4_dp,  1.05971e5_dp,  7.76046e5_dp,  5.81508e5_dp  /
  DATA a3h2v /  1.74660_dp  ,  1.68520_dp  ,  1.73345_dp  ,  1.87951_dp  ,  1.99499_dp    &
             ,  1.92249_dp  ,  1.31044_dp  ,  1.37055_dp  ,  1.39819_dp  ,  1.24048_dp    &
             ,  1.22211_dp  ,  1.20883_dp  ,  0.991646_dp ,  0.784577_dp ,  0.735904_dp   /
  DATA a4h2v /  4.75874e3_dp,  1.91812e3_dp,  3.09006e3_dp,  9.04442e3_dp,  2.32656e4_dp  &
             ,  1.28777e4_dp,  9.55214e2_dp,  3.88065e2_dp,  3.54272e2_dp,  2.28283e2_dp  &
             ,  1.16196e2_dp,  1.26329e2_dp,  1.05518e2_dp,  1.31409e3_dp,  1.69328e3_dp  /
  DATA a5h2v / -0.942775_dp , -0.816838_dp , -0.888414_dp , -0.978327_dp , -1.06294_dp    &
             , -1.02713_dp  , -1.07546_dp  , -0.871521_dp , -0.807563_dp , -0.851591_dp   &
             , -0.735645_dp , -0.815130_dp , -0.193837_dp , -0.0100479_dp,  4.47757e-3_dp /

  INTEGER, PUBLIC                                   :: ifh2gr ! H2 formation on grains reaction number
  INTEGER, PUBLIC                                   :: ifhdgr ! HD formation on grains reaction number

  REAL (KIND=dp), PUBLIC, DIMENSION (nqm)           :: gamm   ! Arrhenius coefficient
  REAL (KIND=dp), PUBLIC, DIMENSION (nqm)           :: alpha  ! Arrhenius coefficient
  REAL (KIND=dp), PUBLIC, DIMENSION (nqm)           :: bet    ! Arrhenius coefficient
  REAL (KIND=dp), PUBLIC, DIMENSION (nqm)           :: de     ! Endothermicity
  INTEGER,        PUBLIC, DIMENSION (nqm)           :: itype  ! Type of reaction

  ! Tabular used to check conservation in chemical reactions
  REAL (KIND=dp), DIMENSION(nqm)                    :: bilanm ! bilan masse
  REAL (KIND=dp), DIMENSION(nqm)                    :: bilanc ! bilan charge
  REAL (KIND=dp), DIMENSION(0:nes+npart)            :: charge ! charge of species

  ! Species related quantities
  CHARACTER (LEN=lenSpeci), PUBLIC, DIMENSION (natom+npart) :: sp ! List of atomic species + reaction partners
  DATA sp / 'h       ', 'c       ', 'n       ', 'o       ', &
            'he      ', 'd       ', 'c*      ', 'n*      ', &
            'o*      ', 'ar      ', 'f       ', 'na      ', &     ! avec Argon pour l'element 10
            'mg      ', 'al      ', 'si      ', 'ne      ', &     ! avec Neon pour l' element 16
            's       ', 'cl      ', 'ca      ', 'fe      ', &
            'electr  ', 'photon  ', 'crp     ', 'phosec  ', &
            'grain   ', '2h      ', 'xray    ', 'elecsec ', &
            '        '/

  INTEGER,           PUBLIC, DIMENSION (natom)       :: atsp  ! List of atomic number
  DATA atsp /  1,  6,  7,  8,  2,  1,  6,  7,  8, 18, 9, &    ! avec Argon pour l'element 10
              11, 12, 13, 14, 10, 16, 17, 20, 26, 0  /        ! avec Neon pour l' element 16

  REAL (KIND=dp),    PUBLIC, DIMENSION (natom)       :: Ipsp         ! List of ionization potential (in eV)
  DATA Ipsp / 13.59844_dp, 11.26030_dp, 14.53414_dp, 13.61806_dp, &  ! NIST chemistry webbook: Lide 1992, Kelly 1987
              24.58741_dp, 13.60300_dp, 11.26030_dp, 14.53414_dp, &  ! assumption : Ip(n*)  = Ip(n) ; Ip(c*) = Ip(c)
              13.61806_dp, 15.75961_dp, 17.42282_dp,  5.13908_dp, &  ! Ip(o*)  = Ip(o) avec Argon pour l'element 10
               7.64624_dp,  5.98577_dp,  8.15169_dp, 21.56454_dp, &  ! assumption : Ip(pah) = 0
              10.36001_dp, 12.96764_dp,  6.11316_dp,  7.90240_dp, &  ! (analytical form required ... search for ref)
               0.00000_dp /

  ! index of specific species that require some particular attention
  INTEGER, PUBLIC                                   :: i_h    = 0
  INTEGER, PUBLIC                                   :: i_d    = 0
  INTEGER, PUBLIC                                   :: i_hgr  = 0               ! H on grains
  INTEGER, PUBLIC                                   :: i_dgr  = 0               ! D on grains
  INTEGER, PUBLIC                                   :: i_hgrc = 0               ! H chemisorbed on grains
  INTEGER, PUBLIC                                   :: i_h2   = 0
  INTEGER, PUBLIC                                   :: i_hd   = 0
  INTEGER, PUBLIC                                   :: i_h2gr = 0               ! H2 on grains
  INTEGER, PUBLIC                                   :: i_hdgr = 0               ! HD on grains
  INTEGER, PUBLIC                                   :: i_he   = 0
  INTEGER, PUBLIC                                   :: i_c    = 0
  INTEGER, PUBLIC                                   :: i_n    = 0
  INTEGER, PUBLIC                                   :: i_o    = 0
  INTEGER, PUBLIC                                   :: i_o2   = 0
  INTEGER, PUBLIC                                   :: i_s    = 0
  INTEGER, PUBLIC                                   :: i_si   = 0
  INTEGER, PUBLIC                                   :: i_ne   = 0
  INTEGER, PUBLIC                                   :: i_c13  = 0
  INTEGER, PUBLIC                                   :: i_o18  = 0
  INTEGER, PUBLIC                                   :: i_h2o  = 0
  INTEGER, PUBLIC                                   :: i_h2ogr = 0              ! H2O on grains
  INTEGER, PUBLIC                                   :: i_oh   = 0
  INTEGER, PUBLIC                                   :: i_c2   = 0
  INTEGER, PUBLIC                                   :: i_co   = 0               ! 12C16O
  INTEGER, PUBLIC                                   :: i_c13o = 0               ! 13C16O
  INTEGER, PUBLIC                                   :: i_co18 = 0               ! 12C18O
  INTEGER, PUBLIC                                   :: i_c13o18 = 0             ! 13C18O
  INTEGER, PUBLIC                                   :: i_cogr = 0               ! CO on grains
  INTEGER, PUBLIC                                   :: i_cs   = 0
  INTEGER, PUBLIC                                   :: i_hcn  = 0
  INTEGER, PUBLIC                                   :: i_hcl  = 0
  INTEGER, PUBLIC                                   :: i_hp   = 0
  INTEGER, PUBLIC                                   :: i_cp   = 0
  INTEGER, PUBLIC                                   :: i_cpp  = 0
  INTEGER, PUBLIC                                   :: i_c13p = 0
  INTEGER, PUBLIC                                   :: i_np   = 0
  INTEGER, PUBLIC                                   :: i_npp  = 0
  INTEGER, PUBLIC                                   :: i_op   = 0
  INTEGER, PUBLIC                                   :: i_opp  = 0
  INTEGER, PUBLIC                                   :: i_sp   = 0
  INTEGER, PUBLIC                                   :: i_spp  = 0
  INTEGER, PUBLIC                                   :: i_sip  = 0
  INTEGER, PUBLIC                                   :: i_nep  = 0
  INTEGER, PUBLIC                                   :: i_nepp = 0
  INTEGER, PUBLIC                                   :: i_fep  = 0
  INTEGER, PUBLIC                                   :: i_h2p  = 0
  INTEGER, PUBLIC                                   :: i_h3p  = 0
  INTEGER, PUBLIC                                   :: i_h2dp = 0
  INTEGER, PUBLIC                                   :: i_hcop = 0
  INTEGER, PUBLIC                                   :: i_chp  = 0
  INTEGER, PUBLIC                                   :: i_ohp  = 0
  INTEGER, PUBLIC                                   :: i_shp  = 0
  INTEGER, PUBLIC                                   :: i_arhp = 0
  INTEGER, PUBLIC                                   :: j_c13o = 0
  INTEGER, PUBLIC                                   :: j_co18 = 0
  INTEGER, PUBLIC                                   :: j_c13o18 = 0

  REAL (KIND=dp), PUBLIC                            :: r_c13 = 90.0_dp          ! 12C / 13C ratio
  REAL (KIND=dp), PUBLIC                            :: r_o18 = 499.0_dp         ! 16O / 18O ratio

  CHARACTER (LEN=lenSpeci), DIMENSION(0:nes+npart)  :: speci   ! List of species in chemistry
  TYPE(CHEMICAL_SPECIES),   DIMENSION(0:nes+npart)  :: Species ! List of species in chemistry
  REAL (KIND=dp), PUBLIC,   DIMENSION(0:nes+npart)  :: abin    ! Initial abundances od species

  REAL (KIND=dp), PUBLIC, DIMENSION(0:nes+npart)    :: mol     ! Molecular weight
  REAL (KIND=dp), PUBLIC, DIMENSION(0:natom)        :: abtot   ! Total relative abundances of atoms
  INTEGER, PUBLIC, DIMENSION(0:nes,0:natom)         :: ael     ! Chemical composition of species
  TYPE(ATOM), PUBLIC, DIMENSION(natom-1)            :: l_atom  ! List of atoms properties
  INTEGER, PUBLIC, DIMENSION(nes+npart)             :: lcon    ! Conservation of species (in the gas)
                                                               ! if lcon(i) = 0 THEN species i is not used for conservation
                                                               ! if lcon(i) = j /= 0 THEN atom j is conserved thru species i
  INTEGER, PUBLIC, DIMENSION(0:natom,2)             :: icx     ! Conservation of atoms
                                                               ! icx(i,1) : index of species used for conservation of i
                                                               ! icx(i,2) : index of second most abundant species containing i
  REAL (KIND=dp), PUBLIC, DIMENSION(0:nes+npart)    :: t_diff  ! Diffusion barrier on grains
  REAL (KIND=dp), PUBLIC, DIMENSION(0:nes+npart)    :: t_evap  ! Evaporation barrier on grains
                                                               ! t_diff and t_evap are used only for species on grains
  INTEGER, PUBLIC, DIMENSION(0:nes+npart)           :: rej_gr  ! Flag for species subject to rejectionon grains
                                                               ! => build monolayer only
  INTEGER                                           :: ijkl
  INTEGER, PUBLIC                                   :: from_CT

  DATA (l_atom(ijkl)%name, ijkl=1,natom-1) / "H", "C", "N", "O", "He", "D", "C13", "N15", "O18", "Ar", "F", "Na", "Mg" &
                                           , "Al", "Si", "Ne", "S", "Cl", "Ca", "Fe" /

END MODULE PXDR_CHEM_DATA
