FERRETGame engine over Babylon.js
Ferret

@ferret/physics-combustion

combustion chambers, guns, rockets, piston engines, steam boilers and jets.

48 exports · source in packages/physics-combustion/src

Classes

Boiler class

class Boiler

A drum of water and steam at saturation, by its total mass and internal energy: heat in raises the temperature and the pressure along the saturation line and boils water off into the space; steam taken out (by a valve, an engine, a turbine) leaves with its enthalpy. Mass and energy close exactly: what went in is the drum's energy plus what left.

readonly volume: number
mass: number
U: number
T: number
quality: numbersteam quality (mass share of vapour) and the water's mass now
safety?: { pressure: number; area: number }
vented: numbersteam vented by the safety valve, kg; heat put in, J; enthalpy that left with steam, J
heatIn: number
energyOut: number
constructor(d: BoilerDef)
get pressure()
get water()
get steamEnthalpy()enthalpy of the saturated steam leaving, J/kg
flowThrough(area: number, outside = 101325, Cd = 0.9)Choked flow of saturated steam through an area at the drum's pressure into outside Pa (γ = 1.3), kg/s.
take(kg: number)Take steam out, kg (at most what is there as vapour); returns the enthalpy that left, J.
feed(kg: number, T = 300)Feed water of temperature T into the drum, kg: the mass and the water's own energy join the drum's, so cold feed cools it.
step(dt: number, heat = 0)Advance by dt with a heat input (W); the safety valve vents what it must.

packages/physics-combustion/src/steam.ts:49

Chamber class

class Chamber
volume: number
mass: number
T: number
readonly gas: GasSpec
fuel?: PremixFuel
fuelMass: number
oxygenMass: number
wall?: WallSpec
burstPressure?: number
burst: boolean
ignited: boolean
burnRate: number1/s: how fast the premix burns once lit
propellant?: Propellant
burnedPropellant: number
lost: numberheat that went to the wall, J
onBurst: ((r: BurstReport) => void) | null
constructor(o: ChamberOptions)
get R()
get gamma()
get cv()
get cp()
get pressure()
get density()
get U()internal energy, J
get sound()speed of sound, m/s
addHeat(joules: number)Add heat to the gas at the present volume.
setVolume(v: number)Change the volume with no heat exchange (compression and expansion do work p·dV).
get equivalence(): numberThe equivalence ratio of the premix: 1 is stoichiometric, above is rich.
ignite(): booleanLight the premix. It does not light outside its limits or with no oxygen or no fuel.
burn(dm: number): numberBurn dm kg of the premix at once: the heat goes into the gas, the mass stays (fuel and oxygen become products). Returns what burned.
burnPropellant(dt: number): numberBurn the propellant surface for dt: mass joins the gas at the grain temperature and brings its heat of burning. Returns the mass burned.
flow(orifice: Orifice, pa: number): numberMass flow, kg/s, through an orifice into a space at pa: choked when the pressure ratio is high enough, subsonic below.
vent(orifice: Orifice, pa: number, dt: number): numberLet gas out through an orifice for dt. The gas left behind expands isentropically. Returns the mass out.
coolWall(dt: number)Heat through the wall for dt (exact for a wall that stays at its temperature).
step(dt: number)One fixed step: propellant, premix, the wall. Venting is the caller's (it knows the ambient pressure).
stored(p0 = P_STD): numberEnergy a vessel releases when it bursts (Brode): (p − p0)·V / (γ − 1), J.

packages/physics-combustion/src/thermo.ts:97

PistonEngine class

class PistonEngine

A four-stroke engine on a crank: intake, compression, spark and a Wiebe burn, expansion, exhaust. The torque on the crank is p·A·dx/dθ summed over the angle it turned, so the idle, the torque curve and the stall come out of the cycle.

