analysis.f90
Go to the documentation of this file.
1 !> @file analysis.f90
2 !!
3 !! The error file code for this file is ***W10***.
4 !! @brief Module \ref analysis with various analysis subroutines
5 !!
6 
7 !> Contains various routines for analysis and diagnostic output
8 #include "macros.h"
9 module analysis
10 
12  use global_class, only: net_size, ihe4, ineu, ipro
14 
15  implicit none
16 
17  real(r_kind),dimension(:),allocatable :: sn !< array of n-separation energies
18  real(r_kind) :: sn_ave !< average n-separation energy
19  integer :: mainout_unit !< file descriptor for the main analysis output file
20  integer :: nrdiag_unit !< diagnostic output inside the Newton-Rhapson loop
21  integer :: track_unit !< file id for tracked nuclei
22  integer :: toplist_unit !< file id for top nuclear energy contributors
23  integer :: nu_loss_gain_unit !< file id for neutrino loss/gain
24  integer :: cl_start, cl_end, cl_rate, cl_cmax !< system clock variables
25  integer,private :: tsfile !< timescale file unit
26  integer,private :: nuc_heat_file !< nuclear heating file unit
27  real(r_kind) :: tsnp, t9snp, rosnp !< for snapshot printing triggers
28  integer :: snapcnt !< snapshot count
29  integer :: flowcnt !< flow printing counter
30  real,dimension(:),allocatable :: snapshot_time !< point in time for custom snapshot
31  integer :: snapshot_amount !< Amount of custom snapshots
32  integer,parameter :: toplist_amount=10 !< Amount of reactions in the toplist
33 
34  !
35  ! Public and private fields and methods of the module
36  !
37  public:: &
40 
41  private:: &
45 
46 contains
47 
48 !>
49 !! Open files, write headers, allocate space etc.
50 !!
51 subroutine analysis_init()
52  use parameter_class
54  use error_msg_class, only: int_to_str
55  use benam_class, only: findaz
57 #ifdef USE_HDF5
58  use hdf5_module, only: init_hdf5_module
59 #endif
60  implicit none
61 
62  ! neutron separation energies
63  real(r_kind) :: val !< aux variable for reading Sn file
64  integer :: ai, ni, zi, snfile, fstat !< temporary variables needed for reading the Sn file
65  character :: nl, buf(30) !< newline character, buffer
66  integer :: i,k
67  character*10,dimension(track_nuclei_nr) :: tmp_nucleinames !< Name of the nuclei that will be tracked
68  character*1500 :: head_toplist
69  character*5 :: help_char
70  info_entry("analysis_init")
71 
72 #ifdef USE_HDF5
73  ! Only initialize if it is really possible to execute it
74  ! (i.e., correct compiler h5fc)
75  call init_hdf5_module()
76 #endif
77 
78  cl_cmax= 100000
79  snapcnt= 1
80  flowcnt= 1
81  nl = new_line('A')
82 
83  ! main output file: create, write header
84  if (mainout_every .gt. 0) then
85  mainout_unit= open_outfile("mainout.dat")
86  write(mainout_unit,'(3A)') &
87  '# 1:iteration 2:time[s], 3:T[GK], 4:rho[g/cm3], 5:Ye '//nl &
88  , '# 6:R[km], 7:Y_n, 8:Y_p, 9:Y_alpha, 10:Y_lights '//nl &
89  , '# 11:Y_heavies 12:<Z> 13:<A> 14:entropy [kB/baryon] (15:Sn [MeV])'
90  endif
91 
92  ! read neutron separation energies
93  if (calc_nsep_energy) then
95 
96  allocate(sn(net_size))
97  sn(1:net_size) = 0d0
98  read(snfile, *) buf ! skip the first line
99  do
100  read(snfile, *, iostat=fstat) zi, ni, ai, val
101  if (fstat /= 0) exit
102  k = findaz(ai, zi)
103  if (k>0) then
104  sn(k) = val
105  endif
106  enddo
107  call close_io_file(snfile,nsep_energies_file)
108  endif
109 
110  ! Open the timescale file and write a header
111  if (timescales_every .gt. 0) then
112  tsfile = open_outfile('timescales.dat')
113  write(tsfile, '((A1,(A22,3x),*(A23,3x)))') &
114  "#","time[s]","Temperature [GK]","tau_ga [s]","tau_ag [s]","tau_ng [s]","tau_gn [s]", &
115  "tau_pg [s]", "tau_gp [s]", "tau_np [s]", "tau_pn [s]", &
116  "tau_an [s]", "tau_na [s]", "tau_ap [s]", "tau_pa [s]", "tau_beta [s]", "tau_alpha [s]", &
117  "tau_nfiss [s]", "tau_sfiss [s]", "tau_bfiss [s]"
118  end if
119 
120  ! Open the track_nuclei file and write a header
121  if (track_nuclei_every .gt. 0) then
122  ! Convert indices to names
123  do i=1, track_nuclei_nr
124  tmp_nucleinames(i) = "Y( "//net_names(track_nuclei_indices(i))//" )"
125  end do
126  ! Write the header
127  track_unit = open_outfile('tracked_nuclei.dat')
128  write(track_unit, '((A,20X,*(A,18X)))') "# time[s]",tmp_nucleinames(:)
129  end if
130 
131  ! Write the header for the toplist
132  if (top_engen_every .gt. 0) then
133  toplist_unit= open_outfile("toplist.dat")
134 
135  ! Give some hint on what is what
136  write (toplist_unit,"('#',31X,A,434X,A,413X,'|',5X,A,185X,A)") "Top nuclear energy producers for each reaction given in erg/g/s", &
137  "Top nuclear energy consumers for each reaction given in erg/g/s", &
138  "Top nuclear energy producers for each isotope given in erg/g/s", &
139  "Top nuclear energy consumers for each isotope given in erg/g/s"
140 
141  ! Construct the rather complicated header of the file
142  head_toplist ="# Time[s] Etot[erg/g/s] Reaction_1"
143  do i=2,toplist_amount
144  head_toplist = trim(adjustl(head_toplist))//" Reaction_"//trim(adjustl(int_to_str(i)))
145  end do
146  head_toplist = trim(adjustl(head_toplist))//" Ereac_1"
147  do i=2,toplist_amount
148  head_toplist = trim(adjustl(head_toplist))//" Ereac_"//trim(adjustl(int_to_str(i)))
149  end do
150  head_toplist = trim(adjustl(head_toplist))//" Reaction_1"
151  do i=2,toplist_amount
152  head_toplist = trim(adjustl(head_toplist))//" Reaction_"//trim(adjustl(int_to_str(i)))
153  end do
154  head_toplist = trim(adjustl(head_toplist))//" Ereac_1"
155  do i=2,toplist_amount
156  head_toplist = trim(adjustl(head_toplist))//" Ereac_"//trim(adjustl(int_to_str(i)))
157  end do
158  head_toplist = trim(adjustl(head_toplist))//" | Iso1"
159  do i=2,toplist_amount
160  help_char = "Iso"//trim(adjustl(int_to_str(i)))
161  head_toplist = trim(adjustl(head_toplist))//" "//adjustr(help_char)
162  end do
163  head_toplist = trim(adjustl(head_toplist))//" Eiso_1"
164  do i=2,toplist_amount
165  head_toplist = trim(adjustl(head_toplist))//" Eiso_"//trim(adjustl(int_to_str(i)))
166  end do
167  head_toplist = trim(adjustl(head_toplist))//" Iso1"
168  do i=2,toplist_amount
169  help_char = "Iso"//trim(adjustl(int_to_str(i)))
170  head_toplist = trim(adjustl(head_toplist))//" "//adjustr(help_char)
171  end do
172  head_toplist = trim(adjustl(head_toplist))//" Eiso_1"
173  do i=2,toplist_amount
174  head_toplist = trim(adjustl(head_toplist))//" Eiso_"//trim(adjustl(int_to_str(i)))
175  end do
176  ! Finally write it out
177  write (toplist_unit,"(A)") trim(adjustl(head_toplist))
178  end if
179 
180 
181  if (nrdiag_every.gt.0) then
182  nrdiag_unit= open_outfile("nrdiag.dat")
183  write(nrdiag_unit,'(11A)') &
184  '# Newton-Raphson diagnostic output'//nl &
185  , '# 1 : global iteration count (cnt)'//nl &
186  , '# 2 : global time [s]'//nl &
187  , '# 3 : temperature T9 [GK]'//nl &
188  , '# 4 : adapt stepsize loop counter (k)'//nl &
189  , '# 5 : NR loop counter (nr_count)'//nl &
190  , '# 6 : global timestep [s]'//nl &
191  , '# 7 : mass conservation error'//nl &
192  , '# 8 : maximal abundance change (eps)'//nl &
193  , '# 9 : most rapidly evolving isotope (epsl)'//nl &
194  , '# 10: abundance of the isotope epsl, y(epsl)'
195  end if
196 
197  ! Open the energy generation file and write a header
198  if (engen_every .gt. 0) then
199  nuc_heat_file = open_outfile('generated_energy.dat')
200  ! Header
201  write(nuc_heat_file, '((A,5X))') "# Generated Energy for each nuclear reaction type given in erg/g/s"
202  write(nuc_heat_file, '(17(A23,3X))') &
203  "# time[s]", "Engen(Total)", "S_src","Engen(weak)","Engen(n,g)",&
204  "Engen(p,g)","Engen(a,g)","Engen(n,p)","Engen(n,a)", &
205  "Engen(p,a)", "Engen(fiss)"
206  end if
207 
208 
209 
210  if ((nu_loss_every .gt. 0)) then
211  nu_loss_gain_unit = open_outfile('nu_loss_gain.dat')
212  write(nu_loss_gain_unit, '(A)') "# File containing the neutrino loss/gain for the nuclear heating."
213  write(nu_loss_gain_unit, '(A)') "# Negative values mean that energy is added to the system."
214  write(nu_loss_gain_unit, '(A)') "# Neutrino energies are given in Erg/g/s."
215  write(nu_loss_gain_unit, '((A1,(A18,3x),*(A19,3x)))') &
216  "#","time[s]","T[GK]", "rho[g/cm3]", "R[km]", "nu_total", "nu_beta",&
217  "nu_nuheat", "nu_thermal"
218  end if
219 
220 
221  info_exit("analysis_init")
222 
223 end subroutine analysis_init
224 
225 
226 !>
227 !! Output first step
228 !!
229 !! This routine calls output_iteration at the first step
230 !!
231 !! @see output_final_step
232 subroutine output_initial_step(ctime,T9,rho_b,entropy,Rkm,Y,pf)
233  implicit none
234  real(r_kind),intent(in) :: ctime !< actual time [s]
235  real(r_kind),intent(in) :: t9 !< initial temperature [GK]
236  real(r_kind),intent(in) :: rho_b !< initial density [gcc]
237  real(r_kind),intent(in) :: entropy !< entropy [kB/nucleon]
238  real(r_kind),intent(in) :: rkm !< Radius [km]
239  real(r_kind),dimension(net_size),intent(in) :: y !< array of abundances (Y_i)
240  real(r_kind),dimension(0:net_size),intent(inout) :: pf !< partition functions
241 
242  info_entry('output_initial_step')
243  call output_iteration(0,ctime,t9,rho_b,entropy,rkm,y,pf)
244  info_exit('output_initial_step')
245 
246 end subroutine output_initial_step
247 
248 
249 !>
250 !! Output final step
251 !!
252 !! This routine calls output_iteration at the last step
253 !!
254 !! @see output_final_step
255 !!
256 !! \b Edited: OK 26.08.2017
257 subroutine output_final_step(cnt,ctime,T9,rho_b,entropy,Rkm,Y,pf)
264  implicit none
265  integer,intent(in) :: cnt !< current iteration counter
266  real(r_kind),intent(in) :: ctime !< actual time [s]
267  real(r_kind),intent(in) :: t9 !< initial temperature [GK]
268  real(r_kind),intent(in) :: rho_b !< initial density [gcc]
269  real(r_kind),intent(in) :: entropy !< entropy [kB/nucleon]
270  real(r_kind),intent(in) :: rkm !< Radius [km]
271  real(r_kind),dimension(net_size),intent(in) :: y !< array of abundances (Y_i)
272  real(r_kind),dimension(0:net_size),intent(inout) :: pf !< partition functions
273 
274  info_entry('output_final_step')
275 
276  ! hack output frequency parameters to output the final step out-of-order
277  if (out_every.gt.0) out_every= 1
278  if (mainout_every.gt.0) mainout_every= 1
279  if (snapshot_every.gt.0) snapshot_every= 1
280  if (flow_every.gt.0) flow_every= 1
283  if (nu_loss_every.gt.0) nu_loss_every= 1
284  if (top_engen_every.gt.0) top_engen_every= 1
285  if (engen_every.gt.0) engen_every= 1
286  ! Same for hdf5 output
288  if (h_mainout_every.gt.0) h_mainout_every= 1
291  if (h_flow_every.gt.0) h_flow_every= 1
292  if (h_nu_loss_every.gt.0) h_nu_loss_every= 1
293  if (h_engen_every.gt.0) h_engen_every= 1
294 
295  print '("---------------")'
296  call output_iteration(cnt,ctime,t9,rho_b,entropy,rkm,y,pf)
297  print '("============================")'
298  select case(termination_criterion)
299  case(0)
300  print'(A)',"End of trajectory file reached."
301  case(1)
302  print'(A)',"Final time reached."
303  case(2)
304  print'(A)',"Final temperature reached."
305  case(3)
306  print'(A)',"Final density reached."
307  case(4)
308  print'(A)',"Freeze-out reached."
309  endselect
310 
311  info_exit('output_final_step')
312 
313 end subroutine output_final_step
314 
315 
316 !>
317 !! Periodic output of analysis data for current iteration
318 !!
319 !! Prints various outputs depending on the input parameter.
320 !!
321 !! \b Edited:
322 !! - MR : 19.01.21
323 !! .
324 subroutine output_iteration(cnt,ctime,T9,rho_b,entropy,Rkm,Y,pf)
332  use nucstuff_class, only: inter_partf
337  use global_class, only: isotope
338  use flow_module, only: flowcalc, flows
339 #ifdef USE_HDF5
340  use hdf5_module
341 #endif
342  implicit none
343 
344  integer,intent(in) :: cnt !< current iteration counter
345  real(r_kind),intent(in) :: ctime !< actual time [s]
346  real(r_kind),intent(in) :: t9 !< temperature [GK]
347  real(r_kind),intent(in) :: rho_b !< density [gcc]
348  real(r_kind),intent(in) :: entropy !< entropy [kB/nucleon]
349  real(r_kind),intent(in) :: rkm !< length scale [km]
350  real(r_kind),dimension(net_size),intent(in) :: y !< array of abundances (Y_i)
351  real(r_kind),dimension(0:net_size),intent(inout) :: pf !< partition functions
352  integer :: i !< Loop variable
353  real(r_kind) :: ysum,yasum,abar,ye
354 
355  info_entry("output_iteration")
356 
357  ! screen output
358  if (out_every.gt.0) then
359  if (mod(cnt,50*out_every)==0) then
360  print *
361  print '(A)',"#-- 1:it 2:time[s] 3:T9[GK] 4:rho[g/cm3] &
362  5:entropy[kB/baryon]"
363  endif
364  if (mod(cnt,out_every) .eq. 0) then
365  print '(I8,X,ES14.7,X,F10.7,X,ES14.7,X,F12.7)', &
366  cnt,ctime,t9,rho_b,entropy
367  endif
368 
369  if(mod(cnt,out_every).eq.0 .and. (heating_mode .eq. 1)) then
370  if (verbose_level.ge.2) then
371  call output_nuclear_heating(cnt,ctime)
372  end if
373  endif
374  endif
375 
376  ! This is only done if the correct compiler (h5fc) was used
377 #ifdef USE_HDF5
378  ! Store snapshots in hdf5
379  if (h_snapshot_every.gt.0) then
380  if (mod(cnt,h_snapshot_every).eq. 0) then
381  ! Ye = sum(isotope(1:net_size)%p_nr*Y(1:net_size))
382  call extend_snaps(ctime,y)
383  end if
384  end if
385 
386  ! Store mainout in hdf5
387  if (h_mainout_every.gt.0) then
388  if (mod(cnt,h_mainout_every).eq. 0) then
389  call extend_mainout(cnt,ctime,t9,rho_b,entropy,rkm,y)
390  end if
391  end if
392 
393  ! Snapshot output for specific times
394  if (h_custom_snapshots) then
395  ! Test if a snapshot should be done
396  h_make_snap: do i=1,snapshot_amount
397  ! Time is within certain tolerance? Do the snapshot!
398  if (abs(ctime-snapshot_time(i)) .le. 1e-20) then
399  call extend_snaps(ctime,y)
400  exit h_make_snap
401  end if
402  enddo h_make_snap
403  end if
404 
405  ! Output the tracked nuclei
406  if (h_track_nuclei_every .gt. 0) then
407  if (mod(cnt,h_track_nuclei_every).eq.0) then
408  call extend_track_nuclei(ctime,y)
409  end if
410  end if
411 
412  ! Output average timescales
413  if (h_timescales_every .gt. 0) then
414  if ((mod(cnt,h_timescales_every).eq.0) .and. (evolution_mode .ne. em_nse)) then
415  ! calculate averaged timescales of various types of reactions
416  ! calculate partition function first
417  call inter_partf (t9, pf)
418  call calc_av_timescales(ctime,t9,y,.true.)
419  end if
420  end if
421 
422  ! Output the flow
423  if ((h_flow_every .gt. 0) .and. (cnt .ne. 0)) then
424  if ((mod(cnt,h_flow_every).eq.0)) then
425  call flowcalc(y)
426  call extend_flow(ctime,t9,rho_b,flows,size(flows),y)
427  end if
428  end if
429 
430  ! Calculate and output generated energy
431  if (h_engen_every .gt. 0) then
432  if (mod(cnt,h_engen_every).eq.0) then
433  call calc_nuclear_heating(.true., .true., .false.)
434  end if
435  end if
436 
437  ! Calculate and output generated energy
438  if ((h_nu_loss_every .gt. 0)) then
439  if (mod(cnt,h_nu_loss_every).eq.0) then
440 
441  if ((heating_mode .eq. 0) .and. (use_thermal_nu_loss)) then
442  ysum= sum(y(1:net_size))
443  yasum= sum(y(1:net_size)*isotope(1:net_size)%mass)
444  ye = sum(isotope(1:net_size)%p_nr*y(1:net_size))
445  abar= yasum / ysum
446  call thermal_neutrinos(abar, ye, t9, rho_b, stepsize, qdot_th)
447  qdot_th = qdot_th * unit%hix ! erg/g -> MeV/baryon
448  else
449  qdot_th = 0d0
450  end if
451 
452  call extend_nu_loss_gain(ctime,t9,rho_b,rkm,qdot_th/unit%hix/stepsize,&
453  qdot_nu/unit%hix/stepsize,&
454  qdot_bet/unit%hix/stepsize)
455  end if
456  end if
457 
458 #endif
459 
460  ! main data log
461  if (mainout_every .gt.0) then
462  if (mod(cnt,mainout_every).eq.0) then
463  call output_mainout(cnt,ctime,t9,rho_b,entropy,rkm,y)
464  end if
465  end if
466 
467  ! Iterative Snapshot and flow output
468  if(snapshot_every.gt.0) then
469  if(mod(cnt,snapshot_every).eq.0) then
470  call output_snapshot(ctime,t9,rho_b,y)
471  end if
472  end if
473 
474  if((flow_every.gt.0) .and. (cnt .ne. 0)) then
475  if(mod(cnt,flow_every).eq.0) then
476  call output_flow(ctime,t9,rho_b,y)
477  end if
478  end if
479 
480  if ((nu_loss_every .gt. 0)) then
481  if (mod(cnt,nu_loss_every).eq.0) then
482 
483  if ((heating_mode .eq. 0) .and. (use_thermal_nu_loss)) then
484  ysum= sum(y(1:net_size))
485  yasum= sum(y(1:net_size)*isotope(1:net_size)%mass)
486  ye = sum(isotope(1:net_size)%p_nr*y(1:net_size))
487  abar= yasum / ysum
488  call thermal_neutrinos(abar, ye, t9, rho_b, stepsize, qdot_th)
489  qdot_th = qdot_th * unit%hix ! erg/g -> MeV/baryon
490  else
491  qdot_th = 0d0
492  end if
493 
494  call output_nu_loss(ctime,t9,rho_b,rkm)
495  end if
496  end if
497 
498 
499  ! Snapshot output for specific times
500  if (custom_snapshots) then
501  ! Test if a snapshot should be done
502  make_snap: do i=1,snapshot_amount
503  ! Time is within certain tolerance? Do the snapshot!
504  if (abs(ctime-snapshot_time(i)) .le. 1e-20) then
505  call output_snapshot(ctime,t9,rho_b,y)
506  exit make_snap
507  end if
508  enddo make_snap
509  end if
510 
511  if (timescales_every .gt. 0) then
512  if ((mod(cnt,timescales_every).eq.0) .and. (evolution_mode .ne. em_nse)) then
513  ! calculate averaged timescales of various types of reactions
514  ! calculate partition function first
515  call inter_partf (t9, pf)
516  call calc_av_timescales(ctime,t9,y)
517  end if
518  end if
519 
520  ! Output the tracked nuclei
521  if (track_nuclei_every .gt. 0) then
522  if (mod(cnt,track_nuclei_every).eq.0) then
523  call output_track_nuclei(ctime,y)
524  end if
525  end if
526 
527  ! Calculate generated energy
528  if (engen_every .gt. 0) then
529  if (mod(cnt,engen_every).eq.0) then
530  call calc_nuclear_heating(.false., .true., .false.)
531  end if
532  end if
533 
534  ! Calculate generated energy
535  if (top_engen_every .gt. 0) then
536  if (mod(cnt,top_engen_every).eq.0) then
537  call calc_nuclear_heating(.false., .false., .true.)
538  end if
539  end if
540 
541 
542  info_exit("output_iteration")
543 end subroutine output_iteration
544 
545 
546 !> Output the abundances of specific nuclei
547 !!
548 !! First column is always the time, followed by the abundances of
549 !! nuclei given in "track_nuclei_file". An example of the file looks like:
550 !! \l_file{
551 !! # time[s] Y( n ) Y( o24 ) Y( f24 )
552 !! 0.0000000000000000E+00 0.0000000000000000E+00 2.0833333333333332E-02 0.0000000000000000E+00
553 !! 1.9999999999999999E-20 8.5150206007805894E-19 2.0833333333333332E-02 1.8661570495808601E-21
554 !! 5.9999999999999994E-20 2.5545061802341771E-18 2.0833333333333332E-02 5.5984711487425806E-21
555 !! 1.3999999999999998E-19 5.9605144205464133E-18 2.0833333333333332E-02 1.3063099347066021E-20
556 !! ...}
557 !!
558 !! @author: Moritz Reichert
559 !!
560 !! \b Edited:
561 !! - 09.06.17
562 !! .
563 subroutine output_track_nuclei(ctime,Y)
565  implicit none
566  real(r_kind),intent(in) :: ctime !< Actual time
567  real(r_kind),dimension(net_size),intent(in) :: y !< array of abundances (Y_i)
568  real(r_kind),dimension(track_nuclei_nr) :: tmp_y !< Stores the abundance of the tracked nuclei
569  integer :: i !< Loop variable
570 
571  info_entry("output_track_nuclei")
572  ! Store the abundance temporary
573  do i=1, track_nuclei_nr
574  tmp_y(i) = y(track_nuclei_indices(i))
575  if (tmp_y(i) .lt. 1d-99) tmp_y(i) = 0.
576  end do
577  ! Output
578  write(track_unit,'(*(es23.16,5x))') ctime,tmp_y(:)
579  info_exit("output_track_nuclei")
580 
581 end subroutine output_track_nuclei
582 
583 
584 !> Output the energy that enters and leaves the system
585 !!
586 !! Outputs the energy that enters and leaves the system when
587 !! nuclear_heating is turned on.
588 !! This output is controlled by the parameter \ref nu_loss_every .
589 !! The output is written to the file "nu_loss_gain_file".
590 !! An example of the file could look like:
591 !! \file{
592 !! \# File containing the neutrino loss/gain for the nuclear heating.
593 !! \# Negative values mean that energy is added to the system.
594 !! \# Neutrino energies are given in MeV/baryon/s.
595 !! \# time[s] T[GK] rho[g/cm3] R[km] nu_total ...
596 !! 1.10385E+00 1.00000E+01 4.89334E+07 3.55626E+02 0.00000E+00 ...
597 !! 1.10385E+00 1.00000E+01 4.89334E+07 3.55626E+02 -5.05524E+00 ...
598 !! 1.10385E+00 1.00000E+01 4.89334E+07 3.55626E+02 -5.05524E+00 ...
599 !! 1.10385E+00 1.00000E+01 4.89334E+07 3.55626E+02 -5.05524E+00 ...
600 !! ...}
601 !! @author Moritz Reichert
602 !! @date 12.04.2023
603 subroutine output_nu_loss(ctime,temp,rho,Rkm)
604  use single_zone_vars,only: stepsize
606  use parameter_class, only: unit
607  implicit none
608  real(r_kind),intent(in) :: ctime !< actual time (s)
609  real(r_kind),intent(in) :: temp !< temperature (GK)
610  real(r_kind),intent(in) :: rho !< density (g/cm3)
611  real(r_kind),intent(in) :: rkm !< radius (km)
612  ! local variables
613  real(r_kind) :: qdot_tot
614 
615  qdot_tot = qdot_bet + qdot_nu + qdot_th
616 
617  write(nu_loss_gain_unit, '(*(es19.5,3x))') ctime, temp, rho, rkm, &
618  qdot_tot/unit%hix/stepsize, &
619  qdot_bet/unit%hix/stepsize, &
620  qdot_nu/unit%hix/stepsize, &
621  qdot_th/unit%hix/stepsize
622 
623 end subroutine output_nu_loss
624 
625 
626 !>
627 !! Output Mainout file
628 !!
629 !! This file contains all basic quantities such as neutron abundance Yn,
630 !! time, temperature, density, Abar, and much more. An example file
631 !! looks like:
632 !! \l_file{
633 !! # 1:iteration 2:time[s], 3:T[GK], 4:rho[g/cm3], 5:Ye
634 !! # 6:R[km], 7:Y_n, 8:Y_p, 9:Y_alpha, 10:Y_lights
635 !! # 11:Y_heavies 12:<Z> 13:<A> 14:entropy [kB/baryon] (15:Sn [MeV])
636 !! 0 0.0000000000000000E+00 1.0964999999999998E+01 8.7095999999999795E+12 3.4880000000001680E-02 4.9272999999999975E+01 8.7430471311642388E-01 1.8154340816658842E-15 1.8313910002116333E-13 8.4293473893924100E-09 1.6154109228777289E-03 3.9820982195819934E-02 1.1416565996507526E+00 9.4638587929828290E-03
637 !! 10 4.0940000000000001E-09 1.0965038071994945E+01 8.7093701186135752E+12 3.4880006806212963E-02 4.9273176232580205E+01 8.7430472419630612E-01 1.8157922458135375E-15 1.8317495847108614E-13 8.4302150496944692E-09 1.6154086944791908E-03 3.9820989563731306E-02 1.1416565881127740E+00 9.4639764072160116E-03
638 !! ...}
639 !!
640 !!
641 subroutine output_mainout(cnt,ctime,T9,rho_b,entropy,Rkm,Y)
643  use global_class, only: isotope
644  implicit none
645 
646  integer,intent(in) :: cnt !< current iteration counter
647  real(r_kind),intent(in) :: ctime !< current time
648  real(r_kind),intent(in) :: t9 !< temperature [GK]
649  real(r_kind),intent(in) :: rho_b !< density [gcc]
650  real(r_kind),intent(in) :: entropy !< entropy [kB/nucleon]
651  real(r_kind),intent(in) :: rkm !< length scale [km]
652  real(r_kind),dimension(net_size),intent(in) :: y !< array of abundances (Y_i)
653  !
654  real(r_kind) :: ye,yneu,ypro,yhe4,ylight,yheavies,ysum,yasum,yzsum,abar,zbar
655 
656  ! calculate neutron separation energy
657  if (calc_nsep_energy) then
659  endif
660 
661  ! output diagnostics
662  ye = sum(isotope(1:net_size)%p_nr*y(1:net_size))
663  ylight= max(1.0d-99,sum(y(ipro+1:ihe4-1)))
664  yheavies= 0.0
665  if (ihe4.ge.1) yheavies= max(1.0d-99,sum(y(ihe4+1:net_size)))
666 
667  ysum = sum(y(1:net_size))
668  yasum = sum(y(1:net_size)*isotope(1:net_size)%mass)
669  yzsum = sum(y(1:net_size)*isotope(1:net_size)%p_nr)
670  abar = yasum/ysum
671  zbar = yzsum/ysum
672  !zbar = yzsum/sum(Y(2:net_size)) !as neutrons have Z=0
673 
674  yneu= 0.0
675  if (ineu.ge.1) yneu= max(1.0d-99,y(ineu))
676 
677  ypro= 0.0
678  if (ipro.ge.1) ypro= max(1.0d-99,y(ipro))
679 
680  yhe4= 0.0
681  if (ihe4.ge.1) yhe4= max(1.0d-99,y(ihe4))
682 
683  if (calc_nsep_energy) then
684  write (mainout_unit,'(i8,X,100(es23.16,2X))') cnt,ctime,t9,rho_b,ye,rkm, &
685  yneu,ypro,yhe4,ylight,yheavies,zbar,abar,entropy,sn_ave
686  else
687  write (mainout_unit,'(i8,X,100(es23.16,2X))') cnt,ctime,t9,rho_b,ye,rkm, &
688  yneu,ypro,yhe4,ylight,yheavies,zbar,abar,entropy
689  endif
690 
691 end subroutine output_mainout
692 
693 
694 !>
695 !! Output Snapshot files
696 !!
697 !! Snapshots store the abundances and mass fractions of all nuclei
698 !! at certain times. An example file looks like:
699 !! \file{
700 !! time temp dens
701 !! 9.77198412010000E-02 9.99927332947922E+00 3.88380373937259E+06
702 !! nin zin y x
703 !! 1 0 5.72194135572689E-01 5.72194135572689E-01
704 !! 0 1 3.92194484636783E-01 3.92194484636783E-01
705 !! 1 1 7.83033243870819E-05 1.56606648774164E-04
706 !! ...}
707 !!
708 !! \b Edited:
709 !! - 03.04.18, M. Jacobi
710 !! .
711 subroutine output_snapshot(ctime,T9,rho_b,Y)
712  implicit none
713 
714  real(r_kind),intent(in) :: ctime !< current time
715  real(r_kind),intent(in) :: t9 !< temperature [GK]
716  real(r_kind),intent(in) :: rho_b !< density [gcc]
717  real(r_kind),dimension(net_size),intent(in):: y !< array of abundances Y_i
718 
719 
720  ! Output Snapshots
721  call printsnap (ctime,t9,rho_b,y)
722 
723 end subroutine output_snapshot
724 
725 
726 !>
727 !! Output flow files
728 !!
729 !! \b Edited:
730 !! - 19.02.20, M. Jacobi
731 subroutine output_flow(ctime,T9,rho_b,Y)
732  use flow_module, only: flowprint, flowcalc
733  implicit none
734 
735  real(r_kind),intent(in) :: ctime !< current time
736  real(r_kind),intent(in) :: T9 !< temperature [GK]
737  real(r_kind),intent(in) :: rho_b !< density [gcc]
738  real(r_kind),dimension(net_size),intent(in):: Y !< array of abundances Y_i
739 
740  call flowcalc(y)
741  call flowprint(ctime,t9,rho_b,y,flowcnt)
742  flowcnt = flowcnt + 1
743 end subroutine output_flow
744 
745 
746 !>
747 !! Output of the Newton-Raphson loop diagnostics
748 !!
749 !! The diagnostic output contains NR iterations, timesteps,
750 !! the nucleus that restricts the timestep and more.
751 !! An example file looks like:
752 !! \l_file{
753 !! # Newton-Raphson diagnostic output
754 !! # 1 : global iteration count (cnt)
755 !! # 2 : global time [s]
756 !! # 3 : temperature T9 [GK]
757 !! # 4 : adapt stepsize loop counter (k)
758 !! # 5 : NR loop counter (nr_count)
759 !! # 6 : global timestep [s]
760 !! # 7 : mass conservation error
761 !! # 8 : maximal abundance change (eps)
762 !! # 9 : most rapidly evolving isotope (epsl)
763 !! # 10: abundance of the isotope epsl, y(epsl)
764 !! 0 5.20740000000E-22 7.42450000000E+00 0 1 5.20740000000E-22 9.32587340685E-15 2.22044604925E-16 cl42 2.43899441583E-08
765 !! 0 5.20740000000E-22 7.42450000000E+00 0 2 5.20740000000E-22 9.32587340685E-15 2.22044604925E-16 s40 2.73320077046E-08
766 !! 1 1.56220000000E-21 7.42450000000E+00 0 1 1.04146000000E-21 9.32587340685E-15 2.22044604925E-16 he4 3.13811866442E-03
767 !! 1 1.56220000000E-21 7.42450000000E+00 0 2 1.04146000000E-21 9.32587340685E-15 2.22044604925E-16 mg30 1.57736344914E-10
768 !! ...}
769 subroutine output_nr_diagnostic(cnt,k,nr_c,ctime,T9,stepsize,mtot,Y_p,Y)
770  use parameter_class, only: nrdiag_every
771  use global_class, only: isotope
772  implicit none
773  integer,intent(in) :: cnt !< global iteration counter
774  integer,intent(in) :: k !< counter in adapt_stepsize loop
775  integer,intent(in) :: nr_c !< counter in the NR loop
776  real(r_kind),intent(in) :: ctime !< global current time
777  real(r_kind),intent(in) :: t9 !< current temperature [GK]
778  real(r_kind),intent(in) :: stepsize !< current step size
779  real(r_kind),intent(in) :: mtot !< total mass
780  real(r_kind),dimension(net_size) :: y_p,y !< old/new abundances
781  !
782  integer :: i
783  real(r_kind) :: eps,epst
784  integer :: epsl
785 
786  info_entry("output_nr_diagnostic")
787 
788  ! check periodicity condition
789  if (nrdiag_every.gt.0) then
790  if (mod(cnt,nrdiag_every) .ne. 0) return
791  else
792  return
793  endif
794 
795  ! which isotope has changed the most
796  eps = 0.d0
797  epsl= 1
798  do i=1,net_size
799  if(y_p(i).lt.1.d-10) cycle
800  if(dabs(y_p(i)-y(i)).eq.0.d0) cycle
801  epst = dabs(y(i)/y_p(i)-1.d0)
802  if (epst.gt.eps) then
803  eps = epst
804  epsl = i
805  end if
806  end do
807 
808  ! output convergence diagnostic
809  write(nrdiag_unit, &
810  '(i7,2(1x,es19.11),2(1x,i4),3(1x,es19.11),a5,x,es19.11)') &
811  cnt,ctime,t9,k,nr_c,stepsize,dabs(mtot-1d0),eps,isotope(epsl)%name, &
812  y(epsl)
813 
814 
815  info_exit("output_nr_diagnostic")
816 
817 end subroutine output_nr_diagnostic
818 
819 
820 !>
821 !! Print final statistics
822 !!
823 !! An example looks like:
824 !! \file{
825 !! Final time reached.
826 !! Final time: 2.000000000000E+17
827 !! Total number of iterations: 5334
828 !! Elapsed time [s]: 5.41572E+02
829 !! }
830 !!
831 !! \b Edited:
832 !! - 2023-02-06, M.R. took care of wrapping of the simulation time
833 !! that could lead to negative simulation times.
834 !! .
835 subroutine output_final_stats(cnt,ctime)
836  implicit none
837  integer,intent(in) :: cnt
838  real(r_kind),intent(in) :: ctime
839  !
840  real(r_kind) :: simtime
841 
842  info_entry('output_final_stats')
843 
844  ! calculate elapsed time, check wrapping at cl_cmax
845  if (cl_end .gt. cl_start) then
846  simtime= float(cl_end-cl_start)/float(cl_rate)
847  else
848  simtime= (float(cl_end)+float(cl_cmax)-float(cl_start))/float(cl_rate)
849  end if
850 
851  ! output final statistics
852  print '(A,ES19.12)', 'Final time: ', ctime
853  print '(A,I10)', 'Total number of iterations: ', cnt
854  print '(A,ES12.5)', 'Elapsed time [s]: ', simtime
855 
856  info_exit('output_final_stats')
857 
858 end subroutine output_final_stats
859 
860 
861 !>
862 !! Print current snapshot
863 !!
864 !! Snapshots store the abundances and mass fractions of all nuclei
865 !! at certain times. An example file looks like:
866 !! \file{
867 !! time temp dens
868 !! 9.77198412010000E-02 9.99927332947922E+00 3.88380373937259E+06
869 !! nin zin y x
870 !! 1 0 5.72194135572689E-01 5.72194135572689E-01
871 !! 0 1 3.92194484636783E-01 3.92194484636783E-01
872 !! 1 1 7.83033243870819E-05 1.56606648774164E-04
873 !! ...}
874 subroutine printsnap (t,T9,rho_b,Y)
875  use global_class, only: isotope
876  implicit none
877 
878  real(r_kind),intent(in) :: t,t9,rho_b
879  real(r_kind),dimension(net_size),intent(in) :: y
880  character (len=21) :: snapfile
881  integer :: snapunit, z
882  real(r_kind) :: xz
883 
884  info_entry("printsnap")
885 
886  write(snapfile,'("snaps/snapsh_",i4.4,".dat")') snapcnt
887  snapunit= open_outfile(snapfile)
888 
889  write(snapunit,'(3a8)')'time','temp','dens'
890  write(snapunit,'(3es23.14)')t,t9,rho_b
891  write(snapunit,'(4(a8))')'nin','zin','y','x'
892  do z=1,net_size
893  xz= y(z)*isotope(z)%mass
894  write(snapunit,'(2(i3,2x),2(es23.14))') &
895  isotope(z)%n_nr, isotope(z)%p_nr, max(1d-99,y(z)), max(1d-99,xz)
896  end do
897  call close_io_file(snapunit,snapfile)
898  snapcnt= snapcnt + 1
899  tsnp= t
900  t9snp= t9
901  rosnp=rho_b
902 
903  info_exit("printsnap")
904 
905 end subroutine printsnap
906 
907 
908 !>
909 !! Calculates average neutron separation energy
910 !!
911 !! This neutron separation energy is printed in the mainout when
912 !! parameter_class::calc_nsep_energy was set to "yes" and
913 !! a valid file for parameter_class::nsep_energies_file.
915  use global_class, only: isotope
916  implicit none
917 
918  real(r_kind),dimension(net_size),intent(in) :: y !< abundances
919  !
920  real(r_kind) :: ysum,yasum,yzsum,abar_ions,zbar_ions
921  integer :: i
922 
923  info_entry("calc_nseparation_energy")
924 
925  abar_ions = 0d0
926  zbar_ions = 0d0
927  do i=max(1,ihe4),net_size
928  abar_ions = abar_ions + isotope(i)%mass * y(i)
929  zbar_ions = zbar_ions + isotope(i)%p_nr * y(i)
930  !Sn_ave = Sn_ave + Sn(i) * Y(i)
931  enddo
932  ysum = sum(y(max(1,ihe4):net_size))
933  abar_ions = abar_ions / ysum
934  zbar_ions = zbar_ions / ysum
935  ysum = 0d0
936  sn_ave = 0d0
937  do i=max(1,ihe4),net_size
938  if (sn(i) /= 0) then
939  if ((isotope(i)%mass.ge.220).and.(isotope(i)%mass.le.260)) then
940  sn_ave = sn_ave + sn(i) * y(i)
941  ysum = ysum + y(i)
942  end if
943  endif
944  enddo
945  sn_ave = sn_ave / ysum
946  ysum = sum(y)
947  yasum = sum(y*isotope%mass)
948  yzsum = sum(y*isotope%p_nr)
949 
950  info_exit("calc_nseparation_energy")
951 
952 end subroutine calc_nseparation_energy
953 
954 
955 
956 !>
957 !! @brief: Calculate the generated energy for each class of reactions separately.
958 !!
959 !! This subroutine calculates the generated energy of the nuclear reactions
960 !! with the help of the Q-values. This energy is written to an output only.
961 !! It is not fed back to the temperature and has therefore
962 !! no impact on the final result. Also, depending on the input the
963 !! subroutine can calculate the top contributors to the energy generation.
964 !! These top contributors can be reactions and isotopes.
965 !!
966 !! @see \ref nuclear_heating
967 !!
968 !! @author: Moritz Reichert
969 !! @date 29.02.20
970 !!
971 !! \b Edited:
972 !! - 08.05.24: M.R. Moved the top list calculation from the nuclear heating to this subroutine.
973 !! .
974 subroutine calc_nuclear_heating(hdf5_mode, write_engen, write_toplist)
977  use nucstuff_class, only: isotope,inter_partf
980  use mergesort_module, only: quicksort
981  use benam_class, only: reaction_string
982  use hdf5_module
983  implicit none
984  ! Declare input variables
985  logical, intent(in) :: hdf5_mode !< whether to store as hdf5 or ascii
986  logical, intent(in) :: write_engen !< whether to write the energy generation
987  logical, intent(in) :: write_toplist!< whether to write the energy toplist
988  ! Local variables
989  type(reactionrate_type) :: rr_tmp !< auxiliary shorthand for reaction
990  type(fissionrate_type) :: fr_tmp !< auxiliary shorthand for fission reaction
991  character*4 :: src !< reaction source
992  integer :: i,j !< Loop variable
993  integer :: help_parts !< Helper variable
994  real(r_kind) :: rat !< storage of the cached reaction rate
995  ! Heating variables
996  real(r_kind) :: engen_q_value !< All reactions
997  real(r_kind) :: engen_q_weak !< weak reactions
998  real(r_kind) :: engen_q_ng,engen_q_gn !< gamma-n reactions
999  real(r_kind) :: engen_q_pg,engen_q_gp !< gamma-p reactions
1000  real(r_kind) :: engen_q_ga,engen_q_ag !< gamma-alpha reactions
1001  real(r_kind) :: engen_q_pa,engen_q_ap !< p-alpha reactions
1002  real(r_kind) :: engen_q_pn,engen_q_np !< p-n reactions
1003  real(r_kind) :: engen_q_na,engen_q_an !< n-alpha reactions
1004  real(r_kind) :: engen_fiss !< fission reactions
1005  real(r_kind) :: engen_tot_ncap, engen_tot_pcap, engen_tot_acap, &
1006  engen_tot_npcap,engen_tot_nacap, engen_tot_pacap !< net energy
1007  real(r_kind) :: engen_tot_exc !< total energy with mass excess formula
1008  real(r_kind) :: entropy_src_term !< Source term of entropy * kBT
1009  real(r_kind) :: mic2,gi,twopi_h2c2,mui!< Helper variables
1010  real(r_kind) :: kbt !< Helper variables
1011  real(r_kind),dimension(0:net_size)::pf!< partition functions
1012  real(r_kind) :: etaele,etapos !< electron and positron chemical potental
1013  real(r_kind) :: mue !< electron chemical potental [MeV]
1014  ! Helpers
1015  real(r_kind) :: tmp_energy !< Temporary energy per reaction
1016  real(r_kind),dimension(net_size) ::det_bet_engen !< Energy of decays per parent nucleus
1017  real(r_kind),dimension(net_size) ::det_ag_engen !< Energy of (a,g)+(g,a) per parent nucleus
1018  real(r_kind),dimension(net_size) ::det_pg_engen !< Energy of (p,g)+(g,p) per parent nucleus
1019  real(r_kind),dimension(net_size) ::det_ng_engen !< Energy of (n,g)+(g,n) per parent nucleus
1020  real(r_kind),dimension(net_size) ::det_pn_engen !< Energy of (p,n)+(n,p) per parent nucleus
1021  real(r_kind),dimension(net_size) ::det_ap_engen !< Energy of (a,p)+(p,a) per parent nucleus
1022  real(r_kind),dimension(net_size) ::det_an_engen !< Energy of (a,n)+(n,a) per parent nucleus
1023  real(r_kind),dimension(net_size) ::det_other_engen!< Energy of other reactions per parent nucleus
1024  real(r_kind),dimension(net_size) ::det_fiss_engen !< Energy of fission per parent nucleus
1025  real(r_kind),dimension(net_size) ::det_tot_engen !< Total energy per parent nucleus
1026  ! Toplist stuff
1027  integer, dimension(nreac) ::toplist_idx !< Toplist indices of reactions
1028  real(r_kind), dimension(nreac) ::toplist_energy !< Energy of reactions
1029  logical, dimension(nreac) ::toplist_mask !< Mask which energy has been calculated
1030  character*30 ::reac_dummy !< reaction source
1031  character*30, dimension(toplist_amount)::tplist_str !< Reduced list of top energies
1032  real(r_kind), dimension(toplist_amount)::tplist !< Reduced list of top energies
1033  character*30, dimension(toplist_amount)::btlist_str !< Reduced list of top energies
1034  real(r_kind), dimension(toplist_amount)::btlist !< Reduced list of bottom energies
1035  real(r_kind), dimension(net_size) ::toplist_energy_iso !< Reduced list of bottom energies
1036  integer, dimension(net_size) ::toplist_idx_iso !< Indices of isotopes
1037  character*5, dimension(toplist_amount) ::tplist_str_iso !< Reduced list of top energies
1038  real(r_kind), dimension(toplist_amount)::tplist_iso !< Reduced list of top energies
1039  character*5, dimension(toplist_amount) ::btlist_str_iso !< Reduced list of top energies
1040  real(r_kind), dimension(toplist_amount)::btlist_iso !< Reduced list of bottom energies
1041 
1042  info_entry("calc_nuclear_heating")
1043 
1044  ! Calculate the heating with help of the q-value
1045  engen_q_value = 0 ! Total energy [erg/g/s]
1046  engen_q_weak = 0 ! Energy generated by weak reactions [erg/g/s]
1047  engen_q_ng = 0 ! Energy generated by n-gamma reactions [erg/g/s]
1048  engen_q_gn = 0 ! Energy generated by gamma-n reactions [erg/g/s]
1049  engen_q_pg = 0 ! Energy generated by p-gamma reactions [erg/g/s]
1050  engen_q_gp = 0 ! Energy generated by gamma-p reactions [erg/g/s]
1051  engen_q_ga = 0 ! Energy generated by gamma-alpha reactions [erg/g/s]
1052  engen_q_ag = 0 ! Energy generated by alpha-gamma reactions [erg/g/s]
1053  engen_q_np = 0 ! Energy generated by n-p reactions [erg/g/s]
1054  engen_q_pn = 0 ! Energy generated by p-n reactions [erg/g/s]
1055  engen_q_na = 0 ! Energy generated by n-alpha reactions [erg/g/s]
1056  engen_q_an = 0 ! Energy generated by alpha-n reactions [erg/g/s]
1057  engen_q_pa = 0 ! Energy generated by p-alpha reactions [erg/g/s]
1058  engen_q_ap = 0 ! Energy generated by alpha-p reactions [erg/g/s]
1059  engen_fiss = 0 ! Energy generated by fission [erg/g/s]
1060 
1061  ! Initialize decay energy
1062  if ((h_engen_detailed) .and. (write_engen)) then
1063  det_bet_engen(:) = 0.0
1064  det_ag_engen(:) = 0.0
1065  det_pg_engen(:) = 0.0
1066  det_ng_engen(:) = 0.0
1067  det_pn_engen(:) = 0.0
1068  det_ap_engen(:) = 0.0
1069  det_an_engen(:) = 0.0
1070  det_other_engen(:) = 0.0
1071  det_fiss_engen(:) = 0.0
1072  det_tot_engen(:) = 0.0
1073  end if
1074 
1075  ! Initialize the energy for the top contributors
1076  ! This list has one entry per reaction
1077  if (write_toplist) then
1078  toplist_energy(:) = 0d0
1079  toplist_energy_iso(:) = 0d0
1080  toplist_mask(:) = .false.
1081  end if
1082 
1083  ! For NSE the reaction rates are not cached and the generated energy would be therefore weird
1084  ! Set it to zero for this case
1085  ! Loop through all reactions
1086  do i=1,nreac
1087  rr_tmp = rrate(i)
1088  src = rr_tmp%source
1089  rat = rr_tmp%cached
1090 
1091  if ((evolution_mode .eq. em_nse) .and. (.not. rr_tmp%is_weak)) cycle
1092 
1093  ! Do nothing if the rate is zero
1094  if (rat .eq. 0) cycle
1095 
1096  ! dYdt depends on the reaclib chapter and we therefore have to separate them
1097  select case (rr_tmp%group)
1098  case(1:3,11)! Reaclib chapter 1-3 and 11
1099  ! Energy per reaction
1100  tmp_energy = rat*y(rr_tmp%parts(1)) * rr_tmp%q_value
1101  ! Total energy
1102  engen_q_value = engen_q_value + tmp_energy
1103  ! Seperate the reaction types, weak reactions and photodissociations should be in chapter 1-3
1104 
1105  ! weak rates (only contained in chapter 1-3)
1106  if (rr_tmp%is_weak) then
1107  engen_q_weak = engen_q_weak + tmp_energy
1108  if ((h_engen_detailed) .and. (write_engen)) then
1109  det_bet_engen(rr_tmp%parts(1)) = det_bet_engen(rr_tmp%parts(1))+tmp_energy
1110  end if
1111  end if
1112  ! (gamma,n) reactions
1113  if(rr_tmp%reac_type.eq.rrt_gn) then
1114  engen_q_gn = engen_q_gn + tmp_energy
1115  ! Detailed output
1116  if ((h_engen_detailed) .and. (write_engen)) then
1117  if (rr_tmp%parts(2) .eq. ineu) then
1118  help_parts = rr_tmp%parts(3)
1119  else
1120  help_parts = rr_tmp%parts(2)
1121  end if
1122  det_ng_engen(help_parts) = det_ng_engen(help_parts)+tmp_energy
1123  end if
1124 
1125  endif
1126  ! (gamma,p) reactions
1127  if(rr_tmp%reac_type.eq.rrt_gp) then
1128  engen_q_gp = engen_q_gp + tmp_energy
1129  ! Detailed output
1130  if ((h_engen_detailed) .and. (write_engen)) then
1131  if (rr_tmp%parts(2) .eq. ipro) then
1132  help_parts = rr_tmp%parts(3)
1133  else
1134  help_parts = rr_tmp%parts(2)
1135  end if
1136  det_pg_engen(help_parts) = det_pg_engen(help_parts)+tmp_energy
1137  end if
1138  endif
1139  ! (gamma,alpha) reactions
1140  if(rr_tmp%reac_type.eq.rrt_ga) then
1141  engen_q_ga = engen_q_ga + tmp_energy
1142  ! Detailed output
1143  if ((h_engen_detailed) .and. (write_engen)) then
1144  if (rr_tmp%parts(2) .eq. ihe4) then
1145  help_parts = rr_tmp%parts(3)
1146  else
1147  help_parts = rr_tmp%parts(2)
1148  end if
1149  det_ag_engen(help_parts) = det_ag_engen(help_parts)+tmp_energy
1150  end if
1151  endif
1152 
1153 
1154  if(rr_tmp%reac_type.eq.rrt_o) then
1155  if ((h_engen_detailed) .and. (write_engen)) then
1156  det_other_engen(rr_tmp%parts(1)) = det_other_engen(rr_tmp%parts(1))+tmp_energy
1157  end if
1158  end if
1159 
1160  case(4:7)! Reaclib chapter 4-7
1161  ! Energy per reaction
1162  tmp_energy = rat*y(rr_tmp%parts(1)) * y(rr_tmp%parts(2)) &
1163  * rr_tmp%q_value
1164  ! Total energy
1165  engen_q_value = engen_q_value + tmp_energy
1166 
1167  ! Seperate the reaction types
1168  ! (n-gamma) reactions
1169  if(rr_tmp%reac_type.eq.rrt_ng) then
1170  engen_q_ng = engen_q_ng + tmp_energy
1171  ! Detailed output
1172  if ((h_engen_detailed) .and. (write_engen)) then
1173  if (rr_tmp%parts(2) .eq. ineu) then
1174  help_parts = rr_tmp%parts(1)
1175  else
1176  help_parts = rr_tmp%parts(2)
1177  end if
1178  det_ng_engen(help_parts) = det_ng_engen(help_parts)+tmp_energy
1179  end if
1180  endif
1181  ! (p-gamma) reactions
1182  if(rr_tmp%reac_type.eq.rrt_pg) then
1183  engen_q_pg = engen_q_pg + tmp_energy
1184  ! Detailed output
1185  if ((h_engen_detailed) .and. (write_engen)) then
1186  if (rr_tmp%parts(2) .eq. ipro) then
1187  help_parts = rr_tmp%parts(1)
1188  else
1189  help_parts = rr_tmp%parts(2)
1190  end if
1191  det_pg_engen(help_parts) = det_pg_engen(help_parts)+tmp_energy
1192  end if
1193  endif
1194  ! (alpha gamma) reactions
1195  if(rr_tmp%reac_type.eq.rrt_ag) then
1196  engen_q_ag = engen_q_ag + tmp_energy
1197  ! Detailed output
1198  if ((h_engen_detailed) .and. (write_engen)) then
1199  if (rr_tmp%parts(2) .eq. ihe4) then
1200  help_parts = rr_tmp%parts(1)
1201  else
1202  help_parts = rr_tmp%parts(2)
1203  end if
1204  det_ag_engen(help_parts) = det_ag_engen(help_parts)+tmp_energy
1205  end if
1206  endif
1207  ! (p,alpha) reactions
1208  if(rr_tmp%reac_type.eq.rrt_pa) then
1209  engen_q_pa = engen_q_pa + tmp_energy
1210  ! Detailed output
1211  if ((h_engen_detailed) .and. (write_engen)) then
1212  if (rr_tmp%parts(3) .eq. ihe4) then
1213  help_parts = rr_tmp%parts(4)
1214  else
1215  help_parts = rr_tmp%parts(3)
1216  end if
1217  det_ap_engen(help_parts) = det_ap_engen(help_parts)+tmp_energy
1218  end if
1219  endif
1220  ! (alpha,p) reactions
1221  if(rr_tmp%reac_type.eq.rrt_ap) then
1222  engen_q_ap = engen_q_ap + tmp_energy
1223  ! Detailed output
1224  if ((h_engen_detailed) .and. (write_engen)) then
1225  if (rr_tmp%parts(2) .eq. ihe4) then
1226  help_parts = rr_tmp%parts(1)
1227  else
1228  help_parts = rr_tmp%parts(2)
1229  end if
1230  det_ap_engen(help_parts) = det_ap_engen(help_parts)+tmp_energy
1231  end if
1232  endif
1233  ! (n,p) reactions
1234  if(rr_tmp%reac_type.eq.rrt_np) then
1235  engen_q_np = engen_q_np + tmp_energy
1236  ! Detailed output
1237  if ((h_engen_detailed) .and. (write_engen)) then
1238  if (rr_tmp%parts(3) .eq. ipro) then
1239  help_parts = rr_tmp%parts(4)
1240  else
1241  help_parts = rr_tmp%parts(3)
1242  end if
1243  det_pn_engen(help_parts) = det_pn_engen(help_parts)+tmp_energy
1244  end if
1245  endif
1246  ! (p,n) reactions
1247  if(rr_tmp%reac_type.eq.rrt_pn) then
1248  engen_q_pn = engen_q_pn + tmp_energy
1249  ! Detailed output
1250  if ((h_engen_detailed) .and. (write_engen)) then
1251  if (rr_tmp%parts(1) .eq. ipro) then
1252  help_parts = rr_tmp%parts(2)
1253  else
1254  help_parts = rr_tmp%parts(1)
1255  end if
1256  det_pn_engen(help_parts) = det_pn_engen(help_parts)+tmp_energy
1257  end if
1258  endif
1259  ! (alpha,n) reactions
1260  if(rr_tmp%reac_type.eq.rrt_an) then
1261  engen_q_an = engen_q_an + tmp_energy
1262  ! Detailed output
1263  if ((h_engen_detailed) .and. (write_engen)) then
1264  if (rr_tmp%parts(1) .eq. ihe4) then
1265  help_parts = rr_tmp%parts(2)
1266  else
1267  help_parts = rr_tmp%parts(1)
1268  end if
1269  det_an_engen(help_parts) = det_an_engen(help_parts)+tmp_energy
1270  end if
1271  endif
1272  ! (n,alpha) reactions
1273  if(rr_tmp%reac_type.eq.rrt_na) then
1274  engen_q_na = engen_q_na + tmp_energy
1275  ! Detailed output
1276  if ((h_engen_detailed) .and. (write_engen)) then
1277  if (rr_tmp%parts(3) .eq. ihe4) then
1278  help_parts = rr_tmp%parts(4)
1279  else
1280  help_parts = rr_tmp%parts(3)
1281  end if
1282  det_an_engen(help_parts) = det_an_engen(help_parts)+tmp_energy
1283  end if
1284  endif
1285 
1286  if(rr_tmp%reac_type.eq.rrt_o) then
1287  if ((h_engen_detailed) .and. (write_engen)) then
1288  det_other_engen(rr_tmp%parts(1)) = det_other_engen(rr_tmp%parts(1))+tmp_energy
1289  end if
1290  end if
1291 
1292  case(8:9)! Reaclib chapter 8-9
1293  ! Energy per reaction
1294  tmp_energy = rat*y(rr_tmp%parts(1)) * y(rr_tmp%parts(2)) &
1295  *y(rr_tmp%parts(3)) * rr_tmp%q_value
1296 
1297  ! Total energy
1298  engen_q_value = engen_q_value + tmp_energy
1299 
1300  if(rr_tmp%reac_type.eq.rrt_o) then
1301  if ((h_engen_detailed) .and. (write_engen)) then
1302  det_other_engen(rr_tmp%parts(1)) = det_other_engen(rr_tmp%parts(1))+tmp_energy
1303  end if
1304  end if
1305 
1306  case(10)! Reaclib chapter 8
1307  ! Energy per reaction
1308  tmp_energy = rat*y(rr_tmp%parts(1)) * y(rr_tmp%parts(2)) &
1309  *y(rr_tmp%parts(3)) * y(rr_tmp%parts(4))* rr_tmp%q_value
1310  ! Total energy
1311  engen_q_value = engen_q_value + tmp_energy
1312 
1313  if(rr_tmp%reac_type.eq.rrt_o) then
1314  if ((h_engen_detailed) .and. (write_engen)) then
1315  det_other_engen(rr_tmp%parts(1)) = det_other_engen(rr_tmp%parts(1))+tmp_energy
1316  end if
1317  end if
1318 
1319 
1320  case default ! This should not happen
1321  cycle
1322  end select
1323 
1324  if (write_toplist) then
1325  ! Store the energy of the top contributors
1326  ! This list has one entry per reaction and will be later sorted
1327  if (tmp_energy .ne. 0d0) then
1328  toplist_energy(i) = tmp_energy
1329  toplist_mask(i) = .true.
1330  end if
1331  end if
1332  end do
1333 
1334  ! Do the same for the fission reactions
1335  if (evolution_mode .ne. em_nse) then
1336  if (fissflag.ne.0) then
1337  fission:do i=1,nfiss
1338  fr_tmp = fissrate(i)
1339  rat = fr_tmp%cached
1340  if (rat .eq. 0) cycle
1341  if ((fr_tmp%mode.eq.2).or.(fr_tmp%mode.eq.3)) then ! spont. and b-delayed fission
1342  engen_q_value = engen_q_value + rat*y(fissrate(i)%fissparts(1)) * fissrate(i)%averageQ
1343  engen_fiss = engen_fiss + rat*y(fissrate(i)%fissparts(1)) * fissrate(i)%averageQ
1344  tmp_energy = rat*y(fissrate(i)%fissparts(1)) * fissrate(i)%averageQ
1345  else if (fr_tmp%mode.eq.1) then ! n-induced fission
1346  engen_q_value = engen_q_value + rat*y(fissrate(i)%fissparts(1))*y(fissrate(i)%fissparts(2)) * fissrate(i)%averageQ
1347  engen_fiss = engen_fiss + rat*y(fissrate(i)%fissparts(1))*y(fissrate(i)%fissparts(2)) * fissrate(i)%averageQ
1348  tmp_energy = rat*y(fissrate(i)%fissparts(1))*y(fissrate(i)%fissparts(2)) * fissrate(i)%averageQ
1349  end if
1350 
1351  if ((h_engen_detailed) .and. (write_engen)) then
1352  det_fiss_engen(fissrate(i)%fissparts(1)) = det_fiss_engen(fissrate(i)%fissparts(1))+tmp_energy
1353  end if
1354 
1355  end do fission
1356  end if
1357  end if
1358 
1359 
1360  engen_tot_exc = 0
1361  do i=1,net_size
1362  if (y(i).gt.1d-25) then
1363  tmp_energy = -(isotope(i)%mass_exc)*(y(i)-y_p(i))
1364  engen_tot_exc = engen_tot_exc + tmp_energy ! energy generated by species i [MeV/baryon]
1365 
1366  if (write_toplist) then
1367  toplist_energy_iso(i) = tmp_energy
1368  end if
1369 
1370  if ((h_engen_detailed) .and. (write_engen)) then
1371  det_tot_engen(i) = -(isotope(i)%mass_exc)*(y(i)-y_p(i))
1372  end if
1373  endif
1374  end do
1375  engen_tot_exc = engen_tot_exc/stepsize / unit%hix
1376 
1377  entropy_src_term = 0.d0
1378  call inter_partf (t9, pf)
1379 
1380  ! Take care that one does not go off-grid
1381  if (rhob .gt. 1d-10) then
1382  ! Get the electron chemical potential
1383  call chempot(t9*1d9,rhob,ye,etaele,etapos)
1384  mue = etaele * unit%k_mev * t9*1d9
1385  else
1386  mue = 0.d0
1387  end if
1388  mue = mue + unit%mass_e
1389 
1390  kbt = t9*1d9 * unit%k_mev ! 8.617332d-11 * T [MeV]
1391  do i=1,net_size
1392  if (y(i).gt.1d-25) then
1393  mic2 = isotope(i)%mass*unit%mass_u - isotope(i)%p_nr * unit%mass_e + isotope(i)%mass_exc ! [MeV]
1394  gi = 2d0*isotope(i)%spin + 1d0 ! statistical weight
1395  twopi_h2c2 = 2d0*unit%pi/(unit%h_mevs*unit%clight)**2 ! 2\pi/(hc)^2 [MeV^-2 cm^-2]
1396  mui = -kbt*log( gi*pf(i) / (rhob*y(i)*unit%n_a) * &
1397  (twopi_h2c2 * mic2 * kbt)**1.5d0 )
1398  ! entropy generated by species i [MeV/baryon]
1399  entropy_src_term = entropy_src_term -(mic2 + mui + isotope(i)%p_nr*mue)*(y(i)-y_p(i))
1400  endif
1401  end do
1402 
1403  entropy_src_term = entropy_src_term/ unit%hix/stepsize
1404  ! Convert from MeV/Baryon/s - > Erg/g/s
1405  engen_q_value = engen_q_value / unit%hix
1406  engen_q_weak = engen_q_weak / unit%hix
1407  engen_q_ng = engen_q_ng / unit%hix
1408  engen_q_gn = engen_q_gn / unit%hix
1409  engen_q_pg = engen_q_pg / unit%hix
1410  engen_q_gp = engen_q_gp / unit%hix
1411  engen_q_ga = engen_q_ga / unit%hix
1412  engen_q_ag = engen_q_ag / unit%hix
1413  engen_q_np = engen_q_np / unit%hix
1414  engen_q_pn = engen_q_pn / unit%hix
1415  engen_q_na = engen_q_na / unit%hix
1416  engen_q_an = engen_q_an / unit%hix
1417  engen_q_pa = engen_q_pa / unit%hix
1418  engen_q_ap = engen_q_ap / unit%hix
1419  engen_fiss = engen_fiss / unit%hix
1420  ! Detailed output
1421  if ((h_engen_detailed) .and. (write_engen)) then
1422  det_tot_engen = det_tot_engen/stepsize / unit%hix
1423  det_bet_engen = det_bet_engen / unit%hix
1424  det_ag_engen = det_ag_engen / unit%hix
1425  det_pg_engen = det_pg_engen / unit%hix
1426  det_ng_engen = det_ng_engen / unit%hix
1427  det_pn_engen = det_pn_engen / unit%hix
1428  det_ap_engen = det_ap_engen / unit%hix
1429  det_an_engen = det_an_engen / unit%hix
1430  det_other_engen = det_other_engen / unit%hix
1431  det_fiss_engen = det_fiss_engen / unit%hix
1432  end if
1433 
1434  !Calculate net energy
1435  engen_tot_ncap = engen_q_ng + engen_q_gn
1436  engen_tot_pcap = engen_q_pg + engen_q_gp
1437  engen_tot_acap = engen_q_ag + engen_q_ga
1438  engen_tot_npcap= engen_q_np + engen_q_pn
1439  engen_tot_nacap= engen_q_na + engen_q_an
1440  engen_tot_pacap= engen_q_pa + engen_q_ap
1441 
1442  if (write_toplist) then
1443  ! Store the energy of the top contributors
1444  ! This list has one entry per reaction and will be later sorted
1445  toplist_energy(:) = toplist_energy(:) / unit%hix
1446  toplist_energy_iso(:) = toplist_energy_iso(:) /stepsize/ unit%hix
1447 
1448  ! Sort the list
1449  call quicksort(0,nreac,toplist_energy,toplist_idx)
1450 
1451  if (toplist_energy(1) .lt. toplist_energy(2)) then
1452  call raise_exception("There was a bug in the toplist. Energy is not sorted.", &
1453  "calc_nuclear_heating")
1454  end if
1455 
1456  i=0
1457  j=1
1458  tplist_str(:) = "---------"
1459  tplist(:) = 0d0
1460  do while(i<10)
1461 
1462  if (j .gt. nreac) exit
1463 
1464  if (toplist_mask(toplist_idx(j))) then
1465  reac_dummy=trim(adjustl(reaction_string(rrate(toplist_idx(j)))))
1466  tplist_str(i+1) = reaction_string(rrate(toplist_idx(j)))
1467  tplist(i+1) = toplist_energy(j)
1468  i = i+1
1469  else
1470  continue
1471  end if
1472 
1473  j = j+1
1474  end do
1475 
1476  if (tplist(1) .lt. tplist(2)) then
1477  call raise_exception("There was a bug in the toplist. Energy is not sorted.", &
1478  "calc_nuclear_heating")
1479  end if
1480 
1481  i=0
1482  j=1
1483  btlist_str(:) = "---------"
1484  btlist(:) = 0d0
1485  do while(i<10)
1486 
1487  if (j .gt. nreac) exit
1488 
1489  if (toplist_mask(toplist_idx(nreac+1-j))) then
1490  reac_dummy=trim(adjustl(reaction_string(rrate(toplist_idx(nreac+1-j)))))
1491  btlist_str(i+1) = reaction_string(rrate(toplist_idx(nreac+1-j)))
1492  btlist(i+1) = toplist_energy(nreac+1-j)
1493  i = i+1
1494  else
1495  continue
1496  end if
1497 
1498  j = j+1
1499  end do
1500 
1501 
1502  ! Do the same for the isotopes
1503  call quicksort(0,net_size,toplist_energy_iso,toplist_idx_iso)
1504 
1505  i=0
1506  j=1
1507  tplist_str_iso(:) = "-----"
1508  tplist_iso(:) = 0d0
1509  do while(i<10)
1510 
1511  if (j .gt. net_size) exit
1512 
1513  if (toplist_energy_iso(j) .ne. 0d0) then
1514  tplist_str_iso(i+1) = net_names(toplist_idx_iso(j))
1515  tplist_iso(i+1) = toplist_energy_iso(j)
1516  i = i+1
1517  else
1518  continue
1519  end if
1520 
1521  j = j+1
1522  end do
1523 
1524  i=0
1525  j=1
1526  btlist_str_iso(:) = "-----"
1527  btlist_iso(:) = 0d0
1528  do while(i<10)
1529 
1530  if (j .gt. net_size) exit
1531 
1532  if (toplist_energy_iso(net_size+1-j) .ne. 0d0) then
1533  btlist_str_iso(i+1) = net_names(toplist_idx_iso(net_size+1-j))
1534  btlist_iso(i+1) = toplist_energy_iso(net_size+1-j)
1535  i = i+1
1536  else
1537  continue
1538  end if
1539 
1540  j = j+1
1541  end do
1542 
1543 
1544 
1545  write(toplist_unit,"(es12.4, 4X, es12.4, 4X, "//int_to_str(toplist_amount)//"(A,3X), 3X,"//&
1546  int_to_str(toplist_amount)//"(es12.4,3X), 4X, "//int_to_str(toplist_amount)//&
1547  "(A,3X), 2X,"//int_to_str(toplist_amount)//"(es12.4,3X),' | ',"//&
1548  int_to_str(toplist_amount)//"(A,3X), 3X,"//int_to_str(toplist_amount)//&
1549  "(es12.4,3X), 4X, "//int_to_str(toplist_amount)//&
1550  "(A,3X), 3X,"//int_to_str(toplist_amount)//"(es12.4,3X))" )&
1551  time,engen_tot_exc, tplist_str, tplist, btlist_str,btlist, tplist_str_iso, tplist_iso, &
1552  btlist_str_iso, btlist_iso
1553 
1554  end if
1555 
1556 
1557 
1558  if ((.not. hdf5_mode) .and. write_engen) then
1559  ! Write the output (detailed)
1560  !write(nuc_heat_file,'(*(es23.14,3x))') time,engen_q_value,engen_q_weak,&
1561  ! engen_q_ng,engen_q_gn,engen_tot_ncap,&
1562  ! engen_q_pg,engen_q_gp,engen_tot_pcap,&
1563  ! engen_q_ag,engen_q_ga,engen_tot_acap,&
1564  ! engen_q_np,engen_q_pn,engen_tot_npcap,&
1565  ! engen_q_na,engen_q_an,engen_tot_nacap,&
1566  ! engen_q_pa,engen_q_ap,engen_tot_pacap,&
1567  ! engen_fiss
1568  ! Write the output (more relaxed)
1569  write(nuc_heat_file,'(*(es23.14E3,3x))') time,engen_tot_exc,entropy_src_term,&
1570  engen_q_weak,&
1571  engen_tot_ncap,&
1572  engen_tot_pcap,&
1573  engen_tot_acap,&
1574  engen_tot_npcap,&
1575  engen_tot_nacap,&
1576  engen_tot_pacap,&
1577  engen_fiss
1578  end if
1579 
1580 #ifdef USE_HDF5
1581  if ((write_engen) .and. (hdf5_mode)) then
1582  call extend_engen(time,engen_tot_exc, entropy_src_term,engen_tot_ncap, &
1583  engen_tot_pcap, engen_tot_acap,engen_tot_npcap, &
1584  engen_tot_nacap, engen_tot_pacap, engen_q_weak, &
1585  engen_fiss, &
1586  det_bet_engen, det_ag_engen, det_pg_engen, &
1587  det_ng_engen, det_pn_engen, det_ap_engen, &
1588  det_an_engen, det_other_engen, det_fiss_engen, &
1589  det_tot_engen, &
1591  end if
1592 #endif
1593 
1594 
1595  info_exit("calc_nuclear_heating")
1596 
1597 end subroutine calc_nuclear_heating
1598 
1599 
1600 
1601 
1602 
1603 
1604 !>
1605 !! Calculate average timescales of different classes of reactions
1606 !!
1607 !! These timescales are calculated as in
1608 !! [Arcones et al. 2012](https://ui.adsabs.harvard.edu/abs/2012ApJ...750...18A/abstract)
1609 !! (Eq. 1-6). The (p,gamma) timescale is given by e.g.,
1610 !! \f[
1611 !! \tau_{p\gamma} = \left[ \frac{\rho Y_p}{Y_h}N_A \sum \langle \sigma \nu \rangle_{p,\gamma}(Z,A)Y(Z,A) \right]^{-1}
1612 !! \f]
1613 !!
1614 !! An example file looks like:
1615 !! \l_file{
1616 !! # time[s] Temperature [GK] tau_ng [s] tau_gn [s] tau_pg [s] tau_gp [s] tau_np [s] tau_pn [s] tau_an [s] tau_na [s] tau_beta [s] tau_alpha [s] tau_nfiss [s] tau_sfiss [s] tau_bfiss [s]
1617 !! 1.1130000000000000E+00 9.1821750000000009E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 1.2642767370327558E+01 2.9487624276191804E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00
1618 !! 1.1220000000000001E+00 8.2638489999999951E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00 1.0557999180036711E+02 2.5923655028366777E+01 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00
1619 !! 1.1247618491767180E+00 7.9904974735555152E+00 9.5690472538317728E-13 5.3150487750907188E-11 7.4419112944811684E-10 9.8479480155439862E-08 1.9792689873245490E-12 1.9444248037144314E-12 4.8686627517806918E-10 3.9657685448682009E-12 1.4600540103519526E+01 5.2634156341152767E+01 0.0000000000000000E+00 0.0000000000000000E+00 0.0000000000000000E+00
1620 !! ...}
1621 subroutine calc_av_timescales(ctime,T9,Y,hdf5)
1625 #ifdef USE_HDF5
1627 #endif
1628  implicit none
1629  real(r_kind),intent(in) :: ctime !< current time [s]
1630  real(r_kind),intent(in) :: t9 !< Temperature [GK]
1631  logical,optional,intent(in) :: hdf5 !< Whether the output is written to hdf5 or not
1632  real(r_kind),dimension(net_size),intent(in) :: y !< abundances
1633 
1634  ! average timescales
1635  real(r_kind) :: tau_ng !< (n,gamma)
1636  real(r_kind) :: tau_gn !< (gamma,n)
1637  real(r_kind) :: tau_pg !< (p,gamma)
1638  real(r_kind) :: tau_gp !< (gamma,p)
1639  real(r_kind) :: tau_np !< (n,p)
1640  real(r_kind) :: tau_pn !< (p,n)
1641  real(r_kind) :: tau_an !< (alpha,n)
1642  real(r_kind) :: tau_na !< (n,alpha)
1643  real(r_kind) :: tau_ag !< (alpha,gamma)
1644  real(r_kind) :: tau_ga !< (gamma,alpha)
1645  real(r_kind) :: tau_pa !< (p,alpha)
1646  real(r_kind) :: tau_ap !< (alpha,p)
1647  !real(r_kind) :: tau_npro !< neutron production timescale
1648  !real(r_kind) :: tau_fdis !< photodissociation timescale
1649  real(r_kind) :: tau_beta !< beta-decay timescale
1650  real(r_kind) :: tau_alpha !< alpha-decay timescale
1651  real(r_kind) :: tau_nfiss !< n-induced fission timescale
1652  real(r_kind) :: tau_sfiss !< spontaneous fission timescale
1653  real(r_kind) :: tau_bfiss !< beta-delayed fission timescale
1654  integer :: nuc !< auxiliary var
1655  real(r_kind) :: rat !< Value of reaction rate
1656  real(r_kind) :: ng_sum,gn_sum,pg_sum,gp_sum,beta_sum
1657  real(r_kind) :: np_sum,pn_sum,an_sum,na_sum,ag_sum,ga_sum
1658  real(r_kind) :: ap_sum,pa_sum
1659  real(r_kind) :: alpha_sum, nfiss_sum, sfiss_sum, bfiss_sum
1660  real(r_kind) :: ysum !< Sum of abundances heavier than helium
1661  integer :: i !< Loop variable
1662  type(reactionrate_type) :: rr_tmp !< auxiliary shorthand for reaction
1663  type(fissionrate_type) :: fr_tmp !< auxiliary shorthand for reaction
1664  character*4 :: src !< reaction source
1665  real(r_kind) :: q_sm = 1.e-20 !< small quantity to add to denominator
1666 
1667  info_entry("calc_av_timescales")
1668 
1669 
1670  ! to avoid division by zero
1671  ng_sum = q_sm
1672  gn_sum = q_sm
1673  pg_sum = q_sm
1674  gp_sum = q_sm
1675  np_sum = q_sm
1676  pn_sum = q_sm
1677  an_sum = q_sm
1678  na_sum = q_sm
1679  ag_sum = q_sm
1680  ga_sum = q_sm
1681  ap_sum = q_sm
1682  pa_sum = q_sm
1683  beta_sum = q_sm
1684  alpha_sum = q_sm
1685  nfiss_sum = q_sm
1686  sfiss_sum = q_sm
1687  bfiss_sum = q_sm
1688 
1689 
1690  ysum = sum(y(max(1,ihe4):net_size))
1691 
1692  do i=1,nreac
1693  rr_tmp = rrate(i)
1694  src = rr_tmp%source
1695  rat = rr_tmp%cached
1696 
1697  ! beta-decays (not including beta-delayed fission)
1698  if ((rr_tmp%group.eq.1).or.(rr_tmp%group.eq.2).or.(rr_tmp%group.eq.3) .or.(rr_tmp%group.eq.11)) then
1699  if ((rr_tmp%reac_type .eq.rrt_betm).or.(rr_tmp%reac_type .eq.rrt_betp).and.(rr_tmp%source.ne.'ms99')) then
1700  ! only include significant reactions
1701  nuc = rr_tmp%parts(1)
1702  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1703  beta_sum = beta_sum + rat*y(nuc)
1704  end if
1705  endif
1706  endif
1707 
1708  ! alpha-decays
1709  if ((rr_tmp%reac_type.eq.rrt_alpd)) then
1710  nuc = rr_tmp%parts(1)
1711  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1712  alpha_sum = alpha_sum + rat*y(nuc)
1713  end if
1714  end if
1715 
1716  ! (a,p)
1717  if(rr_tmp%reac_type.eq.rrt_ap) then
1718  nuc = rr_tmp%parts(2)
1719  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1720  ap_sum = ap_sum + rat*y(nuc)*y(ihe4)
1721  end if
1722  endif
1723 
1724  ! (p,a)
1725  if(rr_tmp%reac_type.eq.rrt_pa) then
1726  nuc = rr_tmp%parts(2)
1727  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1728  pa_sum = pa_sum + rat*y(nuc)*y(ipro)
1729  end if
1730  endif
1731 
1732  ! (n,gamma)
1733  if(rr_tmp%reac_type.eq.rrt_ng) then
1734  nuc = rr_tmp%parts(2)
1735  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1736  ng_sum = ng_sum + rat*y(nuc)*y(ineu)
1737  end if
1738  endif
1739 
1740  ! (gamma,n)
1741  if(rr_tmp%reac_type.eq.rrt_gn) then
1742  nuc = rr_tmp%parts(1)
1743  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1744  gn_sum = gn_sum + rat*y(nuc)
1745  end if
1746  endif
1747 
1748  ! (p,gamma)
1749  if(rr_tmp%reac_type.eq.rrt_pg) then
1750  nuc = rr_tmp%parts(2)
1751  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1752  pg_sum = pg_sum + rat*y(nuc)*y(ipro)
1753  end if
1754  endif
1755 
1756  ! (gamma,p)
1757  if(rr_tmp%reac_type.eq.rrt_gp) then
1758  nuc = rr_tmp%parts(1)
1759  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1760  gp_sum = gp_sum + rat*y(nuc)
1761  end if
1762  endif
1763 
1764  ! (a,g)
1765  if(rr_tmp%reac_type.eq.rrt_ag) then
1766  nuc = rr_tmp%parts(2)
1767  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1768  ag_sum = ag_sum + rat*y(nuc)*y(ihe4)
1769  end if
1770  endif
1771 
1772  ! (g,a)
1773  if(rr_tmp%reac_type.eq.rrt_ga) then
1774  nuc = rr_tmp%parts(1)
1775  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1776  ga_sum = ga_sum + rat*y(nuc)
1777  end if
1778  endif
1779 
1780  ! (n,p)
1781  if(rr_tmp%reac_type.eq.rrt_np) then
1782  nuc = rr_tmp%parts(2)
1783  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1784  np_sum = np_sum + rat*y(nuc)*y(ineu)
1785  end if
1786  endif
1787 
1788  ! (p,n)
1789  if(rr_tmp%reac_type.eq.rrt_pn) then
1790  nuc = rr_tmp%parts(2)
1791  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1792  pn_sum = pn_sum + rat*y(nuc)*y(ipro)
1793  end if
1794  endif
1795 
1796  ! (a,n)
1797  if(rr_tmp%reac_type.eq.rrt_an) then
1798  nuc = rr_tmp%parts(2)
1799  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1800  an_sum = an_sum + rat*y(nuc)*y(ihe4)
1801  end if
1802  endif
1803 
1804  ! (n,a)
1805  if(rr_tmp%reac_type.eq.rrt_na) then
1806  nuc = rr_tmp%parts(2)
1807  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1808  na_sum = na_sum + rat*y(nuc)*y(ineu)
1809  end if
1810  endif
1811 
1812  enddo
1813 
1814  fission:do i=1,nfiss
1815  fr_tmp = fissrate(i)
1816  rat = fr_tmp%cached
1817  ! neutron-induced fission
1818  if(fr_tmp%reac_type.eq.rrt_nf) then
1819  nuc = fr_tmp%fissparts(2)
1820  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1821  nfiss_sum = nfiss_sum + rat*y(nuc)*y(ineu)
1822  end if
1823  end if
1824 
1825  ! spontaneous fission
1826  if(fr_tmp%reac_type.eq.rrt_sf) then
1827  nuc = fr_tmp%fissparts(1)
1828  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1829  sfiss_sum = sfiss_sum + rat*y(nuc)
1830  end if
1831  end if
1832 
1833  ! beta-delayed fission
1834  if(fr_tmp%reac_type.eq.rrt_bf) then
1835  nuc = fr_tmp%fissparts(1)
1836  if(rat.gt.1.d-20 .and. y(nuc).gt.1.d-20) then
1837  bfiss_sum = bfiss_sum + rat*y(nuc)
1838  end if
1839  end if
1840 
1841  end do fission
1842 
1843  tau_ng = ysum / ng_sum
1844  tau_gn = ysum / gn_sum
1845  tau_pg = ysum / pg_sum
1846  tau_gp = ysum / gp_sum
1847  tau_ag = ysum / ag_sum
1848  tau_ga = ysum / ga_sum
1849  tau_np = ysum / np_sum
1850  tau_pn = ysum / pn_sum
1851  tau_an = ysum / an_sum
1852  tau_na = ysum / na_sum
1853  tau_pa = ysum / pa_sum
1854  tau_ap = ysum / ap_sum
1855  tau_beta = ysum / beta_sum
1856  tau_alpha = ysum / alpha_sum
1857  tau_nfiss = ysum / nfiss_sum
1858  tau_sfiss = ysum / sfiss_sum
1859  tau_bfiss = ysum / bfiss_sum
1860 
1861  if (.not. present(hdf5)) then
1862  ! write it to an ascii file
1863  write(tsfile, '(*(es23.16,3x))') &
1864  ctime, t9, tau_ga,tau_ag, tau_ng, tau_gn, tau_pg, tau_gp, tau_np, &
1865  tau_pn, tau_an, tau_na,tau_pa,tau_ap, tau_beta, tau_alpha, &
1866  tau_nfiss, tau_sfiss, tau_bfiss
1867  else
1868 #ifdef USE_HDF5
1869  ! Write it to the hdf5
1870  call extend_av_timescales(ctime,tau_ga, tau_ag, tau_ng, tau_gn, tau_pg, &
1871  tau_gp, tau_np, tau_pn, tau_an, tau_na, &
1872  tau_ap, tau_pa, tau_beta, tau_alpha, &
1873  tau_nfiss, tau_sfiss, tau_bfiss)
1874 
1875 #else
1876  continue
1877 #endif
1878  endif
1879 
1880  info_exit('calc_av_timescales')
1881 
1882 end subroutine calc_av_timescales
1883 
1884 
1885 !>
1886 !! Compute final abundances and write final output
1887 !!
1888 !! There are three files written _finabsum.dat_
1889 !! containing abundances summed over equal A,
1890 !! _finab.dat_ containing all final abundances,
1891 !! _finabelem.dat_ containing all abundances
1892 !! summed over equal Z.
1893 subroutine finab(Y)
1894  use global_class, only: isotope, net_size
1896  implicit none
1897 
1898  real(r_kind),dimension(net_size),intent(in) :: y
1899  integer,dimension(net_size) :: list
1900  real(r_kind),dimension(:),allocatable :: xa,yz
1901  integer :: finfile,finsfile,finzfile
1902  integer :: mval,zmval
1903  integer :: i,k
1904  integer :: mass,protonnum
1905 
1906  info_entry('finab')
1907 
1908  finfile= open_outfile('finab.dat')
1909  write(finfile,'(A)') "# 1:A 2:Z 3:N 4:Yi 5:Xi"
1910 
1911  call finab_sort(net_size,list)
1912 
1913  do k=1,net_size
1914  i=list(k)
1915  if (y(i).le.1.d-20) cycle
1916  write(finfile,'(3(i5,2x),2es23.14)') isotope(i)%mass, &
1917  isotope(i)%p_nr,isotope(i)%n_nr,y(i), &
1918  y(i)*isotope(i)%mass
1919  end do
1920  call close_io_file(finfile,'finab.dat')
1921 
1922  mval = maxval(isotope%mass)
1923  allocate(xa(mval))
1924  zmval = maxval(isotope%p_nr)
1925  allocate(yz(zmval))
1926 
1927  xa = 0.d0
1928  yz = 0.d0
1929 
1930  do i=1,net_size
1931  mass=isotope(i)%mass
1932  protonnum = isotope(i)%p_nr
1933  if(y(i).gt.1.d-20) then
1934  xa(mass) = xa(mass) + y(i)*mass
1935  if (protonnum.gt.0) yz(protonnum) = yz(protonnum) + y(i) ! omit neutrons
1936  end if
1937  end do
1938 
1939  finsfile= open_outfile('finabsum.dat')
1940  write(finsfile,'(A)') "# 1:A 2:Y(A) 3:X(A)"
1941  do i=1,mval
1942  !i:Mass, XA(i)/i: Abundance, XA(i): Mass fraction
1943  write(finsfile,'(i5,2x,es23.14,2x,es23.14)')i, xa(i)/i ,xa(i)
1944  end do
1945  finzfile= open_outfile('finabelem.dat')
1946  write(finzfile,'(A)') "# 1:Z 2:Y(Z)"
1947  do i=1,zmval
1948  write(finzfile,'(i5,2x,es23.14)')i, yz(i)
1949  end do
1950 
1951  call close_io_file(finsfile,'finabsum.dat')
1952 
1953  info_exit('finab')
1954 end subroutine finab
1955 
1956 
1957 !>
1958 !! auxiliary sorting subroutine
1959 !!
1960 subroutine finab_sort(nsize,list)
1961  use global_class, only:isotope
1963 
1964  implicit none
1965 
1966  type :: sorttype
1967  integer :: a
1968  integer :: z
1969  logical :: chk
1970  end type sorttype
1971 
1972  integer,intent(in) :: nsize
1973  integer,dimension(nsize),intent(out) :: list
1974  type(sorttype),dimension(nsize) :: tmp
1975  integer :: i,j
1976  integer :: amin,zmin
1977  integer :: nxt
1978 
1979  info_entry('finab_sort')
1980 
1981  amin = 10000
1982  zmin = 10000
1983 
1984  do i=1,nsize
1985  tmp(i)%a = isotope(i)%mass
1986  tmp(i)%z = isotope(i)%p_nr
1987  tmp(i)%chk = .false.
1988  end do
1989 
1990  do i=1,nsize
1991  do j=1,nsize
1992  if(tmp(j)%chk) cycle
1993  select case (tmp(j)%a-amin)
1994  case(:-1)
1995  nxt = j
1996  amin = tmp(j)%a
1997  zmin = tmp(j)%z
1998  case(0)
1999  if (tmp(j)%z.lt.zmin) then
2000  nxt = j
2001  amin = tmp(j)%a
2002  zmin = tmp(j)%z
2003  end if
2004  case default
2005  cycle
2006  end select
2007  end do
2008  list(i) = nxt
2009  tmp(nxt)%chk = .true.
2010  amin=10000
2011  zmin=10000
2012  end do
2013 
2014  info_exit('finab_sort')
2015 
2016  return
2017 
2018 end subroutine finab_sort
2019 
2020 
2021 !>
2022 !! Close files at the end of the calculation
2023 !!
2024 !! @author: Moritz Reichert
2025 !!
2026 !! \b Edited:
2027 !! - 01.03.17
2028 !! - 25.01.21
2029 !! .
2030 subroutine analysis_finalize()
2033  implicit none
2034 
2035  info_entry('analysis_finalize')
2036 
2037  ! Close the timescale file
2038  if (timescales_every .gt. 0) then
2039  call close_io_file(tsfile,'timescales.dat')
2040  end if
2041 
2042  ! Close the Newton-Raphson diagnostic file
2043  if (nrdiag_every.gt.0) then
2044  call close_io_file(nrdiag_unit,"nrdiag.dat")
2045  end if
2046 
2047  ! Close track nuclei file
2048  if (track_nuclei_every .gt. 0) then
2049  call close_io_file(track_unit,"tracked_nuclei.dat")
2050  end if
2051 
2052  ! Cleanup the toplist
2053  if (top_engen_every .gt. 0) then
2054  call close_io_file(toplist_unit,"toplist.dat")
2055  end if
2056 
2057  info_exit('analysis_finalize')
2058 
2059 end subroutine analysis_finalize
2060 
2061 
2062 end module analysis
parameter_class::h_track_nuclei_every
integer h_track_nuclei_every
frequency of track nuclei output in hdf5 format
Definition: parameter_class.f90:74
single_zone_vars::y
real(r_kind), dimension(:), allocatable y
Definition: single_zone_vars.f90:21
parameter_class::engen_every
integer engen_every
Energy generation output frequency.
Definition: parameter_class.f90:68
nuclear_heating::qdot_bet
real(r_kind), save, public qdot_bet
Total energy radiated away by.
Definition: nuclear_heating.f90:21
analysis::output_mainout
subroutine, private output_mainout(cnt, ctime, T9, rho_b, entropy, Rkm, Y)
Output Mainout file.
Definition: analysis.f90:642
hdf5_module
Module that contains necessary subroutines to write abundances to an hdf5 file.
Definition: hdf5_module.f90:24
hdf5_module::write_engen
subroutine, private write_engen(include_decay)
Write energy generations and time into the hdf5 file.
Definition: hdf5_module.f90:722
parameter_class::out_every
integer out_every
– runtime parameters set when reading parameter file
Definition: parameter_class.f90:61
analysis::tsfile
integer, private tsfile
timescale file unit
Definition: analysis.f90:25
parameter_class::track_nuclei_every
integer track_nuclei_every
frequency of track nuclei output
Definition: parameter_class.f90:73
global_class::net_names
character *5, dimension(:), allocatable, public net_names
list of isotopes contained in the network
Definition: global_class.f90:95
rrt_nf
#define rrt_nf
Definition: macros.h:78
global_class::ipro
integer, public ipro
index of alphas, neutrons and protons
Definition: global_class.f90:94
global_class::reactionrate_type
reaction rate type
Definition: global_class.f90:44
analysis::snapshot_amount
integer snapshot_amount
Amount of custom snapshots.
Definition: analysis.f90:31
ls_timmes_eos_module
Definition: ls_timmes_eos_module.f:2
global_class::rrate
type(reactionrate_type), dimension(:), allocatable, public rrate
array containing all reaction rates used in the network
Definition: global_class.f90:65
analysis::cl_cmax
integer cl_cmax
system clock variables
Definition: analysis.f90:24
analysis::sn_ave
real(r_kind) sn_ave
average n-separation energy
Definition: analysis.f90:18
benam_class::findaz
integer function, public findaz(ai, zi)
Finds an isotope index in the network table, given its A and Z. In case it was not found,...
Definition: benam_class.f90:887
hdf5_module::extend_snaps
subroutine, public extend_snaps(time, Y_array)
Write abundances and time into the hdf5 file.
Definition: hdf5_module.f90:1872
analysis::cl_start
integer cl_start
Definition: analysis.f90:24
parameter_class::h_timescales_every
integer h_timescales_every
timescales output frequency in hdf5 format
Definition: parameter_class.f90:67
single_zone_vars::rhob
real(r_kind) rhob
Definition: single_zone_vars.f90:17
hdf5_module::extend_engen
subroutine, public extend_engen(time, engen_tot, heat, engen_ng_gn, engen_pg_gp, engen_ag_ga, engen_np_pn, engen_an_na, engen_ap_pa, engen_beta, engen_fiss, det_bet_engen, det_ag_engen, det_pg_engen, det_ng_engen, det_pn_engen, det_ap_engen, det_an_engen, det_other_engen, det_fiss_engen, det_tot_engen, include_decay)
Subroutine to write the energy generation per reaction type.
Definition: hdf5_module.f90:665
analysis::printsnap
subroutine, private printsnap(t, T9, rho_b, Y)
Print current snapshot.
Definition: analysis.f90:875
analysis::snapshot_time
real, dimension(:), allocatable snapshot_time
point in time for custom snapshot
Definition: analysis.f90:30
parameter_class::flow_every
integer flow_every
flow output frequency
Definition: parameter_class.f90:64
single_zone_vars::t9
real(r_kind) t9
Definition: single_zone_vars.f90:15
rrt_an
#define rrt_an
Definition: macros.h:72
nuclear_heating
Takes care of the temperature and entropy updates due to the nuclear energy release.
Definition: nuclear_heating.f90:11
analysis::output_iteration
subroutine, public output_iteration(cnt, ctime, T9, rho_b, entropy, Rkm, Y, pf)
Periodic output of analysis data for current iteration.
Definition: analysis.f90:325
analysis::output_final_step
subroutine, public output_final_step(cnt, ctime, T9, rho_b, entropy, Rkm, Y, pf)
Output final step.
Definition: analysis.f90:258
analysis::nrdiag_unit
integer nrdiag_unit
diagnostic output inside the Newton-Rhapson loop
Definition: analysis.f90:20
analysis::output_track_nuclei
subroutine, private output_track_nuclei(ctime, Y)
Output the abundances of specific nuclei.
Definition: analysis.f90:564
parameter_class::h_flow_every
integer h_flow_every
flow output frequency in hdf5 format
Definition: parameter_class.f90:65
error_msg_class
Error handling routines.
Definition: error_msg_class.f90:16
global_class::ihe4
integer, public ihe4
Definition: global_class.f90:94
analysis::toplist_amount
integer, parameter toplist_amount
Amount of reactions in the toplist.
Definition: analysis.f90:32
analysis::output_nu_loss
subroutine, private output_nu_loss(ctime, temp, rho, Rkm)
Output the energy that enters and leaves the system.
Definition: analysis.f90:604
parameter_class::termination_criterion
integer termination_criterion
condition to terminate the simulation ([0]=trajectory_file, 1=final_time, 2=final_temp,...
Definition: parameter_class.f90:127
rrt_np
#define rrt_np
Definition: macros.h:73
benam_class::reaction_string
character(50) function, public reaction_string(reac)
Return a string to represent a given reaction.
Definition: benam_class.f90:119
analysis::rosnp
real(r_kind) rosnp
for snapshot printing triggers
Definition: analysis.f90:27
analysis::finab_sort
subroutine, private finab_sort(nsize, list)
auxiliary sorting subroutine
Definition: analysis.f90:1961
analysis::finab
subroutine, public finab(Y)
Compute final abundances and write final output.
Definition: analysis.f90:1894
fission_rate_module
Module to deal with fission reactions.
Definition: fission_rate_module.f90:16
rrt_gp
#define rrt_gp
Definition: macros.h:70
analysis::output_final_stats
subroutine, public output_final_stats(cnt, ctime)
Print final statistics.
Definition: analysis.f90:836
error_msg_class::int_to_str
character(:) function, allocatable, public int_to_str(num)
Converts a given integer to a string.
Definition: error_msg_class.f90:224
single_zone_vars::evolution_mode
integer evolution_mode
NSE, network hot/cold, etc.
Definition: single_zone_vars.f90:23
flow_module::flows
type(flow_vector), dimension(:), allocatable, public flows
Definition: flow_module.f90:25
parameter_class::timescales_every
integer timescales_every
timescales output frequency
Definition: parameter_class.f90:66
thermal_neutrino_module::thermal_neutrinos
subroutine, public thermal_neutrinos(abar, Ye, temp, den, timestep, neutrino_loss)
Calculates the neutrino emissivity.
Definition: thermal_neutrino_module.f90:109
flow_module::flowprint
subroutine, public flowprint(t, t9, dens, abu, cnt)
Output reaction flows to a file.
Definition: flow_module.f90:206
parameter_class::nsep_energies_file
character(max_fname_len) nsep_energies_file
neutron separation energies
Definition: parameter_class.f90:173
analysis::t9snp
real(r_kind) t9snp
Definition: analysis.f90:27
hdf5_module::init_hdf5_module
subroutine, public init_hdf5_module()
Initialize the hdf5 module.
Definition: hdf5_module.f90:293
parameter_class::top_engen_every
integer top_engen_every
frequency of energy generators toplist
Definition: parameter_class.f90:75
fission_rate_module::nfiss
integer, public nfiss
Amount of fission rates.
Definition: fission_rate_module.f90:68
nuclear_heating::qdot_nu
real(r_kind), save, public qdot_nu
Total energy added to the system by neutrino.
Definition: nuclear_heating.f90:22
analysis::calc_nuclear_heating
subroutine, private calc_nuclear_heating(hdf5_mode, write_engen, write_toplist)
: Calculate the generated energy for each class of reactions separately.
Definition: analysis.f90:975
global_class::ineu
integer, public ineu
Definition: global_class.f90:94
rrt_pn
#define rrt_pn
Definition: macros.h:74
global_class::track_nuclei_indices
integer, dimension(:), allocatable, public track_nuclei_indices
Variables related to tracking individual nuclei.
Definition: global_class.f90:37
global_class::isotope
type(isotope_type), dimension(:), allocatable, public isotope
all nuclides used in the network
Definition: global_class.f90:34
rrt_ga
#define rrt_ga
Definition: macros.h:68
nucstuff_class
Module with helper functions such as rate tabulation, partition functions, and theoretical weak rates...
Definition: nucstuff_class.f90:11
nuclear_heating::qdot_th
real(r_kind), save, public qdot_th
Total energy lost by thermal neutrinos.
Definition: nuclear_heating.f90:23
rrt_alpd
#define rrt_alpd
Definition: macros.h:62
rrt_betp
#define rrt_betp
Definition: macros.h:60
rrt_na
#define rrt_na
Definition: macros.h:71
parameter_class::fissflag
integer fissflag
defines type of fission fragment distribution used
Definition: parameter_class.f90:86
analysis::mainout_unit
integer mainout_unit
file descriptor for the main analysis output file
Definition: analysis.f90:19
rrt_pg
#define rrt_pg
Definition: macros.h:69
hdf5_module::extend_flow
subroutine, public extend_flow(time, temp, dens, flow, n_flows, Y)
Extend the flow in the file With every call a new group is created and the flows are written in this ...
Definition: hdf5_module.f90:762
parameter_class::h_nu_loss_every
integer h_nu_loss_every
Output neutrino loss and gain in hdf5 format.
Definition: parameter_class.f90:101
rrt_ap
#define rrt_ap
Definition: macros.h:76
parameter_class::h_engen_detailed
logical h_engen_detailed
Output the energy per parent nucleus and reaction type.
Definition: parameter_class.f90:122
analysis::toplist_unit
integer toplist_unit
file id for top nuclear energy contributors
Definition: analysis.f90:22
flow_module::flowcalc
subroutine, public flowcalc(Y)
Flow calculation from jacobian. It is calculated with the help of the Jacobian.
Definition: flow_module.f90:110
thermal_neutrino_module
The thermal_neutrino_module serves as interface to the neutrino emission routines from the sneut5....
Definition: thermal_neutrino_module.f90:19
analysis::cl_end
integer cl_end
Definition: analysis.f90:24
hdf5_module::extend_nu_loss_gain
subroutine, public extend_nu_loss_gain(time, temp, dens, rad, the, heat, bet)
Write neutrino gain and loss.
Definition: hdf5_module.f90:415
global_class::net_size
integer, public net_size
total number of isotopes (network size)
Definition: global_class.f90:93
parameter_class::unit
type(unit_type), public unit
constants and unit conversion factors
Definition: parameter_class.f90:54
fission_rate_module::fissrate
type(fissionrate_type), dimension(:), allocatable, public fissrate
Array storing fission reactions.
Definition: fission_rate_module.f90:39
nuclear_heating::output_nuclear_heating
subroutine, public output_nuclear_heating(cnt, ctime)
Output data related to nuclear heating.
Definition: nuclear_heating.f90:757
analysis::analysis_init
subroutine, public analysis_init()
Open files, write headers, allocate space etc.
Definition: analysis.f90:52
file_handling_class
Provide some basic file-handling routines.
Definition: file_handling_class.f90:18
parameter_class::heating_mode
integer heating_mode
Mode for heating: 0 - no heating, 1 - heating using an entropy equation, 2 - heating from the energy ...
Definition: parameter_class.f90:148
parameter_class::nrdiag_every
integer nrdiag_every
frequency of NR loop diagnostic messages (wrt iteration counter)
Definition: parameter_class.f90:70
analysis
Contains various routines for analysis and diagnostic output.
Definition: analysis.f90:9
analysis::tsnp
real(r_kind) tsnp
Definition: analysis.f90:27
single_zone_vars::time
real(r_kind) time
Definition: single_zone_vars.f90:13
global_class::track_nuclei_nr
integer, public track_nuclei_nr
amount of tracked nuclei
Definition: global_class.f90:38
single_zone_vars::stepsize
real(r_kind) stepsize
Stepsize.
Definition: single_zone_vars.f90:14
r_kind
#define r_kind
Definition: macros.h:46
analysis::calc_nseparation_energy
subroutine, private calc_nseparation_energy(Y)
Calculates average neutron separation energy.
Definition: analysis.f90:915
parameter_class::h_mainout_every
integer h_mainout_every
HDF5 output frequency of the mainout.
Definition: parameter_class.f90:72
rrt_gn
#define rrt_gn
Definition: macros.h:66
parameter_class::h_custom_snapshots
logical h_custom_snapshots
Same, but in hdf5 format.
Definition: parameter_class.f90:108
chempot
subroutine chempot(temp, den, ye, etaele, etapos)
Given a temperature temp [K], density den [g/cm**3], and a composition characterized by y_e,...
Definition: chem_pot.f90:25
analysis::track_unit
integer track_unit
file id for tracked nuclei
Definition: analysis.f90:21
fission_rate_module::fissionrate_type
fission rate type, designed to save fragment distribution at initialization
Definition: fission_rate_module.f90:21
flow_module
Provides subroutines to calculate reaction flows.
Definition: flow_module.f90:18
rrt_pa
#define rrt_pa
Definition: macros.h:75
analysis::output_flow
subroutine output_flow(ctime, T9, rho_b, Y)
Output flow files.
Definition: analysis.f90:732
parameter_class::use_thermal_nu_loss
logical use_thermal_nu_loss
Whether to include thermal neutrino loss or not.
Definition: parameter_class.f90:99
analysis::output_snapshot
subroutine, private output_snapshot(ctime, T9, rho_b, Y)
Output Snapshot files.
Definition: analysis.f90:712
analysis::analysis_finalize
subroutine, public analysis_finalize()
Close files at the end of the calculation.
Definition: analysis.f90:2031
rrt_betm
#define rrt_betm
Definition: macros.h:59
single_zone_vars::y_p
real(r_kind), dimension(:), allocatable y_p
Abundances.
Definition: single_zone_vars.f90:21
rrt_o
#define rrt_o
Definition: macros.h:81
parameter_class::nu_loss_every
integer nu_loss_every
Output neutrino loss and gain.
Definition: parameter_class.f90:100
hdf5_module::extend_track_nuclei
subroutine, public extend_track_nuclei(time, Y_array)
Write tracked abundances and time into the hdf5 file.
Definition: hdf5_module.f90:1813
analysis::calc_av_timescales
subroutine, private calc_av_timescales(ctime, T9, Y, hdf5)
Calculate average timescales of different classes of reactions.
Definition: analysis.f90:1622
file_handling_class::open_outfile
integer function, public open_outfile(file_name)
Shorthand for opening a new file for writing (output file)
Definition: file_handling_class.f90:108
nucstuff_class::inter_partf
subroutine, public inter_partf(temp, interpol)
Calculates partition function.
Definition: nucstuff_class.f90:132
hdf5_module::extend_av_timescales
subroutine, public extend_av_timescales(time, tau_ga, tau_ag, tau_ng, tau_gn, tau_pg, tau_gp, tau_np, tau_pn, tau_an, tau_na, tau_ap, tau_pa, tau_beta, tau_alpha, tau_nfiss, tau_sfiss, tau_bfiss)
Subroutine to write the average timescales (1/s) into the hdf5.
Definition: hdf5_module.f90:1759
global_class
Contains types and objects shared between multiple modules.
Definition: global_class.f90:19
parameter_class::h_snapshot_every
integer h_snapshot_every
snapshot output frequency in hdf5 format
Definition: parameter_class.f90:63
single_zone_vars::ye
real(r_kind) ye
Definition: single_zone_vars.f90:19
global_class::nreac
integer, public nreac
total number of reactions
Definition: global_class.f90:98
mergesort_module::quicksort
recursive subroutine, public quicksort(mode, length, arr1, arr2, is_recursion)
Quicksort of array.
Definition: mergesort_module.f90:810
analysis::output_nr_diagnostic
subroutine, public output_nr_diagnostic(cnt, k, nr_c, ctime, T9, stepsize, mtot, Y_p, Y)
Output of the Newton-Raphson loop diagnostics.
Definition: analysis.f90:770
rrt_ag
#define rrt_ag
Definition: macros.h:67
hdf5_module::extend_mainout
subroutine, public extend_mainout(cnt, time, temp, dens, entr, rad, Y)
Write the mainout data to the hdf5.
Definition: hdf5_module.f90:1923
file_handling_class::close_io_file
subroutine, public close_io_file(unit_no, file_name)
Close an external file.
Definition: file_handling_class.f90:144
rrt_bf
#define rrt_bf
Definition: macros.h:79
parameter_class::mainout_every
integer mainout_every
frequency of mainout output
Definition: parameter_class.f90:71
rrt_sf
#define rrt_sf
Definition: macros.h:80
analysis::sn
real(r_kind), dimension(:), allocatable sn
array of n-separation energies
Definition: analysis.f90:17
parameter_class::custom_snapshots
logical custom_snapshots
If true, a file must be provided with numbers in days. Snapshots will be created for these points in ...
Definition: parameter_class.f90:107
rrt_ng
#define rrt_ng
Definition: macros.h:65
analysis::cl_rate
integer cl_rate
Definition: analysis.f90:24
analysis::nu_loss_gain_unit
integer nu_loss_gain_unit
file id for neutrino loss/gain
Definition: analysis.f90:23
mergesort_module
Module mergesort_module for merging arrays of rates.
Definition: mergesort_module.f90:16
single_zone_vars
Simulation variables for a single zone model.
Definition: single_zone_vars.f90:11
parameter_class::h_engen_every
integer h_engen_every
Energy generation output frequency in hdf5 format.
Definition: parameter_class.f90:69
analysis::output_initial_step
subroutine, public output_initial_step(ctime, T9, rho_b, entropy, Rkm, Y, pf)
Output first step.
Definition: analysis.f90:233
analysis::flowcnt
integer flowcnt
flow printing counter
Definition: analysis.f90:29
parameter_class::snapshot_every
integer snapshot_every
snapshot output frequency
Definition: parameter_class.f90:62
analysis::snapcnt
integer snapcnt
snapshot count
Definition: analysis.f90:28
parameter_class::calc_nsep_energy
logical calc_nsep_energy
calculate neutron separation energy?
Definition: parameter_class.f90:121
parameter_class
Contains all runtime parameters as well as phys and math constants.
Definition: parameter_class.f90:24
analysis::nuc_heat_file
integer, private nuc_heat_file
nuclear heating file unit
Definition: analysis.f90:26
benam_class
Subroutines needed to initialise the network.
Definition: benam_class.f90:11