Posted 11 February 2014 - 09:46 PM
I am attempting to create a program that calculates the amount of energy produced by a steam boiler added by the mod Railcraft when it is given a user inputted amount of fuel. It first calculates the amount of steam produced and then converts it into MJ and EU, returning the values for all of the above. There is already a web based calculator, which has been shown to be highly accurate (though I noticed it did not implement the fuel value changes outlined here). My program could eventually be used with OpenPeripherals to detect the types and amount of fuels in a chest and return the amount of energy that can be produced by them. The only problem with the code I came up with is that it does not calculate the correct amount of steam produced.
Here is the code I came up with.
The first part of my code (from "local running = 1" to "print(" Heat Units")") calculates the amount of heat units (or fuel units) that the inputted fuels can produce. It allows for the user to input different kinds of fuels, which the online calculator does not (though it does allow the user to input a custom fuel, which could be used to the same effect). My program currently offers only a limited number of different fuels, though I plan to add more when it actually works. I also plan to create a program or an option within this program that uses liquid fuels instead.
The second part of my code (from "print("High pressure (a) or low pressure (b ) to "N = read()") allows the user to input what type of boiler they are using (high pressure or low pressure) and how many tanks it has (e.g. a 2x2x2 boiler has 8 tanks). This section also sets up several variables that will be used in the next part of the script. The variable "tm" is the maximum temperature of the boiler (1000 for high pressure and 500 for low pressure). The variables H, EH, EP, FPBC, sigma, and N are the Heat Step, fuel heat inefficiency, fuel pressure inefficiency, fuel per boiler cycle, number of tanks, and steam per unit water.
The third part of my code (from "local steam = 0" to "print(" cycles with fuel")") is where my problems occur (there are also likely problems in the fourth part). The first three lines set up the initial values for variables used within the while loop. The while loop simulates the boiler when it is using fuel. I obtained the formulas it uses from this page, which was written by the author of Railcraft, CovertJaguar. It returns several values (maximum temperature, steam produced while the boiler had fuel, and number of cycles with fuel) that can be used for debugging or improving it.
The fourth part of my code simulates the boiler after it has consumed all of its fuel until it reaches a temperature bellow 100 degrees, at which no more steam will be produced. Then it returns the number of cycles spent cooling down, the total steam produced, and how much energy (EU or MJ) that steam can produce.
Can anyone find what is wrong with what I wrote? The source I used contains source code (in Java) from Railcraft that modifies the fuel and temperature. However, I do not understand Java so it would be helpful if someone who does could compare it to the code I wrote. Additionally, the formulas from the source I used use boiler cycles (the source gives a value for them in ticks) but the calculator seems to run on ticks. I think this may be a source of error. Any help or advice would be greatly appreciated.
Here is the code I came up with.
local running = 1
local fuel = 0
print("please input your fuel values.")
while running == 1 do
print("Please type the letter of the fuel to add or type stop to stop adding fuel.")
print("Charcoal (a);Coal (b ); Coke (c); Block of Coke(d); Block of Coal (e)")
write("Fuel:")
local input = read()
if input == "a" then
mult = 1600
elseif input == "b" then
mult = 1600
elseif input == "c" then
mult = 3200
elseif input == "d" then
mult = 28800
elseif input == "e" then
mult = 16000
elseif input == "stop" then
running = 0
end
if running == 1 then
write("Number:")
local number = read()
fuel = fuel + (number * mult)
end
end
write(fuel)
print(" Heat Units")
print("High pressure (a) or low pressure (b )")
write(":")
local input2 = read()
local tm = 0
local H = 0.05
local EH = 0.8
local EP = 4
local FPBC = 8
local sigma = 160
local N = 0
if input2 == "a" then
tm = 1000
elseif input2 == "b" then
tm = 500
end
write("Number of boilers:")
N = read()
local steam = 0
local temp = 20
local n = 1
while fuel > 0 do
if temp < tm then
temp = temp + (H + (((tm - temp) / tm) * H * 3) / N)
elseif temp > tm then
temp = tm
end
fuel = fuel - N * (FPBC + EH * (temp / tm) + EP * (tm / 1000))
if temp > 100 or temp == 100 then
steam = steam + sigma * N * (temp / tm)
end
n = n + 1
end
write(temp)
print(" degrees C.")
write(steam)
print(" mB of steam produced in heat up.")
write(n)
print(" cycles with fuel")
n = 0
local tvar = 1 - ((3 * H) / (tm * N))
while temp > 100 do
temp = tvar * temp - H
steam = steam + sigma * N * (temp / tm)
n = n + 1
end
write(n)
print(" cycles to cool down to bellow 100")
write(steam)
print(" mB of steam produced")
local MJ = steam * 0.2
local EU = steam * 0.625
write(MJ)
print(" MJ")
print("Or")
write(EU)
print(" EU can be produced.")
Note: please remove the space after the b's in parenthesis. I had to put them in so this editor would not mess them up. The first part of my code (from "local running = 1" to "print(" Heat Units")") calculates the amount of heat units (or fuel units) that the inputted fuels can produce. It allows for the user to input different kinds of fuels, which the online calculator does not (though it does allow the user to input a custom fuel, which could be used to the same effect). My program currently offers only a limited number of different fuels, though I plan to add more when it actually works. I also plan to create a program or an option within this program that uses liquid fuels instead.
The second part of my code (from "print("High pressure (a) or low pressure (b ) to "N = read()") allows the user to input what type of boiler they are using (high pressure or low pressure) and how many tanks it has (e.g. a 2x2x2 boiler has 8 tanks). This section also sets up several variables that will be used in the next part of the script. The variable "tm" is the maximum temperature of the boiler (1000 for high pressure and 500 for low pressure). The variables H, EH, EP, FPBC, sigma, and N are the Heat Step, fuel heat inefficiency, fuel pressure inefficiency, fuel per boiler cycle, number of tanks, and steam per unit water.
The third part of my code (from "local steam = 0" to "print(" cycles with fuel")") is where my problems occur (there are also likely problems in the fourth part). The first three lines set up the initial values for variables used within the while loop. The while loop simulates the boiler when it is using fuel. I obtained the formulas it uses from this page, which was written by the author of Railcraft, CovertJaguar. It returns several values (maximum temperature, steam produced while the boiler had fuel, and number of cycles with fuel) that can be used for debugging or improving it.
The fourth part of my code simulates the boiler after it has consumed all of its fuel until it reaches a temperature bellow 100 degrees, at which no more steam will be produced. Then it returns the number of cycles spent cooling down, the total steam produced, and how much energy (EU or MJ) that steam can produce.
Can anyone find what is wrong with what I wrote? The source I used contains source code (in Java) from Railcraft that modifies the fuel and temperature. However, I do not understand Java so it would be helpful if someone who does could compare it to the code I wrote. Additionally, the formulas from the source I used use boiler cycles (the source gives a value for them in ticks) but the calculator seems to run on ticks. I think this may be a source of error. Any help or advice would be greatly appreciated.