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
1 change: 1 addition & 0 deletions const/public/const_def.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module const_def
real(dp), parameter :: ln3 = 1.0986122886681096D+00 ! = log(3d0)
real(dp), parameter :: lnPi = 1.14472988584940017414343_dp ! = log(pi)
real(dp), parameter :: ln10 = 2.3025850929940455_dp ! = log(10d0)
real(qp), parameter :: ln10_qp = 2.3025850929940456840179914546843642076_qp
real(dp), parameter :: iln10 = 0.43429448190325187_dp ! = 1d0/log(10d0)
real(dp), parameter :: a2rad = pi/180.0d0 ! angle to radians
real(dp), parameter :: rad2a = 180.0d0/pi ! radians to angle
Expand Down
2 changes: 1 addition & 1 deletion net/private/net_eval.f90
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ subroutine get_rates_with_screening(n, ierr)
if (dbg) write(*,*) 'call eval_using_rate_tables'
call eval_using_rate_tables( &
g% num_reactions, g% reaction_id, g% rate_table, g% rattab_f1, nrattab, &
n% ye, n% logT, n% temp, n% rho, n% rate_factors, g% logttab, &
n% ye, n% logT, n% temp, n% rho, n% rate_factors, g% ttab, g% logttab, &
n% rate_raw, n% rate_raw_dT, n% rate_raw_dRho, ierr)
if (ierr /= 0) then
if (dbg) write(*,*) 'ierr from eval_using_rate_tables'
Expand Down
14 changes: 7 additions & 7 deletions net/test/test_output
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@
test_one_zone_burn_small_net
number of species 21
large final abundances 1.0000000000000000D-02
c12 1 9.8714342254068388D-01
he4 2 1.2802186836379657D-02
c12 1 9.8714332077632438D-01
he4 2 1.2802288493829255D-02

xsum 1.0000000000006330D+00
xsum 1.0000000000006921D+00


test_one_zone_burn_const_P
number of species 21
large final abundances 1.0000000000000000D-02
o16 1 6.9559810129898159D-01
si28 2 2.0468825030127175D-01
s32 3 4.4368437194011109D-02
mg24 4 3.7858761619376645D-02
o16 1 6.9559810129898070D-01
si28 2 2.0468825030127155D-01
s32 3 4.4368437194010152D-02
mg24 4 3.7858761619377998D-02

xsum 1.0000000000000000D+00

Expand Down
13 changes: 9 additions & 4 deletions rates/private/rates_support.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
! ***********************************************************************

module rates_support
use const_def, only: dp, use_mesa_temp_cache, missing_value, ln10
use const_def, only: dp, qp, use_mesa_temp_cache, missing_value, ln10, ln10_qp
use math_lib
use rates_def
use utils_lib, only: mv, switch_str, mesa_error
Expand All @@ -32,12 +32,12 @@ module rates_support

subroutine do_get_raw_rates( &
num_reactions, reaction_id, rattab, rattab_f1, nT8s, &
ye, logtemp_in, btemp, bden, raw_rate_factor, logttab, &
ye, logtemp_in, btemp, bden, raw_rate_factor, ttab, logttab, &
rate_raw, rate_raw_dT, rate_raw_dRho, ierr)
integer, intent(in) :: num_reactions, reaction_id(:), nT8s
real(dp), intent(in) :: &
ye, logtemp_in, btemp, bden, raw_rate_factor(:), &
rattab(:,:), logttab(:)
rattab(:,:), ttab(:), logttab(:)
real(dp), pointer, intent(in) :: rattab_f1(:)
real(dp), intent(inout), dimension(:) :: rate_raw, rate_raw_dT, rate_raw_dRho
integer, intent(out) :: ierr
Expand Down Expand Up @@ -155,7 +155,12 @@ subroutine get_rates_from_table(r1, r2)
do while (logtemp > logttab(k+1) .and. k+1 < nrattab)
k = k+1
end do
dt = logtemp - logttab(k)
if (logtemp_in >= max_safe_logT_for_rates) then
dt = logtemp - logttab(k)
else
! Preserve local changes lost by subtracting absolute logarithms.
dt = real(log(real(btemp,kind=qp)/real(ttab(k),kind=qp))*(1.0_qp/ln10_qp),kind=dp)
end if

do i = r1,r2

