Advertisement
Guest User

Boilerscience 2

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