readonly chamber: Chamber
throttle: number
running: boolean
work: numberwork the gas did on the piston over its life, J, and the crank angle it has turned
turned: number
readonly spec: Required<Pick<EngineSpec, 'advance' | 'burnDuration' | 'crankcase' | 'cycle' | 'portHalfAngle' | 'scavenging' | 'ignition' | 'autoignition'>> & EngineSpec
misfires: numberwhether the last cycle lit (a diesel that was too cold to light does not)
constructor(spec: EngineSpec)
volume(theta: number)
torque(_omega: number, theta: number): numberThe torque on the crank at angle theta (the engine advances its cycle from the angle of the last call).

packages/physics-combustion/src/assemblies.ts:164

Functions

choke function

function choke: (g: number) => number

packages/physics-combustion/src/thermo.ts:95

combustion function

function combustion(): CombustionCapability

packages/physics-combustion/src/index.ts:33

equilibriumPressure function

function equilibriumPressure(pr: Propellant, throatArea: number, gas: GasSpec, T0: number, z = 0): number

Steady chamber pressure of a burning grain: rho·S·a·p^n = p·At / c*, so p^(1−n) = rho·S·a·c* / At.

packages/physics-combustion/src/thermo.ts:245

exitMach function

function exitMach(areaRatio: number, gamma: number): number

Exit Mach number of a nozzle of the given area ratio (supersonic branch).

packages/physics-combustion/src/assemblies.ts:116

fireGun function

function fireGun(g: GunSpec): GunShot

Fire the gun: the charge burns by Vieille's law in a chamber that grows with the projectile, the mean pressure acts on its base through the Lagrange pressure gradient, friction resists, and the muzzle velocity emerges from the charge, the mass and the barrel length.

packages/physics-combustion/src/assemblies.ts:56

gasSpec function

function gasSpec(gas: string | Record<string, number>, T = 300): GasSpec

A gas as the molar mass and gamma a chamber uses. Any gas of the species library, by formula ('CO2') or as a mixture of mole fractions ({ N2: 0.79, O2: 0.21 }), at the temperature T: the molar mass from the formula, gamma from cp(T) of the species.

packages/physics-combustion/src/thermo.ts:16

latentHeat function

function latentHeat(T: number): number

Latent heat of vaporisation at T, J/kg (Watson, from 2257 kJ/kg at 100 °C).

packages/physics-combustion/src/steam.ts:23

liquidDensity function

function liquidDensity(T: number): number

Density of saturated liquid water, kg/m³ (DIPPR 105).

packages/physics-combustion/src/steam.ts:25

liquidEnergy function

function liquidEnergy(T: number): number

Specific internal energy of saturated liquid from 0.01 °C, J/kg (cp of water 4.18 kJ/kg·K rising slowly with T).

packages/physics-combustion/src/steam.ts:32

nozzle function

function nozzle(gas: GasSpec, p0: number, T0: number, n: NozzleSpec, pa: number): RocketState

Thrust of a chamber at pressure p0 and temperature T0 through a nozzle into ambient pressure pa: F = mdot·ve + (pe − pa)·Ae.

packages/physics-combustion/src/assemblies.ts:126

premixFuel function

function premixFuel(fuel: string, o: { efficiency?: number; limits?: [number, number] } = {}): PremixFuel

The fuel of a chamber from the reaction enthalpy of the library: Q is the lower heating value of burning the species to CO2 and water vapour (J/kg) and oxygenPerFuel the stoichiometric oxygen, both from the formula and the formation enthalpies. CH4, C3H8, H2, C2H5OH(l), C8H18(l); efficiency and limits are the chamber's own.

packages/physics-combustion/src/thermo.ts:29

resolveGas function

function resolveGas(g: GasSpec | string | Record<string, number>, T = 300): GasSpec

a GasSpec, a formula or a mixture, as a GasSpec (at the temperature T)

packages/physics-combustion/src/thermo.ts:18

saturationPressure function

function saturationPressure(T: number): number

Saturation pressure at T (K), Pa.

packages/physics-combustion/src/steam.ts:12

saturationTemperature function

function saturationTemperature(p: number): number

Saturation temperature at p (Pa), K.

packages/physics-combustion/src/steam.ts:17

steamWork function

function steamWork(p1: number, p2: number, efficiency = 0.7): number