Expand Down
6 changes: 3 additions & 3 deletions rates/public/rates_lib.f90
Original file line number Diff line number Diff line change
Expand Up @@ -769,18 +769,18 @@ end subroutine eval_weak_reaction_info

subroutine eval_using_rate_tables( &
num_reactions, reaction_id, rattab, rattab_f1, nT8s, &
ye, logtemp, btemp, bden, raw_rate_factor, logttab, &
ye, logtemp, btemp, bden, raw_rate_factor, ttab, logttab, &
rate_raw, rate_raw_dT, rate_raw_dRho, ierr)
use rates_support, only : do_get_raw_rates
integer, intent(in) :: num_reactions, reaction_id(:), nT8s
real(dp), intent(in) :: &
ye, logtemp, btemp, bden, raw_rate_factor(:), &
rattab(:,:), logttab(:)
rattab(:,:), ttab(:), logttab(:)
real(dp), pointer :: rattab_f1(:)
real(dp), intent(out), dimension(:) :: rate_raw, rate_raw_dT, rate_raw_dRho
integer, intent(out) :: ierr
call do_get_raw_rates(num_reactions, reaction_id, rattab, rattab_f1, nT8s, &
ye, logtemp, btemp, bden, raw_rate_factor, logttab, &
ye, logtemp, btemp, bden, raw_rate_factor, ttab, logttab, &
rate_raw, rate_raw_dT, rate_raw_dRho, ierr)
end subroutine eval_using_rate_tables

Expand Down
25 changes: 25 additions & 0 deletions star/defaults/controls_dev.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,28 @@
! ::

use_hydro_merge_limits_in_mesh_plan = .false.


! Solver
! ======

! solver_use_T_reference
! ~~~~~~~~~~~~~~~~~~~~~~
! During solver iterations, calculate the trial temperature from the
! temperature at the start of the solver call and the logarithmic
! temperature correction. This avoids losing small corrections when
! adding them to the absolute value of lnT.
!
! ::

solver_use_T_reference = .false.

! solver_max_T_correction_factor
! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! For a factor greater than one, shorten the coupled Newton correction
! so that T in each cell stays between T_old/factor and T_old*factor.
! T_old is the temperature at the current solver iteration.
!
! ::

solver_max_T_correction_factor = 0d0
3 changes: 3 additions & 0 deletions star/private/alloc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ subroutine star_info_arrays(s, c_in, action_in, ierr)
call do2(s% xa_sub_xa_start, c% xa_sub_xa_start, species, 'xa_sub_xa_start')
if (failed('xa_sub_xa_start')) exit

call do1(s% solver_T_reference, c% solver_T_reference)
if (failed('solver_T_reference')) exit

call do1(s% lnd_start, c% lnd_start)
if (failed('lnd_start')) exit
call do1(s% lnPgas_start, c% lnPgas_start)
Expand Down
6 changes: 6 additions & 0 deletions star/private/ctrls_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ module ctrls_io
iter_for_resid_tol2, iter_for_resid_tol3, &
solver_itermin, solver_itermin_until_reduce_min_corr_coeff, &
solver_reduced_min_corr_coeff, do_solver_damping_for_neg_xa, &
solver_max_T_correction_factor, &
scale_max_correction_for_negative_surf_lum, max_frac_for_negative_surf_lum, &
hydro_mtx_max_allowed_abs_dlogT, hydro_mtx_max_allowed_abs_dlogRho, &
min_logT_for_hydro_mtx_max_allowed, hydro_mtx_max_allowed_logT, &
Expand All @@ -406,6 +407,7 @@ module ctrls_io
tiny_corr_coeff_limit, scale_correction_norm, corr_param_factor, &
scale_max_correction, ignore_min_corr_coeff_for_scale_max_correction, &
ignore_too_large_correction, ignore_species_in_max_correction, &
solver_use_T_reference, &
corr_norm_jump_limit, max_corr_jump_limit, resid_norm_jump_limit, max_resid_jump_limit, RSP2_use_mass_interp_face_values, &
corr_coeff_limit, tiny_corr_factor, solver_test_partials_call_number, solver_test_partials_iter_number, &
max_tries1, solver_max_tries_before_reject, max_tries_for_retry, max_tries_after_5_retries, solver_test_partials_sink_name, &
Expand Down Expand Up @@ -1937,6 +1939,7 @@ subroutine store_controls(s)
s% solver_itermin_until_reduce_min_corr_coeff = solver_itermin_until_reduce_min_corr_coeff
s% solver_reduced_min_corr_coeff = solver_reduced_min_corr_coeff
s% do_solver_damping_for_neg_xa = do_solver_damping_for_neg_xa
s% solver_max_T_correction_factor = solver_max_T_correction_factor
s% scale_max_correction_for_negative_surf_lum = scale_max_correction_for_negative_surf_lum
s% max_frac_for_negative_surf_lum = max_frac_for_negative_surf_lum
s% hydro_mtx_max_allowed_abs_dlogT = hydro_mtx_max_allowed_abs_dlogT
Expand Down Expand Up @@ -1964,6 +1967,7 @@ subroutine store_controls(s)
s% ignore_min_corr_coeff_for_scale_max_correction = ignore_min_corr_coeff_for_scale_max_correction
s% ignore_too_large_correction = ignore_too_large_correction
s% ignore_species_in_max_correction = ignore_species_in_max_correction
s% solver_use_T_reference = solver_use_T_reference

