Advertisement
Guest User

boilerscience_3

a guest
Feb 15th, 2014
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. --variable declaration
  2. local fuel = 0
  3. local hplp_div = 0
  4. local hp = false
  5. local hpname = ""
  6. local size = 0
  7. local ticks = 0
  8. local upticks = 0
  9. local downticks = 0
  10. local boilticks = 0
  11. local maxticks = 0
  12. local temp = 20
  13. local maxtemp = 0
  14. local finaltemp = 0
  15. local heatstep = 0.05
  16. local heatchange = 0
  17. local heatup = false
  18. local efficiency = 0
  19. local energy = 0
  20. local energymod = 0
  21. local deltafuel = 0
  22. local answer = ""
  23.  
  24. --user input
  25.  
  26. print("For how many ticks should the boiler be active?")
  27. maxticks = tonumber(io.read())
  28.  
  29. while not ((size == "1") or (size == "8") or (size == "12") or (size == "18") or (size == "27") or (size == "36")) do
  30.     print("What size of boiler will you use? (1,8,12,18,27,36)")
  31.     size = io.read()
  32. end
  33.  
  34. while not ((answer == "h") or (answer == "H") or (answer == "l") or (answer == "L")) do
  35.     print("Is it a (H)igh or (L)ow Pressure boiler?")
  36.     answer = io.read()
  37. end
  38.  
  39. if ((answer == "h") or (answer == "H")) then
  40.     hp = true
  41. end
  42.  
  43. if hp then
  44.     maxtemp = 1000
  45.     hplp_div = 8
  46.     hpname = size.." HP"
  47.     energymod = 4
  48. else
  49.     maxtemp = 500
  50.     hplp_div = 16
  51.     hpname = size.." LP"
  52.     energymod = 2
  53. end
  54.  
  55. print("What is the starting temp?")
  56. temp = tonumber(io.read())
  57.  
  58. if temp > maxtemp then
  59.     temp = maxtemp
  60. elseif temp < 20 then
  61.     temp = 20
  62. end
  63.  
  64. local cooltemp = temp
  65.  
  66. print(" ")
  67. print("Simulating a "..hpname.." steam boiler for an active period of "..tostring(maxticks).." ticks...")
  68. print("Starting at "..tostring(temp).." C.")
  69.  
  70. --calculate active burn period
  71. while ticks < maxticks do
  72.     --calculate fuel for tick
  73.     deltafuel = ((6.4 - size * 0.08) / hplp_div) * size * (1 + 8 * (1 - temp / maxtemp))
  74.     fuel = fuel + deltafuel
  75.  
  76.     --calculate MJ output
  77.     if temp >= 100 then
  78.         energy = energy + (energymod * size)
  79.     end
  80.  
  81.     --calculate heatup process
  82.     if temp < maxtemp then
  83.         heatchange = heatstep
  84.         if temp < 0.25*maxtemp then
  85.             heatchange = heatchange + heatstep
  86.         end
  87.         if temp < 0.5*maxtemp then
  88.             heatchange = heatchange + heatstep
  89.         end
  90.         if temp < 0.75*maxtemp then
  91.             heatchange = heatchange + heatstep
  92.         end
  93.         heatchange = heatchange / size
  94.         temp = temp + heatchange
  95.         upticks = upticks + 1
  96.     end
  97.  
  98.     --advance ticks
  99.     ticks = ticks + 1
  100.  
  101.     --note down boiling point
  102.     if ((boilticks == 0) and (temp >= 100)) then
  103.         boilticks = ticks
  104.     end
  105. end
  106.  
  107. finaltemp = temp
  108.  
  109. --calculate cooldown period
  110. while temp >= cooltemp do
  111.  
  112.     --calculate MJ output
  113.     energy = energy + (energymod * size)
  114.  
  115.     ---calculate cooldown process
  116.     heatchange = heatstep
  117.     if temp >= 0.25*maxtemp then
  118.         heatchange = heatchange + heatstep
  119.     end
  120.     if temp >= 0.5*maxtemp then
  121.         heatchange = heatchange + heatstep
  122.     end
  123.     if temp >= 0.75*maxtemp then
  124.         heatchange = heatchange + heatstep
  125.     end
  126.     heatchange = heatchange / size
  127.     temp = temp - heatchange
  128.     downticks = downticks + 1
  129. end
  130.  
  131. efficiency = energy / fuel
  132.  
  133. --output results
  134. print ("Simulation complete.")
  135. if boilticks == 0 then
  136.     print("- The water did not start to boil.")
  137. elseif boilticks > 1 then
  138.     print("- The water started boiling at 100 C after "..tostring(boilticks).." ticks.")
  139. end
  140. if finaltemp >= maxtemp then
  141.     print("- The boiler finished heating up to "..tostring(maxtemp).." C over the course of the first "..tostring(upticks).." ticks.")
  142. else
  143.     print("- The boiler did not finish heating up, reaching a final temperature of "..tostring(finaltemp).." C.")
  144. end
  145. if finaltemp >= 100 then
  146.     print("- After the active period, it spent an additional "..tostring(downticks).." ticks cooling back down to below "..tostring(cooltemp).." C.")
  147. end
  148. print("- The boiler consumed "..tostring(fuel).." Heat Units of fuel during the active period.")
  149. if energy > 0 then
  150.     print("- With this much fuel, it produced enough steam for "..tostring(energy).." MJ worth of Buildcraft energy.")
  151.     print("- The fuel efficiency for this simulation is "..tostring(efficiency).." MJ per HU.")
  152. else
  153.     print("- As the water did not boil, it did not produce any energy.")
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement