Line data Source code
1 : ! ***********************************************************************
2 : !
3 : ! Copyright (C) 2010-2019 The MESA Team
4 : !
5 : ! This program is free software: you can redistribute it and/or modify
6 : ! it under the terms of the GNU Lesser General Public License
7 : ! as published by the Free Software Foundation,
8 : ! either version 3 of the License, or (at your option) any later version.
9 : !
10 : ! This program is distributed in the hope that it will be useful,
11 : ! but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 : ! See the GNU Lesser General Public License for more details.
14 : !
15 : ! You should have received a copy of the GNU Lesser General Public License
16 : ! along with this program. If not, see <https://www.gnu.org/licenses/>.
17 : !
18 : ! ***********************************************************************
19 :
20 : module rates_support
21 : use const_def, only: dp, qp, use_mesa_temp_cache, missing_value, ln10, ln10_qp
22 : use math_lib
23 : use rates_def
24 : use utils_lib, only: mv, switch_str, mesa_error
25 :
26 : implicit none
27 :
28 : integer, parameter :: cache_version = 4
29 :
30 :
31 : contains
32 :
33 81803 : subroutine do_get_raw_rates( &
34 81803 : num_reactions, reaction_id, rattab, rattab_f1, nT8s, &
35 81803 : ye, logtemp_in, btemp, bden, raw_rate_factor, ttab, logttab, &
36 81803 : rate_raw, rate_raw_dT, rate_raw_dRho, ierr)
37 : integer, intent(in) :: num_reactions, reaction_id(:), nT8s
38 : real(dp), intent(in) :: &
39 : ye, logtemp_in, btemp, bden, raw_rate_factor(:), &
40 : rattab(:,:), ttab(:), logttab(:)
41 : real(dp), pointer, intent(in) :: rattab_f1(:)
42 : real(dp), intent(inout), dimension(:) :: rate_raw, rate_raw_dT, rate_raw_dRho
43 : integer, intent(out) :: ierr
44 :
45 : integer :: imax, iat0, iat, ir, i, irho
46 : integer, parameter :: mp = 4
47 : real(dp), allocatable :: dtab(:), ddtab(:)
48 : real(dp), pointer :: rattab_f(:,:,:)
49 : real(dp) :: logtemp, fac
50 :
51 : include 'formats'
52 :
53 81803 : ierr = 0
54 :
55 : nullify(rattab_f)
56 327212 : allocate(dtab(num_reactions), ddtab(num_reactions))
57 :
58 81803 : rattab_f(1:4,1:nT8s,1:num_reactions) => rattab_f1(1:4*nT8s*num_reactions)
59 :
60 2895817 : do i = 1,num_reactions
61 :
62 2814014 : ir = reaction_id(i)
63 : !dtab(i) = ye**reaction_ye_rho_exponents(1,ir)
64 5468903 : select case(reaction_ye_rho_exponents(1,ir))
65 : case (0)
66 2654889 : dtab(i) = 1d0
67 : case (1)
68 159125 : dtab(i) = ye
69 : case (2)
70 2814014 : dtab(i) = ye*ye
71 : end select
72 :
73 : !dtab(i) = dtab(i)*bden**reaction_ye_rho_exponents(2,ir)
74 2814014 : irho = reaction_ye_rho_exponents(2,ir)
75 2447488 : select case(irho)
76 : case (1)
77 2447488 : dtab(i) = dtab(i)*bden
78 : case (2)
79 159121 : dtab(i) = dtab(i)*bden*bden
80 : case (3)
81 0 : dtab(i) = dtab(i)*bden*bden*bden
82 : case (4)
83 2814014 : dtab(i) = dtab(i)*bden*bden*bden*bden
84 : end select
85 :
86 2895817 : ddtab(i) = irho*dtab(i)/bden
87 :
88 : end do
89 :
90 81803 : if(warn_rates_for_high_temp .and. logtemp_in >= max_safe_logT_for_rates) then
91 0 : write(*,'(A,F0.6,A,F0.6,A)') "WARNING: evaluating rates with lgT=",logtemp_in," which is above lgT=",&
92 0 : max_safe_logT_for_rates,", rates have been truncated"
93 : end if
94 :
95 :
96 81803 : if(logtemp_in >= max_safe_logT_for_rates) then
97 0 : logtemp = max_safe_logT_for_rates
98 : else
99 81803 : logtemp = logtemp_in
100 : end if
101 :
102 81803 : if (nrattab > 1) then
103 81803 : imax = nrattab
104 81803 : if (logtemp > rattab_thi) then
105 0 : ierr = -1
106 0 : return
107 : end if
108 81803 : iat0 = int((logtemp - rattab_tlo)/rattab_tstp) + 1
109 81803 : iat = max(1, min(iat0 - mp/2 + 1, imax - mp + 1))
110 81803 : call get_rates_from_table(1, num_reactions)
111 : else ! table only has a single temperature
112 0 : do i=1,num_reactions
113 0 : rate_raw(i) = rattab(i,1)*dtab(i)
114 0 : rate_raw_dT(i) = 0
115 0 : rate_raw_dRho(i) = rate_raw(i)*ddtab(i)/dtab(i)
116 : end do
117 : end if
118 :
119 2895817 : do i=1,num_reactions
120 2895817 : if(raw_rate_factor(i)> max_safe_rate_for_any_temp) then
121 0 : write(*,*) "Rate has exceeded any sensible limit for a reaction rate"
122 0 : write(*,*) trim(reaction_Name(reaction_id(i)))
123 0 : write(*,*) raw_rate_factor(i),max_safe_rate_for_any_temp,raw_rate_factor(i)/max_safe_rate_for_any_temp
124 0 : call mesa_error(__FILE__,__LINE__)
125 : end if
126 : end do
127 :
128 2895817 : do i=1,num_reactions
129 2814014 : fac = raw_rate_factor(i)
130 2814014 : rate_raw(i) = rate_raw(i)*fac
131 2814014 : rate_raw_dT(i) = rate_raw_dT(i)*fac
132 2895817 : rate_raw_dRho(i) = rate_raw_dRho(i)*fac
133 : end do
134 :
135 81803 : if(logtemp >= max_safe_logT_for_rates) then
136 0 : rate_raw_dT(1:num_reactions) = 0d0
137 : end if
138 :
139 81803 : nullify(rattab_f)
140 :
141 : contains
142 :
143 81803 : subroutine get_rates_from_table(r1, r2)
144 : integer, intent(in) :: r1, r2
145 :
146 : integer :: i, k
147 : real(dp) :: dt
148 :
149 : include 'formats'
150 :
151 81803 : k = iat+1 ! starting guess for search
152 100058 : do while (logtemp < logttab(k) .and. k > 1)
153 18255 : k = k-1
154 : end do
155 81803 : do while (logtemp > logttab(k+1) .and. k+1 < nrattab)
156 81803 : k = k+1
157 : end do
158 81803 : if (logtemp_in >= max_safe_logT_for_rates) then
159 0 : dt = logtemp - logttab(k)
160 : else
161 : ! Preserve local changes lost by subtracting absolute logarithms.
162 81803 : dt = real(log(real(btemp,kind=qp)/real(ttab(k),kind=qp))*(1.0_qp/ln10_qp),kind=dp)
163 : end if
164 :
165 2895817 : do i = r1,r2
166 :
167 : rate_raw(i) = &
168 : (rattab_f(1,k,i) + dt*(rattab_f(2,k,i) + &
169 : dt*(rattab_f(3,k,i) + dt*rattab_f(4,k,i))) &
170 2814014 : ) * dtab(i)
171 :
172 2814014 : rate_raw_dRho(i) = rate_raw(i) * ddtab(i) / dtab(i)
173 :
174 : rate_raw_dT(i) = &
175 : (rattab_f(2,k,i) + 2*dt*(rattab_f(3,k,i) + &
176 : 1.5d0*dt*rattab_f(4,k,i)) &
177 2895817 : ) * dtab(i) / (btemp * ln10)
178 :
179 : end do
180 :
181 81803 : end subroutine get_rates_from_table
182 :
183 :
184 : end subroutine do_get_raw_rates
185 :
186 :
187 10 : subroutine do_make_rate_tables( &
188 10 : num_reactions, cache_suffix, net_reaction_id, &
189 10 : rattab, rattab_f1, nT8s, ttab, logttab, ierr)
190 : use interp_1d_lib, only: interp_pm, interp_m3q
191 : use interp_1d_def, only: pm_work_size, mp_work_size
192 : use utils_lib
193 : integer, intent(in) :: nT8s, num_reactions, net_reaction_id(:)
194 : character (len=*), intent(in) :: cache_suffix
195 : real(dp) :: rattab(:,:), ttab(:), logttab(:)
196 : real(dp), pointer :: rattab_f1(:)
197 : integer, intent(out) :: ierr
198 :
199 : integer :: i, j, operr, num_to_add_to_cache,thread_num
200 : real(dp) :: logT, btemp
201 : real(dp), pointer :: work1(:)=>null(), f1(:)=>null(), rattab_f(:,:,:)=>null()
202 : integer, pointer :: reaction_id(:) =>null()
203 10 : real(dp), allocatable, target :: work(:,:)
204 :
205 : logical :: all_okay, a_okay, all_in_cache
206 :
207 : include 'formats'
208 :
209 10 : ierr = 0
210 :
211 : rattab_f(1:4,1:nrattab,1:num_reactions) => &
212 10 : rattab_f1(1:4*nrattab*num_reactions)
213 :
214 30 : allocate(reaction_id(num_reactions))
215 681 : reaction_id(:) = net_reaction_id(:)
216 :
217 10 : num_to_add_to_cache = 0
218 10 : if (nrattab == 1) then
219 : all_in_cache = .false.
220 : else
221 10 : all_in_cache = .true.
222 681 : do i=1, num_reactions
223 671 : if (read_reaction_from_cache( net_reaction_id, cache_suffix, i, rattab)) then
224 493 : reaction_id(i) = 0
225 493 : cycle
226 : end if
227 178 : all_in_cache = .false.
228 178 : num_to_add_to_cache = num_to_add_to_cache + 1
229 : write(*,'(a)') 'create rate data for ' // &
230 188 : trim(reaction_Name(net_reaction_id(i)))
231 : !stop
232 : end do
233 : end if
234 :
235 10 : if (all_in_cache) then
236 :
237 4 : !$OMP PARALLEL DO PRIVATE(i, logT, btemp)
238 : do i=1, nrattab
239 : logT = rattab_tlo + real(i-1,kind=dp)*rattab_tstp
240 : btemp = exp10(logT)
241 : ttab(i) = btemp
242 : logttab(i) = logT
243 : end do
244 : !$OMP END PARALLEL DO
245 :
246 : else
247 :
248 6 : if (num_to_add_to_cache > 20) then
249 3 : write(*,2) 'number not already in cache:', num_to_add_to_cache
250 3 : if (num_to_add_to_cache > 100) write(*,*) 'this will take some time .....'
251 : end if
252 6 : all_okay = .true.
253 : !x$OMP PARALLEL DO PRIVATE(i, operr, logT, btemp, a_okay, j)
254 : ! Disable parralisation as this can cause bugs in the
255 : ! load tables See github bug #360
256 60012 : do i=1, nrattab
257 60006 : logT = rattab_tlo + real(i-1,kind=dp)*rattab_tstp
258 60006 : btemp = exp10(logT)
259 60006 : ttab(i) = btemp
260 60006 : logttab(i) = logT
261 3660366 : do j=1, num_reactions
262 3600360 : if (reaction_id(j) <= 0) cycle
263 3660366 : rattab(j, i) = missing_value ! so can check
264 : end do
265 : operr = 0
266 : !write(*,2) 'logT', i, logT
267 : call get_net_rates_for_tables( &
268 : reaction_id, logT, btemp, num_reactions, &
269 60006 : rattab(1:num_reactions, i), operr)
270 60006 : if (operr /= 0) then
271 0 : ierr = -1
272 0 : cycle
273 : end if
274 60006 : a_okay = .true.
275 3660366 : do j = 1, num_reactions
276 3600360 : if (reaction_id(j) <= 0) cycle
277 1840184 : if (rattab(j, i) == missing_value) then
278 0 : write(*, '(a,i4,2x,a)') 'missing raw rate for ', &
279 0 : j, trim(reaction_Name(reaction_id(j)))
280 0 : a_okay = .false.
281 : end if
282 : end do
283 120018 : if (.not. a_okay) all_okay = .false.
284 : end do
285 : !x$OMP END PARALLEL DO
286 6 : if (.not. all_okay) call mesa_error(__FILE__,__LINE__,'make_rate_tables')
287 6 : if (ierr /= 0) then
288 0 : write(*,*) 'make_rate_tables failed'
289 0 : deallocate(reaction_id)
290 0 : return
291 : end if
292 : end if
293 :
294 10 : if (nrattab > 1) then ! create interpolants
295 40 : allocate(work(nrattab*mp_work_size,utils_OMP_GET_MAX_THREADS()), stat=ierr)
296 10 : call fill_with_NaNs_2D(work)
297 10 : if (ierr /= 0) return
298 10 : !$OMP PARALLEL DO PRIVATE(i,operr,work1,f1,thread_num)
299 : do i=1,num_reactions
300 : thread_num=utils_OMP_GET_THREAD_NUM()+1
301 : work1(1:nrattab*mp_work_size) => work(1:nrattab*mp_work_size,thread_num)
302 : rattab_f(1,1:nrattab,i) = rattab(i,1:nrattab)
303 : f1(1:4*nT8s) => rattab_f1(1+4*nT8s*(i-1):4*nT8s*i)
304 : call interp_m3q(logttab, nrattab, f1, mp_work_size, work1, &
305 : 'rates do_make_rate_tables', operr)
306 : if (operr /= 0) ierr = -1
307 : nullify(f1,work1)
308 : end do
309 : !$OMP END PARALLEL DO
310 10 : deallocate(work)
311 : end if
312 :
313 10 : if (ierr == 0 .and. nrattab > 1 .and. .not. all_in_cache) then
314 366 : do i=1, num_reactions
315 360 : if (reaction_id(i) <= 0) cycle
316 366 : call write_reaction_to_cache(reaction_id, cache_suffix, i, rattab)
317 : end do
318 : end if
319 :
320 10 : deallocate(reaction_id)
321 :
322 10 : end subroutine do_make_rate_tables
323 :
324 :
325 849 : subroutine reaction_filename(ir, cache_suffix, which, cache_filename, temp_cache_filename, ierr)
326 : integer, intent(in) :: ir, which
327 : character (len=*), intent(in) :: cache_suffix
328 : character (len=*), intent(out) :: cache_filename, temp_cache_filename
329 : integer, intent(out) :: ierr
330 : character (len=64) :: suffix
331 849 : ierr = 0
332 0 : if (which == 0 .and. len_trim(cache_suffix) > 0) then
333 0 : suffix = cache_suffix
334 : else
335 849 : if (which < 0) then
336 0 : ierr = -1
337 0 : suffix = '?'
338 849 : else if (which >= 100) then
339 0 : write(suffix,'(i3)') which
340 849 : else if (which >= 10) then
341 0 : write(suffix,'(i2)') which
342 : else
343 849 : write(suffix,'(i1)') which
344 : end if
345 : end if
346 : write(cache_filename,'(a)') &
347 : trim(rates_cache_dir) // '/' // &
348 849 : trim(reaction_Name(ir)) // '_' // trim(suffix) // '.bin'
349 :
350 : write(temp_cache_filename,'(a)') &
351 : trim(rates_temp_cache_dir) // '/' // &
352 849 : trim(reaction_Name(ir)) // '_' // trim(suffix) // '.bin'
353 849 : end subroutine reaction_filename
354 :
355 :
356 :
357 671 : logical function read_reaction_from_cache(reaction_id, cache_suffix, i, rattab)
358 : integer, intent(in) :: i, reaction_id(:)
359 : character (len=*), intent(in) :: cache_suffix
360 : real(dp),intent(out) :: rattab(:,:)
361 :
362 : integer :: file_version, file_nrattab, file_which
363 : real(dp) :: file_rattab_thi, file_rattab_tlo, file_rattab_tstp
364 : character (len=256) :: cache_filename, temp_cache_filename
365 : integer :: io_unit, ios, ir, which, j, ierr, rir
366 : real(dp), parameter :: tiny = 1d-6
367 : character (len=maxlen_reaction_Name) :: name
368 :
369 : logical, parameter :: show_read_cache = .false.
370 : logical :: reverse_is_table
371 :
372 : ierr = 0
373 671 : read_reaction_from_cache = .false.
374 671 : if (.not. rates_use_cache) return
375 :
376 671 : ir = reaction_id(i)
377 671 : which = 1
378 :
379 671 : reverse_is_table = .false.
380 671 : rir = reverse_reaction_id(ir)
381 671 : if(rir>0) reverse_is_table = raw_rates_records(reverse_reaction_id(ir))% use_rate_table
382 :
383 :
384 671 : if (raw_rates_records(ir)% use_rate_table .or. reverse_is_table) then
385 : which = 0
386 : !Dont read a cached version of a users local rate
387 : return
388 : end if
389 :
390 671 : call reaction_filename(reaction_id(i), cache_suffix, which, cache_filename, temp_cache_filename, ierr)
391 671 : if (ierr /= 0) then
392 : if (show_read_cache) write(*,*) 'read cache -- bad reaction_filename ' // trim(cache_filename)
393 : return
394 : end if
395 :
396 671 : ios = 0
397 : open(newunit=io_unit,file=trim(cache_filename),action='read', &
398 671 : status='old',iostat=ios,form='unformatted')
399 671 : if (ios /= 0) then
400 : if (show_read_cache) write(*,*) 'read cache failed for open ' // trim(cache_filename)
401 : return
402 : end if
403 :
404 : read(io_unit, iostat=ios) &
405 493 : name, file_which, file_version, file_nrattab, &
406 986 : file_rattab_thi, file_rattab_tlo, file_rattab_tstp
407 493 : if (ios /= 0) then
408 : if (show_read_cache) write(*,*) 'read cache failed for read header ' // trim(cache_filename)
409 0 : close(io_unit)
410 0 : return
411 : end if
412 :
413 493 : if (name /= reaction_Name(ir)) then
414 : if (show_read_cache) write(*,*) 'read cache failed for name'
415 0 : close(io_unit)
416 0 : return
417 : end if
418 :
419 493 : if (which /= file_which) then
420 : if (show_read_cache) write(*,*) 'read cache failed for which reaction'
421 0 : close(io_unit)
422 0 : return
423 : end if
424 :
425 493 : if (cache_version /= file_version) then
426 : if (show_read_cache) write(*,*) 'read cache failed for version'
427 0 : close(io_unit)
428 0 : return
429 : end if
430 :
431 493 : if (abs(rattab_thi-file_rattab_thi) > tiny) then
432 : if (show_read_cache) write(*,*) 'read cache failed for rattab_thi'
433 0 : close(io_unit)
434 0 : return
435 : end if
436 :
437 493 : if (abs(rattab_tlo-file_rattab_tlo) > tiny) then
438 : if (show_read_cache) write(*,*) 'read cache failed for rattab_tlo'
439 0 : close(io_unit)
440 0 : return
441 : end if
442 :
443 493 : if (abs(rattab_tstp-file_rattab_tstp) > tiny) then
444 : if (show_read_cache) write(*,*) 'read cache failed for rattab_tstp'
445 0 : close(io_unit)
446 0 : return
447 : end if
448 :
449 4930986 : do j = 1, nrattab
450 4930493 : read(io_unit, iostat=ios) rattab(i,j)
451 4930986 : if (ios /= 0) then
452 : if (show_read_cache) write(*,*) 'read cache failed for reaction'
453 0 : close(io_unit)
454 0 : return
455 : end if
456 : end do
457 :
458 493 : close(io_unit)
459 :
460 493 : read_reaction_from_cache = .true.
461 :
462 493 : end function read_reaction_from_cache
463 :
464 :
465 :
466 178 : subroutine write_reaction_to_cache(reaction_id, cache_suffix, i, rattab)
467 : integer, intent(in) :: i
468 : character (len=*), intent(in) :: cache_suffix
469 : integer, intent(in) :: reaction_id(:)
470 : real(dp), intent(in) :: rattab(:,:)
471 :
472 : character (len=256) :: cache_filename, temp_cache_filename
473 : integer :: io_unit, ios, ir, which, ierr, j, rir
474 :
475 : logical, parameter :: show_write_cache = .true.
476 : logical :: reverse_is_table
477 :
478 : ierr = 0
479 178 : if (.not. rates_use_cache) return
480 :
481 178 : ir = reaction_id(i)
482 178 : which = 1
483 :
484 178 : reverse_is_table = .false.
485 178 : rir = reverse_reaction_id(ir)
486 178 : if(rir>0) reverse_is_table = raw_rates_records(reverse_reaction_id(ir))% use_rate_table
487 :
488 :
489 178 : if (raw_rates_records(ir)% use_rate_table .or. reverse_is_table) which = 0
490 :
491 :
492 : ! Write cache file to temporary storage that is local to the run,
493 : ! then at the end move the file atomically to the final cache location
494 178 : call reaction_filename(reaction_id(i), cache_suffix, which, cache_filename, temp_cache_filename, ierr)
495 178 : if (ierr /= 0) return
496 :
497 178 : ios = 0
498 : open(newunit=io_unit, file=trim(switch_str(temp_cache_filename, cache_filename, use_mesa_temp_cache)),&
499 178 : iostat=ios, action='write', form='unformatted')
500 178 : if (ios /= 0) then
501 0 : if (show_write_cache) write(*,*) 'write_cache failed to open ', trim(temp_cache_filename)
502 0 : return
503 : end if
504 :
505 178 : if (show_write_cache) write(*,'(a)') 'write ' // trim(cache_filename)
506 :
507 : write(io_unit) &
508 178 : reaction_Name(ir), which, cache_version, nrattab, &
509 356 : rattab_thi, rattab_tlo, rattab_tstp
510 :
511 1780356 : do j = 1, nrattab
512 1780356 : write(io_unit) rattab(i,j)
513 : end do
514 :
515 178 : close(io_unit)
516 178 : if(use_mesa_temp_cache) call mv(temp_cache_filename,cache_filename,.true.)
517 :
518 :
519 : end subroutine write_reaction_to_cache
520 :
521 :
522 0 : subroutine do_show_reaction_from_cache(cache_filename, ierr)
523 : character (len=*) :: cache_filename
524 : integer, intent(out) :: ierr
525 :
526 : integer :: version, nrattab, which
527 : real(dp) :: rattab_thi, rattab_tlo, rattab_tstp, rate, T8, logT
528 : integer :: ios, j, io_unit
529 : real(dp), parameter :: tiny = 1d-6
530 : character (len=maxlen_reaction_Name) :: name
531 :
532 0 : ierr = 0
533 0 : ios = 0
534 : open(newunit=io_unit,file=trim(cache_filename),action='read', &
535 0 : status='old',iostat=ios,form='unformatted')
536 0 : if (ios /= 0) then
537 0 : write(*,*) 'read cache failed for open ' // trim(cache_filename)
538 0 : return
539 : end if
540 :
541 : read(io_unit, iostat=ios) &
542 0 : name, which, version, nrattab, &
543 0 : rattab_thi, rattab_tlo, rattab_tstp
544 0 : if (ios /= 0) then
545 0 : write(*,*) 'read cache failed for read header ' // trim(cache_filename)
546 0 : close(io_unit)
547 0 : return
548 : end if
549 :
550 0 : write(*,'(a)') '# T8 rate'
551 0 : write(*,'(A)')
552 0 : write(*,*) nrattab
553 :
554 0 : do j = 1, nrattab
555 0 : read(io_unit, iostat=ios) rate
556 0 : if (ios /= 0) then
557 0 : write(*,*) 'read cache failed for reaction data', j
558 0 : close(io_unit)
559 0 : return
560 : end if
561 0 : logT = rattab_tlo + dble(j-1)*rattab_tstp
562 0 : T8 = exp10(logT - 8d0)
563 0 : write(*,'(1pe26.16,3x,1pe26.16e3)') T8, rate
564 : end do
565 0 : write(*,'(A)')
566 :
567 0 : close(io_unit)
568 :
569 : end subroutine do_show_reaction_from_cache
570 :
571 :
572 60006 : subroutine get_net_rates_for_tables( &
573 60006 : reaction_id, logT, btemp, num_reactions, rates, ierr)
574 : use ratelib, only: tfactors
575 : use raw_rates, only: set_raw_rates
576 : use utils_lib, only: is_bad
577 :
578 : real(dp), intent(in) :: logT, btemp
579 : integer, intent(in) :: num_reactions, reaction_id(:)
580 : real(dp), intent(inout) :: rates(:)
581 : integer, intent(out) :: ierr
582 :
583 : integer :: i, ir
584 : type (T_Factors) :: tf
585 :
586 : include 'formats'
587 :
588 60006 : ierr = 0
589 :
590 60006 : call tfactors(tf, logT, btemp)
591 : call set_raw_rates( &
592 60006 : num_reactions, reaction_id, btemp, tf, rates, ierr)
593 60006 : if (ierr /= 0) return
594 :
595 3660366 : do i = 1, num_reactions
596 3600360 : ir = reaction_id(i)
597 3600360 : if (ir <= 0) cycle
598 1840184 : if (is_bad(rates(i))) then
599 0 : write(*,2) trim(reaction_Name(ir)) // ' rates', i, rates(i)
600 0 : call mesa_error(__FILE__,__LINE__,'get_net_rates_for_tables')
601 : end if
602 : end do
603 :
604 : end subroutine get_net_rates_for_tables
605 :
606 :
607 0 : subroutine do_eval_reaclib_21( &
608 0 : ir, temp, den, rate_raw, reverse_rate_raw, ierr)
609 : use raw_rates, only: get_reaclib_rate_and_dlnT
610 : integer, intent(in) :: ir ! reaction_id
611 : real(dp), intent(in) :: temp, den
612 : real(dp), intent(inout) :: rate_raw(:), reverse_rate_raw(:)
613 : integer, intent(out) :: ierr
614 :
615 : real(dp) :: lambda, dlambda_dlnT, rlambda, drlambda_dlnT
616 :
617 : include 'formats'
618 :
619 : ierr = 0
620 : call get_reaclib_rate_and_dlnT( &
621 0 : ir, temp, lambda, dlambda_dlnT, rlambda, drlambda_dlnT, ierr)
622 0 : if (ierr /= 0) return
623 :
624 0 : if (reaction_ye_rho_exponents(2,ir) /= 1) then
625 0 : ierr = -1
626 0 : return
627 : end if
628 :
629 0 : rate_raw(i_rate) = lambda*den
630 0 : rate_raw(i_rate_dT) = dlambda_dlnT*den/temp
631 0 : rate_raw(i_rate_dRho) = lambda
632 :
633 0 : reverse_rate_raw(i_rate) = rlambda
634 0 : reverse_rate_raw(i_rate_dT) = drlambda_dlnT/temp
635 0 : reverse_rate_raw(i_rate_dRho) = 0d0
636 :
637 0 : return
638 :
639 : !$omp critical (rates_eval_reaclib_21)
640 : write(*,1) 'do_eval_reaclib_21 ' // trim(reaction_Name(ir))
641 : write(*,'(A)')
642 : write(*,1) 'den', den
643 : write(*,1) 'temp', temp
644 : write(*,'(A)')
645 : write(*,1) 'lambda', lambda
646 : write(*,1) 'dlambda_dlnT', dlambda_dlnT
647 : write(*,1) 'rate_raw', rate_raw(1:num_rvs)
648 : write(*,'(A)')
649 : write(*,1) 'rlambda', rlambda
650 : write(*,1) 'drlambda_dlnT', drlambda_dlnT
651 : write(*,1) 'reverse_rate_raw', reverse_rate_raw(1:num_rvs)
652 : write(*,'(A)')
653 : !$omp end critical (rates_eval_reaclib_21)
654 :
655 : end subroutine do_eval_reaclib_21
656 :
657 :
658 0 : subroutine do_eval_reaclib_22( &
659 0 : ir, temp, den, rate_raw, reverse_rate_raw, ierr)
660 : use raw_rates, only: get_reaclib_rate_and_dlnT
661 : integer, intent(in) :: ir ! reaction_id
662 : real(dp), intent(in) :: temp, den
663 : real(dp), intent(inout) :: rate_raw(:), reverse_rate_raw(:)
664 : integer, intent(out) :: ierr
665 :
666 : real(dp) :: lambda, dlambda_dlnT, rlambda, drlambda_dlnT
667 :
668 : include 'formats'
669 :
670 : ierr = 0
671 : call get_reaclib_rate_and_dlnT( &
672 0 : ir, temp, lambda, dlambda_dlnT, rlambda, drlambda_dlnT, ierr)
673 0 : if (ierr /= 0) return
674 :
675 0 : if (reaction_ye_rho_exponents(2,ir) /= 1) then
676 0 : ierr = -1
677 0 : return
678 : end if
679 :
680 0 : rate_raw(i_rate) = lambda*den
681 0 : rate_raw(i_rate_dT) = dlambda_dlnT*den/temp
682 0 : rate_raw(i_rate_dRho) = lambda
683 :
684 0 : reverse_rate_raw(i_rate) = rlambda*den
685 0 : reverse_rate_raw(i_rate_dT) = drlambda_dlnT*den/temp
686 0 : reverse_rate_raw(i_rate_dRho) = rlambda
687 :
688 0 : return
689 :
690 : !$omp critical (rates_eval_reaclib_22)
691 : write(*,1) 'do_eval_reaclib_22 ' // trim(reaction_Name(ir))
692 : write(*,'(A)')
693 : write(*,1) 'den', den
694 : write(*,1) 'temp', temp
695 : write(*,'(A)')
696 : write(*,1) 'lambda', lambda
697 : write(*,1) 'dlambda_dlnT', dlambda_dlnT
698 : write(*,1) 'rate_raw', rate_raw(1:num_rvs)
699 : write(*,'(A)')
700 : write(*,1) 'rlambda', rlambda
701 : write(*,1) 'drlambda_dlnT', drlambda_dlnT
702 : write(*,1) 'reverse_rate_raw', reverse_rate_raw(1:num_rvs)
703 : write(*,'(A)')
704 : !call mesa_error(__FILE__,__LINE__,'do_eval_reaclib_22')
705 : !$omp end critical (rates_eval_reaclib_22)
706 :
707 : end subroutine do_eval_reaclib_22
708 :
709 :
710 : end module rates_support
711 :
|