-
Notifications
You must be signed in to change notification settings - Fork 12
/
global_sums.f90
executable file
·762 lines (601 loc) · 35.1 KB
/
global_sums.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
!begin rubric
!****************************************************************************** *
!* Original Author: Mark Gilbert *
!* copyright, 2015 (first version), 2018 (first git repository), UKAEA *
!******************************************************************************
!end rubric
SUBROUTINE add_to_globals(input_pka,recoil_points,tdam_vector,energy_vector)
use globals
IMPLICIT NONE
INTEGER, INTENT (in) :: recoil_points
REAL (KIND=DBL), INTENT(in) :: input_pka(recoil_points)
REAL (KIND=DBL), INTENT(in) :: tdam_vector(recoil_points),energy_vector(recoil_points)
REAL (KIND=DBL), ALLOCATABLE :: tdam_pka_temp(:),pka_temp(:)
LOGICAL :: found
INTEGER :: ii,jj !ii stores isotope position, jj the element position
ii=1
found=.false.
DO WHILE ((ii.LE.number_global_recoils).AND.(.not.found))
IF((daughter_num==global_daughter_nums(ii)).AND. &
(TRIM(ADJUSTL(daughter_ele))==TRIM(ADJUSTL(global_daughter_eles(ii))))) THEN
found=.true.
ELSE
ii=ii+1
END IF
END DO
jj=1
found=.false.
DO WHILE ((jj.LE.number_global_recoil_elements).AND.(.not.found))
IF((TRIM(ADJUSTL(daughter_ele))==TRIM(ADJUSTL(global_elements(jj))))) THEN
found=.true.
ELSE
jj=jj+1
END IF
END DO
IF(ii.GT.number_global_recoils) THEN
number_global_recoils=ii
IF(number_global_recoils.GT.max_global_recoils) THEN
PRINT *,'max number of global nuclide recoils exceeded!'
PRINT *,' increase max_global_recoils - STOP'
WRITE(log_unit,*) 'max number of global nuclide recoils exceeded!'
WRITE(log_unit,*) ' increase max_global_recoils - STOP'
STOP
END IF
global_daughter_eles(ii)=daughter_ele
global_daughter_nums(ii)=daughter_num
IF(do_outputs) WRITE(log_unit,*) 'number global nuclide recoils: ',number_global_recoils,TRIM(ADJUSTL(daughter_ele))
END IF
IF(jj.GT.number_global_recoil_elements) THEN
number_global_recoil_elements=jj
IF(number_global_recoil_elements.GT.max_global_recoils) THEN
WRITE(log_unit,*) 'max number of global recoil elements exceeded- STOP'
STOP
END IF
global_elements(jj)=daughter_ele
WRITE(log_unit,*) 'number global element recoils: ',number_global_recoils
END IF
IF(do_outputs) WRITE(log_unit,*) daughter_ele,daughter_num,'adding to globals'
!24/4/2018 changes to allow for user output grid for sums and globals
! also removes error check for mis-matched grids - now we can just proceed and flag
IF(recoil_points.NE.global_num_pka_recoil_points_master) THEN
! 24/4/2018 allow for possibility of different grid and flag if do_user_output_energy_grid is false
IF ((.NOT.do_user_output_energy_grid).OR.(do_user_output_energy_grid.AND.(user_grid_option==3))) THEN
WRITE(log_unit,*) 'grid of recoil energies do not match global energy grid during summing'
WRITE(log_unit,*) 'interpolation will be used to collapse the current grid onto the global one'
END IF
END IF
ALLOCATE(pka_temp(MAX(global_num_pka_recoil_points_master,recoil_points)))
pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
IF(do_outputs) WRITE(log_unit,*) 'global sum allocate done',size(pka_recoil_energies), &
size(global_pka_recoil_energies_master),recoil_points,global_num_pka_recoil_points_master, &
size(pka_temp)
CALL collapse_fluxes(pka_temp, &
recoil_points,&
global_num_pka_recoil_points_master,&
global_pka_recoil_energies_master,&
energy_vector)
IF(do_outputs) WRITE(log_unit,*) 'global sum flux collapse done'
global_pka_sums(ii,:)=global_pka_sums(ii,:)+pka_temp(1:global_num_pka_recoil_points_master)
global_pka_sums_element(jj,:)=global_pka_sums_element(jj,:)+pka_temp(1:global_num_pka_recoil_points_master)
IF(do_tdam) THEN
global_disp_sums(ii)=global_disp_sums(ii)+displacements*pka_ratios(filenum)
global_disp_sums_element(jj)=global_disp_sums_element(jj)+displacements*pka_ratios(filenum)
! 29/6/2016 collapse pka rates onto global tdam energy spectrum using tdam energy spectrum for
! current channel
!24/4/2018 - this was wrong before - the grids could be different now
ALLOCATE(tdam_pka_temp(MAX(global_num_pka_recoil_points_master,recoil_points)))
tdam_pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
CALL collapse_fluxes(tdam_pka_temp, &
recoil_points,&
global_num_pka_recoil_points_master,&
global_tdam_energies_master,&
tdam_vector)
global_pka_sums_tdam(ii,:)=global_pka_sums_tdam(ii,:)+&
tdam_pka_temp(1:global_num_pka_recoil_points_master)
global_pka_sums_element_tdam(jj,:)=global_pka_sums_element_tdam(jj,:)+&
tdam_pka_temp(1:global_num_pka_recoil_points_master)
END IF
!20/5/2014 - add to total recoil spectra
IF((do_exclude_light_from_total).AND.&
((TRIM(ADJUSTL(daughter_ele))=='He').OR.(TRIM(ADJUSTL(daughter_ele))=='H'))) THEN
WRITE(log_unit,*) 'omitting gas particle from total pkas'
!total_pka_sum(:)=total_pka_sum(:)+input_pka(:)*pka_ratios(filenum)
ELSE IF((do_exclude_unknown_from_total).AND.&
(TRIM(ADJUSTL(daughter_ele))=='unknown')) THEN
WRITE(log_unit,*) 'omitting unknown daughter from total pkas'
ELSE
!24/4/2018 - handling of user_grid_option
IF(do_user_output_energy_grid.AND.(user_grid_option==3)) THEN
IF(do_tdam) DEALLOCATE(tdam_pka_temp)
DEALLOCATE(pka_temp)
ALLOCATE(pka_temp(MAX(totalglobal_num_pka_recoil_points_master,recoil_points)))
pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
IF(do_outputs) WRITE(log_unit,*) SUM(pka_temp(1:recoil_points)), &
SUM(totalglobal_pka_recoil_energies_master),SUM(energy_vector)
CALL collapse_fluxes(pka_temp, &
recoil_points,&
totalglobal_num_pka_recoil_points_master,&
totalglobal_pka_recoil_energies_master,&
energy_vector)
IF(do_outputs) WRITE(log_unit,*) SUM(pka_temp(1:totalglobal_num_pka_recoil_points_master))
IF(do_tdam) THEN
! 24/4/2018 - assume tdam totalglobal matrix is same as totalglobal pka energy matrix
ALLOCATE(tdam_pka_temp(MAX(totalglobal_num_pka_recoil_points_master,recoil_points)))
tdam_pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
CALL collapse_fluxes(tdam_pka_temp, &
recoil_points,&
totalglobal_num_pka_recoil_points_master,&
totalglobal_pka_recoil_energies_master,&
tdam_vector)
END IF
END IF
! 24/4/2018 - need to compute tdam_pka_temp, pka_temp, etc seperately
total_pka_sum(:)=total_pka_sum(:)+pka_temp(1:totalglobal_num_pka_recoil_points_master)
IF(do_tdam) THEN
total_disp=total_disp+displacements*pka_ratios(filenum)
! 29/6/2016 collapse pka rates onto global tdam energy spectrum using tdam energy spectrum for
! current channel
total_pka_sum_tdam=total_pka_sum_tdam+&
tdam_pka_temp(1:totalglobal_num_pka_recoil_points_master)
END IF !do_tdam
END IF
IF(do_tdam) DEALLOCATE(tdam_pka_temp)
DEALLOCATE(pka_temp)
END SUBROUTINE add_to_globals
SUBROUTINE output_global_sums()
use globals
IMPLICIT NONE
INTEGER, allocatable :: order(:),positions(:)
LOGICAL :: found
CHARACTER (LEN=100) :: fmt1='(ES14.6,2x,ES14.6,4(3x,ES11.4),3x,ES11.4,5x,ES11.4)'
CHARACTER (LEN=100) :: fmt2='(1x,a31,a8,6x,a11,3x,a15,a11,a19,a11)'
CHARACTER (LEN=100) :: fmt3='(1x,a31,a8,6x,a11,3x,a15)'
REAL (KIND=DBL) :: energy_min
DO i=1,number_global_recoils
IF(sum(global_pka_sums(i,1:global_num_pka_recoil_points_master)).NE.0) THEN
WRITE(results_unit,*) '### index ',file_index,' ##### ( totals )'
WRITE(number_string,'(I5)') global_daughter_nums(i)
WRITE(results_unit,*) '# recoil matrix of '//TRIM(ADJUSTL(global_daughter_eles(i))) &
//TRIM(ADJUSTL(number_string))
WRITE(index_summary,*) file_index,' recoil matrix of '//TRIM(ADJUSTL(global_daughter_eles(i))) &
//TRIM(ADJUSTL(number_string))
! WRITE(results_unit,*) '#DIFF SPEC AVG. PKA RECOIL DISTRIBUTIONS - per target atom'
WRITE(results_unit,*) '#PKA RECOIL DISTRIBUTIONS - per target atom'
!23/4/2018 - new lower bin bound for first bin -
! if using user grid then set to zero - otherwise half of lowest bin bound.
IF(do_user_output_energy_grid) THEN
energy_min=0_DBL
ELSE
energy_min=global_pka_recoil_energies_master(1)/2._DBL
END IF
IF (do_tdam) THEN
WRITE(results_unit,fmt2) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum',&
'cumulative_sum','tdam-pkas','disp_energy_(eV/s)','NRT_dpa/s'
WRITE(results_unit,'(1x,a30)') '#(or T-dam energy low+high for'
WRITE(results_unit,'(1x,a30)') '# tdam-pkas/disp/dpa)'
j=1
IF((global_pka_sums(i,j).NE.0).or.(global_pka_sums_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
energy_min,global_pka_recoil_energies_master(j), &
global_pka_sums(i,j), &
global_pka_sums(i,j)/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums(i,1:j))/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
global_pka_sums_tdam(i,j), &
(global_pka_sums_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL), &
(global_pka_sums_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL)
DO j=2,global_num_pka_recoil_points_master
IF((global_pka_sums(i,j).NE.0).or.(global_pka_sums_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_pka_sums(i,j), &
global_pka_sums(i,j)/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums(i,1:j))/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
global_pka_sums_tdam(i,j), &
(global_pka_sums_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL), &
(global_pka_sums_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL)
END DO
ELSE
WRITE(results_unit,fmt3) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum','cumulative sum'
j=1
IF(global_pka_sums(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
energy_min,global_pka_recoil_energies_master(j), &
global_pka_sums(i,j), &
global_pka_sums(i,j)/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums(i,1:j))/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master))
DO j=2,global_num_pka_recoil_points_master
IF(global_pka_sums(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_pka_sums(i,j), &
global_pka_sums(i,j)/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums(i,1:j))/SUM(global_pka_sums(i,1:global_num_pka_recoil_points_master))
END DO
END IF !do_tdam
! compute average pka energy
pka_ave=0.5_DBL*(energy_min+global_pka_recoil_energies_master(1))*global_pka_sums(i,1)
DO j=2,global_num_pka_recoil_points_master
pka_ave=pka_ave+0.5_DBL*(global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))*global_pka_sums(i,j)
END DO
pka_ave=pka_ave*1000000._DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A5)') '#','AVERAGE PKA ENERGY = ',pka_ave/SUM(global_pka_sums(i,:)),' (eV)'
IF (do_tdam) then
WRITE(results_unit,'(a1,20x,A,ES11.4)') '#',&
'displacement energy eV/s = ',global_disp_sums(i)*1e6_DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A7,F4.1,a)') '#','equivalent NRT dpa/s = ',&
0.8_DBL*global_disp_sums(i)/(2._DBL*assumed_ed*1e-6_DBL),&
' (E_d=',assumed_ed,' eV)'
END IF
WRITE(results_unit,*)
WRITE(results_unit,*)
file_index=file_index+1
END IF !non zero check
END DO ! loop over global recoils
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!10/10/2013 - and per element sums
!define order based on position in master_elements
ALLOCATE(order(number_global_recoil_elements),positions(number_global_recoil_elements))
order=0
! define element position in list of elements
DO i=1,number_global_recoil_elements
positions(i)=1
found=.false.
DO WHILE ((.not.found).AND.(positions(i).LE.num_master_elements))
IF(TRIM(ADJUSTL(global_elements(i)))==TRIM(ADJUSTL(master_elements(positions(i)))) ) THEN
found=.true.
ELSE
positions(i)=positions(i)+1
END IF
END DO
END DO
DO i=1,number_global_recoil_elements
j=minloc(positions(1:number_global_recoil_elements),1)
order(i)=j
positions(j)=num_master_elements*10
!PRINT *,order(i)
END DO
DO k=1,number_global_recoil_elements
i=order(k)
IF(sum(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)).NE.0) THEN
WRITE(results_unit,*) '### index ',file_index,' ##### ( totals )'
WRITE(results_unit,*) '# elemental recoil matrix of '//TRIM(ADJUSTL(global_elements(i)))
WRITE(index_summary,*) file_index,' elemental recoil matrix of '//TRIM(ADJUSTL(global_elements(i)))
! WRITE(results_unit,*) '#DIFF SPEC AVG. PKA RECOIL DISTRIBUTIONS - per target atom'
WRITE(results_unit,*) '#PKA RECOIL DISTRIBUTIONS - per target atom'
IF(do_tdam) THEN
WRITE(results_unit,fmt2) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum',&
'cumulative_sum','tdam-pkas','disp_energy_(eV/s)','NRT_dpa/s'
WRITE(results_unit,'(1x,a30)') '#(or T-dam energy low+high for'
WRITE(results_unit,'(1x,a30)') '# tdam-pkas/disp/dpa)'
j=1
IF((global_pka_sums_element(i,j).NE.0).or.(global_pka_sums_element_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
energy_min,global_pka_recoil_energies_master(j), &
global_pka_sums_element(i,j), &
global_pka_sums_element(i,j)/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums_element(i,1:j))/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
global_pka_sums_element_tdam(i,j), &
(global_pka_sums_element_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL), &
(global_pka_sums_element_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL)
DO j=2,global_num_pka_recoil_points_master
IF((global_pka_sums_element(i,j).NE.0).or.(global_pka_sums_element_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_pka_sums_element(i,j), &
global_pka_sums_element(i,j)/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums_element(i,1:j))/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
global_pka_sums_element_tdam(i,j), &
(global_pka_sums_element_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL), &
(global_pka_sums_element_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL)
END DO
ELSE
WRITE(results_unit,fmt3) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum','cumulative sum'
j=1
IF(global_pka_sums_element(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
energy_min,global_pka_recoil_energies_master(j), &
global_pka_sums_element(i,j), &
global_pka_sums_element(i,j)/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums_element(i,1:j))/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master))
DO j=2,global_num_pka_recoil_points_master
IF(global_pka_sums_element(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_pka_sums_element(i,j), &
global_pka_sums_element(i,j)/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master)), &
SUM(global_pka_sums_element(i,1:j))/SUM(global_pka_sums_element(i,1:global_num_pka_recoil_points_master))
END DO
END IF
! compute average pka energy
pka_ave=0.5_DBL*(energy_min+global_pka_recoil_energies_master(1))*global_pka_sums_element(i,1)
DO j=2,global_num_pka_recoil_points_master
pka_ave=pka_ave+0.5_DBL*(global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))*global_pka_sums_element(i,j)
END DO
pka_ave=pka_ave*1000000._DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A5)') '#','AVERAGE PKA ENERGY = ',pka_ave/SUM(global_pka_sums_element(i,:)),' (eV)'
IF (do_tdam) then
WRITE(results_unit,'(a1,20x,A,ES11.4)') '#',&
'displacement energy eV/s = ',global_disp_sums_element(i)*1e6_DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A7,F4.1,a)') '#','equivalent NRT dpa/s = ',&
0.8_DBL*global_disp_sums_element(i)/(2._DBL*assumed_ed*1e-6_DBL),&
' (E_d=',assumed_ed,' eV)'
END IF
WRITE(results_unit,*)
WRITE(results_unit,*)
file_index=file_index+1
END IF !non zero check
END DO ! loop over global recoils
DEALLOCATE(order,positions)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 20/5/2014
!total recoil spectrum
!23/4/2018 - new lower bin bound for first bin -
! if using user grid then set to zero - otherwise half of lowest bin bound.
IF(do_user_output_energy_grid) THEN
energy_min=0_DBL
ELSE
energy_min=totalglobal_pka_recoil_energies_master(1)/2._DBL
END IF
IF(do_outputs) WRITE(log_unit,*) 'total sum',SIZE(total_pka_sum),totalglobal_num_pka_recoil_points_master, &
sum(total_pka_sum(1:totalglobal_num_pka_recoil_points_master))
!IF(sum(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)).NE.0) THEN
WRITE(results_unit,*) '### index ',file_index,' ##### ( totals )'
IF((do_exclude_light_from_total).AND.(do_exclude_unknown_from_total)) THEN
WRITE(results_unit,*) '# total recoil matrix (He+H+unknowns excluded)'
WRITE(index_summary,*) file_index,' total recoil matrix (He+H+unknowns excluded)'
ELSE IF (do_exclude_light_from_total) THEN
WRITE(results_unit,*) '# total recoil matrix (He+H excluded)'
WRITE(index_summary,*) file_index,' total recoil matrix (He+H excluded)'
ELSE IF (do_exclude_unknown_from_total) THEN
WRITE(results_unit,*) '# total recoil matrix (unknowns excluded)'
WRITE(index_summary,*) file_index,' total recoil matrix (unknowns excluded)'
ELSE
WRITE(results_unit,*) '# total recoil matrix '
WRITE(index_summary,*) file_index,' total recoil matrix'
END IF
! WRITE(results_unit,*) '#DIFF SPEC AVG. PKA RECOIL DISTRIBUTIONS - per target atom'
WRITE(results_unit,*) '#PKA RECOIL DISTRIBUTIONS - per target atom'
IF(do_tdam) THEN
WRITE(results_unit,fmt2) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum',&
'cumulative_sum','tdam-pkas','disp_energy_(eV/s)','NRT_dpa/s'
WRITE(results_unit,'(1x,a30)') '#(or T-dam energy low+high for'
WRITE(results_unit,'(1x,a30)') '# tdam-pkas/disp/dpa)'
j=1
IF((total_pka_sum(j).NE.0).or.(total_pka_sum_tdam(j).NE.0)) &
WRITE(results_unit,fmt1) &
energy_min,totalglobal_pka_recoil_energies_master(j), &
total_pka_sum(j), &
total_pka_sum(j)/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)) , &
SUM(total_pka_sum(1:j))/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)), &
total_pka_sum_tdam(j), &
(total_pka_sum_tdam(j))*1e6_DBL*((totalglobal_pka_recoil_energies_master(j)+&
totalglobal_pka_recoil_energies_master(j)/2._DBL)/2._DBL), &
(total_pka_sum_tdam(j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((totalglobal_pka_recoil_energies_master(j)+&
totalglobal_pka_recoil_energies_master(j)/2._DBL)/2._DBL)
DO j=2,totalglobal_num_pka_recoil_points_master
IF((total_pka_sum(j).NE.0).or.(total_pka_sum_tdam(j).NE.0)) &
WRITE(results_unit,fmt1) &
totalglobal_pka_recoil_energies_master(j-1),totalglobal_pka_recoil_energies_master(j), &
total_pka_sum(j), &
total_pka_sum(j)/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)), &
SUM(total_pka_sum(1:j))/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)), &
total_pka_sum_tdam(j), &
(total_pka_sum_tdam(j))*1e6_DBL*((totalglobal_pka_recoil_energies_master(j)+&
totalglobal_pka_recoil_energies_master(j-1))/2._DBL), &
(total_pka_sum_tdam(j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((totalglobal_pka_recoil_energies_master(j)+&
totalglobal_pka_recoil_energies_master(j-1))/2._DBL)
END DO
ELSE
WRITE(results_unit,fmt3) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum','cumulative sum'
j=1
IF(total_pka_sum(j).NE.0) WRITE(results_unit,'(5ES11.4)') &
energy_min,totalglobal_pka_recoil_energies_master(j), &
total_pka_sum(j), &
total_pka_sum(j)/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)) , &
SUM(total_pka_sum(1:j))/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master))
DO j=2,totalglobal_num_pka_recoil_points_master
IF(total_pka_sum(j).NE.0) WRITE(results_unit,'(5ES11.4)') &
totalglobal_pka_recoil_energies_master(j-1),totalglobal_pka_recoil_energies_master(j), &
total_pka_sum(j), &
total_pka_sum(j)/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master)), &
SUM(total_pka_sum(1:j))/SUM(total_pka_sum(1:totalglobal_num_pka_recoil_points_master))
END DO
END IF
! compute average pka energy
pka_ave=0.5_DBL*(energy_min+totalglobal_pka_recoil_energies_master(1))*total_pka_sum(1)
DO j=2,totalglobal_num_pka_recoil_points_master
pka_ave=pka_ave+0.5_DBL*(totalglobal_pka_recoil_energies_master(j)+&
totalglobal_pka_recoil_energies_master(j-1))*total_pka_sum(j)
END DO
pka_ave=pka_ave*1000000._DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A5)') '#','AVERAGE PKA ENERGY = ',pka_ave/SUM(total_pka_sum(:)),' (eV)'
IF (do_tdam) then
WRITE(results_unit,'(a1,20x,A,ES11.4)') '#',&
'displacement energy eV/s = ',total_disp*1e6_DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A7,F4.1,a)') '#','equivalent NRT dpa/s = ',&
0.8_DBL*total_disp/(2._DBL*assumed_ed*1e-6_DBL),&
' (E_d=',assumed_ed,' eV)'
END IF
WRITE(results_unit,*)
WRITE(results_unit,*)
file_index=file_index+1
!END IF !non zero check
END SUBROUTINE output_global_sums
SUBROUTINE add_to_mt_globals(input_pka,recoil_points,tdam_vector,energy_vector)
use globals
IMPLICIT NONE
INTEGER, INTENT (in) :: recoil_points
REAL (KIND=DBL), INTENT(in) :: input_pka(recoil_points)
REAL (KIND=DBL), INTENT(in) :: tdam_vector(recoil_points),energy_vector(recoil_points)
REAL (KIND=DBL), ALLOCATABLE :: tdam_pka_temp(:),pka_temp(:)
LOGICAL :: found
INTEGER :: ii,jj !ii stores isotope position, jj the element position
ii=1
found=.false.
DO WHILE ((ii.LE.number_global_mt_recoils).AND.(.not.found))
IF(mtd==global_mt_nums(ii)) THEN
found=.true.
ELSE
ii=ii+1
END IF
END DO
IF(ii.GT.number_global_mt_recoils) THEN
number_global_mt_recoils=ii
IF(number_global_mt_recoils.GT.max_global_recoils) THEN
PRINT *,'max number of global mt recoils exceeded!'
PRINT *,' increase max_global_recoils - STOP'
WRITE(log_unit,*) 'max number of global mt recoils exceeded!'
WRITE(log_unit,*) ' increase max_global_recoils - STOP'
STOP
END IF
global_mt_nums(ii)=mtd
IF(do_outputs) WRITE(log_unit,*) 'number global mt recoils: ',number_global_mt_recoils,mtd
END IF
IF(do_outputs) WRITE(log_unit,*) mtd,'adding to globals'
!24/4/2018 changes to allow for user output grid for sums and globals
! also removes error check for mis-matched grids - now we can just proceed and flag
IF(recoil_points.NE.global_num_pka_recoil_points_master) THEN
! 24/4/2018 allow for possibility of different grid and flag if do_user_output_energy_grid is false
IF ((.NOT.do_user_output_energy_grid).OR.(do_user_output_energy_grid.AND.(user_grid_option==3))) THEN
WRITE(log_unit,*) 'grid of recoil energies do not match global energy grid during summing'
WRITE(log_unit,*) 'interpolation will be used to collapse the current grid onto the global one'
END IF
END IF
ALLOCATE(pka_temp(MAX(global_num_pka_recoil_points_master,recoil_points)))
pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
IF(do_outputs) WRITE(log_unit,*) 'global sum allocate done',size(pka_recoil_energies), &
size(global_pka_recoil_energies_master),recoil_points,global_num_pka_recoil_points_master, &
size(pka_temp)
CALL collapse_fluxes(pka_temp, &
recoil_points,&
global_num_pka_recoil_points_master,&
global_pka_recoil_energies_master,&
energy_vector)
IF(do_outputs) WRITE(log_unit,*) 'global sum flux collapse done'
global_mt_pka_sums(ii,:)=global_mt_pka_sums(ii,:)+pka_temp(1:global_num_pka_recoil_points_master)
IF(do_tdam) THEN
global_mt_disp_sums(ii)=global_mt_disp_sums(ii)+displacements*pka_ratios(filenum)
! 29/6/2016 collapse pka rates onto global tdam energy spectrum using tdam energy spectrum for
! current channel
!24/4/2018 - this was wrong before - the grids could be different now
ALLOCATE(tdam_pka_temp(MAX(global_num_pka_recoil_points_master,recoil_points)))
tdam_pka_temp(1:recoil_points)=input_pka(:)*pka_ratios(filenum)
CALL collapse_fluxes(tdam_pka_temp, &
recoil_points,&
global_num_pka_recoil_points_master,&
global_tdam_energies_master,&
tdam_vector)
global_mt_pka_sums_tdam(ii,:)=global_mt_pka_sums_tdam(ii,:)+&
tdam_pka_temp(1:global_num_pka_recoil_points_master)
END IF
IF(do_tdam) DEALLOCATE(tdam_pka_temp)
DEALLOCATE(pka_temp)
END SUBROUTINE add_to_mt_globals
SUBROUTINE output_global_mt_sums()
use globals
IMPLICIT NONE
INTEGER, allocatable :: order(:),positions(:)
LOGICAL :: found
CHARACTER (LEN=100) :: fmt1='(ES14.6,2x,ES14.6,4(3x,ES11.4),3x,ES11.4,5x,ES11.4)'
CHARACTER (LEN=100) :: fmt2='(1x,a31,a8,6x,a11,3x,a15,a11,a19,a11)'
CHARACTER (LEN=100) :: fmt3='(1x,a31,a8,6x,a11,3x,a15)'
REAL (KIND=DBL) :: energy_min
DO i=1,number_global_mt_recoils
IF(sum(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)).NE.0) THEN
WRITE(results_unit,*) '### index ',file_index,' ##### ( totals )'
WRITE(number_string,'(I5)') global_mt_nums(i)
WRITE(results_unit,*) '# total recoil matrix of mt '// &
TRIM(ADJUSTL(number_string))
WRITE(index_summary,*) file_index,' total recoil matrix of mt '// &
TRIM(ADJUSTL(number_string))
! WRITE(results_unit,*) '#DIFF SPEC AVG. PKA RECOIL DISTRIBUTIONS - per target atom'
WRITE(results_unit,*) '#PKA RECOIL DISTRIBUTIONS - per target atom'
!23/4/2018 - new lower bin bound for first bin -
! if using user grid then set to zero - otherwise half of lowest bin bound.
IF(do_user_output_energy_grid) THEN
energy_min=0_DBL
ELSE
energy_min=global_pka_recoil_energies_master(1)/2._DBL
END IF
IF (do_tdam) THEN
WRITE(results_unit,fmt2) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum',&
'cumulative_sum','tdam-pkas','disp_energy_(eV/s)','NRT_dpa/s'
WRITE(results_unit,'(1x,a30)') '#(or T-dam energy low+high for'
WRITE(results_unit,'(1x,a30)') '# tdam-pkas/disp/dpa)'
j=1
IF((global_mt_pka_sums(i,j).NE.0).or.(global_mt_pka_sums_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
energy_min,global_pka_recoil_energies_master(j), &
global_mt_pka_sums(i,j), &
global_mt_pka_sums(i,j)/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_mt_pka_sums(i,1:j))/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
global_mt_pka_sums_tdam(i,j), &
(global_mt_pka_sums_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL), &
(global_mt_pka_sums_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j)/2._DBL)/2._DBL)
DO j=2,global_num_pka_recoil_points_master
IF((global_mt_pka_sums(i,j).NE.0).or.(global_mt_pka_sums_tdam(i,j).NE.0)) &
WRITE(results_unit,fmt1) &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_mt_pka_sums(i,j), &
global_mt_pka_sums(i,j)/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_mt_pka_sums(i,1:j))/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
global_mt_pka_sums_tdam(i,j), &
(global_mt_pka_sums_tdam(i,j))*1e6_DBL*((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL), &
(global_mt_pka_sums_tdam(i,j))*1e6_DBL*(0.8_DBL/(2._DBL*assumed_ed))*&
((global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))/2._DBL)
END DO
ELSE
WRITE(results_unit,fmt3) '#RECOIL energy (MeV low & high)','PKAs/s','norm_sum','cumulative sum'
j=1
IF(global_mt_pka_sums(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
energy_min,global_pka_recoil_energies_master(j), &
global_mt_pka_sums(i,j), &
global_mt_pka_sums(i,j)/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_mt_pka_sums(i,1:j))/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master))
DO j=2,global_num_pka_recoil_points_master
IF(global_mt_pka_sums(i,j).NE.0) WRITE(results_unit,'(5ES11.4)') &
global_pka_recoil_energies_master(j-1),global_pka_recoil_energies_master(j), &
global_mt_pka_sums(i,j), &
global_mt_pka_sums(i,j)/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master)), &
SUM(global_mt_pka_sums(i,1:j))/SUM(global_mt_pka_sums(i,1:global_num_pka_recoil_points_master))
END DO
END IF !do_tdam
! compute average pka energy
pka_ave=0.5_DBL*(energy_min+global_pka_recoil_energies_master(1))*global_mt_pka_sums(i,1)
DO j=2,global_num_pka_recoil_points_master
pka_ave=pka_ave+0.5_DBL*(global_pka_recoil_energies_master(j)+&
global_pka_recoil_energies_master(j-1))*global_mt_pka_sums(i,j)
END DO
pka_ave=pka_ave*1000000._DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A5)') '#','AVERAGE PKA ENERGY = ',pka_ave/SUM(global_mt_pka_sums(i,:)),' (eV)'
IF (do_tdam) then
WRITE(results_unit,'(a1,20x,A,ES11.4)') '#',&
'displacement energy eV/s = ',global_mt_disp_sums(i)*1e6_DBL
WRITE(results_unit,'(a1,20x,A,ES11.4,A7,F4.1,a)') '#','equivalent NRT dpa/s = ',&
0.8_DBL*global_mt_disp_sums(i)/(2._DBL*assumed_ed*1e-6_DBL),&
' (E_d=',assumed_ed,' eV)'
END IF
WRITE(results_unit,*)
WRITE(results_unit,*)
file_index=file_index+1
END IF !non zero check
END DO ! loop over global recoils
END SUBROUTINE output_global_mt_sums