49 select case (
eos%method_id)
61 eos%update_eos => update_eos_lte
63 eos%get_temperature_from_eint => get_temperature_from_eint_lte
64 eos%get_Te => get_te_lte
67 eos%get_Rfactor => rfactor_from_lte
68 select case (
eos%method_id)
76 subroutine update_eos_lte(ixI^L, ixO^L, w, x)
79 integer,
intent(in) :: ixi^
l,ixo^
l
80 double precision,
intent(in) :: x(ixi^s,1:
ndim)
81 double precision,
intent(inout) :: w(ixi^s,1:nw)
83 double precision :: wlocal(ixi^s,1:nw)
84 double precision :: new_y(ixi^s)
85 double precision :: pth(ixi^s)
86 double precision :: nh_in(ixi^s), nh(ixi^s), eint_in(ixi^s)
87 double precision :: rfactor_fi
88 double precision :: yy
91 wlocal(ixi^s,1:nw)=w(ixi^s,1:nw)
94 pth(ixo^s) =
eos%gamma_minus_1 * wlocal(ixo^s,iw_e)
96 call eos%get_nH(w, x, ixi^
l, ixo^
l, nh)
103 wlocal(ixo^s,iw_e) = max(wlocal(ixo^s,iw_e), nh(ixo^s)*
eos%eint_nH_min)
105 nh_in(ixo^s) = dlog10(nh(ixo^s))
106 eint_in(ixo^s) = dlog10(wlocal(ixo^s,iw_e)) - nh_in(ixo^s)
111 rfactor_fi =
eos%n_per_nH_FI /
eos%nH2rhoFactor
113 {
do ix^db=ixomin^db,ixomax^db\}
114 if (wlocal(ix^
d,iw_e) / w(ix^
d,iw_rho) >
eos%eint_rho_FI_threshold)
then
116 new_y(ix^
d) =
eos%neOnH_FI
119 w(ix^
d,iw_te) =
eos%gamma_minus_1 &
120 * (wlocal(ix^
d,iw_e) -
eos%eion_per_nH * nh(ix^
d)) &
121 / (rfactor_fi * w(ix^
d,iw_rho))
123 w(ix^
d,iw_te) = pth(ix^
d) / (nh(ix^
d) * (1.0d0 +
eos%He_abundance + new_y(ix^
d)))
130 wlocal(ix^
d,iw_e) / nh(ix^
d), &
135 if (.not.
eos%ionE)
then
137 w(ix^
d,iw_te) = pth(ix^
d) / (nh(ix^
d) * (1.0d0 +
eos%He_abundance + new_y(ix^
d)))
142 call t_and_y_from_nh_eint(nh_in(ix^
d), eint_in(ix^
d), &
146 if (eint_in(ix^
d) <
eos%T%var2_max)
then
147 call t_and_y_from_nh_eint(nh_in(ix^
d), eint_in(ix^
d), &
152 new_y(ix^
d) =
eos%neOnH_FI
153 w(ix^
d,iw_te) =
eos%gamma_minus_1 &
154 * (wlocal(ix^
d,iw_e) -
eos%eion_per_nH * nh(ix^
d)) &
155 / (rfactor_fi * w(ix^
d,iw_rho))
162 w(ixo^s,iw_ne) = new_y(ixo^s) * nh(ixo^s)
164 end subroutine update_eos_lte
173 subroutine rfactor_from_lte(w,x,ixI^L,ixO^L,Rfactor)
175 integer,
intent(in) :: ixi^
l, ixo^
l
176 double precision,
intent(in) :: w(ixi^s,1:nw)
177 double precision,
intent(in) :: x(ixi^s,1:
ndim)
178 double precision,
intent(out):: rfactor(ixi^s)
180 double precision :: y_nh
183 {
do ix^db=ixomin^db,ixomax^db\}
184 y_nh = w(ix^
d, iw_ne) * eos%nH2rhoFactor / w(ix^
d, iw_rho)
185 rfactor(ix^
d) = (1.0d0 + eos%He_abundance + y_nh) / eos%nH2rhoFactor
188 end subroutine rfactor_from_lte
197 subroutine get_te_lte(w,x,ixI^L,ixO^L,T)
199 integer,
intent(in) :: ixi^
l, ixo^
l
200 double precision,
intent(in) :: w(ixi^s,1:nw)
201 double precision,
intent(in) :: x(ixi^s,1:
ndim)
202 double precision,
intent(out) :: t(ixi^s)
204 t(ixo^s) = w(ixo^s,iw_te)
206 end subroutine get_te_lte
208 subroutine get_temperature_from_eint_lte(w, x, ixI^L, ixO^L, res)
212 integer,
intent(in) :: ixi^l,ixo^l
213 double precision,
intent(in) :: x(ixi^s,1:ndim)
214 double precision,
intent(in) :: w(ixi^s,1:nw)
215 double precision,
intent(out) :: res(ixi^s)
217 double precision :: nh(ixi^s),nh_in(ixi^s), eint_in(ixi^s)
218 double precision :: rfactor_fi, t_loc, y_loc
221 rfactor_fi = eos%n_per_nH_FI / (1.0d0 + 4.0d0*eos%He_abundance)
223 call eos%get_nH(w, x, ixi^l, ixo^l, nh)
224 nh_in(ixo^s) = dlog10(nh(ixo^s))
225 eint_in(ixo^s) = dlog10(w(ixo^s,iw_e)) - nh_in(ixo^s)
227 {
do ix^db=ixomin^db,ixomax^db\}
228 if (w(ix^d,iw_e) / w(ix^d,iw_rho) > eos%eint_rho_FI_threshold)
then
230 res(ix^d) = eos%gamma_minus_1 &
231 * (w(ix^d,iw_e) - eos%eion_per_nH * nh(ix^d)) &
232 / (rfactor_fi * w(ix^d,iw_rho))
233 else if (eos%method_id == eos_analytic)
then
234 call saha_t_from_nh_eint(nh(ix^d), &
235 w(ix^d,iw_e) / nh(ix^d), t_loc, y_loc)
242 end subroutine get_temperature_from_eint_lte
254 integer,
intent(in) :: ixi^l,ixo^l
255 double precision,
intent(in) :: x(ixi^s,1:ndim)
256 double precision,
intent(in) :: w(ixi^s,1:nw)
257 double precision,
intent(out) :: res(ixi^s)
259 double precision :: inv_rfactor_fi, eion_rho_inv
260 double precision :: log_nh_val, log_eint_nh_val
261 double precision :: fx, fy, rx, ry, nh_loc, t_loc, y_loc
262 integer :: jx, jy, jx1, jy1, ix^d
263 double precision,
parameter :: ln10 = 2.302585092994046d0
265 if (eos%type_id /= eos_type_lte)
call mpistop(
"get_temperature_from_eint_fast_LTE called outside its eos_type (LTE)")
266 call eos_timer_start()
269 inv_rfactor_fi = (1.0d0 + 4.0d0*eos%He_abundance) / eos%n_per_nH_FI
270 eion_rho_inv = eos%eion_per_nH / eos%nH2rhoFactor
274 res(ixo^s) = eos%gamma_minus_1 * inv_rfactor_fi &
275 * (w(ixo^s,iw_e) - eion_rho_inv * w(ixo^s,iw_rho)) &
279 {
do ix^db=ixomin^db,ixomax^db\}
280 if (w(ix^d,iw_e) <= eos%eint_rho_FI_threshold * w(ix^d,iw_rho))
then
281 if (eos%method_id == eos_analytic)
then
282 nh_loc = w(ix^d, iw_rho) / eos%nH2rhoFactor
283 call saha_t_from_nh_eint(nh_loc, &
284 w(ix^d,iw_e) / nh_loc, t_loc, y_loc)
286 else if (eos%method_id == eos_entropy)
then
287 if (iw_log_nh > 0)
then
288 log_nh_val = block%wextra(ix^d, iw_log_nh)
290 log_nh_val = dlog10(w(ix^d, iw_rho) / eos%nH2rhoFactor)
292 log_eint_nh_val = dlog10(w(ix^d, iw_e)) - log_nh_val
293 res(ix^d) = entropy_t_from_nh_eint(log_nh_val, log_eint_nh_val)
295 if (iw_log_nh > 0)
then
296 log_nh_val = block%wextra(ix^d, iw_log_nh)
298 log_nh_val = dlog10(w(ix^d, iw_rho) / eos%nH2rhoFactor)
300 log_eint_nh_val = dlog10(w(ix^d, iw_e)) - log_nh_val
302 if (eos%T%is_uniform)
then
304 ry = max(0.0d0, min((log_nh_val - eos%T%var1_min) * eos%T%step_inv_1, &
306 rx = max(0.0d0, min((log_eint_nh_val - eos%T%var2_min) * eos%T%step_inv_2, &
308 jy = int(ry); jx = int(rx)
309 jy1 = min(jy+1, eos%T%dim1-1)
310 jx1 = min(jx+1, eos%T%dim2-1)
311 fy = ry - dble(jy); fx = rx - dble(jx)
312 res(ix^d) = dexp(ln10 * ( &
313 (1.0d0-fy)*((1.0d0-fx)*eos%T%table(jy+1,jx+1) &
314 + fx *eos%T%table(jy+1,jx1+1)) &
315 + fy *((1.0d0-fx)*eos%T%table(jy1+1,jx+1) &
316 + fx *eos%T%table(jy1+1,jx1+1))))
321 res(ix^d) = dexp(ln10 * bilinear_lookup( &
322 log_nh_val, log_eint_nh_val, eos%T))
328 call eos_timer_stop(timeeos_tfromei)
336 double precision,
intent(in) :: nh, eint_nh
337 double precision,
parameter :: ln10 = 2.302585092994046d0
338 double precision :: t_loc, y_loc
340 if (eos%type_id /= eos_type_lte)
call mpistop(
"y_from_nH_eint called outside its eos_type (LTE)")
342 if (eint_nh > eos%log_eint_nH_FI)
then
343 result_val = eos%neOnH_FI
346 if (eos%method_id == eos_analytic)
then
347 call saha_t_from_nh_eint(10.0d0**nh, 10.0d0**eint_nh, t_loc, y_loc)
349 else if (eos%method_id == eos_entropy)
then
350 result_val = entropy_y_from_nh_eint(nh, eint_nh)
352 result_val = dexp(ln10 * bicubic_lookup(nh, eint_nh, eos%neOnH))
358 double precision,
intent(in) :: nh, eint_nh
359 double precision,
parameter :: ln10 = 2.302585092994046d0
360 double precision :: t_loc, y_loc
362 if (eos%type_id /= eos_type_lte)
call mpistop(
"T_from_nH_eint called outside its eos_type (LTE)")
363 if (eint_nh > eos%log_eint_nH_FI)
then
364 result_val = eos%gamma_minus_1 &
365 * (10.0d0**eint_nh - eos%eion_per_nH) / eos%n_per_nH_FI
368 if (eos%method_id == eos_analytic)
then
369 call saha_t_from_nh_eint(10.0d0**nh, 10.0d0**eint_nh, t_loc, y_loc)
371 else if (eos%method_id == eos_entropy)
then
372 result_val = entropy_t_from_nh_eint(nh, eint_nh)
374 result_val = dexp(ln10 * bicubic_lookup(nh, eint_nh, eos%T))
380 subroutine t_and_y_from_nh_eint(log_nH, log_eint_nH, T_out, y_out)
381 double precision,
intent(in) :: log_nh, log_eint_nh
382 double precision,
intent(out) :: t_out, y_out
383 double precision,
parameter :: ln10 = 2.302585092994046d0
384 double precision :: results(3)
386 if (eos%method_id == eos_analytic)
then
387 call saha_t_from_nh_eint(10.0d0**log_nh, 10.0d0**log_eint_nh, t_out, y_out)
388 else if (eos%method_id == eos_entropy)
then
389 call entropy_t_and_y_from_nh_eint(log_nh, log_eint_nh, t_out, y_out)
390 else if (
allocated(eos%table_eint_il))
then
392 if (eos%T%is_uniform)
then
393 call interp_pchip_interleaved(log_nh, log_eint_nh, &
394 eos%table_eint_il, 3, eos%T%dim2, eos%T%dim1, &
395 eos%T%var1_min, eos%T%var1_max, &
396 eos%T%var2_min, eos%T%var2_max, results)
398 call interp_pchip_interleaved_nu(log_nh, log_eint_nh, &
399 eos%table_eint_il, 3, eos%T%dim2, eos%T%dim1, &
400 eos%T%var1_nodes, eos%T%var2_nodes, &
401 eos%T%guard_1, eos%T%guard_M_1, eos%T%guard_scale_1, &
402 eos%T%guard_2, eos%T%guard_M_2, eos%T%guard_scale_2, &
405 t_out = dexp(ln10 * results(1))
406 y_out = dexp(ln10 * results(2))
408 t_out = dexp(ln10 * bicubic_lookup(log_nh, log_eint_nh, eos%T))
409 y_out = dexp(ln10 * bicubic_lookup(log_nh, log_eint_nh, eos%neOnH))
411 end subroutine t_and_y_from_nh_eint
415 double precision,
intent(in) :: nh, ponh
416 double precision :: nh_code, p_code, t_loc, y_loc, eint_nh_loc
418 if (eos%type_id /= eos_type_lte)
call mpistop(
"p2eint_from_nH_p called outside its eos_type (LTE)")
419 if (ponh > eos%log_p_nH_FI)
then
420 result_val = eos%inv_gamma_minus_1 + eos%eion_per_nH / 10.0d0**ponh
423 if (eos%method_id == eos_analytic)
then
425 p_code = nh_code * 10.0d0**ponh
426 call saha_state_from_nh_p(nh_code, p_code, t_loc, y_loc, eint_nh_loc)
427 result_val = eint_nh_loc * nh_code / p_code
428 else if (eos%method_id == eos_entropy)
then
429 result_val = entropy_eint_from_nh_p(nh, ponh)
431 result_val = bicubic_lookup(nh, ponh, eos%p2eint)
438 double precision,
intent(in) :: log_nh, log_p_nh
439 if (eos%type_id /= eos_type_lte)
call mpistop(
"gamma1_from_nH_p called outside its eos_type (LTE)")
440 if (log_p_nh > eos%log_p_nH_FI)
then
444 if (eos%method_id == eos_entropy)
then
445 g1 = entropy_gamma1_from_nh_p(log_nh, log_p_nh)
446 else if (eos%method_id == eos_analytic)
then
447 g1 = saha_gamma1_from_nh_p(10.0d0**log_nh, 10.0d0**(log_nh + log_p_nh))
449 g1 = bicubic_lookup(log_nh, log_p_nh, eos%gamma1_p)
456 double precision,
intent(in) :: pres, rho_val
457 double precision :: nh_val
458 if (pres/rho_val > eos%p_rho_FI_threshold)
then
461 nh_val = rho_val/eos%nH2rhoFactor
467 double precision function log_p_from_nh_eint(log_nH, log_eint_nH)
result(lp)
468 double precision,
intent(in) :: log_nh, log_eint_nh
469 lp = bicubic_lookup(log_nh, log_eint_nh, eos%log_p)
470 end function log_p_from_nh_eint
474 double precision,
intent(in) :: log_nh, log_eint_nh
475 double precision,
parameter :: ln10 = 2.302585092994046d0
476 double precision :: t_loc, y_loc
478 if (eos%type_id /= eos_type_lte)
call mpistop(
"p_nH_from_eint called outside its eos_type (LTE)")
479 if (log_eint_nh > eos%log_eint_nH_FI)
then
480 p_nh = eos%gamma_minus_1 * (10.0d0**log_eint_nh - eos%eion_per_nH)
483 if (eos%method_id == eos_analytic)
then
484 call saha_t_from_nh_eint(10.0d0**log_nh, 10.0d0**log_eint_nh, t_loc, y_loc)
485 p_nh = (1.0d0 + eos%He_abundance + y_loc) * t_loc
486 else if (eos%method_id == eos_entropy)
then
487 p_nh = entropy_p_nh_from_eint(log_nh, log_eint_nh)
489 p_nh = dexp(ln10 * bicubic_lookup(log_nh, log_eint_nh, eos%p_over_nH))
496 double precision,
intent(in) :: log_nh, log_t
497 double precision,
parameter :: ln10 = 2.302585092994046d0
498 double precision :: log_e_nh
500 if (eos%type_id /= eos_type_lte)
call mpistop(
"eint_nH_from_T called outside its eos_type (LTE)")
501 if (log_t > eos%log_T_FI)
then
502 eint_nh = eos%n_per_nH_FI * eos%inv_gamma_minus_1 * 10.0d0**log_t + eos%eion_per_nH
505 if (eos%method_id == eos_entropy)
then
506 log_e_nh = entropy_eint_from_nh_t(log_nh, log_t)
507 eint_nh = 10.0d0**log_e_nh
508 else if (
allocated(eos%eint_from_T%table))
then
509 eint_nh = dexp(ln10 * bicubic_lookup(log_nh, log_t, eos%eint_from_T))
511 eint_nh = saha_eint_from_nh_t(10.0d0**log_nh, 10.0d0**log_t)
529 subroutine log_p_bisect_cached(log_nH, log_p_target, &
530 log_eint_lo, log_eint_hi, max_iter, log_eint_result)
532 double precision,
intent(in) :: log_nh, log_p_target
533 double precision,
intent(inout) :: log_eint_lo, log_eint_hi
534 integer,
intent(in) :: max_iter
535 double precision,
intent(out) :: log_eint_result
537 integer :: nx, ny, ix, iy, iter, ii
538 integer :: i0, i1, i2, i3, j0, j1, j2, j3
539 double precision :: tx, ty, rx, ry
540 double precision :: xstep_inv, ystep_inv
541 double precision :: vmin_x, vmax_x, vmin_y, vmax_y
542 double precision :: log_eint_mid, log_p_eval
546 double precision :: tv(4,4)
552 is_unif = eos%log_p%is_uniform
555 vmin_x = eos%log_p%var2_min
556 vmax_x = eos%log_p%var2_max
557 vmin_y = eos%log_p%var1_min
558 vmax_y = eos%log_p%var1_max
559 xstep_inv = dble(nx-1) / (vmax_x - vmin_x)
560 ystep_inv = dble(ny-1) / (vmax_y - vmin_y)
565 ry = (log_nh - vmin_y) * ystep_inv
566 ry = max(0.0d0, min(ry, dble(ny-1)))
571 if (log_nh <= eos%log_p%var1_nodes(1))
then
573 else if (log_nh >= eos%log_p%var1_nodes(ny))
then
574 iy = ny - 2; ty = 1.0d0
576 ii = find_index_guard(eos%log_p%var1_nodes, ny, log_nh, &
577 eos%log_p%guard_1, eos%log_p%guard_M_1, eos%log_p%guard_scale_1)
578 iy = max(0, min(ii - 2, ny - 2))
579 ty = (log_nh - eos%log_p%var1_nodes(iy+1)) &
580 / (eos%log_p%var1_nodes(iy+2) - eos%log_p%var1_nodes(iy+1))
581 ty = max(0.0d0, min(ty, 1.0d0))
586 j0 = max(0, min(ny-1, iy-1))
587 j1 = max(0, min(ny-1, iy ))
588 j2 = max(0, min(ny-1, iy+1))
589 j3 = max(0, min(ny-1, iy+2))
593 do iter = 1, max_iter
594 log_eint_mid = 0.5d0 * (log_eint_lo + log_eint_hi)
598 rx = (log_eint_mid - vmin_x) * xstep_inv
599 rx = max(0.0d0, min(rx, dble(nx-1)))
604 if (log_eint_mid <= eos%log_p%var2_nodes(1))
then
606 else if (log_eint_mid >= eos%log_p%var2_nodes(nx))
then
607 ix = nx - 2; tx = 1.0d0
609 ii = find_index_guard(eos%log_p%var2_nodes, nx, log_eint_mid, &
610 eos%log_p%guard_2, eos%log_p%guard_M_2, eos%log_p%guard_scale_2)
611 ix = max(0, min(ii - 2, nx - 2))
612 tx = (log_eint_mid - eos%log_p%var2_nodes(ix+1)) &
613 / (eos%log_p%var2_nodes(ix+2) - eos%log_p%var2_nodes(ix+1))
614 tx = max(0.0d0, min(tx, 1.0d0))
619 if (ix /= ix_cached)
then
620 i0 = max(0, min(nx-1, ix-1))
621 i1 = max(0, min(nx-1, ix ))
622 i2 = max(0, min(nx-1, ix+1))
623 i3 = max(0, min(nx-1, ix+2))
625 tv(1,1) = eos%log_p%table(j0+1, i0+1)
626 tv(1,2) = eos%log_p%table(j0+1, i1+1)
627 tv(1,3) = eos%log_p%table(j0+1, i2+1)
628 tv(1,4) = eos%log_p%table(j0+1, i3+1)
629 tv(2,1) = eos%log_p%table(j1+1, i0+1)
630 tv(2,2) = eos%log_p%table(j1+1, i1+1)
631 tv(2,3) = eos%log_p%table(j1+1, i2+1)
632 tv(2,4) = eos%log_p%table(j1+1, i3+1)
633 tv(3,1) = eos%log_p%table(j2+1, i0+1)
634 tv(3,2) = eos%log_p%table(j2+1, i1+1)
635 tv(3,3) = eos%log_p%table(j2+1, i2+1)
636 tv(3,4) = eos%log_p%table(j2+1, i3+1)
637 tv(4,1) = eos%log_p%table(j3+1, i0+1)
638 tv(4,2) = eos%log_p%table(j3+1, i1+1)
639 tv(4,3) = eos%log_p%table(j3+1, i2+1)
640 tv(4,4) = eos%log_p%table(j3+1, i3+1)
646 log_p_eval = pchip_2d_from_cache(tv, tx, ty)
648 if (log_p_eval < log_p_target)
then
649 log_eint_lo = log_eint_mid
651 log_eint_hi = log_eint_mid
654 if (dabs(log_eint_hi - log_eint_lo) < 1.0d-14)
exit
657 log_eint_result = 0.5d0 * (log_eint_lo + log_eint_hi)
661 pure double precision function pchip_1d(p0, p1, p2, p3, t)
result(v)
662 double precision,
intent(in) :: p0, p1, p2, p3, t
663 double precision :: d0, d1, d2, m1, m2, s, a1, a2, lim
664 double precision :: tt, ttt, h00, h10, h01, h11
666 d0 = p1 - p0; d1 = p2 - p1; d2 = p3 - p2
668 if (d1 == 0.0d0)
then
669 m1 = 0.0d0; m2 = 0.0d0
671 if (d0*d1 <= 0.0d0)
then
674 m1 = 2.0d0*d0*d1 / (d0 + d1)
676 if (d1*d2 <= 0.0d0)
then
679 m2 = 2.0d0*d1*d2 / (d1 + d2)
683 if (a1 < 0.0d0) a1 = 0.0d0
684 if (a2 < 0.0d0) a2 = 0.0d0
686 if (a1 > lim) a1 = lim
687 if (a2 > lim) a2 = lim
692 h00 = 2.0d0*ttt - 3.0d0*tt + 1.0d0
693 h10 = ttt - 2.0d0*tt + t
694 h01 = -2.0d0*ttt + 3.0d0*tt
696 v = h00*p1 + h10*m1 + h01*p2 + h11*m2
699 pure double precision function pchip_2d_from_cache(c, tx, ty)
result(z)
700 double precision,
intent(in) :: c(4,4), tx, ty
701 double precision :: g0, g1, g2, g3
703 g0 =
pchip_1d(c(1,1), c(1,2), c(1,3), c(1,4), tx)
704 g1 =
pchip_1d(c(2,1), c(2,2), c(2,3), c(2,4), tx)
705 g2 =
pchip_1d(c(3,1), c(3,2), c(3,3), c(3,4), tx)
706 g3 =
pchip_1d(c(4,1), c(4,2), c(4,3), c(4,4), tx)
709 end function pchip_2d_from_cache
711 end subroutine log_p_bisect_cached
718 double precision,
intent(in) :: log_nh_val, log_p_val
719 double precision,
intent(out) :: log_eint_nh_out
721 double precision :: log_p_target, p2eint_ratio, log_eint_guess
722 double precision :: log_p_at_guess, log_eint_lo, log_eint_hi
723 double precision :: f_bracket, margin
724 double precision :: eint_lim_lo, eint_lim_hi
727 if (eos%type_id /= eos_type_lte)
call mpistop(
"eint_from_p_bisect called outside its eos_type (LTE)")
728 log_p_target = log_p_val - log_nh_val
729 if (log_p_target > eos%log_p_nH_FI)
then
730 log_eint_nh_out = dlog10(eos%inv_gamma_minus_1*10.0d0**log_p_target + eos%eion_per_nH)
736 if (eos%log_p%is_uniform)
then
737 eint_lim_lo = eos%log_p%var2_min
738 eint_lim_hi = eos%log_p%var2_max
740 eint_lim_lo = eos%log_p%var2_nodes(1)
741 eint_lim_hi = eos%log_p%var2_nodes(eos%log_p%dim2)
746 log_eint_guess = dlog10(p2eint_ratio) + log_p_target
748 log_eint_guess = max(log_eint_guess, eint_lim_lo)
749 log_eint_guess = min(log_eint_guess, eint_lim_hi)
751 log_p_at_guess = log_p_from_nh_eint(log_nh_val, log_eint_guess)
755 if (log_p_at_guess < log_p_target)
then
756 log_eint_lo = log_eint_guess
757 log_eint_hi = min(log_eint_guess + margin, eint_lim_hi)
758 f_bracket = log_p_from_nh_eint(log_nh_val, log_eint_hi) - log_p_target
760 log_eint_lo = max(log_eint_guess - margin, eint_lim_lo)
761 log_eint_hi = log_eint_guess
762 f_bracket = -(log_p_from_nh_eint(log_nh_val, log_eint_lo) - log_p_target)
765 if (f_bracket >= 0.0d0)
then
768 log_eint_lo = eint_lim_lo
769 log_eint_hi = eint_lim_hi
773 call log_p_bisect_cached(log_nh_val, log_p_target, &
774 log_eint_lo, log_eint_hi, max_iter, log_eint_nh_out)
788 integer,
intent(out) :: n_nh
789 double precision,
intent(out) :: lg_nh_min, lg_nh_max
791 if (eos%type_id /= eos_type_lte)
call mpistop(
"eos_get_eintT_grid called outside its eos_type (LTE)")
792 if (
allocated(eos%eint_from_T%table))
then
793 n_nh = eos%eint_from_T%dim1
794 lg_nh_min = eos%eint_from_T%var1_min
795 lg_nh_max = eos%eint_from_T%var1_max
796 else if (
allocated(eos%eintT%table))
then
797 n_nh = eos%eintT%dim1
798 lg_nh_min = eos%eintT%var1_min
799 lg_nh_max = eos%eintT%var1_max
809 double precision function lte_p_from_eint(eint_val,nH_val,log_nH_val,inv_rho)
result(pres)
810 double precision,
intent(in) :: eint_val, nh_val, log_nh_val, inv_rho
811 double precision :: e_use
812 if (.not. eos%ionE)
then
813 pres = eos%gamma_minus_1 * eint_val
817 e_use = max(eint_val, nh_val*eos%eint_nH_min, smalldouble)
818 if (e_use*inv_rho > eos%eint_rho_FI_threshold)
then
819 pres = eos%gamma_minus_1*(e_use - eos%eion_per_nH*nh_val)
820 else if (eos%method_id == eos_entropy)
then
821 pres = entropy_p_from_eint(log_nh_val, dlog10(e_use) - log_nh_val)
823 pres = nh_val *
p_nh_from_eint(log_nh_val, dlog10(e_use) - log_nh_val)
828 double precision function lte_eint_from_p(pres,nH_val,log_nH_val,rho_val)
result(eint)
829 double precision,
intent(in) :: pres, nh_val, log_nh_val, rho_val
830 double precision :: t_solve, y_solve, eint_nh_solve, log_eint_mid
831 if (.not. eos%ionE)
then
832 eint = pres*eos%inv_gamma_minus_1
835 if (pres/rho_val > eos%p_rho_FI_threshold)
then
836 eint = pres*eos%inv_gamma_minus_1 + eos%eion_per_nH*nh_val
837 else if (eos%method_id == eos_analytic)
then
838 call saha_state_from_nh_p(nh_val, pres, t_solve, y_solve, eint_nh_solve)
839 eint = eint_nh_solve*nh_val
840 else if (eos%p2eint_bisect)
then
841 if (eos%method_id == eos_entropy)
then
842 call entropy_eint_from_p_bisect(log_nh_val, dlog10(pres) - log_nh_val, log_eint_mid)
843 eint = nh_val*10.0d0**log_eint_mid
846 eint = nh_val*max(10.0d0**log_eint_mid, eos%eint_nH_min)
pure double precision function pchip_1d(p0, p1, p2, p3, t)
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
integer, parameter, public eos_entropy
type(eos_container), allocatable, public eos
The single EoS state object, allocated in eos_init and shared (read-mostly) across all EoS sub-module...
Interpolation kernels for the EoS tables (pure math; no EoS state).
Entropy-method LTE EoS: every query is ONE bicubic Hermite evaluation.
subroutine, public finalise_entropy_lte()
Entropy-method finalise: shift each loaded table's axes from CGS to code units and run the standard p...
subroutine, public load_entropy_lte()
Forward (log nH, log eint/nH) -> thermodynamic state.
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.
'state' method (eos_method='state', legacy 'tables') of the LTE EoS family.
subroutine, public finalise_state_lte()
Table-based method finalise: shift the loaded T/neOnH (and ionE-derived) tables to code units,...
subroutine, public load_state_lte()
state arms of the eos_init / eos_finalise dispatchers (mod_eos_lte)
Shared LTE lookup-table infrastructure (build/IO; not on the hot path).
LTE (Saha-table) EoS kernels and finalise for the eos% family.
double precision function, public lte_eint_from_p(pres, nh_val, log_nh_val, rho_val)
LTE internal energy from pressure in one cell: FI bypass, else eint(nH, p).
double precision function, public p_nh_from_eint(log_nh, log_eint_nh)
p/nH = (1 + He + y) T from (log10 nH, log10 eint/nH)
double precision function, public p2eint_from_nh_p(nh, ponh)
Ratio eint/p from (log10 nH, log10 p/nH).
subroutine, public eos_finalise_lte()
LTE arm of eos_finalise: wire the LTE runtime pointer targets, then dispatch on eos_method to the per...
double precision function, public eint_nh_from_t(log_nh, log_t)
eint/nH from (log10 nH, log10 T), from the inverse table when one is built and the Saha solve otherwi...
subroutine, public eint_from_p_bisect(log_nh_val, log_p_val, log_eint_nh_out)
Given log10(nH) and log10(p), find log10(eint/nH) by table-guessed bisection on the forward pressure ...
double precision function, public y_from_nh_eint(nh, eint_nh)
Scalar EoS kernels: one cell on (log10 nH, log10 eint/nH) or (log10 nH, log10 p/nH),...
subroutine, public get_temperature_from_eint_fast_lte(w, x, ixil, ixol, res)
subroutine, public eos_get_eintt_grid(n_nh, lg_nh_min, lg_nh_max)
####################################################################### Table-metadata helpers: expos...
double precision function, public lte_gamma1_from_p(pres, rho_val)
Gamma_1 of one cell from (p, rho): the ideal value where fully ionised, else the pressure- indexed ta...
double precision function, public gamma1_from_nh_p(log_nh, log_p_nh)
Gamma_1 from (log10 nH, log10 p/nH): one lookup on the pressure-indexed table, or for the analytic me...
subroutine, public eos_init_lte()
update_eos_LTE, get_Te_LTE, get_temperature_from_eint_LTE and Rfactor_from_LTE are PRIVATE: all bound...
double precision function, public t_from_nh_eint(nh, eint_nh)
Temperature from (log10 nH, log10 eint/nH).
double precision function, public lte_p_from_eint(eint_val, nh_val, log_nh_val, inv_rho)
LTE pressure from internal energy in one cell: ideal without ionE, else the table floor,...
Shared EoS accessors (EoS-type-agnostic) for the eos% family.
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer, parameter ndim
Number of spatial dimensions for grid variables.
double precision, dimension(:), allocatable, parameter d
A Fortran 90 module for creating 1D and 2D lookup tables. These tables can be used to efficiently int...
pure integer function, public find_index_bsearch(list, val)
Binary search of sorted list for the smallest ix such that list(ix) >= val. On failure,...
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_e_to_ei), pointer phys_e_to_ei
subroutine eos_timer_start()
Open an EoS timing window; inside an OpenMP parallel region the EoS is not timed.
subroutine eos_timer_stop(acc)
Close an EoS timing window, adding its time to acc when it is the outermost.
double precision timeeos_tfromei