Go to the documentation of this file.
53 subroutine timestep (ctime,temp,dens,entropy,Y,dYdt,Ye,delYe,h,evmode)
59 real(r_kind),
intent(in) :: ctime
60 real(r_kind),
intent(in) :: temp
61 real(r_kind),
intent(in) :: dens
62 real(r_kind),
intent(in) :: entropy
63 real(r_kind),
dimension(net_size),
intent(in):: Y
64 real(r_kind),
dimension(net_size),
intent(in):: dYdt
65 real(r_kind),
intent(in) :: Ye
66 real(r_kind),
intent(in) :: delYe
67 real(r_kind),
intent(inout) :: h
68 integer,
intent(in) :: evmode
72 real(r_kind) :: tdens =1e24
73 real(r_kind) :: ttemp =1e24
75 info_entry(
"timestep")
86 if (evmode.eq.em_nse)
then
89 if (h .ne. h)
call raise_exception(
"Timestep got NaN after ye_timestep.",&
95 if (h .ne. h)
call raise_exception(
"Timestep got NaN after abchange_timestep.",&
102 h= min(h,
hydro_timestep(h,ctime,temp,dens,entropy,ttemp,tdens,ye))
103 if (h .ne. h)
call raise_exception(
"Timestep got NaN after hydro_timestep.",&
106 elseif (
solver .eq. 1)
then
110 call update_hydro(ctime+h, ttemp, tdens, rad, entropy, ye)
116 if (h .ne. h)
call raise_exception(
"Timestep got NaN after restrict_timestep.",&
119 info_exit(
"timestep")
154 real(
r_kind),
intent(in) :: ctime
155 real(
r_kind),
intent(in) :: temp
156 real(
r_kind),
intent(in) :: dens
157 real(
r_kind),
intent(in) :: ttemp
158 real(
r_kind),
intent(in) :: tdens
159 real(
r_kind),
intent(inout) :: h
187 if (temp_tmp .lt.
final_temp) h = max(tnext-ctime,1e-15)
188 if (temp_tmp .ge.
final_temp) h = min(1.1*max(tnext-ctime,1e-15),h)
196 if (converged .and. (tnext .gt. ctime)) h = max(tnext-ctime,1e-15)
210 if (temp_tmp .lt.
final_dens) h = max(tnext-ctime,1e-15)
211 if (temp_tmp .ge.
final_dens) h = min(1.1*max(tnext-ctime,1e-15),h)
219 if (converged .and. (tnext .gt. ctime)) h = max(tnext-ctime,1e-15)
237 if (temp_tmp .lt.
nsetemp_cold) h = min(max(tnext-ctime,1e-15),h)
238 if (temp_tmp .ge.
nsetemp_cold) h = min(1.1*max(tnext-ctime,1e-15),h)
247 if (converged .and. (tnext .gt. ctime)) h = max(tnext-ctime,1e-15)
265 if (dens_tmp .ge.
heating_density) h = min(1.1*max(tnext-ctime,1e-15),h)
271 if (converged .and. (tnext .gt. ctime)) h = max(tnext-ctime,1e-15)
277 if (timestep_traj_limit .and. &
280 find_next_time:
do i=1,
zsteps-1
281 if (
ztime(i).gt.ctime)
exit find_next_time
284 if ((ctime.lt.tnext).and.(ctime+h.gt.tnext))
then
286 h = max(tnext-ctime,1e-15)
309 if ((ctime.lt.tnext).and.(ctime+h.gt.tnext))
then
311 h = max(tnext-ctime,1e-15)
324 if ((
solver == 1) .and. (h_in .ne. h))
then
347 real(
r_kind),
intent(in):: ye
348 real(
r_kind),
intent(in):: delye
349 real(
r_kind),
intent(in):: h
351 if (abs(delye) .gt. 1d-15)
then
377 real(
r_kind),
dimension(net_size),
intent(in):: y
378 real(
r_kind),
dimension(net_size),
intent(in):: dydt
379 real(
r_kind),
intent(in):: h
387 if (dydt(i) .eq. 0.d0) cycle
422 real(
r_kind),
intent(in):: h1
423 real(
r_kind),
intent(in):: ctime
424 real(
r_kind),
intent(in):: temp
425 real(
r_kind),
intent(in):: dens
426 real(
r_kind),
intent(in):: entropy
427 real(
r_kind),
intent(inout):: ttemp
428 real(
r_kind),
intent(inout):: tdens
429 real(
r_kind),
intent(in):: ye
432 character(200) :: e_message2
437 if (h .ne. h)
call raise_exception(
"Timestep got NaN.",
"hydro_timestep",430007)
457 / max(abs(tdens-dens)/dens,abs(ttemp-temp)/temp) &
465 e_message2 =
'time: t ='//trim(adjustl(
num_to_str(ctime)))//
', h ='//trim(adjustl(
num_to_str(h)))//new_line(
'A')
466 e_message2 = trim(adjustl(e_message2))//
'dens: d(t)='//trim(adjustl(
num_to_str(dens)))//
', d(t+h)='//trim(adjustl(
num_to_str(tdens)))//new_line(
'A')
467 e_message2 = trim(adjustl(e_message2))//
'temp: d(t)='//trim(adjustl(
num_to_str(temp)))//
', d(t+h)='//trim(adjustl(
num_to_str(ttemp)))//new_line(
'A')
471 "Timestep too small (<1e-24). This happened because the hydrodynamic"//new_line(
'A')//&
472 'conditions were changing to fast. Check the hydrodynamic conditions'//new_line(
'A')//&
475 trim(adjustl(e_message2))&
476 ,
'hydro_timestep',430008)
504 logical,
intent(inout):: init
538 subroutine update_hydro(time_i, temperature, density, radius, entropy, efraction, T_tr)
549 real(
r_kind),
intent(in) :: time_i
550 real(
r_kind),
intent(in) :: entropy
551 real(
r_kind),
intent(in) :: efraction
552 real(
r_kind),
intent(inout) :: temperature
553 real(
r_kind),
intent(inout) :: density
554 real(
r_kind),
intent(inout) :: radius
555 real(
r_kind),
intent(out),
optional :: t_tr
556 real(
r_kind) :: ysum, yasum
572 if (
present(t_tr))
then
581 if (density .le. 1d-99) density = 1d-99
582 if (radius .ge. 1d99) radius = 1d99
587 call expansion(
time_p,htmp,efraction,density,radius,temperature,entropy,
vel,yasum/ysum)
588 if (
present(t_tr))
then
598 if (
present(t_tr))
then
653 integer,
intent(in) :: cnt
659 integer :: eos_status
660 logical :: exit_condition
667 if ((1.00001*dabs(m_tot-1d0) .ge.
nr_tol) .and. (
stepsize .le. 1e-15))
then
668 call raise_exception(
"The result did not converge properly. "//new_line(
"A")//&
669 "Mass conservation was "//
num_to_str(dabs(m_tot-1d0))//
"."//new_line(
"A")//&
671 "This error could be a result of inconsistent reaction rates, "//new_line(
"A")//&
672 "if this is not the case,"//&
673 "try to use different values of nr_tol, nr_maxcount, or timestep_factor.",&
674 'advance_implicit_euler',430011)
692 exit_condition = .true.
705 if ((
ye .lt. 0) .or. (
ye .gt. 1))
then
706 if (verbose_level .gt. 1)
then
707 write(*,*)
"Ye went wrong, obtained Ye = "//
num_to_str(
ye)
709 exit_condition = .false.
719 call nuclear_heating_update(nr_count,
rhob,
ye,
pf,
y_p,
y,
ent_p,
ent,
t9_p,
t9,
t9h_p,
t9h,
stepsize,t9_conv)
739 end do newton_raphson
743 exit_condition = exit_condition .and. (nr_count.le.
nr_maxcount)
750 if (exit_condition)
exit adapt_stepsize
759 end do adapt_stepsize
769 if(eos_status.ne.0)
call raise_exception(
"An error occured in the EOS.",&
770 'advance_implicit_euler',430009)
782 if(eos_status.ne.0)
call raise_exception(
"An error occured in the EOS.",&
783 'advance_implicit_euler',430009)
792 call raise_exception(
"Max. number of steps reached. Probably try to change "//new_line(
'A')//&
793 'the "adapt_stepsize_maxcount", "nr_maxcount", or "nr_tol" parameter.',&
794 'advance_implicit_euler',430010)
850 integer,
intent(in) :: cnt
855 real(
r_kind),
dimension(net_size) :: predictor
856 real(
r_kind),
dimension(net_size) :: delta
857 real(
r_kind),
dimension(net_size) :: ydiff
858 real(
r_kind),
dimension(net_size) :: olol
861 integer :: eos_status
862 logical :: exit_condition
900 exit_condition = .true.
916 if (
ye .lt. 0 .or.
ye .gt. 1)
then
917 exit_condition = .false.
927 call nuclear_heating_update(
gear_nr_count,
rhob,
ye,
pf,
y_p,
y,
ent_p,
ent,
t9_p,
t9,
t9h_p,
t9h,
stepsize,t9_conv)
949 end do newton_raphson
963 if (exit_condition)
exit adapt_stepsize
977 end do adapt_stepsize
981 call raise_exception(
"Max. number of steps reached. Probably try to change "//new_line(
'A')//&
982 'the "adapt_stepsize_maxcount", "gear_nr_maxcount", or "gear_nr_eps" parameter.',&
983 'advance_gear',430010)
995 if(eos_status.ne.0)
call raise_exception(
"An error occured in the EOS.",&
996 'advance_implicit_euler',430009)
1008 if(eos_status.ne.0)
call raise_exception(
"An error occured in the EOS.",&
1009 'advance_implicit_euler',430009)
The timestep_module contains all timestep subroutines and newton-raphsons to solve the ODE system.
real(r_kind), dimension(:), allocatable y
real(r_kind), dimension(:), allocatable, public pf
Partition function for a given temperature.
real(r_kind) function, dimension(net_size), public get_predictor_dydt()
Determines the predicted dydt_next.
subroutine, public select_optimistic_timestep(init)
Selects the timestep.
real(r_kind) function, public get_time()
The current time.
logical, public heating_switch
Variables related to nuclear heating.
real(r_kind) freeze_rate_temp
Tmperature at which rates get frozen (for reacl. rates this should be 1d-2GK)
real(r_kind) timestep_ymin
Lower limit of the abundance to contribute to the timestep calculation, default value is 1....
integer nse_calc_every
Compute NSE abundances every x step.
subroutine, public winnse_guess(t9, rho, ye, yn_guess, yp_guess, ysol)
Calculate NSE composition with an initial guess.
integer, public ipro
index of alphas, neutrons and protons
subroutine expansion(t, dt, ye, dens, rad_in, temp, entropy, vel_in, abar)
Returns temperature, radius, density, and entropy after the trajectory has ended.
integer snapshot_amount
Amount of custom snapshots.
Module inter_module with interpolation routines.
real(r_kind) timestep_factor
Factor for the change of the timestep (see nu in Winteler 2012 Eq. 2.49). Default value is 1....
integer gear_nr_maxcount
Maximum newton-raphson iterations for gear solver.
real, dimension(:), allocatable snapshot_time
point in time for custom snapshot
subroutine, public advance_implicit_euler(cnt)
Advance system to the next step for the implicit Euler method.
Takes care of the temperature and entropy updates due to the nuclear energy release.
real(r_kind) timestep_max
Maximum factor for the change of the timestep. The new timestep is only allowed to be timestep_max * ...
subroutine, public get_solution_at(time_inter, Y_inter)
Determines the solution at a given point in time for [ti-h, ti].
real(r_kind) gear_nr_eps
Convergence criterion for the newton-raphson of the gear solver.
real(r_kind) function, public get_timestep()
The current timestep.
Subroutines to handle parametric evolution of hydrodynamic quantities after the final timestep of the...
subroutine, private update_hydro(time_i, temperature, density, radius, entropy, efraction, T_tr)
Returns temperature, density, and radius for a given time "time_i".
integer termination_criterion
condition to terminate the simulation ([0]=trajectory_file, 1=final_time, 2=final_temp,...
real(r_kind) rad
radial distance [km]
subroutine, public set_xi
Function to calculate xi (needed for getting l in the corrector step)
real(r_kind) gear_escale
Normalization cutoff for gear solver, similar to timestep_Ymin for Euler.
real(r_kind) t9h_p
Temperature [GK] storage for heating mode 2.
integer, public gear_nr_count
counter for NR steps
real(r_kind) nsetemp_cold
T [GK] for the nse->network switch.
subroutine, public masscalc(Y, m_tot)
Total mass used to check the mass conservation.
integer evolution_mode
NSE, network hot/cold, etc.
subroutine timestep(ctime, temp, dens, entropy, Y, dYdt, Ye, delYe, h, evmode)
Network timestepping along the thermodynamic trajectory, specified by {ztime, ztemp,...
subroutine, public netsolve(rhs, res)
The solver core.
subroutine timmes_eos(var, vin, d, Ye, state, status)
real(r_kind) final_dens
termination density [g/cm3]
integer nr_maxcount
– Newton-Raphson iterative loop parameters
subroutine, public raise_exception(msg, sub, error_code)
Raise a exception with a given error message.
real(r_kind) initial_stepsize
this value is used as a stepsize at initial step
integer nr_mincount
Minimum iterations in NR.
logical timestep_traj_limit
Should the timestep be limited by the timestep of the trajectory.
real(r_kind) timestep_hydro_factor
Factor for the maximum change of the hydrodynamic quantities (density and temperature)
real(r_kind) rkm_p
Radius of the outflow [km].
real(r_kind) function, private hydro_timestep(h1, ctime, temp, dens, entropy, ttemp, tdens, Ye)
Estimate the hydro timestep.
real(r_kind) function, private ye_timestep(h, Ye, delYe)
Estimate the timestep from the change of electron fraction.
subroutine, public abchange(time, itemp, rho, Ye, rkm, Y, dYdt, evolution_mode)
This subroutine calculates the change in abundances (dYdt) due to reaction rates at given temperature...
real(r_kind) function, dimension(net_size), public get_solution()
Gives a copy of the solution at the current time.
integer gear_nr_mincount
Minimum newton-raphson iterations for gear solver.
logical gear_ignore_adapt_stepsize
Flag whether gear should ignore the adapt stepsize loop.
subroutine, public set_new_result(ydiff)
Updates the solution (corrector step)
character(max_fname_len) rho_analytic
analytic density [g/cm3]
type(isotope_type), dimension(:), allocatable, public isotope
all nuclides used in the network
real(r_kind), dimension(:), allocatable, public ztime
time information from trajectory
Module with helper functions such as rate tabulation, partition functions, and theoretical weak rates...
character(max_fname_len) rkm_analytic
analytic radial scale [km]
subroutine, public interp1d(n, xp, xb, yp, res, flin, itype)
Interface for 1D interpolation routines.
real(r_kind) heating_density
Density at which nuclear heating will be switched on (-1) to always include heating.
subroutine, public set_timestep(timestep)
Set the current timestep.
real(r_kind) heating_t9_tol
Convergence parameter for the temperature in the heating mode.
real(r_kind) ent_p
Entropy [kB/baryon].
real(r_kind), dimension(:), allocatable f
Subroutines for equation parsing in case of an analytic trajectory or luminosity mode.
real(r_kind), dimension(:), allocatable, public zrad
radii from trajectory
subroutine, public find_start_value(input_string, eq_value, initial_guess, converged, result)
Finds a value of the variable for a given y-value.
real(r_kind) vel
velocity [km/s]
real(r_kind) function, public get_l1()
The current l_1 (in Fortran: l(2))
integer solver
solver flag (0 - implicit Euler, 1 - Gear's method, ...), is integer as it is faster than comparing s...
subroutine, public el_ab(Y, Ye)
Computes the electron fraction.
real(r_kind) function, public parse_string(input_string, var_value)
Takes a string and evaluates the expression.
integer, public net_size
total number of isotopes (network size)
real(r_kind) function, dimension(net_size), public get_predictor_y()
Determines the predicted y_next.
subroutine, public nuclear_heating_update(nr_count, rho, Ye, pf, Y_p, Y, entropy_p, entropy, T9_p, T9, T9_tr_p, T9_tr, timestep, T9conv)
Modifies the temperature and entropy to account for nuclear heating.
integer adapt_stepsize_maxcount
max. iterations in adapting the stepsize
character *20 trajectory_mode
determines how trajectory is calculated (from_file|analytic|expand)
character(:) function, allocatable, public num_to_str(num)
Converts a given real to a string with format "(1pE10.2)".
integer heating_mode
Mode for heating: 0 - no heating, 1 - heating using an entropy equation, 2 - heating from the energy ...
Contains various routines for analysis and diagnostic output.
Contains subroutines for sparse matrix assembly and the solver core.
real(r_kind) stepsize
Stepsize.
logical h_custom_snapshots
Same, but in hdf5 format.
subroutine, private restrict_timestep(ctime, h, temp, dens, ttemp, tdens)
Restricting the previously selected timestep.
subroutine, public set_l
Function to calculate (needed for the corrector step)
integer zsteps
number of timesteps in the hydro trajectory
Contains arrays representing thermodynamic conditions from hydro trajectory file.
real(r_kind), dimension(:), allocatable, public zdens
density information from trajectory
real(r_kind) nr_tol
exit NR if tolerance less than this value
real(r_kind), dimension(:), allocatable dydt
Time derivative of the abundances.
subroutine, public prepare_next_step
Stepsize and order control to pepare the next step.
subroutine, public jacobi_init(time, itemp, rho, rkm, Y, Y_p, dYdt, rhs, h, evolution_mode)
This subroutine calculates the entries in the jacobian and the right-hand side of the numerical integ...
real(r_kind), dimension(:), allocatable y_p
Abundances.
real(r_kind) final_time
termination time in seconds
Contains subroutines to assemble the system Jacobian and changes in the abundances.
real(r_kind) final_temp
termination temperature [GK]
Contains types and objects shared between multiple modules.
real(r_kind) nu_max_time
Maximum time for neutrino reactions to react.
character(max_fname_len) t9_analytic
analytic temperature [T9]
subroutine, public output_nr_diagnostic(cnt, k, nr_c, ctime, T9, stepsize, mtot, Y_p, Y)
Output of the Newton-Raphson loop diagnostics.
real(r_kind) function, private abchange_timestep(h, Y, dYdt)
Estimate the timestep from the abundances change.
real(r_kind), dimension(:), allocatable, public ztemp
temperature information from trajectory
subroutine, public nordsieck_product
Nordsieck vector-matrix product.
logical custom_snapshots
If true, a file must be provided with numbers in days. Snapshots will be created for these points in ...
integer nuflag
defines type of neutrino reactions used
Simulation variables for a single zone model.
subroutine, public revert_timestep(timestep)
Revert a timestep.
subroutine, public shift_tau
Shifts tau vector and controls the current time.
subroutine, public advance_gear(cnt)
Advance system to the next step using the Gear method (using gear_module)
gear_module contains adaptive high-order Gear solver
real(r_kind) t9_p
Temperature [GK].
subroutine, public inverse_interp1d(n, xp, xb, yp, res, flin, itype, reverse_type)
The inverse of the 1D interpolation function.
subroutine, public init_dydt(dYdt)
Initialize dYdt component of the Nordsieck vector.
Contains all runtime parameters as well as phys and math constants.
real(r_kind) ye_p
Electron fraction [mol/g].