Haxton_Sale2

oldNC_Route.py

Sep 25th, 2021 (edited)
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.61 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import cvxpy as cvx
  4.  
  5. ## Initialization
  6.  
  7. oxide = True
  8. decayHastener = True
  9. maxHeat = 9999
  10.  
  11. enableTBU = True
  12. enableLE = True
  13. enableHE = True
  14. enableMOX = True
  15.  
  16. # Concatenate with comma(,) not semicolon(,)
  17. forbiddenFuels = np.array([
  18.     'placeholder'
  19.     ])
  20.  
  21. # RF / RTG
  22. goal = 'RTG'
  23. print(goal)
  24.  
  25. # Starting resources
  26.  
  27. # Ingots
  28. Thorium = 500.
  29. Uranium = 600.
  30.  
  31. # will use amount specified above in ticks specified below
  32. cycle = 138000.
  33.  
  34. # Cell multiplier: Cell numbers will be a multiple of this number
  35. multiplier = 1
  36.  
  37. #will be scaled inverse to the sqrt(heat) of the fuel
  38. cellN = 80
  39.  
  40. reactorN = 0
  41.  
  42. efficiencyMin = 100
  43. efficiencyMax = 100
  44.  
  45. ## Tables
  46.  
  47. TBU = np.zeros((27,1))
  48. LE = np.zeros((27,1))
  49. HE = np.zeros((27,1))
  50. MOX = np.zeros((27,1))
  51.  
  52. TBU[0] = 1
  53. LE[1:6:2] = 1
  54. LE[9:27:2] = 1
  55. HE[2:7:2] = 1
  56. HE[10:27:2] = 1
  57. MOX[7:9] = 1
  58.  
  59. fuelOrder = np.array([
  60.     'TBU',      'LEU-235',  'HEU-235',  'LEU-233',  'HEU-233',
  61.     'LEN-236',  'HEN-236',  'MOX-239',  'MOX-241',
  62.     'LEP-239',  'HEP-239',  'LEP-241',  'HEP-241',  'LEA-242',  'HEA-242',
  63.     'LECm-243', 'HECm-243', 'LECm-245', 'HECm-245', 'LECm-247', 'HECm-247',
  64.     'LEB-248',  'HEB-248',  'LECf-249', 'HECf-249', 'LECf-251', 'HECf-251'
  65.     ])
  66.  
  67. isoOrder = np.array([
  68.     'Th-230','Th-232',
  69.     'U-233','U-235','U-238',
  70.     'Np-236','Np-237',
  71.     'Pu-238','Pu-239','Pu-241','Pu-242',
  72.     'Am-241','Am-242','Am-243',
  73.     'Cm-243','Cm-245','Cm-246','Cm-247',
  74.     'Bk-247','Bk-248','Cf-249','Cf-250','Cf-251','Cf-252'
  75.     ])
  76.  
  77. heat = np.array([
  78.     18,     50,     300,    60,     360,                
  79.     36,     216,    57.5,   97.5,                      
  80.     40,     240,    70,     420,    94,     564,        
  81.     112,    672,    68,     408,    54,     324,        
  82.     52,     312,    116,    696,    120,    720
  83.     ])
  84.  
  85. if oxide == True:
  86.     heat[0:7] *= 1.25
  87.     heat[9:27] *= 1.25
  88.    
  89. ## Simulating reactor efficiency
  90. # eff = -heat;
  91. # eff = -log(heat);
  92. eff = np.min(heat) / np.log(heat) + 1
  93. eff = eff - np.min(eff)
  94. eff = eff / np.max(eff) * (efficiencyMax-efficiencyMin) + efficiencyMin
  95.  
  96. eff = eff/100
  97.  
  98. ## Taking into account time it takes to burn fuels
  99. tick = np.array([
  100.     144000, 72000,  72000,  64000,  64000,            
  101.     102000, 102000, 84000,  56000,                      
  102.     92000,  92000,  60000,  60000,  54000,  54000,      
  103.     52000,  52000,  68000,  68000,  78000,  78000,      
  104.     86000,  86000,  60000,  60000,  58000,  58000
  105.     ])
  106.  
  107. CC = cycle / tick * multiplier
  108.  
  109. RFtNormal = np.array([[
  110.     60,     120,    480,    144,    576,
  111.     90,     360,    155.4,  243.6,
  112.     105,    420,    165,    660,    192,    768,
  113.     210,    840,    162,    648,    138,    552,
  114.     135,    540,    216,    864,    225,    900]])
  115.    
  116. RFtNormal = RFtNormal * CC * eff
  117.  
  118. RFtOxide = RFtNormal*1.4
  119. RFtOxide[0,8] = RFtNormal[0,8]
  120. RFtOxide[0,9] = RFtNormal[0,9]
  121.  
  122. ## Hardcoded arrays
  123. separatorMatrix = np.array([
  124.     [1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  125.     [0,0,0,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]])
  126.  
  127. fuelMatrix = np.array([
  128.     [0,-81,16,8,0,8,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  129.     [0,0,0,-9,-32,0,8,0,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  130.     [0,0,0,-36,-25,0,16,0,4,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0],
  131.     [0,0,-9,0,-72,0,0,0,4,4,32,0,0,24,0,0,0,0,0,0,0,0,0,0],
  132.     [0,0,-36,0,-45,32,8,0,0,0,16,0,0,8,0,0,0,0,0,0,0,0,0,0],
  133.     [0,0,0,0,0,-9,-68,0,0,0,32,0,8,20,0,0,0,0,0,0,0,0,0,0],
  134.     [0,0,0,0,16,-36,-45,8,8,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0],
  135.     [0,0,0,0,-32,0,0,0,-9,0,12,0,0,8,4,0,0,0,0,0,0,0,0,0],
  136.     [0,0,0,0,-32,0,0,0,0,-1,8,0,0,0,0,0,8,0,0,0,0,0,0,0],
  137.     [0,0,0,0,0,0,0,0,-1,0,-48,0,0,0,4,0,28,0,0,0,0,0,0,0],
  138.     [0,0,0,0,0,0,0,0,-36,0,-45,8,24,0,0,8,24,0,0,0,0,0,0,0],
  139.     [0,0,0,0,0,0,0,0,0,-9,-68,0,4,8,0,0,48,0,0,0,0,0,0,0],
  140.     [0,0,0,0,0,0,0,0,0,-36,-45,8,0,0,0,8,24,24,0,0,0,0,0,0],
  141.     [0,0,0,0,0,0,0,0,0,0,0,0,-9,-72,8,8,40,8,0,0,0,0,0,0],
  142.     [0,0,0,0,0,0,0,0,0,0,0,0,-36,-45,0,16,32,8,8,0,0,0,0,0],
  143.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,-9,0,-40,0,16,8,8,0,0,0],
  144.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,-36,0,-21,0,24,8,8,0,0,0],
  145.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-9,-72,0,40,8,4,0,0,12],
  146.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-36,-45,0,48,4,4,0,8,0],
  147.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-72,-9,20,4,0,0,8,32],
  148.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-45,-36,0,8,8,0,24,24],
  149.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-72,-9,4,0,4,56],
  150.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-45,-36,0,8,8,48],
  151.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-9,16,8,-32],
  152.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-36,32,16,-29],
  153.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-5,-12],
  154.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-20,3]])
  155.  
  156. fuelMatrix = np.diag(CC)@fuelMatrix
  157.  
  158. decayMatrix = np.array([
  159.     [1,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  160.     [0,1,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  161.     [0,0,1,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  162.     [1,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  163.     [0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  164.     [0,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  165.     [0,0,0,0,1,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0],
  166.     [0,0,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0],
  167.     [1,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0],
  168.     [0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0],
  169.     [0,0,0,0,0,0,0,0,1,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0],
  170.     [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,-1,0,0,0,0,0,0,0,0],
  171.     [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,-1,0,0,0,0,0,0,0],
  172.     [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,-1,0,0,0,0,0,0],
  173.     [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,0],
  174.     [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0],
  175.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0,0,0],
  176.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0,0],
  177.     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0],
  178.     [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1]])
  179.  
  180. #isotopeSeparatorRF = .5 #kRF that takes to process one ingot
  181. #decayHastenerRF = .5 #kRF that takes to process small clumps
  182.  
  183. A = np.concatenate((separatorMatrix, fuelMatrix, decayMatrix)).T
  184.  
  185. # if goal == "RF" and oxide == True:
  186. #     f1 = RFtOxide
  187. #     f2 = np.zeros((20))
  188. # elif goal == "RF":
  189. #     f1 = RFtNormal
  190. #     f2 = np.zeros((20))
  191. # elif goal == "RTG":
  192. #     f1 = fuelMatrix[:,21]
  193. #     f2 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0])
  194. #     #HEB-248, LECf-249, HECf-249 produces Cf-250 for these amounts
  195. # f1 = f1[..., np.newaxis]
  196. # f2 = f2[..., np.newaxis]
  197.  
  198. C0 = heat > maxHeat
  199. maximumN = cellN / np.sqrt(heat/heat[1])
  200.  
  201. FF = np.squeeze(((enableLE * LE + enableHE * HE + enableMOX * MOX + enableTBU * TBU)==0).T) | \
  202.     np.isin(fuelOrder, forbiddenFuels) | C0
  203.  
  204. FF = FF[..., np.newaxis]
  205.    
  206. N = 27
  207. M = N+1
  208. C = np.zeros(49)
  209. Result = np.zeros([50, 27])
  210.  
  211. x = cvx.Variable((27, 1))
  212. Z = cvx.Variable((27, 1), integer = True)
  213. y = cvx.Variable((20, 1))
  214.  
  215. tol = 10 ** -6
  216.  
  217. ub = maximumN / multiplier
  218. ub = ub[..., np.newaxis]
  219.  
  220. if goal == "RF" and oxide == True:
  221.     f1 = RFtOxide
  222.     objective = cvx.Maximize(f1.T @ x)
  223. elif goal == "RF":
  224.     f1 = RFtNormal
  225.     objective = cvx.Maximize(f1.T @ x)
  226. elif goal == "RTG":
  227.     f1 = fuelMatrix[:,21]
  228.     f2 = np.array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0])
  229.     objective = cvx.Maximize(f1.T @ x + f2.T @ y)
  230.  
  231. constraints = [x >= 0, x <= ub]
  232.  
  233. if decayHastener == True:
  234.     constraints += [y >= 0]
  235. else:
  236.     constraints += [y == 0]
  237.  
  238. constraints += [separatorMatrix.T @ np.array([[Thorium], [Uranium]])+
  239.                 fuelMatrix.T @ x +
  240.                 decayMatrix.T @ y >= 0]
  241.  
  242. constr_int = [x == Z]
  243.  
  244. while True:
  245.  
  246.     FuelConstraints = [cvx.multiply(x, FF) == 0]
  247.  
  248.     prob = cvx.Problem(objective,
  249.                           constraints + FuelConstraints + constr_int)
  250.    
  251.     prob.solve()
  252.     N = np.sum(x.value!=0)
  253.     print('Number of reactors: ' + str(N))
  254.     if prob.status == 'infeasible':
  255.         break
  256.     if prob.value == 0:
  257.         break
  258.     if M>N:
  259.         Result[0, N-1] = prob.value
  260.         Result[1, N-1] = Thorium
  261.         Result[2, N-1] = Uranium
  262.         Result[3:30, N-1] = np.squeeze(x.value)
  263.         Result[30:50, N-1] = np.squeeze(y.value)
  264.         M=N
  265.    
  266.     fArray = np.zeros(27)
  267.     for k in np.where(x.value>tol)[0]:
  268.         FF2 = np.copy(FF)
  269.         FF2[k] = True
  270.         FuelConstraints = [cvx.multiply(x, FF2) == 0]
  271.         prob = cvx.Problem(objective, constraints + FuelConstraints)
  272.         prob.solve()
  273.         fArray[k] = prob.value
  274.        
  275.    
  276.     k = np.where(fArray == np.amax(fArray))
  277.     FF[k] = True
  278.     print('Eliminating: ')
  279.     for fuel in fuelOrder[fArray == np.amax(fArray)]:
  280.         print(fuel)
Advertisement
Add Comment
Please, Sign In to add comment