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 diff --git a/eos/test/src/test_eos_support.f90 b/eos/test/src/test_eos_support.f90 index e76f335707..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,6 +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 (*, 2) ' eos calls', eos_calls write (*, '(A)') end if 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