-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreader.py
137 lines (121 loc) · 4.65 KB
/
reader.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
## =========================================
## cross sections
## for individual compositions
## could be an isotope, element, mixture, etc.
## also some isotopes/elements have different
## sets weighted by different spectra
## for specific regions of shielding problems
## such as 1/4T iron
class isotope:
def __init__(self, lines):
title = lines[0]
self.id = int(title.split()[3])
self.name = ' '.join(title.split()[5:])
self.n_groups = int(title.split()[0])
self.n_neutrons = 47
self.n_gammas = 20
self.n_responses = int(title.split()[1])
self.xs = []
if self.id < 7000:
self.read_data(lines)
else:
self.read_data(lines)
def read_data(self, lines):
data = []
for line in lines[1:]:
values = line.split()[:-1]
for v in range(0, len(values)):
if 'r' in values[v]:
fido = values[v].split('r')
for null in range(0, int(fido[0])):
data.append(convert_ascii_number(''+fido[1]))
else:
data.append(convert_ascii_number(values[v]))
if self.id < 7000:
siga = []
nsgf = []
sigt = []
sigs = []
for g in range(0, self.n_groups):
siga.append(data[0])
nsgf.append(data[1])
sigt.append(data[2])
data[:3] = []
sigs.append([response for response in data[:self.n_groups+4]])
data[:self.n_groups+4] = []
self.xs.append([siga, nsgf, sigt, sigs])
self.siga = siga
self.nusigf = nsgf
self.sigt = sigt
self.sigs = sigs
sigst = []
for s in sigs:
sigst.append(s[4])
for s in range(0, self.n_neutrons):
for g in range(s+1, self.n_neutrons):
sigst[s] += sigs[g][4+g-s]
for s in range(4, self.n_neutrons):
for g in range(0, 4):
sigst[s] += sigs[s-g-1][4-g-1]
self.sigst = sigst
elif self.id < 8000:
responses = []
for r in range(0, self.n_responses):
responses.append(data[:self.n_groups])
data[:self.n_groups] = []
self.xs.append(responses)
else:
responses = []
for r in range(0, self.n_responses):
responses.append(data[:self.n_groups])
data[:self.n_groups] = []
self.xs.append(responses)
## =========================================
## =========================================
## read in all cross sections
## from a '.bcd' file
class multigroup_library:
def __init__(self, file_name):
lines = [line.replace('\r','').replace('\n','') for line in open(file_name, 'r').readlines()]
start = 0
self.nuclides = {}
for l in range(1, len(lines)):
if len(lines[l]) < 80:
finish = l-1
title = lines[start]
if title.split() == ['7', '7', '7', '7']:
break
nuclide = int(title.split()[3])
## if nuclide < 7000 and 'mixed' not in title:
## nuclide = int(title.split()[6])
if nuclide not in self.nuclides:
self.nuclides[nuclide] = isotope(lines[start:finish+1])
else:
self.nuclides[nuclide].read_data(lines[start:finish+1])
start = l
def get_mt(self, id, mts=[1], legendre=0):
if not isinstance(mts, list):
mts = [mts]
sigmas = []
for mt in mts:
sigmas.append(self.nuclides[id].xs[legendre][mt])
if len(sigmas) == 1:
return sigmas
else:
return sigmas
def sigt(self, id):
return self.nuclides[id].sigst
## =========================================
## =========================================
def convert_ascii_number(value):
sign = 1.0
if value[0] == '-':
sign = -1.0
value = value[1:]
if '-' in value:
return sign*float(value.split('-')[0])*(10.0**(-1.0*float(value.split('-')[1])))
elif '+' in value:
return sign*float(value.split('+')[0])*(10.0**(1.0*float(value.split('+')[1])))
else:
return sign*float(value)
## =========================================