26 double precision,
parameter :: saha_pf = 2.4146830395719654d15
27 double precision,
parameter :: saha_kB_cgs = 1.380649
d-16
29 double precision,
parameter :: saha_chi_H_cgs = const_chi_h * const_ev
30 double precision,
parameter :: saha_chi_kB = saha_chi_h_cgs / saha_kb_cgs
35 logical :: saha_nonconv_warned = .false.
43 write(*,*)
'EoS method: analytic (hydrogen Saha, helium neutral)'
44 write(*,*)
' gamma1_method: ', trim(
eos%gamma1_method)
55 double precision function saha_y_cgs(nH_cgs, T_cgs)
result(y)
56 double precision,
intent(in) :: nh_cgs, t_cgs
57 double precision :: sqx
65 sqx = dsqrt(saha_pf) * t_cgs**0.75d0 * dexp(-0.5d0 * saha_chi_kb / t_cgs)
66 y = 2.0d0 * sqx / (sqx + dsqrt(sqx * sqx + 4.0d0 * nh_cgs))
68 end function saha_y_cgs
71 double precision function saha_y_from_nh_t(nH_code, T_code)
result(y)
72 double precision,
intent(in) :: nh_code, t_code
76 end function saha_y_from_nh_t
79 double precision function saha_eint_cgs(y, T_cgs)
result(e)
80 double precision,
intent(in) :: y, t_cgs
81 e = 1.5d0 * (1.0d0 +
eos%He_abundance + y) * saha_kb_cgs * t_cgs
82 if (
eos%ionE) e = e + y * saha_chi_h_cgs
83 end function saha_eint_cgs
87 double precision,
intent(in) :: nh_code, t_code
90 eint_nh_code = saha_eint_cgs(saha_y_from_nh_t(nh_code, t_code), t_code *
unit_temperature) &
98 double precision,
intent(in) :: nh_code, p_code
99 double precision,
intent(out) :: t_out, y_out
100 double precision,
intent(out),
optional :: eint_nh_out
102 double precision :: nh_cgs, ut
103 double precision :: t_lo, t_hi, t_mid, y_mid, p_eval
105 integer,
parameter :: max_iter = 30
106 double precision,
parameter :: tol = 1.0
d-8
113 t_hi = p_code / (nh_code * (1.0d0 +
eos%He_abundance))
114 t_lo = p_code / (nh_code * (2.0d0 +
eos%He_abundance))
115 t_lo = max(t_lo, 100.0d0 / ut)
117 do iter = 1, max_iter
118 t_mid = 0.5d0 * (t_lo + t_hi)
119 y_mid = saha_y_cgs(nh_cgs, t_mid * ut)
120 p_eval = nh_code * (1.0d0 +
eos%He_abundance + y_mid) * t_mid
122 if (p_eval < p_code)
then
128 if (dabs(t_hi - t_lo) < tol * t_mid)
exit
131 if (iter > max_iter .and. .not. saha_nonconv_warned .and.
mype == 0)
then
132 saha_nonconv_warned = .true.
133 write(*,*)
"WARNING: saha_state_from_nH_p bisection reached max_iter ", &
134 "without converging; using last iterate. Not reported again."
140 if (
present(eint_nh_out)) &
147 double precision,
intent(in) :: nh_code, eint_nh_code
148 double precision,
intent(out) :: t_out, y_out
151 call saha_t_bisection(nh_code, eint_nh_code, t_out, y_out)
156 subroutine saha_t_bisection(nH_code, eint_nH_code, T_out, y_out)
157 double precision,
intent(in) :: nh_code, eint_nh_code
158 double precision,
intent(out) :: t_out, y_out
160 double precision :: nh_cgs, eint_nh_cgs, t_lo, t_hi, t_mid
161 double precision :: y_mid, cv_ion, cv_neu
163 integer,
parameter :: max_iter = 30
164 double precision,
parameter :: tol = 1.0
d-8
170 cv_ion = 1.5d0 * (2.0d0 +
eos%He_abundance) * saha_kb_cgs
171 cv_neu = 1.5d0 * (1.0d0 +
eos%He_abundance) * saha_kb_cgs
173 t_lo = (eint_nh_cgs - saha_chi_h_cgs) / cv_ion
175 t_lo = eint_nh_cgs / cv_ion
177 t_lo = max(t_lo, 100.0d0)
178 t_hi = max(eint_nh_cgs / cv_neu, t_lo + 1.0d0)
183 if (saha_y_cgs(nh_cgs, t_lo) > 1.0d0 - 1.0
d-10)
then
191 do iter = 1, max_iter
192 t_mid = 0.5d0 * (t_lo + t_hi)
193 y_mid = saha_y_cgs(nh_cgs, t_mid)
194 if (saha_eint_cgs(y_mid, t_mid) < eint_nh_cgs)
then
200 if (dabs(t_hi - t_lo) < tol * t_mid)
exit
203 if (iter > max_iter .and. .not. saha_nonconv_warned .and.
mype == 0)
then
204 saha_nonconv_warned = .true.
205 write(*,*)
"WARNING: saha_T_bisection reached max_iter without ", &
206 "converging; using last iterate. Not reported again."
212 end subroutine saha_t_bisection
222 double precision,
intent(in) :: nh_code, p_code
223 double precision :: t_code, y, theta, dlny, npart, cv, chi_t, chi_rho
226 dlny = (1.0d0 - y) / (2.0d0 - y) * (1.5d0 + theta)
227 npart = 1.0d0 +
eos%He_abundance + y
228 cv = 1.5d0 * npart + (1.5d0 + theta) * y * dlny
229 chi_t = 1.0d0 + y * dlny / npart
230 chi_rho = 1.0d0 - y * (1.0d0 - y) / ((2.0d0 - y) * npart)
231 g1 = chi_rho + chi_t**2 * npart / cv
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
EoS state container – the single thermodynamic authority for AMRVAC.
integer, parameter, public eos_analytic
type(eos_container), allocatable, public eos
The single EoS state object, allocated in eos_init and shared (read-mostly) across all EoS sub-module...
Analytic hydrogen Saha EoS with neutral helium (eos_method == 'analytic').
subroutine, public finalise_analytic_lte()
Analytic-method finalise: there are no tables, only the shared FI-bypass constants.
subroutine, public saha_t_from_nh_eint(nh_code, eint_nh_code, t_out, y_out)
Temperature and ionisation fraction from (nH, eint/nH) in code units, by bisection.
subroutine, public load_analytic_lte()
Analytic-method load: no binary tables (on-the-fly Saha solve); just announce the method.
double precision function, public saha_gamma1_from_nh_p(nh_code, p_code)
Gamma_1 at (nH, p) in code units, in closed form from the hydrogen Saha balance. T and y come from th...
double precision function, public saha_eint_from_nh_t(nh_code, t_code)
eint/nH from Saha at (nH, T), in code units
subroutine, public saha_state_from_nh_p(nh_code, p_code, t_out, y_out, eint_nh_out)
Given (nH, p) in code units, T, y and optionally eint/nH: bisection on p = nH*(1+He+y(T))*T,...
Shared LTE lookup-table infrastructure (build/IO; not on the hot path).
subroutine, public precompute_fi_bypass_constants(chi_h_only)
Precompute constants for bypassing table lookups when gas is fully ionised. Physics: above T ~ 50 kK,...
This module contains definitions of global parameters and variables and some generic functions/subrou...
double precision unit_numberdensity
Physical scaling factor for number density.
double precision unit_pressure
Physical scaling factor for pressure.
integer mype
The rank of the current MPI task.
double precision, dimension(:), allocatable, parameter d
double precision unit_temperature
Physical scaling factor for temperature.