Module:Rocketry
From Stationeers Community Wiki
More actions
Documentation for this module may be created at Module:Rocketry/doc
local Gas = require("Module:Gas")
local Combustion = require("Module:Combustion")
local CombustionData = require("Module:Combustion/data")
local GasData = mw.loadData("Module:Gas/data")
local p = {}
function p.GetCombustionTemperature(fuel, oxidizer, reactiondata, combustionRatio, fuelTemperature, oxidizerTemperature)
local EnthalpyMultiplier = 1
fuelTemperature = fuelTemperature or 100
oxidizerTemperature = oxidizerTemperature or 100
combustionRatio = combustionRatio or 0.96
if not outputs then
if not oxidizer then
reactiondata = CombustionData[fuel]
else
reactiondata = CombustionData[fuel][oxidizer]
EnthalpyMultiplier = Gas.GetGas(oxidizer).EnthalpyMultiplier
end
end
local FuelEnthalpy = Gas.GetGas(fuel).Enthalpy
local FuelHeatEnergy = (Gas.GetGas(fuel).SpecificHeat*fuelTemperature)*reactiondata.FuelAmount
local OxidizerHeatEnergy = (Gas.GetGas(oxidizer).SpecificHeat*oxidizerTemperature)*reactiondata.OxidizerAmount
local CombustionEnergy = FuelEnthalpy*reactiondata.FuelAmount*combustionRatio*EnthalpyMultiplier
local TotalEnergy = FuelHeatEnergy + OxidizerHeatEnergy + CombustionEnergy
--add uncombusted contents to reaction outputs
if combustionRatio < 1 then
table.insert(reactiondata.Outputs,
{
Gas = Gas.GetGas(fuel),
Amount = reactiondata.FuelAmount*(1-combustionRatio)
}
)
table.insert(reactiondata.Outputs,
{
Gas = Gas.GetGas(oxidizer),
Amount = reactiondata.OxidizerAmount*(1-combustionRatio)
}
)
end
--calculate Heat Capacity of reaction output
local OutputHeatCapacity = 0
for k,v in pairs(reactiondata.Outputs) do
OutputHeatCapacity = OutputHeatCapacity + (v.Gas.SpecificHeat * v.Amount)
end
return TotalEnergy / OutputHeatCapacity, reactiondata --i'll want that later on for exhaust velocity because of heat capacity ratio.
end
function p.GetExhaustVelocity(engineEfficiency, combustiontemperature, heatcapacityratio)
if not heatcapacityratio then heatcapacityratio = GasData.TriatomicHeatCapacityRatio end
if type(heatcapacityratio) == "table" and type(heatcapacityratio.Outputs) == "table" then
--calculate heat capacity ratio by averaging out the heat capacity ratio of exhaust composition
local TotalMoles = 0
local TotalMolarHeatCapacityRatio = 0
for k,v in pairs(heatcapacityratio.Outputs) do
TotalMoles = TotalMoles + v.Amount
TotalMolarHeatCapacityRatio = TotalMolarHeatCapacityRatio + (v.Amount * v.Gas.HeatCapacityRatio)
end
heatcapacityratio = TotalMolarHeatCapacityRatio/TotalMoles
end
if type(heatcapacityratio) == "string" then heatcapacityratio = tonumber(heatcapacityratio) end
if type(heatcapacityratio) ~= number then
mw.log.warn("WARN: UNABLE TO PARSE HEAT CAPACITY RATIO. ASSUMING TriatomicHeatCapacityRatio")
heatcapacityratio = GasData.TriatomicHeatCapacityRatio
end
return 25*engineEfficiency*((8.3144*heatcapacityratio*combustiontemperature)^0.5)
end
function p.GetThrust(ExhaustVelocity, MassFlowRate)
if type(MassFlowRate) == "table" and type(MassFlowRate.Outputs) == "table" then
--calculate the molar mass of exhaust composition
local TotalMoles = 0
for k,v in pairs(heatcapacityratio.Outputs) do
TotalMoles = TotalMoles + v.Amount
end
MassFlowRate = TotalMoles
end
return 2*ExhaustVelocity*MassFlowRate --2 ticks/second; MassFlowRate is given in mols/tick.
end
return p