Skip to content

Instantly share code, notes, and snippets.

@Towdium
Created February 21, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Towdium/9de50cd1c82da468be072d6e01fc1fd2 to your computer and use it in GitHub Desktop.
Save Towdium/9de50cd1c82da468be072d6e01fc1fd2 to your computer and use it in GitHub Desktop.
Simple script to calculate resource usage of Nuclear Craft breeding
from collections import defaultdict
duration = 0.5
selections = {
'HEB-248': 2,
'LECm-243': 6,
'LEP-239': 24,
'LEU-233': 12,
'HEU-235': 12
}
# Here are some examples
'''
'HEB-248': 1,
'HECm-243': 3,
'LEP-239': 48,
'LEU-233':24,
'HEU-235':24
'''
'''
'LECf-249': 1,
'HECm-247': 3,
'HEA-242': 3,
'HEP-239': 3,
'LEN-236': 16,
'LEU-235': 50,
'HEU-233': 6,
'TBU': 3
'''
'''
'HECf-249': 1,
'HECm-247': 6,
'HEP-241': 9,
'LEU-233':25,
'LEU-235':25
'''
stats = '''
TBU, U-233 x16, U-235 x8, Np-236 x8, Np-237 x32, 144000, Th-232 x9,
LEU-233, Pu-239 x4, Pu-241 x4, Pu-242 x32, Am-243 x24, 64000, U-233 x1, U-238 x8
HEU-233, Np-236 x32, Np-237 x8, Pu-242 x16, Am-243 x8, 64000, U-233 x4, U-238 x5
LEU-235, U-238 x40, Np-237 x8, Pu-239 x8, Pu-241 x8, 72000, U-235 x1, U-238 x8
HEU-235, U-238 x20, Np-237 x16, Pu-239 x4, Pu-242 x24, 72000, U-235 x4, U-238 x5
LEN-236, Np-237 x4, Pu-242 x32, Am-242 x8, Am-243 x20, 102000, Np-236 x1, Np-237 x8
HEN-236, U-238 x16, Pu-238 x8, Pu-239 x8, Pu-242 x32, 102000, Np-236 x4, Np-237 x5
LEP-239, Pu-239 x8, Pu-242 x24, Cm-243 x4, Cm-246 x28, 92000, Pu-239 x1, Pu-242 x8
HEP-239, Am-241 x8, Am-242 x24, Cm-245 x8, Cm-246 x24, 92000, Pu-239 x4, Pu-242 x5
LEP-241, Pu-242 x4, Am-242 x4, Am-243 x8, Cm-246 x48, 60000, Pu-241 x1, Pu-242 x8
HEP-241, Am-241 x8, Cm-245 x8, Cm-246 x24, Cm-247 x24, 60000, Pu-241 x4, Pu-242 x5
MOX-239, U-238 x40, Pu-242 x12, Am-243 x8, Cm-243 x4, 84000, Pu-239 x1, U-238 x8
MOX-241, U-238 x40, Pu-241 x8, Pu-242 x8, Cm-246 x8, 56000, Pu-241 x1, U-238 x8
LEA-242, Cm-243 x8, Cm-245 x8, Cm-246 x40, Cm-247 x8, 54000, Am-242 x1, Am-243 x8
HEA-242, Cm-245 x16, Cm-246 x32, Cm-247 x8, Bk-247 x8, 54000, Am-242 x4, Am-243 x5
LECm-243, Cm-246 x32, Bk-247 x16, Bk-248 x8, Cf-249 x8, 52000, Cm-243 x1, Cm-246 x8
HECm-243, Cm-246 x24, Bk-247 x24, Bk-248 x8, Cf-249 x8, 52000, Cm-243 x4, Cm-246 x5
LECm-245, Bk-247 x40, Bk-248 x8, Cf-249 x4, Cf-252 x12, 68000, Cm-245 x1, Cm-246 x8
HECm-245, Bk-247 x48, Bk-248 x4, Cf-249 x4, Cf-251 x8, 68000, Cm-245 x4, Cm-246 x5
LECm-247, Bk-247 x20, Bk-248 x4, Cf-251 x8, Cf-252 x32, 78000, Cm-247 x1, Cm-246 x8
HECm-247, Bk-248 x8, Cf-249 x8, Cf-251 x24, Cf-252 x24, 78000, Cm-247 x4, Cm-246 x5
LEB-248, Cf-249 x4, Cf-251 x4, Cf-252 x28, Cf-252 x28, 86000, Bk-248 x1, Bk-247 x8
HEB-248, Cf-250 x8, Cf-251 x8, Cf-252 x24, Cf-252 x24, 86000, Bk-248 x4, Bk-247 x5
LECf-249, Cf-250 x16, Cf-251 x8, Cf-252 x20, Cf-252 x20, 60000, Cf-249 x1, Cf-252 x8
HECf-249, Cf-250 x32, Cf-251 x16, Cf-252 x8, Cf-252 x8, 60000, Cf-249 x4, Cf-252 x5
LECf-251, Cf-251 x4, Cf-252 x20, Cf-252 x20, Cf-252 x20, 58000, Cf-251 x1, Cf-252 x8
HECf-251, Cf-251 x16, Cf-252 x16, Cf-252 x16, Cf-252 x16, 58000, Cf-251 x4, Cf-252 x5
'''
recipes = '''
Th-230, Pb
Th-232, Pb
U-233, Pb
U-235, Pb
U-238, Th-230
Np-236, Th-232
Np-237, U-233
Pu-238, Th-230
Pu-239, U-235
Pu-241, Np-237
Pu-242, U-238
Am-241, Np-237
Am-242, Th-230
Am-243, Pu-239
Cm-243, Pu-239
Cm-245, Pu-241
Cm-246, Pu-242
Cm-247, Am-243
Bk-247, Am-243
Bk-248, Th-232
Cf-249, Cm-245
Cf-251, Cm-247
Cf-252, Th-232
'''
# Cf-250, Cm-246
# removed Cf-250 decay since it's destination
class Reaction:
def __init__(self, s):
cells = s.strip().split(',')
cells = [i.strip() for i in cells]
self.name = cells[0]
self.outputs = {}
for i in range(1, 5):
tokens = cells[i].split(' x')
self.outputs[tokens[0]] = int(tokens[1])
self.time = int(cells[5]) / 60 / 20
self.inputs = {}
for i in range(6, 8):
if not cells[i]:
continue
tokens = cells[i].split(' x')
self.inputs[tokens[0]] = int(tokens[1]) * 9
reactions = {}
for line in stats.strip().splitlines():
reaction = Reaction(line)
reactions[reaction.name] = reaction
fallbacks = {}
for line in recipes.strip().splitlines():
cells = line.strip().split(', ')
fallbacks[cells[0]] = cells[1]
results = defaultdict(int)
for fuel, mul in selections.items():
reaction = reactions[fuel]
for isotope, amount in reaction.inputs.items():
results[isotope] -= mul * amount / reaction.time
for isotope, amount in reaction.outputs.items():
results[isotope] += mul * amount / reaction.time
raw = {i: a for i, a in results.items()}
print('Decay:')
for isotope, amount in results.items():
decay = fallbacks.get(isotope)
while decay and amount > 0:
if decay in results and results[decay] < 0:
if amount + results[decay] < 0:
amount_ = amount / duration
print('{} => {} x{:.3f}'.format(isotope, decay, amount_))
results[decay] += amount
amount = 0
else:
amount_ = -results[decay] / duration
print('{} => {} x{:.3f}'.format(isotope, decay, amount_))
amount += results[decay]
results[decay] = 0
decay = fallbacks.get(decay)
results[isotope] = amount
print('\nAmount:')
for isotope in results:
result_ = results[isotope] / duration
raw_ = raw[isotope] / duration
print("{}: {:.3f} ({:.3f})".format(isotope, result_, raw_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment