forked from TAMU-CLASS/barnfire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadgroupr.py
executable file
·2510 lines (2405 loc) · 119 KB
/
Readgroupr.py
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python
'''
Andrew Till
Summer 2014
Read in a GROUPR file from NJOY and store in a useful data structure.
See Readgroupr_readme.py for more information.
TODO: Find way to sneak in (3,457) and (3,458) into inputDict
TODO: Add depletion print option, or more generally, allow a list of mt numbers to be printed
TODO: Renormalize MT 2 with the thermal cross section
'''
#STDLIB
import os
import sys
import cPickle as pickle
#import cProfile as profile
from datetime import datetime
#TPL
import numpy as np
from scipy import sparse
#MINE
def execute_reader(inputDict):
if 'finishedParsing' not in inputDict:
raise ValueError('Invalid inputDict specified. Be sure to call finish_parsing(inputDict).')
verbosity = inputDict['verbosity']
#
inDirr = inputDict['inputdir']
gendfFilename = inputDict['inname']
filePathIn = os.path.join(inDirr, gendfFilename)
#
outDirr = inputDict['outputdir']
pdtXSName = inputDict['outname']
pdtXSPath = os.path.join(outDirr, pdtXSName)
pickleName = inputDict['picklename']
if pickleName.lower() == 'none':
picklePath = None
else:
picklePath = os.path.join(outDirr, pickleName)
#
mtsForMF3 = inputDict['mf3list']
mtsForMF5 = inputDict['mf5list']
mtsForMF6 = inputDict['mf6list']
#thermalMTs = [241, 242]
#thermalMTs = [221]
#thermalMTs = []
#thermalMTs = [239, 240]
#thermalMTs = [222]
thermalMTs = inputDict['thermallist']
#
desiredT = inputDict['temperature']
desiredSig0 = inputDict['sig0']
if inputDict['sig0Vec'] is not None:
desiredSig0 = inputDict['sig0Vec']
#
flux = inputDict['flux']
energyMesh = inputDict['energyMesh']
doCondensation = False
# TODO: Generalize in a smart way if flux is not specified
if flux is not None and energyMesh is not None:
doCondensation = True
#
format = inputDict['format']
whichXS = inputDict['printopt']
#
workOpt = inputDict['workopt']
outputDict = {}
if workOpt == 'gendf':
xsData = read_xs(filePathIn, mtsForMF3, mtsForMF5, mtsForMF6, verbosity)
if picklePath is not None:
pickle_xs(xsData, picklePath)
if doCondensation:
xsData = condense_xs(xsData, energyMesh, flux, verbosity)
interpolate_T_sig0_xs(xsData, desiredT, desiredSig0, outputDict, verbosity)
if whichXS != 'none':
combine_transfer_matrix(xsData, thermalMTs)
convert_to_scipy_sparse_scat_matrix(xsData, format)
write_pdt_xs(pdtXSPath, xsData, desiredT, format, whichXS)
print_xs_summary(filePathIn, xsData, verbosity)
elif workOpt == 'pickle':
xsData = unpickle_xs(picklePath)
if doCondensation:
xsData = condense_xs(xsData, energyMesh, flux, verbosity)
interpolate_T_sig0_xs(xsData, desiredT, desiredSig0, outputDict, verbosity)
if whichXS != 'none':
combine_transfer_matrix(xsData, thermalMTs)
convert_to_scipy_sparse_scat_matrix(xsData, format)
write_pdt_xs(pdtXSPath, xsData, desiredT, format, whichXS)
print_xs_summary(filePathIn, xsData, verbosity)
elif workOpt == 'rxn':
get_reaction_list(filePathIn, verbosity)
elif workOpt == 'scat':
get_scattering_sizes(filePathIn, verbosity)
elif workOpt == 'pen':
get_pointwise_xs(filePathIn, mtsForMF3, desiredT, outputDict, verbosity)
elif workOpt == 'pot':
get_pot_scat_xs(filePathIn, outputDict, verbosity)
elif workOpt == 'decay':
get_decay_parameters(filePathIn, outputDict, verbosity)
elif workOpt == 'meta':
get_metastable_branching_ratios(filePathIn, outputDict, verbosity)
elif workOpt == 'fp':
get_fission_product_yields(filePathIn, outputDict, verbosity)
elif workOpt == 'qvalue':
get_reaction_Q_values(filePathIn, mtsForMF3, outputDict, verbosity)
return outputDict
####################################################################################
def read_xs(filePath, desiredMTsForMF3, desiredMTsForMF5, desiredMTsForMF6, verbosity):
'''Read desired xs and transfer matrices from GROUPR file with handle fid'''
data = {}
# Loop through entire file once to figure out temperatures and reactions
mfmtsAvail, numGroups, numLegMoments, thermList, numSig0 = get_reaction_list(filePath, verbosity)
# Keep intersection of what you desire and what is available
mfmtsKeep = determine_rxns_to_keep(desiredMTsForMF3, desiredMTsForMF5, desiredMTsForMF6, mfmtsAvail, verbosity)
# Initialize data structure, which houses everything.
populate_data_dict(data, mfmtsKeep, numGroups, numLegMoments, thermList, numSig0)
# Go through file and store reactions in mfmtsKeep
with open(filePath, 'r') as fid:
line = get_next_line(fid)
line = get_next_line(fid)
while line != '':
mf, mt, lineNum = get_mf_mt_lineNum(line)
if not (is_continue(mf, mt, lineNum)):
# Read header
xsDict = {}
read_xs_header(line, xsDict)
if (mf == 1) and (mt == 451):
# Read new temperature
eBdrDict = {}
read_group_bdr_header(line, eBdrDict)
read_group_bdr_body(fid, eBdrDict)
merge_data_ebdrdict(data, eBdrDict)
line = get_next_line(fid)
line = get_next_line(fid)
elif (mf, mt) in mfmtsKeep:
if mf == 3:
# Read new xs
read_xs_vector_body(fid, xsDict, verbosity)
merge_data_xs_vector(data, xsDict)
line = get_next_line(fid)
elif (mf, mt) == (6, 18):
# Read prompt fission transfer matrices, which are special
read_prompt_fission_matrix_body(fid, xsDict, verbosity)
merge_data_prompt_fission_matrix(data, xsDict)
line = get_next_line(fid)
elif (mf, mt) == (5, 455):
# Read delayed fission chi, nu, lambda (decay constant)
read_delayed_fission_spectrum(fid, xsDict, verbosity)
merge_data_delayed_fission_xs(data, xsDict)
line = get_next_line(fid)
key = 2055
elif mf == 6:
# Read non-fission matrix
read_xs_matrix_body(fid, xsDict, verbosity)
#if mt == 2:
# profile.runctx('read_xs_matrix_body(fid, xsDict, verbosity)', globals(), locals())
#else:
# read_xs_matrix_body(fid, xsDict, verbosity)
merge_data_xs_matrix(data, xsDict)
line = get_next_line(fid)
key = get_pdt_mt(mf, mt)
else:
line = seek_to_next_useful_entry(fid, mf, mt, verbosity)
else:
# Skip reaction
line = seek_to_next_useful_entry(fid, mf, mt, verbosity)
unify_scattering_sparsity_patterns(data)
return data
####################################################################################
def populate_data_dict(data, mfmtsSet, numGroups, numLegMoments, thermList, numSig0):
'''Populate the data dictionary with sizes and reaction lists. Allocate what you know the size of (xs, flux, csc param; not sparse xfer matrix, fission matrix)'''
numTherm = len(thermList)
data['mfmts'] = mfmtsSet
data['thermList'] = sorted(thermList)
data['numLegMoments'] = numLegMoments
data['numTherm'] = numTherm
data['numSig0'] = numSig0
data['rxn'] = {}
data['flux'] = np.zeros((numTherm, numSig0, numGroups))
for (mf,mt) in mfmtsSet:
actualNumTherm = lookup_num_therm(numTherm, mf, mt)
actualNumSig0 = lookup_num_sig0(numSig0, mf, mt)
data['rxn'][(mf,mt)] = {}
rxn = data['rxn'][(mf,mt)]
rxn['numSig0'] = actualNumSig0
rxn['numTherm'] = actualNumTherm
# Cannot allocate XS for MF 6 here because we don't know the sparsity patterns yet
if mf == 3:
rxn['xs'] = np.zeros((actualNumTherm, actualNumSig0, numGroups))
rxn['numLegMoments'] = 1
elif mf == 5 and mt == 455:
rxn['numLegMoments'] = 6 # Assuming 6 delayed neutron groups
rxn['numDNGs'] = 6
elif mf == 6 and mt == 18:
rxn['numLegMoments'] = 1
rxn['flux'] = np.zeros((actualNumTherm, numGroups))
# rxn['lowEnergySpectrum'] = np.zeros((actualNumTherm, numGroups))
# rxnDict['lowEnergySpectrum'] = xsDict['lowEnergySpectrum'][::-1].copy()
# rxnDict['lowEnergyProd'] = xsDict['lowEnergyProd'][::-1].copy()
# rxnDict['highEnergyMatrix'] = xsDict['highEnergyMatrix'][::-1,::-1].copy()
# rxnDict['highestHighEnergyGroup'] = numGroups - xsDict['lowestHighEnergyGroup'] - 1
# rxnDict['promptChi'] = xsDict['promptChi'][::-1].copy()
# rxnDict['promptProd'] = xsDict['promptProd'][::-1].copy()
rxn['FissionMatrix'] = np.zeros((actualNumTherm, numGroups, numGroups))
elif mf == 6:
#'List' is indexed by temperature
# Cannot set numLegMoments because some transfer matrices have fewer
rxn['xsList'] = []
rxn['rowStartMat'] = np.zeros((actualNumTherm, numGroups), dtype=np.int)
rxn['colSizeMat'] = np.zeros((actualNumTherm, numGroups), dtype=np.int)
rxn['numLegMoments'] = numLegMoments
def merge_data_ebdrdict(data, eBdrDict):
'''Merge eBdrDict into data. Overwrite group boundaries, sigma0 values. Make energy run high to low.'''
data['Z'] = eBdrDict['Z']
data['A'] = eBdrDict['A']
data['weight'] = eBdrDict['weight']
data['numSig0'] = eBdrDict['numSig0']
data['numGroups'] = eBdrDict['numNeutronGroups']
#The following data is copied, not aliased
data['sig0List'] = sorted(eBdrDict['sigma0List'], reverse=True)
data['groupBdrs'] = np.array(eBdrDict['neutronEnergyBdrs'][::-1])
def merge_data_xs_vector(data, xsDict):
'''Merge xsDict into data. Overwrite flux, add to xs of (mf,mt). Make energy run high to low.'''
mf,mt = xsDict['mf'], xsDict['mt']
rxnDict = data['rxn'][(mf,mt)]
#
flux = data['flux']
xs = rxnDict['xs']
thermIndex = 0
if rxnDict['numTherm'] != 1:
thermIndex = data['thermList'].index(xsDict['temperature'])
#The data is copied, not aliased
xs[thermIndex, :, :] = xsDict['xs'][:, ::-1]
if mt == 1:
flux[thermIndex, :, :] = xsDict['flux'][:, ::-1]
#xs and flux are indexed by xs[thermIndex, sig0Index, groupIndex]
def unify_scattering_sparsity_patterns(data):
'''For each reaction, take a union over temperature of the sparsity patterns, because they may be different. Copy the xs into this global sparse format. This will allow for easy interpolation between temperatures later.'''
#
numGroups = data['numGroups']
identityForMin = numGroups
mfmtList = [(mf,mt) for (mf,mt) in data['mfmts'] if (mf == 6 and mt != 18)]
for (mf,mt) in mfmtList:
rxnDict = data['rxn'][(mf,mt)]
numTherm = rxnDict['numTherm']
numSig0 = rxnDict['numSig0']
numLegMoments = rxnDict['numLegMoments']
#
rowStartMat = rxnDict['rowStartMat']
rowStartMat[rowStartMat == -1] = identityForMin
minRowStart = np.min(rowStartMat, axis=0)
rowEndMat = rowStartMat + rxnDict['colSizeMat']
maxRowEnd = np.max(rowEndMat, axis=0)
maxColSize = maxRowEnd - minRowStart
minRowStart, maxColSize = remove_sparse_holes(minRowStart, maxColSize)
minRowStart[minRowStart == identityForMin] = -1
unionIndexPtr = np.zeros(numGroups + 1, dtype=np.int)
unionIndexPtr[1:] = np.cumsum(maxColSize)
xsSize = unionIndexPtr[-1]
rxnDict['xs'] = np.zeros((numTherm, numSig0, numLegMoments, xsSize))
xs = rxnDict['xs']
#
for thermIndex in range(numTherm):
localXS = rxnDict['xsList'][thermIndex]
localColSize = rxnDict['colSizeMat'][thermIndex, :]
localIndexPtr = np.zeros(numGroups+1, dtype=np.int)
localIndexPtr[1:] = np.cumsum(localColSize)
localRowStart = rxnDict['rowStartMat'][thermIndex, :]
for fromGroup in range(numGroups):
localStrt, localEnd = localIndexPtr[fromGroup], localIndexPtr[fromGroup + 1]
unionStrt = unionIndexPtr[fromGroup] + (localRowStart[fromGroup] - minRowStart[fromGroup])
unionEnd = unionStrt + localColSize[fromGroup]
xs[thermIndex, :, :, unionStrt:unionEnd] = localXS[:, :, localStrt:localEnd]
rxnDict['rowStart'] = minRowStart
rxnDict['indexPtr'] = unionIndexPtr
del(rxnDict['xsList'])
del(rxnDict['rowStartMat'])
del(rxnDict['colSizeMat'])
#Scattering from group g may be found via this indexing:
#xs[thermIndex, sig0Index, legIndex, indexPtr[g]:indexPtr[g+1]]
#The groups into which g scatters are:
#rowStart[g]:(rowStart[g]+indexPtr[g+1]-indexPtr[g]-1)
def merge_data_xs_matrix(data, xsDict):
'''Merge xsDict into data. Append new temperatures to the scattering matrix. Make energy run high to low. Because reactions at different temperatures may have different sparsity patterns (e.g., thermal reactions), we store the scattering kernel as a list of CSC matrices, where the list is indexed by temperature.'''
#
mf,mt = xsDict['mf'], xsDict['mt']
rxnDict = data['rxn'][(mf,mt)]
#
numGroups = data['numGroups']
#
# The number of Legendre moments may be truncated due to insufficient data in evaluations
actualNumLegMoments = xsDict['numLegMoments']
numLegMoments = rxnDict['numLegMoments']
#
numSig0 = rxnDict['numSig0']
numTherm = rxnDict['numTherm']
#
high2lowIndexPtr = np.zeros(numGroups+1, dtype=np.int)
high2lowIndexPtr[1:] = np.cumsum(xsDict['colSize'][::-1])
#
# Copy from xs to rxnDict and flip ordering of sparse matrix
xsSize = high2lowIndexPtr[-1]
rxnDict['xsList'].append(np.zeros((numSig0, numLegMoments, xsSize)))
xs = rxnDict['xsList'][-1]
numRows = xsDict['lastRow'] - xsDict['firstRow'] + 1
firstRow = xsDict['firstRow']
for g in range(numRows):
high2LowGroupFrom = numGroups - (g + firstRow) - 1
strt = high2lowIndexPtr[high2LowGroupFrom]
end = high2lowIndexPtr[high2LowGroupFrom + 1]
for legIndex in range(actualNumLegMoments):
for sig0Index in range(numSig0):
# The data is copied, not aliased
# Be careful: the index ordering is different on the left and right
xs[sig0Index, legIndex, strt:end] = xsDict['xs'][g][legIndex, sig0Index, :][::-1]
# Use the full number of Legendre moments for all transfer rxn, even if there is no data.
xs[:, actualNumLegMoments:, :] = 0.
# Each temperature in general has a different sparsity pattern, so store CSC indexing for each
thermIndex = 0
if numTherm !=1:
thermIndex = data['thermList'].index(xsDict['temperature'])
# Copy rowStart to rxnDict and flip ordering
high2lowRowStart = rxnDict['rowStartMat'][thermIndex, :]
# The starting group from high to low is the ending group from low to high
high2lowRowStart[:] = (xsDict['colSize'] + xsDict['rowStart'] - 1)[::-1]
# Flipping order changes the index of a group and we refer directly to indexes with this array
high2lowRowStart[:] = numGroups - high2lowRowStart[:] - 1
unusedRows = (xsDict['rowStart'] == -1)
high2lowRowStart[unusedRows[::-1]] = -1
# Copy colSize to rxnDict and flip ordering
rxnDict['colSizeMat'][thermIndex, :] = xsDict['colSize'][::-1]
def merge_data_prompt_fission_matrix(data, xsDict):
'''Merge xsDict into data. Overwrite fission spectrum, fission matrix, and group where matrix starts'''
mf,mt = xsDict['mf'], xsDict['mt']
rxnDict = data['rxn'][(mf,mt)]
numGroups = data['numGroups']
thermIndex = 0
if rxnDict['numTherm'] != 1:
thermIndex = data['thermList'].index(xsDict['temperature'])
#The data is copied, not aliased
rxnDict['flux'][thermIndex, :] = xsDict['flux'][::-1].copy()
# rxnDict['lowEnergySpectrum'] = xsDict['lowEnergySpectrum'][::-1].copy()
# rxnDict['lowEnergyProd'] = xsDict['lowEnergyProd'][::-1].copy()
# rxnDict['highEnergyMatrix'] = xsDict['highEnergyMatrix'][::-1,::-1].copy()
# rxnDict['highestHighEnergyGroup'] = numGroups - xsDict['lowestHighEnergyGroup'] - 1
# rxnDict['promptChi'] = xsDict['promptChi'][::-1].copy()
# rxnDict['promptProd'] = xsDict['promptProd'][::-1].copy()
rxnDict['FissionMatrix'][thermIndex, :, :] = xsDict['FissionMatrix'][::-1, ::-1].copy()
#lowEnergySpectrum is indexed by (groupTo)
#highEnergyMatrix is indexed by (groupFrom, groupTo)
#highEnergyMatrix applies to groups 0 through highestHighEnergyGroup (inclusive)
#FissionMatrix is indexed by (groupFrom, groupTo)
def merge_data_delayed_fission_xs(data, xsDict):
'''Merge xsDict into data. Overwrite delayed fission chi, nu, and decay constant'''
mf,mt = xsDict['mf'], xsDict['mt']
rxnDict = data['rxn'][(mf,mt)]
numGroups = data['numGroups']
numLegMoments = data['numLegMoments']
#The data is copied, not aliased
rxnDict['decayConst'] = xsDict['decayConst']
rxnDict['delayedChi'] = xsDict['delayedChi'][:,::-1].copy()
rxnDict['numDNGs'] = xsDict['numDNGs'] # For mt 455 numLegMoments is numDelayedNeutronGroups
####################################################################################
def read_group_bdr_header(line, paramDict):
'''Reads in a CONT record (see NJOY manual, page 2801). Adds Z, A, weight, numSig0, titleLength to paramDict.'''
ZZAAA = '{0:5g}'.format(int(get_float(line, 1)))
Z = int(ZZAAA[0:2])
A = int(ZZAAA[2:5])
# weight is relative to a neutron
weight = get_float(line, 2)
numSig0 = get_int(line, 4)
titleLength = get_int(line, 6)
headerDict = {'Z': Z, 'A': A, 'weight': weight, 'numSig0': numSig0, 'titleLength': titleLength}
paramDict.update(headerDict)
def read_group_bdr_body(fid, paramDict):
'''Reads in a LIST record. Advances fid. Adds temperature, title, sigma0List, neutronEnergyList, and gammaEnergyList to paramDict'''
titleLength = paramDict['titleLength']
numSig0 = paramDict['numSig0']
line = get_next_line(fid)
#
temperature = get_float(line, 1)
numNeutronGroups = get_int(line, 3)
numGammaGroups = get_int(line, 4)
numEntries = get_int(line, 5)
pos = 6
titleList, pos, line = get_list(pos, line, fid, titleLength, get_str)
sigma0List, pos, line = get_list(pos, line, fid, numSig0, get_float)
neutronEnergyBdrs, pos, line = get_list(pos, line, fid, numNeutronGroups+1, get_float)
gammaEnergyBdrs, pos, line = get_list(pos, line, fid, numGammaGroups+1, get_float)
title = ''.join(titleList)
bodyDict = {'temperature': temperature, 'numNeutronGroups': numNeutronGroups, 'numGammaGroups': numGammaGroups, 'title': title, 'sigma0List': sigma0List, 'neutronEnergyBdrs': neutronEnergyBdrs, 'gammaEnergyBdrs': gammaEnergyBdrs}
paramDict.update(bodyDict)
####################################################################################
def read_xs_header(line, xsDict):
'''Reads in a CONT record. Adds Z, A, weight, numLegMoments, numSig0, numGroups, mf, mt, lineNum to xsDict.'''
ZZAAA = '{0:5g}'.format(int(get_float(line, 1)))
Z = int(ZZAAA[0:2])
A = int(ZZAAA[2:5])
weight = get_float(line, 2)
numLegMoments = get_int(line, 3)
numSig0 = get_int(line, 4)
numGroups = get_int(line, 6)
mf, mt, lineNum = get_mf_mt_lineNum(line)
headerDict = {'Z': Z, 'A': A, 'weight': weight, 'numLegMoments': numLegMoments, 'numSig0': numSig0, 'numGroups': numGroups, 'mf': mf, 'mt': mt, 'lineNum': lineNum}
xsDict.update(headerDict)
def read_xs_vector_body(fid, xsDict, verbosity=0):
'''Reads in a LIST record. Advances fid. Writes flux and xs to xsDict.'''
numLegMoments = xsDict['numLegMoments']
numSig0 = xsDict['numSig0']
numGroups = xsDict['numGroups']
mf = xsDict['mf']
mt = xsDict['mt']
pdtMT = get_pdt_mt(mf, mt)
if verbosity > 1:
print 'Reading MF {0}, MT {1:3g} and storing in PDT-MT {2:4g}'.format(mf, mt, pdtMT)
line = get_next_line(fid)
temperature = get_float(line, 1)
groupIndex = 0
flux = np.zeros((numSig0, numGroups))
xs = np.zeros((numSig0, numGroups))
# Read cross section from file and store in xsDict
while groupIndex < numGroups:
numSecondaryPos = get_int(line, 3)
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
pos = 0
#xsForOneGroup, pos, line = get_list(pos, line, fid, numEntries, get_float)
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
strt, end = 0, numSig0 * numLegMoments
flux[:, groupIndex-1] = xsForOneGroup[strt:end:numLegMoments]
strt, end = numSig0 * numLegMoments, 2 * numSig0 * numLegMoments
xs[:, groupIndex-1] = xsForOneGroup[strt:end:numLegMoments]
line = get_next_line(fid)
bodyDict = {'flux': flux, 'xs': xs, 'temperature': temperature}
xsDict.update(bodyDict)
def read_xs_matrix_body(fid, xsDict, verbosity=0):
'''Reads in a LIST record. Advances fid. Writes xs, colSize, rowStart, firstRow, and LastRow to xsDict.'''
numLegMoments = xsDict['numLegMoments']
numSig0 = xsDict['numSig0']
numGroups = xsDict['numGroups']
mf = xsDict['mf']
mt = xsDict['mt']
pdtMT = get_pdt_mt(mf, mt)
if verbosity > 1:
print 'Reading MF {0}, MT {1:3g} and storing in PDT-MT {2:4g}'.format(mf, mt, pdtMT)
line = get_next_line(fid)
temperature = get_float(line, 1)
groupIndex = 0
xs = []
colSize = np.zeros(numGroups, dtype=np.int)
rowStart = -1 * np.ones(numGroups, dtype=np.int)
firstGroupFrom = get_int(line, 6) - 1
lastGroupFrom = firstGroupFrom - 1
# Read transfer matrix from file and store in CSC-like format in xsDict
while groupIndex < numGroups:
numSecondaryPos = get_int(line, 3)
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
pos = 0
#xsForOneGroup, pos, line = get_list(pos, line, fid, numEntries, get_float)
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
# Once the thermal data is done, GENDF skips to a null record for the highest group, which we skip
if mt in range(221, 250): # if mt is thermal process
if (groupIndex-1) != (lastGroupFrom+1):
line = get_next_line(fid)
break
lastGroupFrom += 1
colSize[groupIndex-1] = numSecondaryPos - 1
rowStart[groupIndex-1] = indexLowestGroup - 1
# When reshaping, the fastest index should go first for Fortran ordering
xsRearrange = np.reshape(np.asarray(xsForOneGroup), (numLegMoments, numSig0, numSecondaryPos), order='F')
xs.append(xsRearrange[:,:,1:])
if np.all(xsRearrange[:,:,1:] == 0.0) and groupIndex == numGroups:
# If thermal reaction is null, prevent combine_transfer_matrix from overwriting xfer matrix with all zeros
rowStart[-1] = -1
colSize[-1] = 0
line = get_next_line(fid)
bodyDict = {'xs': xs, 'colSize': colSize, 'rowStart': rowStart, 'firstRow': firstGroupFrom, 'lastRow': lastGroupFrom, 'temperature': temperature}
xsDict.update(bodyDict)
def read_prompt_fission_matrix_body(fid, xsDict, verbosity=0):
'''Reads in a LIST record. Advances fid. Writes xs to xsDict. No temperature or sigma0 dependence is expected for the fission spectrum.'''
numLegMoments = xsDict['numLegMoments']
numSig0 = xsDict['numSig0']
numGroups = xsDict['numGroups']
mf = xsDict['mf']
mt = xsDict['mt']
pdtMT = 1018
if verbosity > 1:
print 'Reading MF {0}, MT {1:3g} and storing in PDT-MT {2:4g}'.format(mf, mt, pdtMT)
flux = np.zeros(numGroups)
lowEnergySpectrum = np.zeros(numGroups)
line = get_next_line(fid)
temperature = get_float(line, 1)
numSecondaryPos = get_int(line, 3)
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
if groupIndex == 0:
# Read piece 1: Low-energy fission spectrum (may not exist)
pos = 0
#xsForOneGroup, pos, line = get_list(pos, line, fid, numEntries, get_float)
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
strt, end = (indexLowestGroup - 1), (indexLowestGroup - 1) + numSecondaryPos
lowEnergySpectrum[strt:end] = xsForOneGroup
# Read piece 2: Low-energy neutron production cross section
line = get_next_line(fid) #read CONT card for first prod section
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
indexIncidentGroup = get_int(line, 6)
lowEnergyProd = np.zeros(0)
while not(indexLowestGroup) and not(indexIncidentGroup == numGroups):
pos = 0
#read data in this prod section
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
flux[indexIncidentGroup - 1] = xsForOneGroup[0]
lowEnergyProd = np.append(lowEnergyProd, xsForOneGroup[1]) #2nd entry is nuSig_f
line = get_next_line(fid) #read CONT card for consecutive prod section
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
indexIncidentGroup = get_int(line, 6)
hasHighEnergyPiece = True
if not(indexLowestGroup) and (indexIncidentGroup == numGroups):
hasHighEnergyPiece = False
pos = 0
#read data in this prod section
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
lowEnergyProd = np.append(lowEnergyProd, xsForOneGroup[1]) #2nd entry is nuSig_f
line = get_next_line(fid) # skip blank line at the end of this section
else:
hasHighEnergyPiece = True
# Read piece 3: High-energy transfer matrix (may not exist)
if hasHighEnergyPiece:
groupIndex = get_int(line, 6)
lowestHighEnergyGroup = groupIndex - 1
numHighEnergyGroups = numGroups - groupIndex + 1
highEnergyMatrix = np.zeros((numHighEnergyGroups, numGroups))
groupIndex = 0
while groupIndex < numGroups:
numSecondaryPos = get_int(line, 3)
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
pos = 0
#xsForOneGroup, pos, line = get_list(pos, line, fid, numEntries, get_float)
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
strt, end = (indexLowestGroup - 1), (indexLowestGroup - 1) + (numSecondaryPos - 1)
rowIndex = groupIndex - lowestHighEnergyGroup - 1
flux[groupIndex - 1] = xsForOneGroup[0]
highEnergyMatrix[rowIndex, strt:end] = xsForOneGroup[1:]
line = get_next_line(fid)
else:
lowestHighEnergyGroup = numGroups
highEnergyMatrix = np.zeros((0, numGroups))
assert len(lowEnergyProd) + numHighEnergyGroups == numGroups
assert len(lowEnergyProd) == lowestHighEnergyGroup
# Reconstruct full prompt fission matrix (F)
FissionMatrix = np.zeros((numGroups, numGroups))
FissionMatrix[0:lowestHighEnergyGroup, :] = np.outer(lowEnergyProd, lowEnergySpectrum)
FissionMatrix[lowestHighEnergyGroup:numGroups, :] = highEnergyMatrix
# Compute prompt fission source = F'*phi
F_phi = np.dot(flux, FissionMatrix)
# prompt Chi is normalized promt fission source
promptChi = F_phi/np.sum(F_phi)
# prompt nu*sig_f (Prod) is row sum of F
promptProd = np.sum(FissionMatrix, 1)
bodyDict = {'flux': flux, 'lowEnergySpectrum': lowEnergySpectrum, 'lowEnergyProd': lowEnergyProd, \
'lowestHighEnergyGroup': lowestHighEnergyGroup, 'highEnergyMatrix': highEnergyMatrix, \
'FissionMatrix': FissionMatrix, 'promptChi': promptChi, 'promptProd': promptProd, \
'temperature': temperature}
xsDict.update(bodyDict)
def read_delayed_fission_spectrum(fid, xsDict, verbosity=0):
'''Reads in a LIST record. Advances fid. Writes xs to xsDict. No temperature or sigma0 dependence is expected for the fission spectrum.'''
numDNGs = xsDict['numLegMoments'] # number of delayed neutron groups
numSig0 = xsDict['numSig0']
assert numSig0 == 1 # delayed Chi does not have sigma0 depencence
numGroups = xsDict['numGroups']
mf = xsDict['mf']
mt = xsDict['mt']
pdtMT = 2055
if verbosity > 1:
print 'Reading MF {0}, MT {1:3g} and storing in PDT-MT {2:4g}'.format(mf, mt, pdtMT)
nu = np.zeros(numGroups)
line = get_next_line(fid)
temperature = get_float(line, 1)
numSecondaryPos = get_int(line, 3)
numSecondaryGroups = numSecondaryPos - 1 # First position is for decay constant
indexLowestGroup = get_int(line, 4) - 1
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
decayConst = np.zeros(numDNGs)
delayedChi = np.zeros((numDNGs, numGroups))
pos = 0
xsForOneGroup, pos, line = get_float_list(pos, line, fid, numEntries)
xsStrt, xsEnd = 0, numDNGs
decayConst = xsForOneGroup[xsStrt:xsEnd]
xsStrt, xsEnd = numDNGs, numDNGs * (numSecondaryGroups + 1)
chiStrt, chiEnd = indexLowestGroup, indexLowestGroup + numSecondaryGroups
delayedChi[:, chiStrt:chiEnd] = np.reshape(np.asarray(xsForOneGroup[xsStrt:xsEnd]), (numDNGs, numSecondaryGroups), order='F')
bodyDict = {'decayConst': decayConst, 'delayedChi': delayedChi, 'numDNGs': numDNGs, 'temperature': temperature}
line = get_next_line(fid)
xsDict.update(bodyDict)
####################################################################################
def get_pointwise_xs(filePathIn, mtsForMF3, desiredT, outputDict, verbosity):
'''Read in a pointwise xs from a pendf file. Reads in the temperature specified by desiredT.
If this temperature is negative, read in the first temperature.
Multiple temperatures are represented in a PENDF file by simply repeating the entire PENDF
structure for each temperature.
'''
if 0 in mtsForMF3:
mtsForMF3 = [1,2]
mfmtList = [(3,mt) for mt in mtsForMF3]
foundMFMTDict = {}
for (mf,mt) in mfmtList:
foundMFMTDict[(mf,mt)] = False
foundT = False
if desiredT < 0:
foundT = True
with open(filePathIn, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if (mf, mt) == (1, 451):
for i in range(3):
line = get_next_line(fid)
temperature = get_float(line, 1)
if abs(temperature - desiredT) < (1E-8 * desiredT):
foundT = True
elif (foundT and (mf, mt) in mfmtList):
foundMFMTDict[(mf,mt)] = True
for i in range(2):
line = get_next_line(fid)
numPoints = get_int(line, 1)
numEntries = 2 * numPoints
outputDict['energy'] = np.zeros(numPoints)
outputDict[(mf,mt)] = np.zeros(numPoints)
data, pos, line = get_float_list(0, line, fid, numEntries)
strt, end = 0, numEntries - 1
outputDict['energy'][:] = data[strt:end:2]
strt, end = 1, numEntries
outputDict[(mf,mt)][:] = data[strt:end:2]
if np.all(foundMFMTDict.values()):
break
if not foundT:
print 'Did not find a temperature at {0} K.'.format(desiredT)
elif verbosity:
print 'Found a temperature at {0} K with {1} points.'.format(temperature, numPoints)
####################################################################################
def get_pot_scat_xs(filePath, outputDict, verbosity=False):
'''Read a potential scattering XS from an ENDF file'''
'''Resonance extents are given in mf 2, line 3 (first two numbers) for the resolved range.
The unresolved range is harder to find, but always starts at the end of the resolved range,
so if you know where the resolved range ends, you can look for the first number in each row
to match. The second number of the matching row is the end of the unresolved resonance range.
This location may not occur (e.g., H-1), so make sure you're still in mf 2, mt 151.
'''
with open(filePath, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
# Look through the file for each reaction type
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if (mf, mt) == (2,151):
for i in range(3):
line = get_next_line(fid)
scatLength = get_float(line, 2)
potXS = 4 * np.pi * scatLength * scatLength
outputDict['pot'] = potXS
if verbosity:
print os.path.split(filePath)[-1], potXS
return
def get_decay_parameters(filePath, outputDict, verbosity=0):
'''Read the radioactive decay parameters in MF 8, MT 457, skipping the spectrum information)'''
decayParticleDict = {0: None, 1: 'B-', 2: 'EC', 3: 'IT', 4: 'A', 5: 'N', 6: 'SF', 7: 'P'}
with open(filePath, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if (mf,mt) == (8,457):
line = get_next_line(fid)
outputDict['halfLife'] = get_float(line, 1)
#
numDecayEnergyEntries = get_int(line, 5)
numDecayLines = numDecayEnergyEntries // 6
if (numDecayEnergyEntries % 6):
numDecayLines += 1
for i in range(numDecayLines+1):
line = get_next_line(fid)
#
numDecayModes = get_int(line, 5) // 6
decayModes = []
for i in range(numDecayModes):
line = get_next_line(fid)
reactionType = get_float(line, 1)
metastableState = int(get_float(line, 2))
branchingRatio = get_float(line, 5)
#
decayParticles = []
while reactionType > 1E-6:
# divmod(a,b) returns (a//b, a%b)
decayParticle, remainder = divmod(reactionType, 1)
decayParticleStr = decayParticleDict[int(decayParticle)]
reactionType = 10 * remainder
if decayParticle:
decayParticles.append(decayParticleStr)
if branchingRatio > 1E-4:
decayModes.append(DecayMode(decayParticles, metastableState, branchingRatio))
outputDict['decayModes'] = decayModes
line, pos = seek_to_next_entry(fid, mf, mt)
class DecayMode():
def __init__(self, decayParticles, metastableState, branchingRatio):
self.decayParticles = decayParticles
self.M = metastableState
self.branchingRatio = branchingRatio
def get_metastable_branching_ratios(filePath, outputDict, verbosity=0):
'''Read branching ratios (MF9) and cross sections (MF10) for production of metastable states'''
with open(filePath, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if mf in (9,10):
numMetaStates = get_int(line, 5)
for i in range(numMetaStates):
line = get_next_line(fid)
ZZAAA = get_int(line, 3)
Z, A = divmod(ZZAAA, 1000)
# Metastable state number is specified in file 8, which we don't read.
# This assumes groundstate is M == 0 and first metastable state is M == 1.
M = get_int(line, 4)
if M > 1:
M = 1
if (mf,mt,M) in outputDict:
raise ValueError('({0},{1},{2}) already exists. Too many metastable states?'.format(mf,mt,M))
outputDict[(mf,mt,M)] = {}
xsData = outputDict[(mf,mt,M)]
xsData['Z'] = Z
xsData['A'] = A
#
numEnergyRanges = get_int(line, 5)
numEnergyPoints = get_int(line, 6)
energyInterpolation, pos, line = get_list(0, line, fid, 2*numEnergyRanges, get_int)
strt, end = 0, 2 * numEnergyRanges - 1
xsData['numEnergies'] = energyInterpolation[strt:end:2]
strt, end = 1, 2 * numEnergyRanges
#To interpolate in 'x-y', the interpolation scheme is:
#{1: 'histogram', 2: 'lin-lin', 3: 'log-lin', 4: 'lin-log', 5: 'log-log'}
xsData['interpolationSchemes'] = energyInterpolation[strt:end:2]
#
energyBranchingRatios, pos, line = get_float_list(0, line, fid, 2*numEnergyPoints)
strt, end = 0, 2 * numEnergyPoints - 1
xsData['energies'] = np.array(energyBranchingRatios[strt:end:2])
strt, end = 1, 2 * numEnergyPoints
if mf == 9:
xsData['branchingRatios'] = np.array(energyBranchingRatios[strt:end:2])
if mf == 10:
xsData['xs'] = np.array(energyBranchingRatios[strt:end:2])
#line, pos = seek_to_next_entry(fid, mf, mt)
def get_fission_product_yields(filePath, outputDict, verbosity=0):
'''Read independent (MT454) and cumulative (MT459) fission product yields (MF8) for spontaneous fission or neutron-induced fission'''
with open(filePath, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if (mf,mt) in [(8,454), (8,459)]:
if mt == 454:
# MT 454 is independent yield
outputDict['indepYield'] = {}
yieldData = outputDict['indepYield']
else:
# MT 459 is cumulative yield
outputDict['cumulYield'] = {}
yieldData = outputDict['cumulYield']
# Fission product yield data is given on an energy grid
numEnergies = get_int(line, 3) #??
yieldData['energies'] = np.zeros(numEnergies)
energies = yieldData['energies']
#{1: 'histogram', 2: 'lin-lin', 3: 'log-lin', 4: 'lin-log', 5: 'log-log'}
yieldData['interpolationSchemes'] = np.zeros(numEnergies-1, dtype=np.int)
interpSchemes = yieldData['interpolationSchemes']
#
line = get_next_line(fid)
yieldLists = []
fpDicts = []
for energyPoint in range(numEnergies):
energies[energyPoint] = get_float(line, 1)
numFissionProducts = get_int(line, 6)
if energyPoint:
interpSchemes[energyPoint-1] = get_int(line, 3)
fpYieldData, pos, line = get_float_list(0, line, fid, 4*numFissionProducts)
#
strt, end = 0, 4 * numFissionProducts - 3
ZAList = np.array(fpYieldData[strt:end:4], dtype=np.int)
ZList, AList = divmod(ZAList, 1000)
#
strt, end = 1, 4 * numFissionProducts - 2
MList = np.array(fpYieldData[strt:end:4], dtype=np.int)
#
# Temporarily store the yields as a list of lists
strt, end = 2, 4 * numFissionProducts - 1
yieldLists.append(fpYieldData[strt:end:4])
#
# Temporarily store the fission products as a dict of (Z,A,M)
# whose value is an index in the yieldMatrix
ZAMDict = {}
for i in range(numFissionProducts):
ZAMDict[(ZList[i], AList[i], MList[i])] = i
fpDicts.append(ZAMDict)
line = get_next_line(fid)
# Create yield matrix (energy,nuclide). Different energies may have different fp.
ZAMSet = set()
for ZAMDict in fpDicts:
ZAMSet.update(ZAMDict.keys())
numNuclides = len(ZAMSet)
indexToZAMList = []
ZAMtoIndexDict = {}
for i, (Z,A,M) in enumerate(sorted(ZAMSet)):
indexToZAMList.append((Z,A,M))
ZAMtoIndexDict[(Z,A,M)] = i
yieldMatrix = np.zeros((numNuclides, numEnergies))
for energyPoint in range(numEnergies):
for (Z,A,M) in fpDicts[energyPoint]:
nuclideIndexFrom = fpDicts[energyPoint][(Z,A,M)]
nuclideIndexTo = ZAMtoIndexDict[(Z,A,M)]
yieldMatrix[nuclideIndexTo, energyPoint] = yieldLists[energyPoint][nuclideIndexFrom]
yieldData['indexToZAM'] = indexToZAMList
yieldData['ZAMtoIndex'] = ZAMtoIndexDict
yieldData['yields'] = yieldMatrix
def get_reaction_Q_values(filePathIn, mtsForMF3, outputDict, verbosity=0):
'''Read Q values (QI parameter) from ENDF file for each desired MT'''
if 0 in mtsForMF3:
mtsForMF3 = [18]
mfmtList = [(3,mt) for mt in mtsForMF3]
foundMFMTDict = {}
for (mf,mt) in mfmtList:
foundMFMTDict[(mf,mt)] = False
with open(filePathIn, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if (mf, mt) in mfmtList:
foundMFMTDict[(mf,mt)] = True
line = get_next_line(fid)
# The Q-value, in eV
outputDict[(mf,mt)] = get_float(line, 2)
if np.all(foundMFMTDict.values()):
break
####################################################################################
def get_scattering_sizes(filePath, verbosity=False):
'''Determine the number of secondary groups (summed over incident group, max'd over temperatures)'''
with open(filePath, 'r') as fid:
line = get_next_line(fid)
mf, mt, lineNum = get_mf_mt_lineNum(line)
startList = []
mfList = []
mtList = []
# Look through the file for each reaction type
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if not(is_continue(mf, mt, lineNum)) and not(is_section_end(mf, mt, lineNum)):
if mf == 6:
startList.append(pos)
mfList.append(mf)
mtList.append(mt)
# Find the number of groups
fid.seek(0)
for i in range(3):
line = get_next_line(fid)
numGroups = get_int(line, 3)
# Find the secondary size for each reaction
secondarySizeDict = {}
for mf, mt, startPos in zip(mfList, mtList, startList):
secondarySizeDict[(mf,mt)] = 0
for mf, mt, startPos in zip(mfList, mtList, startList):
fid.seek(startPos)
#Have to look at each group
line = get_next_line(fid)
line = get_next_line(fid)
temperature = get_float(line, 1)
groupIndex = 0
secondarySize = 0
# Read transfer matrix from file and store in CSC-like format in xsDict
while groupIndex < numGroups:
numSecondaryPos = get_int(line, 3)
indexLowestGroup = get_int(line, 4)
numEntries = get_int(line, 5)
groupIndex = get_int(line, 6)
pos = 0
line = get_next_line(fid)
#xs, pos, line = get_list(pos, line, fid, numEntries, get_float)
xs, pos, line = get_float_list(pos, line, fid, numEntries)
secondarySize += numSecondaryPos - 1
if verbosity > 2:
print '{0} {1:3g} {2:5.1f} {3:3g} {4:3g}'.format(mf, mt, temperature, groupIndex, numSecondaryPos - 1)
if verbosity > 1:
print 'total: {0}, {1:3g}, {2:5.1f}, {3:3g}'.format(mf, mt, temperature, secondarySize)
secondarySizeDict[(mf,mt)] = max(secondarySizeDict[(mf,mt)], secondarySize)
if verbosity:
print 'secondarySizeDict (max over temperatures)'
print secondarySizeDict
return secondarySizeDict
def get_reaction_list(filePath, verbosity):
'''Get all the reactions in the file.'''
print filePath
with open(filePath, 'r') as fid:
line = get_next_line(fid)
print line
mf, mt, lineNum = get_mf_mt_lineNum(line)
startList = []
mfList = []
mtList = []
# Look through the file for each reaction type
while line != '':
line, pos = seek_to_next_entry(fid, mf, mt)
if line == '':
break
mf, mt, lineNum = get_mf_mt_lineNum(line)
if not(is_continue(mf, mt, lineNum)) and not(is_section_end(mf, mt, lineNum)):
startList.append(pos)
mfList.append(mf)
mtList.append(mt)
# Find the number of groups
fid.seek(0)
for i in range(3):
line = get_next_line(fid)
numGroups = get_int(line, 3)
# For each reaction, figure out the temperatures, Leg moments, and sig0
thermList = []
numLegList = []
numSig0List = []
for startPos in startList:
fid.seek(startPos)
line = get_next_line(fid)
numLegList.append(get_int(line, 3))