Work of steam expanded through a turbine or an engine from p1 to p2, J/kg: the isentropic drop of a perfect gas with γ = 1.3 from the saturation temperature at p1, times the machine's efficiency. A sketch of the steam chart, not Mollier's: within about 10 % for saturated steam expanded to a condenser.

packages/physics-combustion/src/steam.ts:121

turbofan function

function turbofan(spec: FanSpec, V0: number, T0 = 288.15, p0 = 101325): FanPoint

The same cycle with a fan: the fan lifts all the air, a fraction bypass / (1 + bypass) goes round the core to its own nozzle, the turbine drives fan and compressor together, and an optional afterburner reheats the core gas to T7 before the hot nozzle. Per kg/s of core air, so bypass = 0, fanRatio = 1 and no reheat is exactly turbojet.

packages/physics-combustion/src/jet.ts:72

turbojet function

function turbojet(spec: JetSpec, V0: number, T0 = 288.15, p0 = 101325): JetPoint

The engine at a flight speed V0 (m/s) in air of temperature T0 and pressure p0.

packages/physics-combustion/src/jet.ts:32

vapourVolume function

function vapourVolume(T: number): number

Specific volume of saturated steam, m³/kg, from Clapeyron.

packages/physics-combustion/src/steam.ts:27

Interfaces

BoilerDef interface

interface BoilerDef
volume: numberdrum volume, m³
water: numberwater in it, kg, and the starting temperature, K (saturated: the space above is steam)
T?: number
safety?: { pressure: number; area: number }the safety valve: opening pressure (Pa) and its flow area (m²)

packages/physics-combustion/src/steam.ts:34

BurstReport interface

interface BurstReport
pressure: number
energy: number
volume: number
mass: number
T: number

packages/physics-combustion/src/thermo.ts:93

ChamberEntry interface

interface ChamberEntry
chamber: Chamber
vent?: Orifice
entity?: Entity
casing?: number

packages/physics-combustion/src/index.ts:24

ChamberOptions interface

interface ChamberOptions
volume: number
gas?: GasSpec | string | Record<string, number>the gas: a GasSpec, or a formula / mixture of the species library (default air)
mass?: numberkg of gas (with the fuel and oxygen inside it), or give a pressure with the temperature
pressure?: number
T?: number
fuel?: PremixFuel
fuelMass?: numberkg of fuel and of oxygen inside the gas
oxygenMass?: number
wall?: WallSpec
burstPressure?: numberthe chamber ruptures above this pressure

packages/physics-combustion/src/thermo.ts:76

CombustionCapability interface

interface CombustionCapability extends Capability
readonly chambers: Map<string, ChamberEntry>
addChamber(name: string, chamber: Chamber, o?: { vent?: Orifice; entity?: Entity; casing?: number }): Chamber
fire(name: string, spec: GunSpec, o?: { body?: RigidBody; direction?: Vec3; muzzle?: Vec3; spawn?: boolean }): GunShotFire a gun; with a body the recoil impulse is applied to it opposite to direction, and a projectile is spawned.
engine?: PistonEngine

packages/physics-combustion/src/index.ts:25

EngineSpec interface

interface EngineSpec
bore: numberbore and crank radius (half the stroke) and rod length, m
crank: number
rod: number
compressionRatio: number
fuel: PremixFuel
airFuelRatio: numberkg of air per kg of fuel
advance?: numberspark advance before top dead centre, rad, and how long the burn takes, rad of crank
burnDuration?: number
air?: () => { pressure: number; temperature: number; oxygen: number }the air the engine breathes: pressure, temperature and the oxygen share by mass
crankcase?: numberpressure under the piston, Pa
cycle?: 'four' | 'two''four' (default): intake, compression, power, exhaust over two turns; 'two': a power stroke every turn, the gas exchanged through ports near the bottom
portHalfAngle?: numbertwo-stroke: how far each side of the bottom dead centre the ports stay open, rad of crank (1.0), and the share of the cylinder the fresh charge fills (0.8)
scavenging?: number
ignition?: 'spark' | 'compression''spark' (default): a premixed charge lit at the advance; 'compression' (a diesel): air alone is drawn in, fuel is injected at the advance (the throttle is the fuel quantity) and lights if the compressed air is hotter than autoignition (K, 750)
autoignition?: number