s% corr_norm_jump_limit = corr_norm_jump_limit
s% max_corr_jump_limit = max_corr_jump_limit
Expand Down Expand Up @@ -3626,6 +3630,7 @@ subroutine set_controls_for_writing(s, ierr)
solver_itermin_until_reduce_min_corr_coeff = s% solver_itermin_until_reduce_min_corr_coeff
solver_reduced_min_corr_coeff = s% solver_reduced_min_corr_coeff
do_solver_damping_for_neg_xa = s% do_solver_damping_for_neg_xa
solver_max_T_correction_factor = s% solver_max_T_correction_factor
scale_max_correction_for_negative_surf_lum = s% scale_max_correction_for_negative_surf_lum
max_frac_for_negative_surf_lum = s% max_frac_for_negative_surf_lum
hydro_mtx_max_allowed_abs_dlogT = s% hydro_mtx_max_allowed_abs_dlogT
Expand Down Expand Up @@ -3653,6 +3658,7 @@ subroutine set_controls_for_writing(s, ierr)
ignore_min_corr_coeff_for_scale_max_correction = s% ignore_min_corr_coeff_for_scale_max_correction
ignore_too_large_correction = s% ignore_too_large_correction
ignore_species_in_max_correction = s% ignore_species_in_max_correction
solver_use_T_reference = s% solver_use_T_reference

corr_norm_jump_limit = s% corr_norm_jump_limit
max_corr_jump_limit = s% max_corr_jump_limit
Expand Down
7 changes: 5 additions & 2 deletions star/private/solver_support.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@ subroutine set1(k,report,ierr)
if (do_lnT) then

