MODULE AlCooling
   USE GlobalDeclarations
   USE PhysicsDeclarations
   USE Tables
   IMPLICIT NONE
   TYPE(TableDef), POINTER :: AlTab
   SAVE

CONTAINS

   SUBROUTINE InitAlCool
      INTEGER :: iErr
      CALL ReadTable('TABLES/Alcooling.tab', AlTab, iErr)
   END SUBROUTINE InitAlCool

   !> Al cooling source term
   !! @details Implementation of Al Cooling curve
   !! @param q Fluid variable vector q
   !! @param dqdt Update to be applied to q
   !! @param temp Temperature
   SUBROUTINE Al_Cooling(q,dqdt,Temp)
      REAL(KIND=qPrec) :: q(:), dqdt(:), Temp
      dqdt(iE) = dqdt(iE) - AlCoolingStrength(q,Temp)
   END SUBROUTINE Al_Cooling

   FUNCTION AlCoolingStrength(q,Temp)
      REAL(KIND=qPrec) :: q(:), AlCoolingStrength, Temp, ne, nAl, logne, logtemp
      ne = (6d0/7d0)*q(1)*nScale  ! number densities based on Z = 6
      nAl = (1d0/7d0)*q(1)*nScale
      logne = LOG10(ne)
      Temp = Temp/1.16045d4       ! K to eV
      logtemp = LOG10(Temp)
      AlCoolingStrength=ne*nAl*GetTableValue(AlTab, (/logtemp, logne/))/(nScale**2d0)
      AlCoolingStrength=AlCoolingStrength*ScaleCool
   END FUNCTION AlCoolingStrength

END MODULE AlCooling
