Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions eos/private/eosdt_eval.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2499,27 +2499,34 @@ 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
dfdx = degas_dlnT*ln10
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
Expand Down
2 changes: 2 additions & 0 deletions eos/test/src/test_eos_support.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
Expand Down Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions eos/test/test_output
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading