-
Notifications
You must be signed in to change notification settings - Fork 0
/
eranos.py
442 lines (387 loc) · 16.3 KB
/
eranos.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
#!/usr/bin/env python
"""
Copyright (C) 2010 Paul K. Romano
Code to process mass output data from ERANOS and rewrite it in a
form that VISION can use.
"""
from __future__ import division, print_function
import re
import math
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from isotope import Isotope, FissionProduct
from material import Material
from cycle import Cycle
from fileIO import fileReSeek, fileReSeekList
from parameters import pf
def loadData(filename, parent=None, gui=True):
"""
Loads material data from an ERANOS output file.
Returns a list 'cycles' with all the Cycle instances.
"""
# Open file
eranosFile = open(filename, "r")
cycles = []
# Find the names of all the fuel regions
fuelNames = []
m = fileReSeek(eranosFile, "^->LISTE_MILIEUX.*")
fuelNames += re.findall("'(FUEL\d+)'", m.group())
while True:
line = eranosFile.readline().strip()
fuelNames += re.findall("'(FUEL\d+)'", line)
if line[-1] == ";": break
# Determine if there is a blanket material
m = fileReSeek(eranosFile, "^->BLANKET.*")
if m:
fuelNames += ["BLANK"]
else:
eranosFile.seek(0)
# Determine default cooling period
position = eranosFile.tell()
m = fileReSeek(eranosFile, "^->COOLINGTIME\s+(\S+).*")
if m:
try:
if m.groups()[0][:6] == "(PASSE":
auto_cooling = True
else:
auto_cooling = False
cooling_time = float(m.groups()[0])
except:
cooling_time = 30
else:
cooling_time = None
eranosFile.seek(position)
# Determine cycle information
while True:
m = fileReSeek(eranosFile, ".*->CYCLE\s+(\d+).*")
if not m: break
n = int(m.groups()[0])
m = fileReSeek(eranosFile, "^->PASSE\s\((\d+)\).*")
if not m: break
timestep = int(m.groups()[0])
m = fileReSeek(eranosFile, "^->ITER\s(\d+).*")
iterations = int(m.groups()[0])
# Determine cooling period
if auto_cooling:
cooling_time = timestep*iterations*0.15/0.85
cycles.append(Cycle(n, timestep, iterations, cooling_time))
eranosFile.seek(0)
# Determine how many materials to read total
n_materials = 0
for cycle in cycles:
n_materials += len(cycle.times())*len(fuelNames)
# Create progress bar
if gui:
progress = QProgressDialog("Loading ERANOS Data...",
"Cancel", 0, n_materials, parent)
progress.setWindowModality(Qt.WindowModal)
progress.setWindowTitle("Loading...")
progress.setMinimumDuration(0)
progress.setValue(0)
pValue = 0
for cycle in cycles:
print("Loading Cycle {0}...".format(cycle.n))
# Determine critical mass
fileReSeek(eranosFile, " ECCO6.*")
xsDict = {}
for i in fuelNames:
m = fileReSeek(eranosFile, "\sREGION :(FUEL\d+|BLANK)\s*")
name = m.groups()[0]
m = fileReSeek(eranosFile,
"\s*TOTAL\s+(\S+)\s+(\S+)\s+\S+\s+(\S+).*")
nuSigmaF = float(m.groups()[0])
SigmaA = float(m.groups()[1])
Diff = float(m.groups()[2])
xsDict[name] = (nuSigmaF, SigmaA, Diff)
# Find beginning of cycle
m = fileReSeek(eranosFile, ".*M A T E R I A L B A L A N C E.*")
# Find TIME block and set time
for node, time in enumerate(cycle.times()):
# Progress bar
if gui:
QCoreApplication.processEvents()
if (progress.wasCanceled()):
return None
# Loop over fuel names
for i in fuelNames:
m = fileReSeek(eranosFile,"\s+MATERIAL\s(FUEL\d+|BLANK)\s+")
name = m.groups()[0]
volume = float(eranosFile.readline().split()[-1])
for n in range(5): eranosFile.readline()
# Read in material data
material = readMaterial(eranosFile)
material.volume = volume
if time == 0:
material.nuFissionRate = xsDict[name][0]
material.absorptionRate = xsDict[name][1]
material.diffRate = xsDict[name][2]
cycle.materials[(node,name)] = material
#print (node,name)
# Set progress bar value
pValue += 1
if gui:
progress.setValue(pValue)
#print((cycle.n, time, name)) # Only for debugging
# Read uranium added/required feed
for i in range(3):
# Determine if there is additional mass or not enough
regexList = [" 'REQUIRED FEED FOR FUEL (\d).*",
" 'ADDITIONAL FEED FOR FUEL (\d).*"]
m, index = fileReSeekList(eranosFile,regexList)
if index == 0:
# We don't have enough fissile material
cycle.extraMass = False
mat = "FUEL{0}".format(m.groups()[0])
m = fileReSeek(eranosFile," ->REPLMASS2\s+(\S+).*")
cycle.requiredFeed += float(m.groups()[0])
m = fileReSeek(eranosFile," ->REPLMASS1\s+(\S+).*")
cycle.uraniumAdded[mat] = float(m.groups()[0])
m = fileReSeek(eranosFile," ->POWER\d\s+(\S+).*")
cycle.materials[(5,mat)].power = float(m.groups()[0])
else:
# Additional mass was produced
cycle.extraMass = True
mat = "FUEL{0}".format(m.groups()[0])
m = fileReSeek(eranosFile," ->EXTRA\s+(\S+).*")
cycle.additionalFeed[mat] = float(m.groups()[0])
m = fileReSeek(eranosFile," ->REPLMASS\s+(\S+).*")
cycle.uraniumAdded[mat] = float(m.groups()[0])
m = fileReSeek(eranosFile," ->POWER\d\s+(\S+).*")
cycle.materials[(5,mat)].power = float(m.groups()[0])
posb = eranosFile.tell()
for i in range(4):
# Get DPA information
regexList = [" 'DPA of FUEL (\d).*",
" 'DPA of BLANKET'.*"]
m, index = fileReSeekList(eranosFile,regexList)
if index == 0:
# We don't have enough fissile material
mat = "FUEL{0}".format(m.groups()[0])
m = fileReSeek(eranosFile," ->DPA\dC\s+(\S+).*")
#print (m.group(), m.groups())
#print (mat)
cycle.materials[(5,mat)].dpa = float(m.groups()[0])
else:
# Additional mass was produced
mat = "BLANK"
m = fileReSeek(eranosFile," ->DPABC\s+(\S+).*")
#print (m.group(), m.groups())
cycle.materials[(5,mat)].dpa = float(m.groups()[0])
#cycle.materials[(0,mat)].dpa = float(m.groups()[0])
eranosFile.seek(posb)
# Read charge and discharge vectors at end of ERANOS output file
charge = Material()
discharge = Material()
onestreamch = Material()
onestreamdis = Material()
listeiso = ['Th232','Pa231','Pa233','U232','U233','U234','U235','U236','U238','Np237',
'Np239','Np238','Pu238','Pu239','Pu240','Pu241','Pu242','Am241','Am242g',
'Am242m','Am243','Cm242','Cm243','Cm244','Cm245','Cm246','Cm247','Cm248',
'Bk249','Cf249','Cf250','Cf251','Cf252','sfpU234','sfpU235','sfpU236',
'sfpU238','sfpNp237','sfpPu238','sfpPu239','sfpPu240','sfpPu241','sfpPu242',
'sfpAm241','sfpAm242m','sfpAm243','sfpCm243','sfpCm244','sfpCm245']
m = fileReSeek(eranosFile," ->CHARGE\s+(\S+).*")
words = m.group().split()
words.pop(0)
value = [float(val) for val in words]
for i in range(10):
words = eranosFile.readline().split()
value.extend([float(val) for val in words])
for iso in range(33):
charge.addMass(listeiso[iso],value[iso])
onestreamch.addMass(listeiso[iso],value[iso])
for iso in range(16):
charge.addMass(listeiso[iso+33],value[iso+33],True)
onestreamch.addMass(listeiso[iso+33],value[iso+33],True)
charge.expandFPs()
m = fileReSeek(eranosFile," ->DISCHARGE\s+(\S+).*")
words = m.group().split()
words.pop(0)
value = [float(val) for val in words]
for i in range(10):
words = eranosFile.readline().split()
value.extend([float(val) for val in words])
for iso in range(33):
discharge.addMass(listeiso[iso],value[iso])
onestreamdis.addMass(listeiso[iso],value[iso])
for iso in range(16):
discharge.addMass(listeiso[iso+33],value[iso+33],True)
onestreamdis.addMass(listeiso[iso+33],value[iso+33],True)
discharge.expandFPs()
chblank = Material()
disblank = Material()
m = fileReSeek(eranosFile," ->CHBLANK\s+(\S+).*")
words = m.group().split()
words.pop(0)
value = [float(val) for val in words]
for i in range(10):
words = eranosFile.readline().split()
value.extend([float(val) for val in words])
for iso in range(33):
chblank.addMass(listeiso[iso],value[iso])
onestreamch.addMass(listeiso[iso],value[iso])
for iso in range(16):
chblank.addMass(listeiso[iso+33],value[iso+33],True)
onestreamch.addMass(listeiso[iso+33],value[iso+33],True)
chblank.expandFPs()
onestreamch.expandFPs()
m = fileReSeek(eranosFile," ->DISBLANK\s+(\S+).*")
words = m.group().split()
words.pop(0)
value = [float(val) for val in words]
for i in range(10):
words = eranosFile.readline().split()
value.extend([float(val) for val in words])
for iso in range(33):
disblank.addMass(listeiso[iso],value[iso])
onestreamdis.addMass(listeiso[iso],value[iso])
for iso in range(16):
disblank.addMass(listeiso[iso+33],value[iso+33],True)
onestreamdis.addMass(listeiso[iso+33],value[iso+33],True)
disblank.expandFPs()
onestreamdis.expandFPs()
#posb = eranosFile.tell()
eranosFile.seek(posb)
try:
mat = "BLANK"
m = fileReSeek(eranosFile," ->POWERB\s+(\S+).*")
n = len(cycles)
#print (n, float(m.groups()[0]))
cycle.materials[(5,mat)].power = float(m.groups()[0])
except:
print('WARNING: No Blanket Discharge Power')
eranosFile.seek(posb)
try:
# Determine reaction rates for FUEL3, FUEL6, FUEL9, and
# BLANK. First we need to load material balance data. Is this
# just reading the same data as the last timestep of the last
# cycle???
n = len(cycles) + 1
cycle = Cycle(n, 0, 0, 0)
cycles.append(cycle)
for i in fuelNames:
m = fileReSeek(eranosFile,"\s+MATERIAL\s(FUEL\d+|BLANK)\s+")
name = m.groups()[0]
volume = float(eranosFile.readline().split()[-1])
for n in range(5): eranosFile.readline()
# Read in material data
material = readMaterial(eranosFile)
material.volume = volume
cycle.materials[(0,name)] = material
# Now read fission, absorption, and diffusion rates to be able to
# determine the critical mass
fuelNames = ['FUEL3', 'FUEL6', 'FUEL9', 'BLANK']
fileReSeek(eranosFile, " ECCO6.*")
for name in fuelNames:
m = fileReSeek(eranosFile, "\sREGION :(FUEL\d+|BLANK)\s*")
name = m.groups()[0]
m = fileReSeek(eranosFile,
"\s*TOTAL\s+(\S+)\s+(\S+)\s+\S+\s+(\S+).*")
cycle.materials[(0,name)].nuFissionRate = float(m.groups()[0])
cycle.materials[(0,name)].absorptionRate = float(m.groups()[1])
cycle.materials[(0,name)].diffRate = float(m.groups()[2])
m = fileReSeek(eranosFile, "\s*TOTAL FLUX =\s+(\S+)\s*")
cycle.materials[(0,name)].flux = float(m.groups()[0])
#print(m.groups()[0])
except:
# No ECCO calculation at end?
print('WARNING: No ECCO_BLANK calculation at end of run?')
# Create progress bar
if gui:
progress = QProgressDialog("Expanding fission products...",
"Cancel", 0, n_materials, parent)
progress.setWindowModality(Qt.WindowModal)
progress.setWindowTitle("Loading...")
progress.setMinimumDuration(0)
progress.setValue(0)
pValue = 0
# Expand all fission products
for cycle in cycles:
# Progress bar
if gui:
QCoreApplication.processEvents()
if (progress.wasCanceled()):
return None
print("Expanding fission products for Cycle {0}...".format(cycle.n))
for mat in cycle.materials.values():
mat.expandFPs()
# Set progress bar value
pValue += 1
if gui:
progress.setValue(pValue)
# Close file and return
eranosFile.close()
return cycles, charge, discharge, chblank, disblank, onestreamch, onestreamdis
def readMaterial(fh):
"""
Read in material data on fh starting from first line (usually Na23)
of data and return it in a Material instance.
"""
mat = Material()
while True:
words = fh.readline().split()
if len(words) == 1: break
name = words[1]
if name == "Am242g":
name = "Am242"
original_mass = float(words[3])
if name[0:3] == "sfp":
mat.isotopes[name] = FissionProduct(name,original_mass)
else:
mat.isotopes[name] = Isotope(name, original_mass)
return mat
def writeData(filename, cycles):
"""
Write out all material data in the 'cycles' list to 'filename'.
"""
# Open file for writing
fh = open(filename, "w")
# Write material and cycle information
materialNames = cycles[0].materialNames()
fh.write("Materials:\n")
for name in materialNames:
fh.write(" {0}\n".format(name))
fh.write("\n")
for cycle in cycles:
fh.write("Cycle {0}: {1}\n".format(
cycle.n, " ".join([str(i) for i in cycle.times()])))
fh.write("\n")
# Write data from materials dictionary
# TODO: encapsulate some of this logic in a Material object method?
for cycle in cycles:
for node, time in enumerate(cycle.times()):
for name in materialNames:
fh.write("Cycle {0} Time {1} {2}\n".format(
cycle.n, time, name))
material = cycle.materials[(node,name)]
fh.write(" Volume = {0}\n".format(material.volume))
fh.write(" Heating Rate = {0} W/kg\n".format(
material.heat()/material.mass()))
fh.write(" Photon Heating Rate = {0} W/kg\n".format(
material.gammaHeat()/material.mass()))
fh.write(" Neutron Production Rate = {0} N/s/kg\n".format(
material.neutronProduction()/material.mass()))
fh.write(" External Dose Rate = {0} Sv/hr/kg at 1 m\n".format(
material.externalDose()/material.mass()))
fh.write(" Critical Mass = {0} kg\n".format(
material.criticalMass()))
fh.write(" Charlton: DOE Attrativeness (u1) = {0}\n".format(
material.charlton1()))
fh.write(" Charlton: Pu Heating Rate (u2) = {0}\n".format(
material.charlton2()))
fh.write(" Charlton: Weight Fraction of Even Pu (u3) = {0}\n".format(
material.charlton3()))
fh.write(" Charlton: Concentration (u4) = {0}\n".format(
material.charlton4()))
fh.write(" Charlton: Dose Rates (u5) = {0}\n".format(
material.charlton5()))
fh.write(" Bathke: Sub-national (FOM1) = {0}\n".format(
material.bathke1()))
fh.write(" Bathke: Unadvanced Nation (FOM2) = {0}\n".format(
material.bathke2()))
for isotope in material.isotopes.values():
fh.write(" {0:7} {1:12.6e} kg\n".format(
str(isotope) + ":", isotope.mass))
fh.write("\n")
fh.close()
return