From c93cf8111916b5573a725deb6422d733335f5307 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 27 Nov 2026 12:58:33 -0500 Subject: [PATCH 1/4] work on the EOS inversion --- eos/test/src/test_eos_support.f90 | 1 + 1 file changed, 1 insertion(+) diff --git a/eos/test/src/test_eos_support.f90 b/eos/test/src/test_eos_support.f90 index e76f335707..1adf06b216 100644 --- a/eos/test/src/test_eos_support.f90 +++ b/eos/test/src/test_eos_support.f90 @@ -351,6 +351,7 @@ subroutine test_get_Rho_T ! using most recent values from subroutine Do_One_TRh Pgas = exp(res(i_lnPgas)) logP = log10(Prad + Pgas) write (*, 1) ' got logP', logP + write (*, *) ' eos calls', eos_calls write (*, '(A)') end if From da24f979d4a9376da0b8cd267ec0c96135852a70 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 27 Nov 2026 13:02:52 -0500 Subject: [PATCH 2/4] update benchmark --- eos/test/test_output | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eos/test/test_output b/eos/test/test_output index 2162c12438..ef354860ce 100644 --- a/eos/test/test_output +++ b/eos/test/test_output @@ -410,9 +410,10 @@ actual logT 4.7999999999999989E+00 guess logT 5.1010299956639793E+00 - found logT 4.8009654664974457E+00 + found logT 4.8009668411615838E+00 wanted logP 5.9454245456689820E+00 - got logP 5.9454340392078686E+00 + got logP 5.9454259247730139E+00 + eos calls 4 test1_eosPT From a79399b1ae2f62ec489b6997042fb656e42e5e6d Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 27 Nov 2026 13:03:11 -0500 Subject: [PATCH 3/4] better output --- eos/test/src/test_eos_support.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eos/test/src/test_eos_support.f90 b/eos/test/src/test_eos_support.f90 index 1adf06b216..76a4e883d2 100644 --- a/eos/test/src/test_eos_support.f90 +++ b/eos/test/src/test_eos_support.f90 @@ -252,6 +252,7 @@ subroutine test_get_Rho_T ! using most recent values from subroutine Do_One_TRh othertol = 1d-12 1 format(a30, 1pe24.16) +2 format(a30, i8) if (.not. quietly) then write (*, '(A)') @@ -351,7 +352,7 @@ subroutine test_get_Rho_T ! using most recent values from subroutine Do_One_TRh Pgas = exp(res(i_lnPgas)) logP = log10(Prad + Pgas) write (*, 1) ' got logP', logP - write (*, *) ' eos calls', eos_calls + write (*, 2) ' eos calls', eos_calls write (*, '(A)') end if From 03c06708232f2cf1f73821573e3a9c54ef689313 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 27 Nov 2026 13:03:40 -0500 Subject: [PATCH 4/4] fix the EOS dervaitives for inversion --- eos/private/eosdt_eval.f90 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/eos/private/eosdt_eval.f90 b/eos/private/eosdt_eval.f90 index c2570419b2..78e6ec3a43 100644 --- a/eos/private/eosdt_eval.f90 +++ b/eos/private/eosdt_eval.f90 @@ -2499,13 +2499,18 @@ real(dp) function f(x, dfdx, lrpar, rpar, lipar, ipar, ierr) call mesa_error(__FILE__,__LINE__,'do_safe_get_Rho_T') end if + ! which_other is the quantity we know, and other_value is + ! the value of that quantity we are trying to match. + ! we want f = 0, which we get via Newton iteration + ! with x = log_10(T) or log_10(rho) + if (which_other == -1) then ! other_value is egas erad = crad*pow4(T)/rho egas = energy - erad f = egas - other_value if (doing_Rho) then derad_dlnRho = -erad - dfdx = energy*d_dlnRho_c_T(i_lnE)*ln10 - derad_dlnRho + dfdx = (energy*d_dlnRho_c_T(i_lnE) - derad_dlnRho) * ln10 else derad_dlnT = 4d0*erad degas_dlnT = energy*d_dlnT_c_Rho(i_lnE) - derad_dlnT @@ -2513,13 +2518,15 @@ real(dp) function f(x, dfdx, lrpar, rpar, lipar, ipar, ierr) end if else if (which_other == 0) then ! other_value is log10P f = log10(Pgas + Prad) - other_value + ! note: since both the f and x are in terms of log_10, + ! the conversion factors ln10 cancel. if (doing_Rho) then dPgas_dlnRho = Pgas*d_dlnRho_c_T(i_lnPgas) - dfdx = dPgas_dlnRho/(Pgas + Prad)*ln10 + dfdx = dPgas_dlnRho/(Pgas + Prad) else dPgas_dlnT = Pgas*d_dlnT_c_Rho(i_lnPgas) dPrad_dlnT = 4d0*Prad - dfdx = (dPgas_dlnT + dPrad_dlnT)/(Pgas + Prad)*ln10 + dfdx = (dPgas_dlnT + dPrad_dlnT)/(Pgas + Prad) end if else f = res(which_other) - other_value