s% lnT(k) = x(i_lnT)
s% T(k) = exp(s% lnT(k))
s% dxh_lnT(k) = s% solver_dx(i_lnT,k)
if (abs(s% lnT(k) - s% lnT_start(k)) > &
ln10*s% hydro_mtx_max_allowed_abs_dlogT .and. &
Expand Down Expand Up @@ -1160,7 +1159,11 @@ subroutine set1(k,report,ierr)
ierr = -1
return
end if
s% T(k) = exp(s% lnT(k))
if (s% solver_use_T_reference) then
s% T(k) = s% solver_T_reference(k)*exp(s% solver_dx(i_lnT,k))
else
s% T(k) = exp(s% lnT(k))
end if
if (is_bad_num(s% T(k))) then
s% retry_message = 'bad num for T'
if (s% stop_for_bad_nums) then
Expand Down
14 changes: 14 additions & 0 deletions star/private/star_solver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ subroutine do_solver( &
contains

subroutine do_solver_work
integer :: i_lnT, k_max_dlnT
real(dp) :: max_dlnT, dlnT_limit
include 'formats'

err_msg = ''
Expand Down Expand Up @@ -421,6 +423,18 @@ subroutine do_solver_work
exit iter_loop
end if

i_lnT = s% i_lnT
if (s% solver_max_T_correction_factor > 1d0 .and. i_lnT > 0 .and. i_lnT <= nvar) then
k_max_dlnT = maxloc(abs(soln(i_lnT,1:nz)*s% x_scale(i_lnT,1:nz)), dim=1)
max_dlnT = abs(soln(i_lnT,k_max_dlnT)*s% x_scale(i_lnT,k_max_dlnT))
dlnT_limit = log(s% solver_max_T_correction_factor)
if (correction_factor*max_dlnT > dlnT_limit) then
correction_factor = dlnT_limit/max_dlnT
if (s% trace_solver_damping) write(*,4) 'temperature correction limit', &
s% model_number, iter, k_max_dlnT, correction_factor
end if
end if

if (min_corr_coeff < 1d0) then
! compute gradient of f = equ<dot>jacobian
! NOTE: NOT jacobian<dot>equ
Expand Down
1 change: 1 addition & 0 deletions star/private/struct_burn_mix.f90
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ subroutine save_start_values(s, ierr)
end if

do k=1,s% nz
s% solver_T_reference(k) = s% T(k)
do j=1,s% nvar_hydro
s% xh_start(j,k) = s% xh(j,k)
end do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
fix_d_eos_dxa_partials = .false.

use_gold_tolerances = .true.
solver_use_T_reference = .true.
tol_correction_high_T_limit = 1d9 ! Switch to lower tol at high temp for large Mass
gold_solver_iters_timestep_limit = 20

Expand All @@ -320,7 +321,6 @@
convergence_ignore_equL_residuals = .false.
make_gradr_sticky_in_solver_iters = .true.
xa_scale = 1d-5
iter_for_resid_tol2 = 10
min_timestep_limit = 1d-12 ! (seconds) ! 1d-20 if things are sticky

warn_rates_for_high_temp = .true.
Expand Down
15 changes: 13 additions & 2 deletions star/test_suite/20M_pre_ms_to_core_collapse/inlist_to_cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/ ! end of star_job namelist

&eos
mass_fraction_limit_for_skye = 1d-16
/ ! end of eos namelist

&kap
Expand Down Expand Up @@ -56,8 +57,15 @@ ignore_too_large_correction = .true. ! for conv_vel's
! mixing

! timesteps
limit_for_rel_error_in_energy_conservation = 1d-3
hard_limit_for_rel_error_in_energy_conservation = 1d-2

! Relax the energy error limits on timesteps for core collapse.
! If one is concerned about energy conservation, tighten these limits
! and the solver residual tolerances (see inlist_common).
! Be careful, some timesteps can be difficult or impossible to converge
! with tight energy constraints.
max_abs_rel_run_E_err = 1d99 ! this is the MESA default (same as -1)
limit_for_rel_error_in_energy_conservation = 1d99 ! default is 1d-3
hard_limit_for_rel_error_in_energy_conservation = 1d99 ! default is 1d-4

delta_XSi_cntr_limit = 0.0025

Expand All @@ -66,6 +74,9 @@ ignore_too_large_correction = .true. ! for conv_vel's

! solver

gold_tol_residual_norm3 = 1d-5
gold_tol_max_residual3 = 1d-3

calculate_Brunt_B = .true. ! needed for tau_conv
max_q_for_conv_timescale = 0.2d0
max_X_for_conv_timescale = 1d-6 ! must be > 0
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions star/test_suite/make_pre_ccsn_13bvn/inlist_to_cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


&controls
use_momentum_outer_BC = .true.

! 300 km/s core infall stopping condition
fe_core_infall_limit = 3d7
Expand Down
3 changes: 3 additions & 0 deletions star_data/private/star_controls_dev.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
logical :: use_TDC_Y_face_seeded_newton
character(32) :: hydro_matrix_solver

logical :: solver_use_T_reference
real(dp) :: solver_max_T_correction_factor

logical :: TDC_adjust_mass_fallback_to_mlt
logical :: include_mlt_Pturb_in_thermodynamic_gradients
logical :: use_TDC_enthalpy_flux_limiter
Expand Down
1 change: 1 addition & 0 deletions star_data/public/star_data_step_work.inc
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
real(dp), pointer :: xh_start(:,:) ! (nvar_hydro,nz)
real(dp), pointer :: xa_start(:,:) ! (species,nz)
real(dp), pointer :: xa_sub_xa_start(:,:) ! (species,nz)
real(dp), pointer :: solver_T_reference(:) ! (nz)
real(dp), pointer :: lnd_start(:) ! (nz)
real(dp), pointer :: Peos_start(:) ! (nz)
real(dp), pointer :: Peos_face_start(:) ! (nz)
Expand Down