Module:Gas/data
More actions
--[[-- This module is intended to be loaded through mw.loaddata, giving the following restrictions: The loaded module is evaluated only once per page, rather than once per Script error: You must specify a function to call. call. The loaded module is not recorded in package.loaded. The value returned from the loaded module must be a table. Other data types are not supported. The returned table (and all subtables) may contain only booleans, numbers, strings, and other tables. Other data types, particularly functions, are not allowed. The returned table (and all subtables) may not have a metatable. All table keys must be booleans, numbers, or strings. The table actually returned by mw.loadData() has metamethods that provide read-only access to the table returned by the module. Since it does not contain the data directly, pairs() and ipairs() will work but other methods, including #value, next(), and the functions in the Table library, will not work correctly. --]]--
local p = {}
-- Gas Constants: p.StefanBoltzmannConstant = 5.6703e-8 p.R = 8.3144 --J/mol*K p.PolyatomicHeatCapacityRatio = 1.26 p.TriatomicHeatCapacityRatio = 1.333333 p.DiatomicHeatCapacityRatio = 1.4 p.MonoatomicHeatCapacityRatio = 1.666666
--[[-- Gas fields: --Name(string, Required): Lua-indexable name for the gas. Should use the english localization with spaces removed. gases["Liquid Hydrochloric Acid"] is a handful to use compared to gases.LiquidHydrochloricAcid. --ID(number, Required): Internal Game-specific ID for the gas. --HumanReadableName: (string, default: Autofilled from name by prepending 2nd+ uppercase letters with spaces, NYI): Printable name. --HumanReadableSymbol: (string, NYI): Community-defined chemical name for the gas. Aim for simple: X instead of POL, Alc instead of EtOH|MeOH|CH3CH2OH|CH4O.
--Image: (string, NYI): wiki-local URI to an icon of the gas.
--MolarMass (number, g/mol, Required): Molar mass of the gas for rocketry. --HeatCapacityRatio (number, Default: p.MonoatomicHeatCapacityRatio): The gas's heat capacity ratio. Used in rocketry to calculate exhaust velocity. --State(string, Autofilled as "Gas"): Phase the gas is in. (Internally, liquids are treated as gases) --MolarVolume (number, L/mol, Defaults to 0 for gases): Volume taken by a Liquid.
--SpecificHeat(number, J/mol*K, Default: nil): Heat capacity for the gas. --LatentHeat (number, J/mol, Default: nil): latent heat for the gas. --CondensesInto: (Default: nil): Name of gas it condenses in. nil for things that don't condense. --EvaporatesInto: (Default: nil): Name of gas it evaporates in. nil for things that don't evaporate. --TriplePressure: (number, kPa, Default: nil): Minimum condensation pressure. --CriticalPressure: (number, kPa, Default: nil): Maximum liquid pressure. --A: (number, Default: nil): Coefficient A for the phase change pressure-temperature curve. --B: (number, Default: nil): Coefficient B for the phase change pressure-temperature curve. --FreezingTemperature: (number, K, Autofilled from TriplePressure, A, B): Temperature at which the gas starts to freeze. --CriticalTemperature: (number, K, Autofilled from CriticalPressure, A, B): Temperature at which liquid starts to evaporate regardless of pressure.
--Enthalpy: (Default: nil) Enthalpy of combustion per mol. Non-0 values indicate it's a fuel or hypergol. --AutoignitionTemperature: Temperature at which autoignition occurs under oxygen. --IsHypergol: (Default: nil) Whether it autoignites in the presence of an oxidizer regardless of autoignition offset. --AutoignitionOffset: (Default: nil) How far it changes autoignition temperatures (relative to oxygen) for fuels that react with it. --EnthalpyMultiplier: (Default: nil) How much it multiplies a Fuel's combustion enthalpy when reacting with it. 1 for oxygen, 2 for Ozone/Nitrous Oxide.
--ThermalEfficiency: (Default: 0.03 for gases, forced to 0 for liquids) The efficiency of a gas inside a stirling engine. --]]--
local function AddGas(gas)
if gas.State == "Gas" then
gas.MolarVolume = gas.MolarVolume or 0
gas.ThermalEfficiency = gas.ThermalEfficiency or 0.03
elseif gas.State == "Liquid" then
gas.ThermalEfficiency = 0 --FIXME: If any liquid gets a non-zero thermal efficiency. Kept this way for the time being as liquid generation copies from gases.
end
if gas.CondensesInto or gas.EvaporatesInto then
gas.FreezingTemperature = gas.FreezingTemperature or (gas.TriplePressure/gas.A)^(1/gas.B)
gas.CriticalTemperature = gas.CriticalTemperature or (gas.CriticalPressure/gas.A)^(1/gas.B)
end
gas.HeatCapacityRatio = gas.HeatCapacityRatio or 0.03
for k,v in pairs(gas) do
if k ~= "Name" then
--print (k, v)
if not p[k] then p[k]={} end
p[k][gas.Name]=v
end
end
p[gas.Name]=gas
p[gas.ID]=gas --for iterating over all gases, run pairs then filter by type(key)=="number"
end
local function makeliquidfromgas(gas) --creates a deep copy of the original argument with basic changes to make it into a liquid. Some fields still have to be filled in manually. local liquid = {} for k,v in pairs(gas) do liquid[k] = v end liquid.EvaporatesInto = gas.Name liquid.Name = liquid.CondensesInto liquid.CondensesInto = nil liquid.State = "Liquid" liquid.ThermalEfficiency = 0 return liquid end
local Oxygen = { Name = "Oxygen", ID = 1, MolarMass = 16, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, --Oxygen itself is diatomic, but that's not used on any gas right now. argh. (recheck after rocketry overhaul) State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 21.1, LatentHeat = 800, CondensesInto = "LiquidOxygen", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 2.6854996004e-11, B = 6.49214937325, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = 0, EnthalpyMultiplier = 1,
ThermalEfficiency = 0.12 } local LiquidOxygen = makeliquidfromgas(Oxygen) LiquidOxygen.ID = 256 LiquidOxygen.MolarVolume = 0.03 AddGas(Oxygen) AddGas(LiquidOxygen)
local Nitrogen = { Name = "Nitrogen", ID = 2, MolarMass = 64, --recheck after rocketry overhaul. HeatCapacityRatio = p.TriatomicHeatCapacityRatio, --Nitrogen itself is diatomic, but that's not used on any gas right now. argh. (recheck after rocketry overhaul) State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 20.6, LatentHeat = 500, CondensesInto = "LiquidNitrogen", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 5.5757107833e-7, B = 4.40221368946, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.12 }
local LiquidNitrogen = makeliquidfromgas(Nitrogen) LiquidNitrogen.ID = 128 LiquidNitrogen.MolarVolume = 0.0348 AddGas(Nitrogen) AddGas(LiquidNitrogen)
local CarbonDioxide = { Name = "CarbonDioxide", ID = 4, MolarMass = 44, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, --Triatomic at room temperatures. Gains vibrational freedom on high temperatures making polyatomic-ish there IRL but notingame. (recheck after rocketry overhaul) State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 28.2, LatentHeat = 600, CondensesInto = "LiquidCarbonDioxide", EvaporatesInto = nil, TriplePressure = 517, CriticalPressure = 6000, A = 1.579573e-26, B = 12.195837931, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.08 } local LiquidCarbonDioxide = makeliquidfromgas(CarbonDioxide) LiquidCarbonDioxide.ID = 2048 LiquidCarbonDioxide.MolarVolume = 0.04 AddGas(CarbonDioxide) AddGas(LiquidCarbonDioxide)
local Methane = { Name = "Methane", ID = 8, MolarMass = 16, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 20.4, LatentHeat = 1000, CondensesInto = "LiquidMethane", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 5.863496734e-15, B = 7.8643601035, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = 286000, AutoignitionTemperature = 573.15, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.15 } local LiquidMethane = makeliquidfromgas(Methane) LiquidMethane.MolarVolume = 0.04 LiquidMethane.ID = 512 AddGas(Methane) AddGas(LiquidMethane)
local Pollutant = { Name = "Pollutant", ID = 16, MolarMass = 28, HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --not triatomic. State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 24.8, LatentHeat = 2000, CondensesInto = "LiquidPollutant", EvaporatesInto = nil, TriplePressure = 1800, CriticalPressure = 6000, A = 2.079033884, B = 1.31202194555, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.05 } local LiquidPollutant = makeliquidfromgas(Pollutant) LiquidPollutant.MolarVolume = 0.04 LiquidPollutant.ID = 4096 AddGas(Pollutant) AddGas(LiquidPollutant)
--next is theoretically Water, but because i'm too lazy to create a makegasfromliquid function, here goes Steam instead. local Steam = { Name = "Steam", ID = 1024, MolarMass = 48, --higher than IRL water. recheck after rocketry overhaul. HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 72, LatentHeat = 8000, CondensesInto = "Water", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 3.8782059839e-19, B = 7.90030107708, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.05 } local Water = makeliquidfromgas(Steam) Water.MolarVolume = 0.018 Water.ID = 32 AddGas(Steam) AddGas(Water)
local NitrousOxide = { Name = "NitrousOxide", ID = 64, MolarMass = 46, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 37.2, LatentHeat = 4000, CondensesInto = "LiquidNitrousOxide", EvaporatesInto = nil, TriplePressure = 800, CriticalPressure = 2000, A = 0.065353501531, B = 1.70297431874, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = -250, EnthalpyMultiplier = 2, --strong oxidizer
ThermalEfficiency = 0.12 } local LiquidNitrousOxide = makeliquidfromgas(NitrousOxide) LiquidNitrousOxide.MolarVolume = 0.026 LiquidNitrousOxide.ID = 8192 AddGas(NitrousOxide) AddGas(LiquidNitrousOxide)
--earlier liquids and steam get slotted here, so their IDs are already represented.
local Hydrogen = { Name = "Hydrogen", ID = 16384, MolarMass = 2, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 20.4, --used to be 2, recheck after rocketry overhaul LatentHeat = 200, CondensesInto = "LiquidHydrogen", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 3.18041e-5, B = 4.4843872973, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = 306000, AutoignitionTemperature = 573.15, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.18 } local LiquidHydrogen = makeliquidfromgas(Hydrogen) LiquidHydrogen.MolarVolume = 0.028 LiquidHydrogen.ID = 32768 AddGas(Hydrogen) AddGas(LiquidHydrogen)
--Polluted water lacks a gas form. reeeee local PollutedWater = { Name = "PollutedWater", ID = 65536, MolarMass = 48, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Liquid", --NOT a gas. MolarVolume = 0.018,
SpecificHeat = 72, LatentHeat = 8000, CondensesInto = nil, EvaporatesInto = "Steam", TriplePressure = 6.3, CriticalPressure = 6000, A = 4e-20, B = 8.27025711260823, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.00 } AddGas(PollutedWater)
local Hydrazine = {
Name = "Hydrazine",
ID = 131072,
MolarMass = 32,
HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --NOT triatomic.
State = "Gas",
MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 48.4, LatentHeat = 4000, CondensesInto = "LiquidHydrazine", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 6000, A = 8E-22, B = 9.15642808045339, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = 204000, AutoignitionTemperature = (6000/8e-22)^(1/9.15642808045339), -- = evaporation temperature at critical pressure IsHypergol = true, --Only hypergol in the game as of now (along with liquid hydrazine) AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.08 } local LiquidHydrazine = makeliquidfromgas(Hydrazine) LiquidHydrogen.MolarVolume = 0.03 LiquidHydrogen.ID = 262144 AddGas(Hydrazine) AddGas(LiquidHydrazine)
--Liquid Alcohol lacks a gas form. reeeee local LiquidAlcohol = { Name = "LiquidAlcohol", ID = 524288, MolarMass = 46, --same as Ethanol HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --NOT triatomic. State = "Liquid", --NOT a gas. MolarVolume = 0.058,
SpecificHeat = 63, LatentHeat = 18000, CondensesInto = nil, EvaporatesInto = "Methane", TriplePressure = 6.3, CriticalPressure = 1000, A = 9e-20, B = 8.391884446078986, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = 418000, AutoignitionTemperature = 673.15, -- 100°C higher than other fuels IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.00 } AddGas(LiquidAlcohol)
local Helium = { Name = "Helium", ID = 1048576, MolarMass = 4, HeatCapacityRatio = p.MonoatomicHeatCapacityRatio, --the only monoatomic gas currently ingame. State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 20.8, LatentHeat = 0, --Chemistry.LATENT_HEAT_HELIUM CondensesInto = nil, EvaporatesInto = nil, TriplePressure = 0, --Chemistry.MINIMUM_LIQUID_PRESSURE_HELIUM CriticalPressure = 515, --Mole.MinimumLiquidPressureAtMaxTemperature. Same as molten salt for some reason. A = 0, -- These are actually defined. Were it not defined, these would return an ArgumentOutOfRangeException when queried ingame. B = 0, -- Enjoy the divisions by 0 while trying to calculate evaporation pressure, i guess. FreezingTemperature = 0, --Chemistry.FREEZING_POINT_HELIUM CriticalTemperature = 0, --Chemistry.CRITICAL_TEMPERATURE_HELIUM_K
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.18 } AddGas(Helium)
local LiquidSodiumChloride = { Name = "LiquidSodiumChloride", ID = 2097152, MolarMass = 101, HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --NOT triatomic. State = "Liquid", --NOT a gas. MolarVolume = 0.04,
SpecificHeat = 130, LatentHeat = 1000, CondensesInto = nil, EvaporatesInto = "Pollutant", TriplePressure = 6.3, CriticalPressure = 515, A = 6.211737044295E-08, B = 2.8774143233482707, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.00 } AddGas(LiquidSodiumChloride)
local Silanol = { Name = "Silanol", ID = 4194304, MolarMass = 166, HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --not triatomic. State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 101, LatentHeat = 10000, CondensesInto = "LiquidSilanol", EvaporatesInto = nil, TriplePressure = 516, CriticalPressure = 6000, A = 0.22176555607618392, B = 1.5206578718752168, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.05 } local LiquidSilanol = makeliquidfromgas(Silanol) LiquidPollutant.MolarVolume = 0.16 LiquidPollutant.ID = 8388608 AddGas(Silanol) AddGas(LiquidSilanol)
local HydrochloricAcid = { Name = "HydrochloricAcid", ID = 16777216, MolarMass = 36, HeatCapacityRatio = p.PolyatomicHeatCapacityRatio, --NOT triatomic. State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 37, --used to be 2, recheck after rocketry overhaul LatentHeat = 1000, CondensesInto = "LiquidHydrochloricAcid", EvaporatesInto = nil, TriplePressure = 6.3, CriticalPressure = 1000, A = 1E-21, B = 9.108844460789863, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = nil, EnthalpyMultiplier = nil,
ThermalEfficiency = 0.05 } local LiquidHydrochloricAcid = makeliquidfromgas(HydrochloricAcid) LiquidHydrochloricAcid.MolarVolume = 0.028 LiquidHydrochloricAcid.ID = 33554432 AddGas(HydrochloricAcid) AddGas(LiquidHydrochloricAcid)
local Ozone = { Name = "Ozone", ID = 67108864, MolarMass = 24, HeatCapacityRatio = p.TriatomicHeatCapacityRatio, State = "Gas", MolarVolume = nil, --will be defaulted to 0 on AddGas
SpecificHeat = 38.6, LatentHeat = 1000, CondensesInto = "LiquidOzone", EvaporatesInto = nil, TriplePressure = 250, CriticalPressure = 6000, A = 0.006219763823043718, B = 2.4097251251207226, FreezingTemperature = nil, --will be calculated later on AddGas CriticalTemperature = nil, --will be calculated later on AddGas
Enthalpy = nil, AutoignitionTemperature = nil, IsHypergol = nil, AutoignitionOffset = -150, --strong oxidizer. EnthalpyMultiplier = 2,
ThermalEfficiency = 0.12 } local LiquidOzone = makeliquidfromgas(Ozone) LiquidOxygen.ID = 134217728 LiquidOxygen.MolarVolume = 0.026 AddGas(Ozone) AddGas(LiquidOzone) return p