reaclib_rate_module.f90
Go to the documentation of this file.
1 !> @file reaclib_rate_module.f90
2 !!
3 !! The error file code for this file is ***W38***.
4 !!
5 !! Contains the module \ref reaclib_rate_module
6 
7 
8 !> @brief Module that deals with reaclib reaction rates.
9 !!
10 !! This module initializes reaclib reaction rates and stores it into a
11 !! rate array.
12 #include "macros.h"
15  implicit none
16 
17  integer,private :: nrea !< Amount of reaclib rates
18  integer,private :: n_w,n_ng,n_gn,n_ap,n_pa,n_o,n_pg,n_gp !< Amount of individual reaction types
19  integer,private :: n_np,n_pn,n_ag,n_ga,n_an,n_na !< Amount of individual reaction types
20  integer,private :: n_bm,n_bp,n_ad,n_pe,n_ne,n_ec !< Amount of individual reaction types
21  type(reactionrate_type), dimension(:), allocatable, private :: rrate_reaclib !< Reaclib reaction rates
22 
23  character(len=*), parameter, private :: rrate_binary_name = "rrate.windat" !< Name of the binary file for rrate array
24  real(r_kind),private :: infty
25  !
26  ! Public and private fields and methods of the module
27  !
28  public:: &
30  private:: &
32 
33 contains
34 
35 
36 !> Count and read reaclib reactions
37 !!
38 !! This subroutine will fill \ref nrea with the amount
39 !! of reaclib reactions and the \ref rrate_reaclib array
40 !! with reaction rates from a reaclib file.
41 !!
42 !! @author M. Reichert
43 !! @date 25.01.21
44 subroutine init_reaclib_rates()
47  implicit none
48  integer :: alloc_stat !< Status of allocation
49 
50  ! Amount of individual reaction types
51  n_ne=0; n_ng=0; n_gn=0; n_ap=0; n_pa=0; n_o=0
52  n_np=0; n_pn=0; n_ag=0; n_ga=0; n_an=0; n_na=0
53  n_pg=0; n_gp=0; n_bm=0; n_bp=0; n_ad=0; n_pe=0
54  n_ec=0
55 
56  ! Get a variable for comparison for overflows
57  infty = huge(infty)
58 
59  if (use_prepared_network) then
61  else
62  !-- Count the amount of rates
63  call count_reaclib_rates()
64  !-- Allocate the reaclib rate array
65  allocate(rrate_reaclib(nrea),stat=alloc_stat)
66  if ( alloc_stat /= 0) call raise_exception('Allocation of "rrate_reaclib" failed.',&
67  "init_reaclib_rates",380001)
68 
69  !-- Read the reaclib rates into rrate_reaclib
70  call read_reaclib()
71  end if
72 
74 
75 end subroutine init_reaclib_rates
76 
77 
78 
79 !> Write the amount of individual reactions to the out
80 !!
81 !! The rates are always counted, for a certain verbose level they
82 !! are also printed to the OUT file
83 !!
84 !! @author M. Reichert
85 !! @date 27.01.21
88  implicit none
89  character(len=7) :: tmp !< temporary character for pretty output
90 
91  if (verbose_level .ge. 1) then
92  call write_data_to_std_out("Amount reaclib rates",int_to_str(nrea))
93  end if
94  if (verbose_level .ge. 2) then
95  if (nrea .gt. 0) write(*,"(A)") ""
96  if (nrea .gt. 0) write(*,"(A)") " Reaclib rates: "
97  if (nrea .gt. 0) write(*,"(A)") " |----------------|"
98  tmp = int_to_str(nrea)
99  if (nrea .gt. 0) write(*,"(A)") " | Total :"//adjustr(tmp)//" |"
100  tmp = int_to_str(n_ng)
101  if (n_ng .gt. 0) write(*,"(A)") " | (n,g) :"//adjustr(tmp)//" |"
102  tmp = int_to_str(n_gn)
103  if (n_gn .gt. 0) write(*,"(A)") " | (g,n) :"//adjustr(tmp)//" |"
104  tmp = int_to_str(n_pg)
105  if (n_pg .gt. 0) write(*,"(A)") " | (p,g) :"//adjustr(tmp)//" |"
106  tmp = int_to_str(n_gp)
107  if (n_gp .gt. 0) write(*,"(A)") " | (g,p) :"//adjustr(tmp)//" |"
108  tmp = int_to_str(n_ag)
109  if (n_ag .gt. 0) write(*,"(A)") " | (a,g) :"//adjustr(tmp)//" |"
110  tmp = int_to_str(n_ga)
111  if (n_ga .gt. 0) write(*,"(A)") " | (g,a) :"//adjustr(tmp)//" |"
112  tmp = int_to_str(n_an)
113  if (n_an .gt. 0) write(*,"(A)") " | (a,n) :"//adjustr(tmp)//" |"
114  tmp = int_to_str(n_na)
115  if (n_na .gt. 0) write(*,"(A)") " | (n,a) :"//adjustr(tmp)//" |"
116  tmp = int_to_str(n_ap)
117  if (n_an .gt. 0) write(*,"(A)") " | (a,p) :"//adjustr(tmp)//" |"
118  tmp = int_to_str(n_pa)
119  if (n_na .gt. 0) write(*,"(A)") " | (p,a) :"//adjustr(tmp)//" |"
120  tmp = int_to_str(n_pn)
121  if (n_pn .gt. 0) write(*,"(A)") " | (p,n) :"//adjustr(tmp)//" |"
122  tmp = int_to_str(n_np)
123  if (n_np .gt. 0) write(*,"(A)") " | (n,p) :"//adjustr(tmp)//" |"
124  tmp = int_to_str(n_bm)
125  if (n_bm .gt. 0) write(*,"(A)") " | beta- :"//adjustr(tmp)//" |"
126  tmp = int_to_str(n_bp)
127  if (n_bp .gt. 0) write(*,"(A)") " | beta+ :"//adjustr(tmp)//" |"
128  tmp = int_to_str(n_ec)
129  if (n_ec .gt. 0) write(*,"(A)") " | EC :"//adjustr(tmp)//" |"
130  tmp = int_to_str(n_ad)
131  if (n_ad .gt. 0) write(*,"(A)") " | a-dec.:"//adjustr(tmp)//" |"
132  tmp = int_to_str(n_ne)
133  if (n_ne .gt. 0) write(*,"(A)") " | n emis:"//adjustr(tmp)//" |"
134  tmp = int_to_str(n_pe)
135  if (n_pe .gt. 0) write(*,"(A)") " | p emis:"//adjustr(tmp)//" |"
136  tmp = int_to_str(n_o)
137  if (n_o .gt. 0) write(*,"(A)") " | other :"//adjustr(tmp)//" |"
138  if (nrea .gt. 0) write(*,"(A)") " |----------------|"
139  if (nrea .gt. 0) write(*,"(A)") ""
140  end if
141 
142 end subroutine write_reac_verbose_out
143 
144 
145 !> Read the complete rrate array from a binary file
146 !!
147 !! This subroutine reads the complete rrate array from a binary file.
148 !! The binary file has to be created beforehand. If the binary data is read,
149 !! no other data has to be read
150 !!
151 !! @author M. Reichert
152 !! @date 21.07.23
155  use global_class, only: rrate, nreac
157  implicit none
158  character(len=*), intent(in) :: path
159  integer :: file_id
160  integer :: alloc_stat
161 
162  ! Open an unformatted file
163  file_id = open_unformatted_outfile(trim(adjustl(path))//trim(adjustl(rrate_binary_name)))
164  ! Read reaction info
165  read(file_id) n_ne,n_ng,n_gn,n_ap,n_pa,n_o
166  read(file_id) n_np,n_pn,n_ag,n_ga,n_an,n_na
167  read(file_id) n_pg,n_gp,n_bm,n_bp,n_ad,n_pe
168  read(file_id) n_ec
169  ! Read the amount of reactions
170  read(file_id) nreac
171  nrea = nreac
172  ! Allocate rrate if not already allocated
173  if (.not. allocated(rrate)) then
174  allocate(rrate(nreac),stat=alloc_stat)
175  if ( alloc_stat /= 0) call raise_exception('Allocation of "rrate" failed.',&
176  "read_binary_reaclib_reaction_data",380001)
177  end if
178 
179  read(file_id) rrate
180 
181  close(file_id)
182 
183 
185 
186 
187 !> Save the complete rrate array to a binary file
188 !!
189 !! This subroutine saves the complete rrate array to a binary file.
190 !!
191 !! @author M. Reichert
192 !! @date 21.07.23
195  use global_class, only: rrate, nreac
196  implicit none
197  character(len=*), intent(in) :: path
198  integer :: file_id
199 
200  ! Open an unformatted file
201  file_id = open_unformatted_outfile(trim(adjustl(path))//trim(adjustl(rrate_binary_name)))
202 
203  ! Write reaction info
204  write(file_id) n_ne,n_ng,n_gn,n_ap,n_pa,n_o
205  write(file_id) n_np,n_pn,n_ag,n_ga,n_an,n_na
206  write(file_id) n_pg,n_gp,n_bm,n_bp,n_ad,n_pe
207  write(file_id) n_ec
208  ! Save the path and the format for sanity check
209  write(file_id) nreac
210  write(file_id) rrate
211 
212  close(file_id)
213 
214 
216 
217 
218 !> Calculate a reaclib rate.
219 !!
220 !! The rate is calculated according to the reaclib fit function:
221 !! \f[ \lambda = \exp\left[ a_0 + \sum_{i=1}^5 a_i T_9^{(2i-5)/3} +a_6 \log T_9 \right] \f]
222 !!
223 !! @see nucstuff_class::calc_t9_pow
224 !!
225 !! \b Edited:
226 !! - 26.07.22, MR: created this subroutine from code parts in jacobian_class.
227 !! .
228 subroutine calculate_reacl_rate(rrate,rat_calc)
230  use nucstuff_class, only: t9_pow
231  use benam_class, only: reaction_string
232  implicit none
233  ! Declare the pass
234  type(reactionrate_type),intent(in) :: rrate !< rate instance
235  real(r_kind),intent(out) :: rat_calc !< rate value
236  ! Internal variables
237  integer :: j !< Loop variable
238 
239  rat_calc = 0.d0
240  do j=1,9
241  rat_calc = rat_calc +rrate%param(j)*t9_pow(j)
242  end do
243 
244  if (rat_calc .gt. dlog(infty)) then
245  ! Complain about overflow
246  if (verbose_level .ge. 2) then
247  print*,"Warning, rate overflow! Rate was "
248  print*,reaction_string(rrate)
249  end if
250  rat_calc = dlog(infty)
251  end if
252 
253  rat_calc = dexp(rat_calc)
254 
255 end subroutine calculate_reacl_rate
256 
257 
258 
259 
260 !> Merge the reaclib rates into a larger array
261 !!
262 !! The subroutine combines a larger rate array with
263 !! \ref rrate_reaclib. Afterwards it deallocates \ref rrate_reaclib.
264 !!
265 !! @returns Large rate array with new size, containing the reaclib reactions
266 !!
267 !! @author M. Reichert
268 !! @date 25.01.21
269 subroutine merge_reaclib_rates(rrate_array,rrate_length)
272  implicit none
273  type(reactionrate_type),dimension(:),allocatable,intent(inout) :: rrate_array !< Large rate array, containing all reactions
274  integer,intent(inout) :: rrate_length !< length of rrate_array
275  type(reactionrate_type),dimension(:),allocatable :: rrate_tmp !< Temporary rate array
276  integer :: alloc_stat !< Allocation state
277  integer :: new_length !< New length of rrate_array
278 
279  if (.not. use_prepared_network) then
280  new_length = rrate_length+nrea
281  if (nrea .ne. 0) then
282  if (.not. allocated(rrate_array)) then
283  !-- Allocate the reaclib rate array
284  allocate(rrate_array(nrea),stat=alloc_stat)
285  if ( alloc_stat /= 0) call raise_exception('Allocation of "rrate_array" failed.',&
286  "merge_reaclib_rates",380001)
287  rrate_array(1:nrea) = rrate_reaclib(1:nrea)
288  else
289  !-- Allocate a temporary array to store the content of rrate_array
290  allocate(rrate_tmp(rrate_length),stat=alloc_stat)
291  if ( alloc_stat /= 0) call raise_exception('Allocation of "rrate_tmp" failed.',&
292  "merge_reaclib_rates",380001)
293  rrate_tmp(1:rrate_length) = rrate_array(1:rrate_length)
294 
295  !-- Deallocate the input array
296  deallocate(rrate_array)
297  allocate(rrate_array(new_length),stat=alloc_stat)
298  if ( alloc_stat /= 0) call raise_exception('Allocation of "rrate_array" failed.',&
299  "merge_reaclib_rates",380001)
300  rrate_array(1:rrate_length) = rrate_tmp(1:rrate_length)
301  rrate_array(rrate_length+1:new_length) = rrate_reaclib(1:nrea)
302 
303  deallocate(rrate_tmp)
304  end if
305  !-- Deallocate the reaclib rate array
306  deallocate(rrate_reaclib)
307  end if
308  !-- Output the new length
309  rrate_length = new_length
310  end if
311 
312 end subroutine merge_reaclib_rates
313 
314 
315 
316 
317 !> Read reaclib reaction rates
318 !!
319 !! This routine reads the reaclib file and stores
320 !! the reactions into \ref rrate_reaclib. An example file
321 !! looks like:
322 !! \file{...
323 !! li9 be9 wc12w 1.36060e+01
324 !! 6.501820e-01 0.000000e+00 0.000000e+00 0.000000e+00
325 !! 0.000000e+00 0.000000e+00 0.000000e+00
326 !! li11 be11 wc12w 2.05510e+01
327 !! 2.322150e+00 0.000000e+00 0.000000e+00 0.000000e+00
328 !! 0.000000e+00 0.000000e+00 0.000000e+00
329 !! ...}
330 !!
331 !! @see [Reaclib file format](https://reaclib.jinaweb.org/help.php?topic=reaclib_format&intCurrentNum=0)
332 !!
333 !! \b Edited:
334 !! - 25.01.21, MR - Moved it from network_init to this subroutine
335 !! - 28.07.22, MR - Introduced new chapters
336 !! .
337 subroutine read_reaclib()
342  use global_class, only: qnuloss,ipro,ineu
344  use format_class
345  implicit none
346  integer :: i !< Count of the rates
347  integer :: j !< Loop variable
348  integer :: read_stat !< Read status
349  integer :: reaclib !< File id of reaclib
350  character(5), dimension(6) :: parts !< Participating nuclei names
351  integer, dimension(6) :: parts_index !< Participating nuclei indices
352  real(r_kind), dimension(9) :: params !< Reaclib fitting parameter
353  character(4) :: src !< Reaclib source label
354  character(1) :: res !< Reaclib weak flag label
355  character(1) :: rev !< Reaclib reverse label
356  real(r_kind) :: q !< Reaclib Q-Value
357  integer :: grp !< Reaclib chapter
358  integer :: group_index !< Reaclib chapter storage
359 
360  ! Open the reaclib
361  reaclib= open_infile(reaclib_file)
362 
363  ! Set flags false by default
364  rrate_reaclib%is_weak = .false.
365  rrate_reaclib%is_resonant = .false.
366  rrate_reaclib%is_reverse = .false.
367  rrate_reaclib%cached = -1
368  rrate_reaclib%reac_type = rrt_o ! Initialize as "other" reaction
369  rrate_reaclib%reac_src = rrs_reacl ! Initialize as reaclib reaction
370  rrate_reaclib%nu_frac = 0 ! No neutrinos, only for beta decays later on
371 
372 
373  i = 1
374  outer_loop: do
375  read(reaclib,my_format(1), iostat = read_stat) &
376  grp, parts(1:6), src, res, rev, q
377  if (read_stat /= 0) exit outer_loop
378  !!read(reaclib,my_format(2)) params(1:7) ! *** my_format(2) reads only 4 numbers but somehow this works...
379  read(reaclib,"(4E13.6)") params(1:4)
380  read(reaclib,"(5E13.6)") params(5:9)
381 
382  !--- fission rates are read in separately. For a transition period, the fission rates are probably still present in the reaclib file
383  if ((src.eq.'ms99').or.(src.eq.'mp01').or.(src.eq.'sfis').or.(src.eq.'fiss')) cycle outer_loop
384  !--- grp =/ 0 only for group separators in reaclib
385  ! explanation: reaclib is structured to have group separators with same number of chars
386  ! of blocks containing data for each reaction; variable grp gets overwritten with a 0
387  ! in blocks containing data and is not 0 only for separators
388  select case (grp)
389  case(1:11)
390  group_index = grp
391  cycle
392  case default
393  parts_index = 0
394  inner_loop: do j=1,6
395  if (parts(j) .eq. ' ') exit inner_loop
396  parts_index(j) = benam(parts(j))
397  !----- parts_index(i) = 0 if nuclide i is not in network
398  if (parts_index(j) .eq. 0) cycle outer_loop
399  end do inner_loop
400  end select
401 
402  rrate_reaclib(i)%group = group_index
403  rrate_reaclib(i)%parts = parts_index
404  rrate_reaclib(i)%source = src
405  rrate_reaclib(i)%q_value = q
406  ! Give errors if the reaclib introduces something new...
407  if (res == "r") then
408  rrate_reaclib(i)%is_resonant = .true.
409  elseif (res =="w") then
410  rrate_reaclib(i)%is_weak = .true.
411  elseif (res =="s") then
412  rrate_reaclib(i)%is_weak = .true.
413  elseif (res =="p") then
414  rrate_reaclib(i)%is_weak = .true.
415  elseif ((res ==" ") .or. (res =="n")) then
416  continue
417  else
418  call raise_exception('Flag within reaclib not known! (res = "'//res//'"). '//&
419  'Source flag was '//trim(adjustl(src))//'.',&
420  "read_reaclib",380003)
421  end if
422  ! Same for the rev flag
423  if (rev == "v") then
424  rrate_reaclib(i)%is_reverse = .true.
425  elseif (rev == " ") then
426  continue
427  else
428  call raise_exception('Flag within reaclib not known! (rev = "'//rev//'"). '//&
429  'Source flag was '//trim(adjustl(src))//'.',&
430  "read_reaclib",380004)
431  end if
432 
433  rrate_reaclib(i)%param = params
434 
435  !-- Set the reaction type (e.g., (Alpha,n) )
437  i=i+1
438  end do outer_loop
439 
440  ! Close the file again
441  close(reaclib)
442 
443  ! Set the fraction of energy radiated away by neutrinos
445 
446  ! get the correct coefficients to prevent double counting
448 
449 
450 end subroutine read_reaclib
451 
452 
453 !> Set the fraction of energy radiated away by neutrinos
454 !!
455 !! This subroutine sets the fraction of energy radiated away by neutrinos
456 !! for each reaction. This is done either by a user defined file,
457 !! or by a default value.
458 !!
459 !! @author M. Reichert
460 !! @date 31.03.2023
461 subroutine set_heating_frac(reac_rate_array,length)
464 
465  implicit none
466  type(reactionrate_type),dimension(length), intent(inout) :: reac_rate_array
467  integer, intent(in) :: length
468  ! internal variables
469  integer :: i,j
470  real(r_kind),dimension(net_size) :: av_Q
471  real(r_kind),dimension(net_size) :: heat_f
472  real(r_kind),dimension(net_size) :: rate
473  real(r_kind) :: rate_tmp
474 
475  if (use_neutrino_loss_file) then
476  av_q(:) = 0
477  rate(:) = 0
478 
479  do i=1,length
480  if (reac_rate_array(i)%is_weak) then
481  ! Identify if it is a beta decay
482  if ((reac_rate_array(i)%reac_type == rrt_betm) .or. (reac_rate_array(i)%reac_type == rrt_betp)) then
483  rate_tmp = dexp(reac_rate_array(i)%param(1))
484  ! Identify the nuclide that is being heated
485  av_q(reac_rate_array(i)%parts(1)) = av_q(reac_rate_array(i)%parts(1)) + reac_rate_array(i)%q_value*rate_tmp
486  rate(reac_rate_array(i)%parts(1)) = rate(reac_rate_array(i)%parts(1)) + rate_tmp
487  end if
488  end if
489  end do
490 
491  ! Calculate average Q value
492  do i=1,net_size
493  if (rate(i) .gt. 0) then
494  av_q(i) = av_q(i)/rate(i)
495  else
496  av_q(i) = 0
497  end if
498  end do
499 
500  ! Calculate the heating fraction
501  do i=1,net_size
502  if ((av_q(i) .gt. 0) .and. (qnuloss(i) .ne. -1)) then
503  heat_f(i) = qnuloss(i)/av_q(i)
504  else
505  heat_f(i) = heating_frac
506  end if
507  end do
508  else
509  heat_f(:) = heating_frac
510  end if
511 
512  do i=1,length
513  if (reac_rate_array(i)%is_weak) then
514  ! Identify if it is a beta decay
515  if ((reac_rate_array(i)%reac_type == rrt_betm) .or. (reac_rate_array(i)%reac_type == rrt_betp) .or. &
516  (reac_rate_array(i)%reac_type == rrt_ec)) then
517  reac_rate_array(i)%nu_frac = heat_f(reac_rate_array(i)%parts(1))
518  else
519  reac_rate_array(i)%nu_frac = 0
520  end if
521  end if
522  end do
523 
524 
525 end subroutine set_heating_frac
526 
527 
528 
529 !> Set a flag for the reaction type
530 !!
531 !! Possible reaction types are
532 !! <table>
533 !! <caption id="multi_row">Reaction types</caption>
534 !! <tr><th> Reaction type <th> Meaning
535 !! <tr><td> rrt_betm <td> Beta minus
536 !! <tr><td> rrt_betp <td> Beta plus
537 !! <tr><td> rrt_ec <td> Electron capture
538 !! <tr><td> rrt_alpd <td> Alpha-decay
539 !! <tr><td> rrt_nemi <td> neutron emission
540 !! <tr><td> rrt_pemi <td> proton emission
541 !! <tr><td> rrt_ng <td> \f$(n,\gamma)\f$
542 !! <tr><td> rrt_gn <td> \f$(\gamma,n)\f$
543 !! <tr><td> rrt_ag <td> \f$(\alpha,\gamma)\f$
544 !! <tr><td> rrt_ga <td> \f$(\gamma,\alpha)\f$
545 !! <tr><td> rrt_pg <td> \f$(p,\gamma)\f$
546 !! <tr><td> rrt_gp <td> \f$(\gamma,p)\f$
547 !! <tr><td> rrt_na <td> \f$(n,\alpha)\f$
548 !! <tr><td> rrt_an <td> \f$(\alpha,n)\f$
549 !! <tr><td> rrt_np <td> \f$(n,p)\f$
550 !! <tr><td> rrt_pn <td> \f$(p,n)\f$
551 !! <tr><td> rrt_pa <td> \f$(p,\alpha)\f$
552 !! <tr><td> rrt_ap <td> \f$(\alpha,p)\f$
553 !! <tr><td> rrt_nu <td> Neutrino
554 !! <tr><td> rrt_nf <td> Neutron induced fission
555 !! <tr><td> rrt_bf <td> \f$\beta\f$-delayed fission
556 !! <tr><td> rrt_sf <td> Spontaneous fission
557 !! <tr><td> rrt_o <td> Other reaction
558 !! </table>
559 !! Not all flags are set in this routine (for example, neutrino and fission types).
560 !! The rrt_* variables are defined as preprocessor integer variables in
561 !! macros.h.
562 !!
563 !! @author M. Reichert
564 !!
565 !! \b Edited:
566 !! - 25.01.21, MR - Moved it to separate subroutine
567 !! .
568 subroutine set_reaction_type(rr_tmp)
569  use benam_class, only: get_net_name
571  use global_class, only: ineu,ipro,ihe4,isotope
572  implicit none
573  type(reactionrate_type),intent(inout) :: rr_tmp !< Reaction rate to classify
574  integer :: group_index !< Reaclib chapter
575  integer, dimension(6) :: parts_index !< Participating nuclei indices
576  logical :: trimmed !< Flag to return the name trimmed
577  integer :: zsum_r !< Count for amount of neutrons
578  integer :: zsum_p !< Count for amount of neutrons
579  integer :: nsum_r !< Count for amount of neutrons
580  integer :: nsum_p !< Count for amount of neutrons
581  integer :: neutron_c_r !< Count for amount of neutrons
582  integer :: neutron_c_p !< Count for amount of neutrons
583  integer :: proton_c_r !< Count for amount of protons
584  integer :: proton_c_p !< Count for amount of protons
585  integer :: alpha_c_r !< Count for amount of alphas
586  integer :: alpha_c_p !< Count for amount of alphas
587  integer :: i !< Loop variable
588 
589  trimmed = .true. ! Set some value
590 
591  parts_index = rr_tmp%parts ! Shorthand variable for the part indices
592  group_index = rr_tmp%group ! Shorthand variable for the chapter
593 
594  ! Classify weak reactions (Remove hardcoded flags in future)
595  if (rr_tmp%is_weak) then
596  neutron_c_r = 0 ; neutron_c_r = 0 ; proton_c_r = 0
597  alpha_c_r = 0
598  zsum_r=0 ; nsum_r=0
599  ! Count amount of neutrons in reactants
600  do i=1,get_nr_reactants(group_index)
601  if (parts_index(i) .le. 0) cycle
602  if (parts_index(i) .eq. ineu) then
603  neutron_c_r = neutron_c_r +1
604  else if (parts_index(i) .eq. ipro) then
605  proton_c_r = proton_c_r +1
606  else if (parts_index(i) .eq. ihe4) then
607  alpha_c_r = alpha_c_r +1
608  end if
609  zsum_r = zsum_r + isotope(parts_index(i))%p_nr
610  nsum_r = nsum_r + isotope(parts_index(i))%n_nr
611  end do
612 
613  ! Same for products
614  neutron_c_p = 0 ; neutron_c_p = 0 ; proton_c_p = 0
615  alpha_c_p = 0;
616  zsum_p=0 ; nsum_p=0
617 
618  ! Count amount of neutrons in products
619  do i=get_nr_reactants(group_index)+1,get_nr_products(group_index)+get_nr_reactants(group_index)+1
620  if (parts_index(i) .le. 0) cycle
621  if (parts_index(i) .eq. ineu) then
622  neutron_c_p = neutron_c_p +1
623  else if (parts_index(i) .eq. ipro) then
624  proton_c_p = proton_c_p +1
625  else if (parts_index(i) .eq. ihe4) then
626  alpha_c_p = alpha_c_p +1
627  end if
628  zsum_p = zsum_p + isotope(parts_index(i))%p_nr
629  nsum_p = nsum_p + isotope(parts_index(i))%n_nr
630  end do
631 
632  ! Electron capture
633  if (rr_tmp%source .eq. ' ec') then
634  rr_tmp%reac_type = rrt_ec
635  n_ec = n_ec + 1
636  ! Neutron emission
637  elseif ((zsum_p .eq. zsum_r) .and. (neutron_c_p .gt. 0)) then
638  rr_tmp%reac_type = rrt_nemi
639  n_ne = n_ne + 1
640  ! Proton emission
641  elseif ((zsum_p .eq. zsum_r) .and. (proton_c_p .gt. 0)) then
642  rr_tmp%reac_type = rrt_pemi
643  n_pe = n_pe + 1
644  ! Alpha decay
645  elseif ((zsum_p .eq. zsum_r) .and. (alpha_c_p .gt. 0)) then
646  rr_tmp%reac_type = rrt_alpd
647  n_ad = n_ad + 1
648  ! Beta minus
649  elseif ((zsum_p-1 .eq. zsum_r) .and. (nsum_p+1 .eq. nsum_r)) then
650  rr_tmp%reac_type = rrt_betm
651  n_bm = n_bm + 1
652  ! Beta plus
653  elseif ((zsum_p+1 .eq. zsum_r) .and. (nsum_p-1 .eq. nsum_r)) then
654  rr_tmp%reac_type = rrt_betp
655  n_bp = n_bp + 1
656  else
657  rr_tmp%reac_type = rrt_o
658  n_o = n_o + 1
659  end if
660 
661  ! Classify neutron capture reactions
662  else if ((group_index.eq.4) .and. &
663  ((get_net_name(parts_index(1),trimmed).eq.'n').or.&
664  (get_net_name(parts_index(2),trimmed).eq.'n'))) then
665  rr_tmp%reac_type = rrt_ng
666  n_ng = n_ng +1 ! Count reaction type for statistics
667  ! Classify gamma-neutron
668  else if (((group_index.eq.2)).and.&
669  ((get_net_name(parts_index(2),trimmed).eq.'n').or.&
670  (get_net_name(parts_index(3),trimmed).eq.'n')))then
671  rr_tmp%reac_type = rrt_gn
672  n_gn = n_gn +1 ! Count reaction type for statistics
673  ! Classify alpha capture reactions
674  else if ((group_index.eq.4).and. &
675  ((get_net_name(parts_index(1),trimmed).eq.'he4').or. &
676  (get_net_name(parts_index(2),trimmed).eq.'he4'))) then
677  rr_tmp%reac_type = rrt_ag
678  n_ag = n_ag +1 ! Count reaction type for statistics
679  ! Classify gamma-alpha
680  else if (((group_index.eq.2)).and.&
681  ((get_net_name(parts_index(2),trimmed).eq.'he4').or.&
682  (get_net_name(parts_index(3),trimmed).eq.'he4')))then
683  rr_tmp%reac_type = rrt_ga
684  n_ga = n_ga +1 ! Count reaction type for statistics
685  ! Classify proton capture reactions
686  else if ((group_index.eq.4).and.&
687  ((get_net_name(parts_index(1),trimmed).eq.'p').or. &
688  (get_net_name(parts_index(2),trimmed).eq.'p'))) then
689  rr_tmp%reac_type = rrt_pg
690  n_pg = n_pg +1 ! Count reaction type for statistics
691  ! Classify gamma-p
692  else if (((group_index.eq.2)).and.&
693  ((get_net_name(parts_index(2),trimmed).eq.'p').or.&
694  (get_net_name(parts_index(3),trimmed).eq.'p'))) then
695  rr_tmp%reac_type = rrt_gp
696  n_gp = n_gp +1 ! Count reaction type for statistics
697  ! Classify n-a
698  else if ( (group_index.eq.5).and.&
699  ((get_net_name(parts_index(1),trimmed).eq.'n') .or.&
700  (get_net_name(parts_index(2),trimmed).eq.'n')).and.&
701  ((get_net_name(parts_index(3),trimmed).eq.'he4').or.&
702  (get_net_name(parts_index(4),trimmed).eq.'he4'))) then
703  rr_tmp%reac_type = rrt_na
704  n_na = n_na +1 ! Count reaction type for statistics
705  ! Classify a-n
706  else if ( (group_index.eq.5).and.&
707  ((get_net_name(parts_index(1),trimmed).eq.'he4').or.&
708  (get_net_name(parts_index(2),trimmed).eq.'he4')).and.&
709  ((get_net_name(parts_index(3),trimmed).eq.'n') .or.&
710  (get_net_name(parts_index(4),trimmed).eq.'n'))) then
711  rr_tmp%reac_type = rrt_an
712  n_an = n_an +1 ! Count reaction type for statistics
713  ! Classify n-p
714  else if ( (group_index.eq.5).and.&
715  ((get_net_name(parts_index(1),trimmed).eq.'n').or.&
716  (get_net_name(parts_index(2),trimmed).eq.'n')).and.&
717  ((get_net_name(parts_index(3),trimmed).eq.'p').or.&
718  (get_net_name(parts_index(4),trimmed).eq.'p'))) then
719  rr_tmp%reac_type = rrt_np
720  n_np = n_np +1 ! Count reaction type for statistics
721  ! Classify p-n
722  else if ( (group_index.eq.5).and.&
723  ((get_net_name(parts_index(1),trimmed).eq.'p').or.&
724  (get_net_name(parts_index(2),trimmed).eq.'p')).and.&
725  ((get_net_name(parts_index(3),trimmed).eq.'n').or.&
726  (get_net_name(parts_index(4),trimmed).eq.'n'))) then
727  rr_tmp%reac_type = rrt_pn
728  n_pn = n_pn +1 ! Count reaction type for statistics
729  ! Classify p-a
730  else if ( (group_index.eq.5).and.&
731  ((get_net_name(parts_index(1),trimmed).eq.'p') .or.&
732  (get_net_name(parts_index(2),trimmed).eq.'p')).and.&
733  ((get_net_name(parts_index(3),trimmed).eq.'he4').or.&
734  (get_net_name(parts_index(4),trimmed).eq.'he4'))) then
735  rr_tmp%reac_type = rrt_pa
736  n_pa = n_pa +1 ! Count reaction type for statistics
737  ! Classify a-p
738  else if ( (group_index.eq.5).and.&
739  ((get_net_name(parts_index(1),trimmed).eq.'he4').or.&
740  (get_net_name(parts_index(2),trimmed).eq.'he4')).and.&
741  ((get_net_name(parts_index(3),trimmed).eq.'p') .or.&
742  (get_net_name(parts_index(4),trimmed).eq.'p'))) then
743  rr_tmp%reac_type = rrt_ap
744  n_ap = n_ap +1 ! Count reaction type for statistics
745  else
746  rr_tmp%reac_type = rrt_o
747  n_o = n_o +1 ! Count reaction type for statistics
748  end if
749 
750 end subroutine set_reaction_type
751 
752 
753 
754 
755 
756 !> Count the amount of reaclib reactions
757 !!
758 !! After the subroutine has been called
759 !! \ref nrea will store the amount of reaclib reaction rates.
760 !!
761 !! \b Edited:
762 !! - 25.01.21, MR - Moved this routine from network_init_module to this new subroutine
763 !! .
766  use parameter_class, only: reaclib_file
767  use benam_class, only: benam
768  use format_class
769  implicit none
770  integer :: i !< Count of the rates
771  integer :: j !< Loop variable
772  integer :: read_stat !< Read status
773  integer :: reaclib !< File id of reaclib
774  character(5), dimension(6) :: parts !< Participating nuclei names
775  integer, dimension(6) :: parts_index !< Participating nuclei indices
776  real(r_kind), dimension(9) :: params !< Reaclib fitting parameter
777  character(4) :: src !< Reaclib source label
778  character(1) :: res !< Reaclib weak flag label
779  character(1) :: rev !< Reaclib reverse label
780  real(r_kind) :: q !< Reaclib Q-Value
781  integer :: grp !< Reaclib chapter
782 
783  i=0
784  reaclib= open_infile(reaclib_file)
785 
786  outer: do
787  read(reaclib,my_format(1), iostat = read_stat) &
788  grp, parts(1:6), src, res, rev, q
789 
790  if (read_stat /= 0) exit
791  read(reaclib,"(4E13.6)") params(1:4)
792  read(reaclib,"(5E13.6)") params(5:9)
793  !--- fission rates are read in separately. For a transition period, the fission rates are probably still present in the reaclib file
794  if ((src.eq.'ms99').or.(src.eq.'mp01').or.(src.eq.'sfis').or.(src.eq.'fiss')) cycle outer
795  !--- grp =/ 0 only for group separators in reaclib
796  ! explaination: reaclib is structured to have group separators with same number of chars
797  ! of blocks containing data for each reaction; variable grp gets overwritten with a 0
798  ! in blocks containing data and is not 0 only for separators
799  if (grp.ne.0) cycle outer
800  parts_index = 0
801  inner: do j=1,6
802  if (parts(j) .eq. ' ') exit inner
803  parts_index(j) = benam(parts(j))
804  !----- parts_index(i) = 0 if nuclide i is not in network
805  if (parts_index(j) .eq. 0) cycle outer
806  end do inner
807 
808  i = i+1
809 
810  end do outer
811 
812  ! Close the fileagain
813  close(reaclib)
814 
815  ! Store the amount of rates
816  nrea = i
817 
818 end subroutine count_reaclib_rates
819 
820 
821 
822 
823 
824 
825 
826 end module reaclib_rate_module
reaclib_rate_module::n_ne
integer, private n_ne
Definition: reaclib_rate_module.f90:20
parameter_class::use_prepared_network
logical use_prepared_network
Use a prepared folder with all necessary data in binary format.
Definition: parameter_class.f90:94
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
global_class::rrate
type(reactionrate_type), dimension(:), allocatable, public rrate
array containing all reaction rates used in the network
Definition: global_class.f90:65
reaclib_rate_module::n_an
integer, private n_an
Definition: reaclib_rate_module.f90:19
reaclib_rate_module::n_bp
integer, private n_bp
Definition: reaclib_rate_module.f90:20
reaclib_rate_module::merge_reaclib_rates
subroutine, public merge_reaclib_rates(rrate_array, rrate_length)
Merge the reaclib rates into a larger array.
Definition: reaclib_rate_module.f90:270
reaclib_rate_module
Module that deals with reaclib reaction rates.
Definition: reaclib_rate_module.f90:13
reaclib_rate_module::n_np
integer, private n_np
Definition: reaclib_rate_module.f90:19
rrt_an
#define rrt_an
Definition: macros.h:72
rrs_reacl
#define rrs_reacl
Definition: macros.h:49
error_msg_class
Error handling routines.
Definition: error_msg_class.f90:16
global_class::ihe4
integer, public ihe4
Definition: global_class.f90:94
rrt_ec
#define rrt_ec
Definition: macros.h:61
benam_class::benam
integer function, public benam(name)
Returns the index number of isotope 'name'.
Definition: benam_class.f90:251
rrt_np
#define rrt_np
Definition: macros.h:73
reaclib_rate_module::n_pg
integer, private n_pg
Definition: reaclib_rate_module.f90:18
benam_class::reaction_string
character(50) function, public reaction_string(reac)
Return a string to represent a given reaction.
Definition: benam_class.f90:119
rrt_gp
#define rrt_gp
Definition: macros.h:70
parameter_class::use_neutrino_loss_file
logical use_neutrino_loss_file
Use a file with Qnu values?
Definition: parameter_class.f90:105
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
reaclib_rate_module::n_ga
integer, private n_ga
Definition: reaclib_rate_module.f90:19
error_msg_class::raise_exception
subroutine, public raise_exception(msg, sub, error_code)
Raise a exception with a given error message.
Definition: error_msg_class.f90:245
reaclib_rate_module::init_reaclib_rates
subroutine, public init_reaclib_rates()
Count and read reaclib reactions.
Definition: reaclib_rate_module.f90:45
reaclib_rate_module::n_ag
integer, private n_ag
Definition: reaclib_rate_module.f90:19
global_class::ineu
integer, public ineu
Definition: global_class.f90:94
rrt_pn
#define rrt_pn
Definition: macros.h:74
global_class::isotope
type(isotope_type), dimension(:), allocatable, public isotope
all nuclides used in the network
Definition: global_class.f90:34
reaclib_rate_module::n_o
integer, private n_o
Definition: reaclib_rate_module.f90:18
reaclib_rate_module::n_pn
integer, private n_pn
Definition: reaclib_rate_module.f90:19
error_msg_class::write_data_to_std_out
subroutine, public write_data_to_std_out(str_msg, value_str, unit)
Write data to the standard output (usually OUT)
Definition: error_msg_class.f90:122
reaclib_rate_module::n_na
integer, private n_na
Amount of individual reaction types.
Definition: reaclib_rate_module.f90:19
format_class::my_format
character(60), dimension(100) my_format
Definition: format_class.f90:19
rrt_ga
#define rrt_ga
Definition: macros.h:68
reaclib_rate_module::n_w
integer, private n_w
Definition: reaclib_rate_module.f90:18
nucstuff_class
Module with helper functions such as rate tabulation, partition functions, and theoretical weak rates...
Definition: nucstuff_class.f90:11
reaclib_rate_module::count_reaclib_rates
subroutine, private count_reaclib_rates()
Count the amount of reaclib reactions.
Definition: reaclib_rate_module.f90:765
rrt_pemi
#define rrt_pemi
Definition: macros.h:63
rrt_alpd
#define rrt_alpd
Definition: macros.h:62
rrt_betp
#define rrt_betp
Definition: macros.h:60
reaclib_rate_module::n_pa
integer, private n_pa
Definition: reaclib_rate_module.f90:18
rrt_na
#define rrt_na
Definition: macros.h:71
rrt_pg
#define rrt_pg
Definition: macros.h:69
rrt_ap
#define rrt_ap
Definition: macros.h:76
reaclib_rate_module::n_ec
integer, private n_ec
Amount of individual reaction types.
Definition: reaclib_rate_module.f90:20
reaclib_rate_module::infty
real(r_kind), private infty
Definition: reaclib_rate_module.f90:24
reaclib_rate_module::n_pe
integer, private n_pe
Definition: reaclib_rate_module.f90:20
global_class::qnuloss
real(r_kind), dimension(:), allocatable, public qnuloss
Qnu for decay of each isotope [MeV].
Definition: global_class.f90:96
reaclib_rate_module::set_heating_frac
subroutine set_heating_frac(reac_rate_array, length)
Set the fraction of energy radiated away by neutrinos.
Definition: reaclib_rate_module.f90:462
global_class::net_size
integer, public net_size
total number of isotopes (network size)
Definition: global_class.f90:93
parameter_class::heating_frac
real(r_kind) heating_frac
use this fraction of nuclear-generated energy for heating
Definition: parameter_class.f90:123
reaclib_rate_module::rrate_binary_name
character(len= *), parameter, private rrate_binary_name
Name of the binary file for rrate array.
Definition: reaclib_rate_module.f90:23
file_handling_class
Provide some basic file-handling routines.
Definition: file_handling_class.f90:18
reaclib_rate_module::read_binary_reaclib_reaction_data
subroutine read_binary_reaclib_reaction_data(path)
Read the complete rrate array from a binary file.
Definition: reaclib_rate_module.f90:154
reaclib_rate_module::n_ap
integer, private n_ap
Definition: reaclib_rate_module.f90:18
r_kind
#define r_kind
Definition: macros.h:46
rrt_gn
#define rrt_gn
Definition: macros.h:66
reaclib_rate_module::n_ad
integer, private n_ad
Definition: reaclib_rate_module.f90:20
parameter_class::reaclib_file
character(max_fname_len) reaclib_file
reaction rate library (reaclib)
Definition: parameter_class.f90:158
reaclib_rate_module::n_gn
integer, private n_gn
Definition: reaclib_rate_module.f90:18
reaclib_rate_module::set_reaction_type
subroutine, public set_reaction_type(rr_tmp)
Set a flag for the reaction type.
Definition: reaclib_rate_module.f90:569
rrt_pa
#define rrt_pa
Definition: macros.h:75
reaclib_rate_module::read_reaclib
subroutine, private read_reaclib()
Read reaclib reaction rates.
Definition: reaclib_rate_module.f90:338
reaclib_rate_module::output_binary_reaclib_reaction_data
subroutine output_binary_reaclib_reaction_data(path)
Save the complete rrate array to a binary file.
Definition: reaclib_rate_module.f90:194
rrt_betm
#define rrt_betm
Definition: macros.h:59
nucstuff_class::get_nr_reactants
integer function get_nr_reactants(group)
Get number of reactants of the reaction based on the reaclib chapter.
Definition: nucstuff_class.f90:301
rrt_o
#define rrt_o
Definition: macros.h:81
reaclib_rate_module::n_ng
integer, private n_ng
Definition: reaclib_rate_module.f90:18
nucstuff_class::t9_pow
real(r_kind), dimension(9), public t9_pow
Powers of T, used for the rates.
Definition: nucstuff_class.f90:15
file_handling_class::open_infile
integer function, public open_infile(file_name)
Same for reading (input file)
Definition: file_handling_class.f90:126
global_class
Contains types and objects shared between multiple modules.
Definition: global_class.f90:19
rrt_nemi
#define rrt_nemi
Definition: macros.h:64
benam_class::get_net_name
character(:) function, allocatable, public get_net_name(index, trimmed)
Getter of net_names, translating indices to a nucleus name.
Definition: benam_class.f90:280
reaclib_rate_module::write_reac_verbose_out
subroutine, private write_reac_verbose_out()
Write the amount of individual reactions to the out.
Definition: reaclib_rate_module.f90:87
global_class::nreac
integer, public nreac
total number of reactions
Definition: global_class.f90:98
reaclib_rate_module::calculate_reacl_rate
subroutine calculate_reacl_rate(rrate, rat_calc)
Calculate a reaclib rate.
Definition: reaclib_rate_module.f90:229
rrt_ag
#define rrt_ag
Definition: macros.h:67
file_handling_class::open_unformatted_outfile
integer function, public open_unformatted_outfile(file_name)
Shorthand for opening a new unformatted file for writing (output file)
Definition: file_handling_class.f90:74
reaclib_rate_module::n_bm
integer, private n_bm
Definition: reaclib_rate_module.f90:20
format_class
Define custom format statements used to read in major data files.
Definition: format_class.f90:16
rrt_ng
#define rrt_ng
Definition: macros.h:65
parameter_class::prepared_network_path
character(max_fname_len) prepared_network_path
Prepared network folder.
Definition: parameter_class.f90:198
reaclib_rate_module::rrate_reaclib
type(reactionrate_type), dimension(:), allocatable, private rrate_reaclib
Reaclib reaction rates.
Definition: reaclib_rate_module.f90:21
reaclib_rate_module::n_gp
integer, private n_gp
Amount of individual reaction types.
Definition: reaclib_rate_module.f90:18
reaclib_rate_module::nrea
integer, private nrea
Amount of reaclib rates.
Definition: reaclib_rate_module.f90:17
parameter_class
Contains all runtime parameters as well as phys and math constants.
Definition: parameter_class.f90:24
benam_class::getcoefficients
subroutine, public getcoefficients(rate_array, length_rate_array)
Returns the 1/n! factor where n is the number of equal isotopes entering a reaction....
Definition: benam_class.f90:307
benam_class
Subroutines needed to initialise the network.
Definition: benam_class.f90:11
nucstuff_class::get_nr_products
integer function get_nr_products(group)
Get number of products of the reaction based on the reaclib chapter.
Definition: nucstuff_class.f90:345