FERRETGame engine over Babylon.js
Ferret

@ferret/physics-heat

temperature of parts, conduction, convection, radiation, phase change, expansion and melting.

23 exports · source in packages/physics-heat/src

Classes

HeatLibrary class

class HeatLibrary
constructor(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 HeatNetwork

Lumped 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) | nullcalled for phase changes and passed limits
boundary: numberheat 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(): numberThermal energy stored in all free parts, J.
ambientOf(p: Part)
stress(p: Part): numberThermal 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): number

packages/physics-heat/src/network.ts:77

erfc function

function erfc(x: number): number

Complementary 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) => number

Free 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 } = {}): HeatCapability

packages/physics-heat/src/index.ts:40

strengthFactor function

function strengthFactor(m: HeatMaterial, T: number): number

Strength 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) => number

Stress 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): number

Conductance 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 Capability
readonly network: HeatNetwork
readonly materials: HeatLibrary
attach(entity: Entity, def: AttachDef): PartGive a body's entity a temperature.
partOf(entity: Entity): Part | undefined

packages/physics-heat/src/index.ts:26

HeatMaterial interface

interface HeatMaterial

A material's thermal record: the same data for a rod, a wall, a block of ice and a brake disc.

density: numberkg/m³
c: numberspecific heat of the solid, J/(kg·K)
k: numberthermal conductivity, W/(m·K)
emissivity?: numbersurface 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?: numberlinear thermal expansion, 1/K, and Young's modulus, Pa
E?: number
sigmaMax?: numberstress (Pa) the material holds at room temperature, and its fall with temperature as [K, factor] points
strengthCurve?: Array<[number, number]>
ignition?: numberignition temperature, K

packages/physics-heat/src/material.ts:2

Part interface

interface Part
readonly id: number
readonly name: string
readonly mass: number
readonly material: HeatMaterial
T: number
H: numberenthalpy, 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?: stringthe entity this part belongs to (a vessel standing in it takes its thresholds from that entity's scope)
phase: Phase
flowed: numberenergy that has flowed into the part from its links and surroundings, J (negative = out)

packages/physics-heat/src/network.ts:35

PartDef interface

interface PartDef
name: string
mass?: numberkg; or give volume and the density of the material is used
volume?: number
material: HeatMaterial
T?: numberstarting temperature, K
area?: numberarea exposed to the surroundings, m²
h?: numberconvection coefficient to the surroundings, W/(m²·K); 0 = none
radiates?: booleanemissivity; the material's when missing (and radiation is only counted when radiates is true)
fixed?: booleanheld at its temperature (a heat bath, a wall face at a given temperature)
ambient?: numbersurroundings of this part, K; the network's ambient when missing
power?: numbercontinuous heating, W
length?: numberlength (m) and whether both ends are held: a bar that cannot grow carries a thermal stress
held?: boolean
reference?: numberinstalled (stress-free) temperature, K
limit?: numbera 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-8

packages/physics-heat/src/material.ts:61

T_ROOM const

const T_ROOM: 293.15

packages/physics-heat/src/material.ts:62