Heat and fire
Open the live demo · Read the source · View on GitHub
Every body in a world of the physics core has a material and a temperature. It loses heat to the air by convection and radiation, takes heat from what it touches and from hot bodies near it, and can carry water, which holds it at the boiling point until it has boiled away. Wood, paper and rubber catch at their ignition temperature and burn at the rate their heat balance gives: the flame's heat and what reaches the burning patch, less what it radiates and what the wood under it draws, over the heat it takes to turn a kilogram to fuel gas. A patch that cannot keep itself alight goes out. A burning body gets lighter.
This page puts a wooden board and a steel one either side of a block of stone at a thousand degrees Celsius. The wood catches and burns, the steel only warms, and water on the wood puts it out. The page runs twenty times faster than real time, so the wait to catch is about fifteen seconds rather than five minutes.
Step 1: A heater and two boards #
The page owns a world of the physics core's and steps it itself, faster than
the clock; the effects package's Elements adopt it, which means they draw
and hear it and never step it. All three bodies are put in through the
elements as solids of a shape, a material and a density, and fixed: nothing
here needs to move to burn. A fixed body's mass is its thermal mass, and it
is what burns away. The heater has no density, so no mass, which makes it a
reservoir: whatever heat it gives, it stays at the temperature it was set to.
The boards are twenty centimetres square and four thick, one pine at
500 kg/m³ and one steel at 7800, each with the core's preset for its
material.
/// The world, once, and the elements that draw its fires, adopting it:
/// the page steps it itself, faster than the clock.
@override
Future<void> prepare(DemoContext context) async {
try {
final world = NativeWorld();
_world = world;
final scene = _scene = Scene();
_elements = await Elements.adopt(
world,
device: context.device,
renderer: context.renderer,
scene: scene,
load: rootBundle.load,
quality: const ElementsQuality(
liquid: LiquidDetail.light,
fire: FireDetail.light,
),
);
} on Object catch (e) {
_world?.dispose();
_world = null;
fallback = physicsCoreLoaded
? '$e'
: 'the core is not loaded in this browser yet';
}
}
/// The heater and the two boards, all fixed: nothing here has to move to
/// burn. The heater has no mass, which makes it a reservoir: whatever it
/// gives, it stays at its temperature.
void _setUp() {
final elements = _elements!;
for (final TrackedBody body in _bodies) {
elements.remove(body);
}
_heaterBody = elements.addBody(
Solid.box(
Vector3.all(0.15),
material: NativeMaterial.stone(),
density: 0,
),
at: Vector3(0.0, 0.15, 0.0),
type: NativeBodyType.fixed,
);
elements.world.setTemperature(_heater, _hot);
// A fixed body's mass is its thermal mass, and what burns away.
_woodBody = elements.addBody(
Solid.box(_board, material: NativeMaterial.wood(), density: 500.0),
at: Vector3(-_apart, 0.1, 0.0),
type: NativeBodyType.fixed,
look: _woodNode,
);
_steelBody = elements.addBody(
Solid.box(_board, material: NativeMaterial.steel(), density: 7800.0),
at: Vector3(_apart, 0.1, 0.0),
type: NativeBodyType.fixed,
look: _steelNode,
);
_bodies = <TrackedBody>[_heaterBody, _woodBody, _steelBody];
_setWind();
_clock = 0.0;
_caught = null;
_doused = null;
}
List<TrackedBody> _bodies = const <TrackedBody>[];
/// What the steps since the elements last drew said happened: the page
/// reads the world's events, and hands them on.
final List<NativeEvent> _said = <NativeEvent>[];
Step 2: The heat the heater throws #
Nothing on the page passes heat from the heater to the boards: the core does. Every body gives the room εσA(T⁴ − Tₐ⁴) above what it would at the air's temperature, and each body near it catches its solid angle's share of that, as much as nothing stands in the way. A burning body also sends its material's radiant share of its fire's heat, and anything standing in its flame is heated by the flame's gas. Both boards get the same. The steel, with fifteen times the wood's mass, warms slowly; it has no ignition temperature in its preset, so it never catches however hot it gets. What the page draws of it is what the core says of it: its surface's temperature, glowing as a grey body of steel's emissivity does at that temperature.
/// The steel glows as hot metal does: a grey body at its surface's
/// temperature, ε·σT⁴·η(T)/π candela a square metre, η the lumens a
/// radiated watt is worth at T, in the renderer's units — nothing to see
/// at the room's temperature, a dull red past 800 K. Its surface's
/// temperature is what the core says, held at boiling while water is on
/// it.
void _look(RenderMaterial look, NativeBody body) {
final NativeWorld world = _world!;
final double t = world.surfaceTemperatureOf(body);
final double nits =
NativeMaterial.steel().emissivity *
stefanBoltzmann *
t *
t *
t *
t *
Blackbody.efficacy(t) /
math.pi;
final LinearColor color = Blackbody.color(t);
final double y = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
// Over `bulbAtOneMeter` and drawn at the default emissive strength: about 29 times the
// true luminance, the gain `FireView` draws its flames with, so the hot
// block glows beside them as it would beside a fire.
look.emissive = color.scaled(
y > 0.0 ? nits / Photometric.bulbAtOneMeter / y : 0.0,
);
look.emissiveStrength = 1.0 * RenderMaterial.defaultEmissiveStrength;
}
Step 3: Wind #
The air has a wind, uniform and from a grid. This grid has two samples, still
air at the floor and a metre and a half a second a metre up, read trilinearly
between them, and the slider adds a uniform wind on top. Wind past a body
cools it faster, so a strong enough wind keeps the wood from catching at all.
The flames in Step 5 are carried by the same field, read with windAt.
/// A breeze that grows with height, from still air at the floor to a
/// metre and a half a second a metre up, read trilinearly between the
/// grid's two samples; and the uniform [wind] added everywhere.
void _setWind() {
_world!
..setWindGrid(
origin: Vector3.zero(),
cell: 1.0,
nx: 1,
ny: 2,
nz: 1,
velocities: Float32List.fromList(<double>[0, 0, 0, 1.5, 0, 0]),
)
..wind = Vector3(wind, 0.0, 0.0);
}
Step 4: Step, and listen #
Each frame steps the world a third of a second. readEvents says what
happened in it; this page keeps the fire's events: ignited, extinguished
and burntOut. A minute after the wood catches, half a litre of water goes
on it and the heater is let cool to the air. The water holds the board at
100 °C, below where wood burns, so the next step puts the fire out. The
switch beside the viewport pours it sooner.
_world!.step(dt);
final List<NativeEvent> said = _world!.readEvents();
_said.addAll(said);
final List<NativeEvent> fire = <NativeEvent>[
for (final NativeEvent e in said)
if (e.kind == NativeEventKind.ignited ||
e.kind == NativeEventKind.extinguished ||
e.kind == NativeEventKind.burntOut)
e,
];
/// Half a litre of water on the wood, and the heater let cool to the air.
/// The water holds the board at its boiling point, below where wood
/// burns, so the next step puts the fire out.
void _douse() {
final NativeWorld world = _world!;
world
..addWater(_wood, 0.5)
..setTemperature(_heater, world.airTemperature);
_doused = _clock;
}
Step 5: Flames #
The elements draw every fire the core has: the flame standing on the patch alight and as long as the core says, smoke rising in the fire's own plume and drifting with the wind where it is, embers lagging it, and the firelight the radiant share of the fire's heat, as bright and as coloured as a blackbody at the temperature of the flame's soot. The wood chars and glows as it burns; the steel glows from dull red to orange with its temperature.
/// The fires drawn as the world has them: the elements adopted the world,
/// so they draw and do not step it. Each flame stands on the patch alight
/// and is as long as the core says, its smoke and embers carried by the
/// wind where it is, its light the radiant share of its heat.
void _flicker(double seconds, Vector3 eye) {
_elements?.update(seconds, eye: eye, events: List<NativeEvent>.of(_said));
_said.clear();
}
Step 6: What has to happen #
From cold, a second a step: the wood has to catch, which it does after about
three hundred steps, and say so with an ignited event. Twenty seconds later it has
to be still burning and lighter by more than ten grams; it loses about
twenty-five. The steel has to have warmed, to about 350 K, and never caught.
Then water goes on, and the next step has to put the fire out with an
extinguished event.
// From cold, in still air but for the grid's breeze, a second a step.
wind = 0.0;
_setUp();
final NativeWorld world = _world!;
final List<NativeEvent> said = <NativeEvent>[];
var steps = 0;
while (_caught == null && steps < 600) {
said.addAll(_advance(1.0));
steps++;
}
if (_caught == null) throw StateError('the wood never caught');
// Burning, it loses what it gives off, over a patch that is still
// small twenty seconds after it caught.
final double atIgnition = world.massOf(_wood);
for (var i = 0; i < 20; i++) {
said.addAll(_advance(1.0));
}
if (!world.isBurning(_wood)) throw StateError('the wood went out');
if (world.massOf(_wood) >= atIgnition) {
throw StateError('the wood burnt nothing: ${world.massOf(_wood)} kg');
}
// The steel had the same heater, and was warmed by it, but never caught:
// with fifteen times the wood's mass it warms slowly, a few kelvin in
// the half minute the wood took to catch and burn.
if (world.temperatureOf(_steel) <= world.airTemperature + 1.0) {
throw StateError('the steel was never warmed');
}
if (world.isBurning(_steel) || said.any((e) => e.body == _steel)) {
throw StateError('the steel caught fire');
}
// Water puts the fire out on the next step, and says so.
_douse();
final List<NativeEvent> after = _advance(1.0);
if (world.isBurning(_wood) ||
!after.any(
(e) => e.body == _wood && e.kind == NativeEventKind.extinguished,
)) {
throw StateError('the water did not put the fire out');
}
Note. A body keeps its surface's temperature apart from its middle's, so a log's outside catches long before its middle has warmed. Radiation sees every body as a ball of its own surface, and five rays decide how much of it a wall hides. A crate stacked on a burning one catches in its flame; one beside it catches when the fire is big enough or the wind lays the flame over it, and one a few metres off only warms. Heat across a contact is modest by design. Wood is an insulator, and a burning block warms the one it touches without lighting it.