@ferret/physics-heat
temperature of parts, conduction, convection, radiation, phase change, expansion and melting.
Read the guide: how to use it →
Classes
HeatLibrary class
class HeatLibraryconstructor(initial: Record<string, HeatMaterial> = EXAMPLE_HEAT_MATERIALS) | |
add(name: string, m: HeatMaterial) | |
get(name: string): HeatMaterial | |
has(name: string) | |
names() |
packages/physics-heat/src/material.ts:47
HeatNetwork class
class HeatNetworkLumped parts joined by conductances, with convection and radiation to the surroundings. Stepped by Crank-Nicolson (second order, stable at any step); the state is the enthalpy, so a phase change holds the temperature while latent heat is paid and the energy balance closes exactly. Order is fixed (insertion), so a replay gives the same temperatures.
readonly parts: Part[] | |
readonly links: Link[] | |
ambient: number | |
onEvent: ((e: HeatEvent) => void) | null | called for phase changes and passed limits |
boundary: number | heat that crossed the boundary (surroundings, fixed parts), J: lets a test check the balance |
addPart(d: PartDef): Part | |
removePart(p: Part) | |
join(a: Part, b: Part, G: number): Link | |
unjoin(l: Link) | |
part(name: string): Part | undefined | |
add(p: Part, joules: number) | Put heat into a part now (J). |
setTemperature(p: Part, T: number) | |
stored(): number | Thermal energy stored in all free parts, J. |
ambientOf(p: Part) | |
stress(p: Part): number | Thermal stress in a held bar (Pa, negative = compression) and the free growth of a bar. |
strength(p: Part): number | |
grown(p: Part): number | |
step(dt: number) | |
grid(o: { name: string; material: HeatMaterial; nx: number; ny?: number; dx: number; dy?: number; thickness: number; T?: number; edge?: { left?: number; right?: number } }): Part[][] | A bar, a slab or a plate as a grid of parts (cells), joined along the faces: ny = 1 makes a rod. The cell at (0, j) can be held
at a temperature with edge. Returns the cells by [j][i]. |
packages/physics-heat/src/network.ts:108
Functions
enthalpy function
function enthalpy(m: HeatMaterial, mass: number, T: number): numberpackages/physics-heat/src/network.ts:77
erfc function
function erfc(x: number): numberComplementary error function (Abramowitz-Stegun 7.1.26, error under 1.5e-7).
packages/physics-heat/src/material.ts:91
expansion function
function expansion: (m: HeatMaterial, length: number, dT: number) => numberFree thermal growth of a bar: dL = alpha·L·dT.
packages/physics-heat/src/material.ts:74
heat function
function heat(o: { network?: HeatNetwork; materials?: HeatLibrary } = {}): HeatCapabilitypackages/physics-heat/src/index.ts:40
strengthFactor function
function strengthFactor(m: HeatMaterial, T: number): numberStrength factor 0..1 of a material at a temperature, from its curve (linear between points, flat beyond).
packages/physics-heat/src/material.ts:65
temperatureOf function
function temperatureOf(m: HeatMaterial, mass: number, H: number): { T: number; phase: Phase; cap: number }Temperature and phase for an enthalpy: the plateaus hold the melting and boiling points.
packages/physics-heat/src/network.ts:86
thermalStress function
function thermalStress: (m: HeatMaterial, dT: number) => numberStress in a bar held at both ends: sigma = E·alpha·dT (compression when heated).
packages/physics-heat/src/material.ts:76
wallConductance function
function wallConductance(layers: Array<{ thickness: number; k: number }>, area: number): numberConductance of a wall of layers in series, W/K: A / sum(L_i / k_i).
packages/physics-heat/src/material.ts:79
Interfaces
AttachDef interface
interface AttachDef extends Omit<PartDef, 'material' | 'name'>material: string | |
name?: string |
packages/physics-heat/src/index.ts:24
HeatCapability interface
interface HeatCapability extends Capabilityreadonly network: HeatNetwork | |
readonly materials: HeatLibrary | |
attach(entity: Entity, def: AttachDef): Part | Give a body's entity a temperature. |
partOf(entity: Entity): Part | undefined |
packages/physics-heat/src/index.ts:26
HeatMaterial interface
interface HeatMaterialA material's thermal record: the same data for a rod, a wall, a block of ice and a brake disc.
density: number | kg/m³ |
c: number | specific heat of the solid, J/(kg·K) |
k: number | thermal conductivity, W/(m·K) |
emissivity?: number | surface emissivity, 0..1 |
melt?: { T: number; latent: number; c: number } | melting and boiling: the temperature (K), the latent heat (J/kg) and the specific heat of what comes after |
boil?: { T: number; latent: number; c: number } | |
alpha?: number | linear thermal expansion, 1/K, and Young's modulus, Pa |
E?: number | |
sigmaMax?: number | stress (Pa) the material holds at room temperature, and its fall with temperature as [K, factor] points |
strengthCurve?: Array<[number, number]> | |
ignition?: number | ignition temperature, K |
packages/physics-heat/src/material.ts:2
Link interface
interface Linkpackages/physics-heat/src/network.ts:62
Part interface
interface Partreadonly id: number | |
readonly name: string | |
readonly mass: number | |
readonly material: HeatMaterial | |
T: number | |
H: number | enthalpy, J, from 0 K as a solid |
area: number | |
h: number | |
radiates: boolean | |
fixed: boolean | |
ambient?: number | |
power: number | |
length: number | |
held: boolean | |
reference: number | |
limit?: number | |
limitHit: boolean | |
userData?: unknown | |
entity?: string | the entity this part belongs to (a vessel standing in it takes its thresholds from that entity's scope) |
phase: Phase | |
flowed: number | energy that has flowed into the part from its links and surroundings, J (negative = out) |
packages/physics-heat/src/network.ts:35
PartDef interface
interface PartDefname: string | |
mass?: number | kg; or give volume and the density of the material is used |
volume?: number | |
material: HeatMaterial | |
T?: number | starting temperature, K |
area?: number | area exposed to the surroundings, m² |
h?: number | convection coefficient to the surroundings, W/(m²·K); 0 = none |
radiates?: boolean | emissivity; the material's when missing (and radiation is only counted when radiates is true) |
fixed?: boolean | held at its temperature (a heat bath, a wall face at a given temperature) |
ambient?: number | surroundings of this part, K; the network's ambient when missing |
power?: number | continuous heating, W |
length?: number | length (m) and whether both ends are held: a bar that cannot grow carries a thermal stress |
held?: boolean | |
reference?: number | installed (stress-free) temperature, K |
limit?: number | a limit of temperature (K) that raises over once |
userData?: unknown |
packages/physics-heat/src/network.ts:5
Types
HeatEvent type
type HeatEvent = | { kind: 'phase'; part: Part; to: Phase; from: Phase } | { kind: 'over'; part: Part; limit: 'temperature' | 'stress'; value: number }packages/physics-heat/src/network.ts:64
Phase type
type Phase = 'solid' | 'melting' | 'liquid' | 'boiling' | 'gas'packages/physics-heat/src/network.ts:3
Constants
EXAMPLE_CONVECTION const
const EXAMPLE_CONVECTION: Record<string, (v: number) => number>Convection coefficient, W/(m²·K), of a medium at a flow speed: still values plus a velocity term (McAdams-type, as data).
packages/physics-heat/src/material.ts:84
EXAMPLE_HEAT_MATERIALS const
const EXAMPLE_HEAT_MATERIALS: Record<string, HeatMaterial>packages/physics-heat/src/material.ts:24
HEAT_DEFAULTS const
const HEAT_DEFAULTS: { ambient: number; frictionToHeat: number; contactConductance: number; }temperature. Every part (a body, a wall, a gas, a reservoir) has a temperature; heat moves by conduction between parts, by convection and radiation to the surroundings, and a phase change holds the temperature while its latent heat is paid. Work lost in contacts (friction, rolling, inelastic hits) becomes heat in the parts that touched, so the energy balance closes.
values (each at world / level / zone / entity scope):
ambient temperature of the surroundings, K (293.15)
frictionToHeat share of the mechanical energy lost in a contact that becomes heat (1)
contactConductance W/K between two parts that touch; 0 = no conduction at contacts (0)events: heat:phase { part, to, from }, heat:over { part, limit, value }, heat:ignite { part }.
packages/physics-heat/src/index.ts:22
SIGMA const
const SIGMA: 5.670374419e-8packages/physics-heat/src/material.ts:61
T_ROOM const
const T_ROOM: 293.15packages/physics-heat/src/material.ts:62