packages/physics-combustion/src/assemblies.ts:135

FanPoint interface

interface FanPoint extends JetPoint
thrustPerAir: numberthrust per kg/s of all the air (core plus bypass), m/s; specificThrust is per kg/s of core air
fuelAfterburner: numberfuel burned in the afterburner per kg of core air, and the exit speeds of the hot and the bypass streams
hotExhaust: number
bypassExhaust: number

packages/physics-combustion/src/jet.ts:60

FanSpec interface

interface FanSpec extends JetSpec
bypass: numberbypass ratio: kg of air past the core per kg through it (0 = a turbojet)
fanRatio: numberfan pressure ratio (the bypass stream leaves at this ratio; the core compressor adds pressureRatio on top) and the fan efficiency
etaFan?: number
T7?: numberafterburner (reheat) exit temperature, K, its combustion efficiency and total pressure ratio; absent = dry
etaAfterburner?: number
afterburnerPressure?: number

packages/physics-combustion/src/jet.ts:52

GasSpec interface

interface GasSpec
molarMass: number
gamma: number

packages/physics-combustion/src/thermo.ts:11

GunShot interface

interface GunShot
muzzleVelocity: number
time: numbers
peakPressure: number
muzzlePressure: number
kinetic: numberkinetic energy of the projectile and the chemical energy of the charge, J
chemical: number
projectileMomentum: numbermomentum of the projectile and of the gas in the barrel at exit (Lagrange: half of the gas mass at the projectile speed), kg·m/s
gasMomentum: number
recoilImpulse: numbermomentum the gun takes while the projectile is in the bore: the integral of the breech force less friction
muzzleImpulse: numberimpulse of the gas that escapes after the muzzle, with a nozzle-less exhaust speed, kg·m/s
burst: boolean
burned: number
wallLoss: numberheat the wall took, J
trace: Array<{ t: number; x: number; v: number; p: number }>

packages/physics-combustion/src/assemblies.ts:29

GunSpec interface

interface GunSpec
bore: numberbore diameter, m
length: numbertravel of the projectile in the barrel, m
projectile: numberprojectile mass, kg
chamberVolume: numberempty chamber volume behind the projectile at the start, m³
charge: Propellant
gas?: GasSpec | string | Record<string, number>
startForce?: numberforce that holds the projectile until it is overcome (engraving), N, and the friction while it moves, N
friction?: number
efficiency?: numbershare of the heat of burning that reaches the gas (the rest is lost to the walls)
covolume?: numberNoble-Abel covolume of the gas, m³/kg: the molecules take room, p (V − η m) = m R T (about 1e-3 for a propellant gas; 0 = ideal)
wallHeat?: numberheat the bore takes from the gas: coefficient W/(m² K) over the wetted wall (the chamber's and the bore's behind the base), and the wall temperature, K
wallTemperature?: number
burstPressure?: numberbarrel rupture pressure, Pa
ambient?: number

packages/physics-combustion/src/assemblies.ts:4

JetPoint interface

interface JetPoint
specificThrust: numberthrust per kg/s of air, N·s/kg (the specific thrust, m/s)
fuelAir: numberfuel per kg of air, and per newton of thrust per second (the thrust-specific fuel consumption), kg/(N·s)
tsfc: number
exhaust: numberexhaust speed, m/s, and the temperatures after compressor and turbine, K
T3: number
T5: number
thermal: numberthermal efficiency (kinetic energy gained over fuel energy), propulsive efficiency 2 V0 / (Ve + V0) and their product
propulsive: number
overall: number

packages/physics-combustion/src/jet.ts:19

JetSpec interface

interface JetSpec

A turbojet as a Brayton cycle with the losses of its parts: ram compression in the inlet, a compressor of pressure ratio π_c and efficiency η_c, a burner that heats the air to T4 (fuel from the energy balance, with its efficiency and pressure loss), a turbine that takes exactly the power the compressor needs, and a nozzle that expands to the ambient pressure. Constant specific heat and gamma through the engine; the gas leaving is air plus fuel. One kilogram per second of air is the unit: thrust and fuel flow scale with the mass flow.

pressureRatio: numbercompressor pressure ratio and the isentropic efficiencies of compressor, turbine and nozzle
etaCompressor?: number
etaTurbine?: number
etaNozzle?: number
inletRecovery?: numberpressure recovery of the inlet, pressure ratio of the burner, burner efficiency, mechanical efficiency of the shaft
burnerPressure?: number
etaBurner?: number
etaMechanical?: number
T4: numberturbine inlet temperature, K
lhv?: numberheating value of the fuel, J/kg
gamma?: number
cp?: number

packages/physics-combustion/src/jet.ts:7

NozzleSpec interface

interface NozzleSpec
throatArea: number
exitArea: number

packages/physics-combustion/src/assemblies.ts:113

Orifice interface

interface Orifice
area: number
Cd?: number

packages/physics-combustion/src/thermo.ts:63

PremixFuel interface

interface PremixFuel

A fuel mixed into the gas of the chamber (petrol vapour in air, hydrogen, a gas fuel).

Q: numberheating value, J per kg of fuel
efficiency?: numbershare of it that becomes heat in the gas (combustion efficiency)
oxygenPerFuel: numberstoichiometric kg of oxygen per kg of fuel
limits?: [number, number]burn only when the equivalence ratio (fuel / stoichiometric fuel for the oxygen present) lies in this range

packages/physics-combustion/src/thermo.ts:35

Propellant interface

interface Propellant

A solid propellant that burns on its surface by Vieille's law r = a·p^n.

density: numberkg/m³
a: numberburn rate coefficient: r in m/s with p in Pa
n: number
Q: numberheat of burning, J/kg
T?: numbertemperature of the grain before it burns, K
surface: (z: number) => numberburning surface as a function of the burned fraction z (0..1), m²
mass: numbertotal charge, kg

packages/physics-combustion/src/thermo.ts:47

RocketState interface

interface RocketState
mdot: number
exitVelocity: number
exitPressure: number
thrust: number

packages/physics-combustion/src/assemblies.ts:123

WallSpec interface

interface WallSpec
area: numberm²
h: numberW/(m²·K)
T?: numbertemperature of the wall, K; kept fixed unless it has a heat capacity
C?: numberJ/K of the wall; infinite when missing (the wall stays at its temperature)

packages/physics-combustion/src/thermo.ts:65

Constants

AIR const

const AIR: GasSpec

dry air, from the species library

packages/physics-combustion/src/thermo.ts:20

COMBUSTION_DEFAULTS const

const COMBUSTION_DEFAULTS: { ambient: number; }

combustion and gas under pressure. Chambers are stepped with the world: the premix burns, the propellant burns by Vieille's law, heat goes to the wall, gas leaves through its vent, and a chamber past its burst pressure ruptures into the blast of X. Guns are fired as a whole (the interior ballistics run in a few milliseconds) and give the muzzle velocity and the recoil.

values (each at world / level / zone / entity scope):

  ambient   pressure outside the chambers, Pa      (101325)

events: chamber:burst { name, pressure, energy }, combustion:out { name }, gun:fired { name, shot }.

packages/physics-combustion/src/index.ts:22

COMBUSTION_GAS const

const COMBUSTION_GAS: GasSpec

the gas of a propellant charge, a default for when no mixture is given (a propellant's products are not species of the library)

packages/physics-combustion/src/thermo.ts:22

P_CRIT const

const P_CRIT: 22064000

packages/physics-combustion/src/steam.ts:9

P_STD const

const P_STD: 101325

packages/physics-combustion/src/thermo.ts:9

R_STEAM const

const R_STEAM: 461.526

packages/physics-combustion/src/steam.ts:9

R_UNIVERSAL const

const R_UNIVERSAL: 8.314462618

packages/physics-combustion/src/thermo.ts:8

T_CRIT const

const T_CRIT: 647.096

packages/physics-combustion/src/steam.ts:9