diff --git a/const/public/const_def.f90 b/const/public/const_def.f90 index 8b2b8248cf..cb9d40b20d 100644 --- a/const/public/const_def.f90 +++ b/const/public/const_def.f90 @@ -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 diff --git a/net/private/net_eval.f90 b/net/private/net_eval.f90 index b499cc41e8..57477ba2f7 100644 --- a/net/private/net_eval.f90 +++ b/net/private/net_eval.f90 @@ -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' diff --git a/net/test/test_output b/net/test/test_output index f1208edc06..78519061b4 100644 --- a/net/test/test_output +++ b/net/test/test_output @@ -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 diff --git a/rates/private/rates_support.f90 b/rates/private/rates_support.f90 index 57703b6812..57c336b33b 100644 --- a/rates/private/rates_support.f90 +++ b/rates/private/rates_support.f90 @@ -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 @@ -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 @@ -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 diff --git a/rates/public/rates_lib.f90 b/rates/public/rates_lib.f90 index 6d3378ed6d..4de9078233 100644 --- a/rates/public/rates_lib.f90 +++ b/rates/public/rates_lib.f90 @@ -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 diff --git a/star/defaults/controls_dev.defaults b/star/defaults/controls_dev.defaults index 6f8a71516c..e4597eefbf 100644 --- a/star/defaults/controls_dev.defaults +++ b/star/defaults/controls_dev.defaults @@ -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 diff --git a/star/private/alloc.f90 b/star/private/alloc.f90 index c69697799c..40bc15e89d 100644 --- a/star/private/alloc.f90 +++ b/star/private/alloc.f90 @@ -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) diff --git a/star/private/ctrls_io.f90 b/star/private/ctrls_io.f90 index 644812f5d9..609e32125d 100644 --- a/star/private/ctrls_io.f90 +++ b/star/private/ctrls_io.f90 @@ -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, & @@ -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, & @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/star/private/solver_support.f90 b/star/private/solver_support.f90 index 8c3b12b0a7..69fa78ee96 100644 --- a/star/private/solver_support.f90 +++ b/star/private/solver_support.f90 @@ -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. & @@ -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 diff --git a/star/private/star_solver.f90 b/star/private/star_solver.f90 index c2449dc548..ddcc5a2ace 100644 --- a/star/private/star_solver.f90 +++ b/star/private/star_solver.f90 @@ -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 = '' @@ -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 = equjacobian ! NOTE: NOT jacobianequ diff --git a/star/private/struct_burn_mix.f90 b/star/private/struct_burn_mix.f90 index 2b0fea579a..a04da2b12c 100644 --- a/star/private/struct_burn_mix.f90 +++ b/star/private/struct_burn_mix.f90 @@ -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 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/inlist_common b/star/test_suite/20M_pre_ms_to_core_collapse/inlist_common index b7366abb69..21fc9951af 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/inlist_common +++ b/star/test_suite/20M_pre_ms_to_core_collapse/inlist_common @@ -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 @@ -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. diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/inlist_to_cc b/star/test_suite/20M_pre_ms_to_core_collapse/inlist_to_cc index f4dba2a266..fb4588b603 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/inlist_to_cc +++ b/star/test_suite/20M_pre_ms_to_core_collapse/inlist_to_cc @@ -14,6 +14,7 @@ / ! end of star_job namelist &eos + mass_fraction_limit_for_skye = 1d-16 / ! end of eos namelist &kap @@ -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 @@ -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 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_c_burn.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_c_burn.mod index 012bb11a6d..a1bfa65793 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_c_burn.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_c_burn.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0609b4a87637a4ca045f1a3fcf3cc95c3a3d2abcc4835b88b3d96359095c4d0a -size 785409 +oid sha256:ca7e55690054b5e8e20d806fcca96f993add49bee52a982fbd6b4e985341ee35 +size 768023 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_he_burn.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_he_burn.mod index d7e2e7d07c..044f3b9d24 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_he_burn.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_after_core_he_burn.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3740c086d883a6065fdf3b3fdb8a6ab6504539cdcb19ccec93773e52a2829b8c -size 644789 +oid sha256:b814e1680828ed83295c25d69d14fcdd262564d17a63e44f4429f4863570e775 +size 652683 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_late_pre_zams.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_late_pre_zams.mod index c9513855d5..d2a505b9b6 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_late_pre_zams.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_late_pre_zams.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7b5a393d49c70fcaa19d527e3031f1a613695e37e858b22fbd66e8e3b31906b8 -size 200341 +oid sha256:aa0fbeec9aa7fb26b1b7406441b59bb2926e6f6fe6a8136c2fd1175b0efe9f11 +size 200335 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_lgTmax.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_lgTmax.mod index 02de2ece0f..b8b6e1bd26 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_lgTmax.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_lgTmax.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9be9d3754b2b73cec9cd69bbcd42f2583942a7472454cc31b5c8aa44fe3e4e31 -size 1457699 +oid sha256:04adce011edd59eab44481e69ebbc4d58b9690bfe51324372423c925c8f20d7a +size 1518523 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_removed_envelope.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_removed_envelope.mod index 74f42299ab..cc69bced3f 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_removed_envelope.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_removed_envelope.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a3144bd6e900962bad6b501a99ff219706f9310707b1fce8f1cf31153130a0be -size 644789 +oid sha256:4b987b2e81b2afd978e93fb24ffdd3cada25118d19e31e3245932eea5f618aa8 +size 652683 diff --git a/star/test_suite/20M_pre_ms_to_core_collapse/standard_zams.mod b/star/test_suite/20M_pre_ms_to_core_collapse/standard_zams.mod index bacd4546e1..1a27ea22e3 100644 --- a/star/test_suite/20M_pre_ms_to_core_collapse/standard_zams.mod +++ b/star/test_suite/20M_pre_ms_to_core_collapse/standard_zams.mod @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5b2e86db353451b093d276fcd5b93e7421876a7eed76a5a9bddd38d17be30ef3 -size 311409 +oid sha256:d0eda20ecaa393146c4cf35490d40ecfdf5232653953e91ba8335978a9d5132e +size 311403 diff --git a/star/test_suite/make_pre_ccsn_13bvn/inlist_to_cc b/star/test_suite/make_pre_ccsn_13bvn/inlist_to_cc index 7f9f5a58dc..67a88d5bbb 100644 --- a/star/test_suite/make_pre_ccsn_13bvn/inlist_to_cc +++ b/star/test_suite/make_pre_ccsn_13bvn/inlist_to_cc @@ -17,6 +17,7 @@ &controls + use_momentum_outer_BC = .true. ! 300 km/s core infall stopping condition fe_core_infall_limit = 3d7 diff --git a/star_data/private/star_controls_dev.inc b/star_data/private/star_controls_dev.inc index 788b0f52bf..6b40d5e3a7 100644 --- a/star_data/private/star_controls_dev.inc +++ b/star_data/private/star_controls_dev.inc @@ -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 diff --git a/star_data/public/star_data_step_work.inc b/star_data/public/star_data_step_work.inc index 28eeacfaf5..1ce618a036 100644 --- a/star_data/public/star_data_step_work.inc +++ b/star_data/public/star_data_step_work.inc @@ -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)