# EsIschFlüssig — how the model works A 2D thermal fluid laboratory. Every drop of liquid, lump of ice and puff of vapour is a particle that carries heat; walls and pipes are solids with their own temperature; the room is a grid of air. This document describes what is simulated, how, with which numbers, and — just as important — what is not. Everything lives in three files: `index.html` (page), `style.css`, `app.js` (the whole simulation). --- ## 1. Scale and units | Quantity | Value | |---|---| | World | 1200 × 760 px = 4.8 m × 3.0 m | | Length | 1 px = 4 mm | | Gravity | 9.81 m/s², i.e. 2452 px/s² | | Particle | ~2 cm across at the default size (0.8×) | | Temperature | °C throughout | | Energy | joules; enthalpy per particle in J/g | One deliberate distortion: **heat moves about 60× faster than in reality**, so an hour of refrigerator or half an hour of a still fits into a minute of watching. Mechanics (gravity, pressure, flow) run at real speed. This means a temperature *history* is fast-forwarded, but every temperature, pressure and composition it passes through is the one real physics would give. --- ## 2. The fluid Position-based fluid, following Clavet, Beaudoin and Poulin, *Particle-based viscoelastic fluid simulation* (2005): a double-density relaxation that pushes particles toward a rest density and, with a near-density term, keeps surfaces from clumping. - Rest density `RHO0 = 5.4` (in Σq² units), stiffness `1.2`, near-stiffness `2.6`. Those are four times Clavet's values at half his timestep, because gravity here is real and a deep tank would otherwise compress visibly. - 4 to 10 substeps per frame, chosen from the fastest particle so nothing moves more than ~⅓ of the interaction radius in a substep. - Negative pressure (cohesion) is scaled down to 15% — a crude stand-in for surface tension. - Viscosity is a radial impulse between neighbours, scaled by the real dynamic viscosity of the fluid at the local temperature. Water uses the Vogel-type fit `μ = 2.414e-2 · 10^(247.8/(T+273.15−140))` Pa·s, so hot water really is thinner than cold. - Particle size is adjustable. Heat conduction, wall contact and viscosity are rescaled with it (diffusive rates by 1/size², surface rates by 1/size) so the physics does not change when you change the resolution; only the detail does. ### Density and buoyancy - Water uses the real density curve with its **maximum at 4 °C**, so a pond turns over and then freezes from the top. - Other liquids use `ρ = ρ₀(1 − β(T−20))` with their own thermal expansion coefficient. - Buoyancy compares a particle's density with its neighbourhood's. The **thermal expansion slider** multiplies this difference (default 12×): real thermal expansion is far too small to see against the numerical noise of a few thousand particles, so convection has to be exaggerated to be visible. Set it to 1× for the true value. - Vapour density comes from the **ideal gas law**, `ρ = PM/RT`, so hot steam is light and cold heavy vapours (alcohol, refrigerant) sink in room air, as they do in life. - Ice floats because its density (917 kg/m³) is used against the surrounding liquid. --- ## 3. Heat and phase Each particle stores **enthalpy** `h` in J/g, not temperature. Temperature and phase are derived from it: ``` h < cp_s·Tm − Lf solid, T = Tm + (h − h_melt0)/cp_s h between the melting bounds melting, T = Tm (latent plateau, Lf) h up to cp_l·Tb liquid, T = h/cp_l h between the boiling bounds boiling, T = Tb (latent plateau, Lv) h above vapour, T = Tb + (h − h_boil1)/cp_g ``` This is why the model shows the latent-heat plateaus: water sits at 0 °C while it gives up 334 J/g, and at 100 °C while it takes in 2260 J/g. Nothing else in the model has to know about phase change. Phase flips carry a hysteresis band and a per-particle random threshold, so a pot does not flash over all at once. ### Fluids | Fluid | Freezes | Boils (1 bar) | Boils (high side) | Density | Latent heat of vaporisation | |---|---|---|---|---|---| | Water | 0 °C | 100 °C | 180 °C | 1000 | 2260 J/g | | Refrigerant (R‑134a-like) | −104 °C | −26 °C | 40 °C | 1295 | 218 J/g | | Oil | −6 °C | 300 °C | 400 °C | 920 | 250 J/g | | Ethanol | −114 °C | 78 °C | 151 °C | 789 | 841 J/g | | Mercury | −39 °C | 357 °C | 515 °C | 13534 | 295 J/g | | Liquid nitrogen | −210 °C | −196 °C | −169 °C | 808 | 199 J/g | Heat capacities, conductivities and molar masses are the real ones. Vapour pressure comes from the **Antoine equation** for water and ethanol (the two that matter for distilling) and from **Clausius–Clapeyron** anchored on the boiling point and latent heat for the rest. ### Two pressures There is no continuous pressure field. Instead each particle carries a flag: it is either on the atmospheric side or on the **high-pressure side** of a compressor (about 10 bar). The high side has its own boiling point and latent heat per fluid. A particle is put on the high side by a compressor and returns to the low side through a throttle valve, or as soon as it leaves a pipe. That is enough to build a heat pump, and it is why the refrigerant condenses at 40 °C behind the compressor and boils at −26 °C after the valve. --- ## 4. Mixtures and distillation Two fluids in the same place are treated as a real solution when they are miscible (water and ethanol), and as immiscible layers otherwise (oil, mercury). **Composition** is computed on a coarse grid (20 px cells, one box blur), not from each particle's handful of neighbours: a cell holds tens of particles, so the mixture behaves like a solution rather than like a few lumps of one substance or the other. **Boiling point.** For a liquid cell the bubble point solves ``` Σ xᵢ γᵢ p°ᵢ(T) = P ``` by bisection, where `xᵢ` are mole fractions, `p°ᵢ` the pure vapour pressures, and `γᵢ` activity coefficients. Vapour cells use the dew point instead. For ethanol and water the activity coefficients use the **van Laar** model with A = 1.6798, B = 0.9227, which is what makes the mixture non-ideal. The resulting curve is the real one: | Wash | Boils at | Vapour | |---|---|---| | 5% ABV | 95.9 °C | 37% ABV | | 10% ABV | 92.8 °C | 53% ABV | | 20% ABV | 88.5 °C | 67% ABV | | 60% ABV | 81.5 °C | 82% ABV | | 96% ABV | 78.2 °C | 96% ABV | The last row is the **azeotrope**, at 95.6% ABV and 78.1 °C in reality. There the vapour has the same strength as the liquid, so no amount of distilling gets past it — and the model reproduces that, because at that composition every K value is 1. **Which molecule leaves.** For each species, `K = γp°/P` says how much richer the vapour is in it than the liquid. Boiling neighbours first level out how far through boiling they are (energy in a boiling liquid is shared, and this only moves enthalpy within a pair, so it is conserved). Then each particle is drawn to evaporate with a probability proportional to `K·Lv·m`, and to condense with the inverse. The `Lv·m` factor cancels an artefact: a particle boils once it has absorbed its own latent heat, which on its own would favour whichever fluid has the smaller latent heat. What is left is an evaporation rate proportional to K, which is vapour–liquid equilibrium. **Miscibility.** Miscible partners share one effective mass in the pressure solver and one density in the buoyancy term, so a wash cannot separate into layers, and they swap places at a set rate — explicit diffusion, standing in for the molecular mixing that keeps a real solution uniform. Immiscible fluids keep their own mass and density, and stack up by density. **Measured against the equilibrium curve**, a 20% wash in the sim boils at 88–90 °C and gives vapour that starts near 100% and settles at 67% while the pot is still near 20% — the equilibrium value — then declines as the pot is stripped, which is the shape of a real still run. A 90% wash gives 89–95%, close to the azeotrope, and does not run away past it. --- ## 5. Solids Walls and pipes are polylines. A wall is a thick line; a pipe is a hollow line with a bore, and fluid inside stays inside. - Each segment has its own temperature, a heat capacity proportional to its area and material, and conducts along the polyline to its neighbours. - Contact with particles and with air cells uses per-material coefficients. Steel exchanges readily, insulation barely at all, copper is the heat-exchanger material. - Heaters and chillers are walls pinned to a temperature. - Pipe ends are open into free space and sealed where they meet another pipe or a pump, where they act as an elbow and deflect the flow along the joined pipe. A pipe drawn back onto its own start is recognised as a closed loop. - Contact heat exchange is capped per contact (30% of the smaller heat capacity, divided by the previous step's contact count) so a slug of particles cannot make a pipe explode in temperature. ## 6. Air The room is a 20 px grid of air temperature with conduction, buoyancy-driven vertical mixing (warm air below cold air mixes faster), exchange with solids and particles, and a fixed-temperature boundary outside the margin that acts as the outside world. Fans advect it. It is a temperature field only: there is no air velocity field, so draughts are not modelled. ## 7. Devices - **Liquid pump**: moves liquid from IN to OUT, and inside pipes imposes a flow direction along the whole connected network, found by a shortest-path walk from the intake. - **Inline pump**: sits in a pipe, pushes along it, and its pressure is felt around the whole connected loop, so it can lift liquid up a vertical leg. - **Compressor**: takes vapour only, moves it to the high-pressure side and adds work equal to 0.2 × the fluid's latent heat (about 45 J/g for the refrigerant, which is roughly an R‑134a compressor; about 450 J/g for steam). It refuses to inject into a crowded pipe, so a blocked loop stalls it. - **Throttle valve**: a one-way plane across a pipe. Anything crossing drops to atmospheric pressure at constant enthalpy, so part of it flashes to vapour and the rest gets very cold. Low-side fluid cannot come back through. - **Thermostat**: switches the compressors wired to it, with 1° of hysteresis. - **Alcohol meter**: counts ethanol against water particles nearby. Particles all have the same volume, so that count *is* percent by volume. - **Mounted heat lamp / cold spot**: a fixed emitter that drives particles and air within its radius toward its temperature. --- ## 8. Assumptions and limitations Things that are deliberately not real, in rough order of how much they matter: 1. **Heat runs ~60× fast.** Temperatures are right; the clock is not. 2. **Two-dimensional.** A "volume" is an area. Flow rates, heat transfer areas and convection patterns are all 2D analogues, so absolute rates are indicative, not predictive. 3. **Thermal expansion is exaggerated** (slider, default 12×) or convection would be invisible. 4. **Pressure is two discrete levels**, not a field. There is no pressure drop along a pipe, no cavitation, no boiling point that varies with depth or altitude. 5. **No air velocity field.** Air carries temperature and is stirred by fans, but wind and draughts are not modelled, and vapour is not blown around by air currents except near a fan. 6. **A particle is a 2 cm blob of one pure substance.** A solution is emulated by grid-averaged composition plus explicit diffusion. Diffusion is therefore far faster than molecular diffusion — that is what keeps a wash uniform at this particle size. 7. **Distillation is calibrated, not derived.** The equilibrium curve, the boiling points and the azeotrope come from real thermodynamics; the rate at which particles are drawn to change phase is a discrete stand-in for a continuous process, and single-stage separation is sharper than a real pot still at the start of a run. 8. **No chemistry.** No fermentation, no combustion, no dissolution of solids, no freezing point depression in mixtures (a salt or alcohol solution still freezes at the pure fluid's freezing point). 9. **Surface tension is a crude cohesion term**, so droplets, menisci and capillary rise are approximate. Capillary action up a narrow tube does not happen. 10. **Ice is rigid clusters** matched to their previous shape; it does not fracture, and it sticks to surfaces below 0 °C rather than modelling adhesion properly. 11. **Vapour is not confined by pressure.** Inside pipes it moves by a density-gradient drift and by pumps; a sealed vessel will not build up pressure and raise its own boiling point. ## 9. What has been checked - Ethanol/water bubble points and vapour compositions against the published equilibrium curve (table above); the azeotrope lands at 96% ABV and 78.2 °C against a real 95.6% and 78.1 °C. - A 20% wash in the still boils at 88–90 °C and produces distillate that starts strong and weakens. - The refrigerator holds a 4 °C setpoint with the freezer below 0 °C, cycles its compressor on the thermostat, and reports a coefficient of performance around 3, which is the right range for a domestic fridge. - Water in a pipe network driven by an inline pump circulates at about 1 m/s with no leaks at joints. - Flow through pipes of different bores follows the expected steep dependence on diameter. - A pond at −20 °C air turns over until it is 4 °C at the bottom, then freezes from the top. ## 10. Where things are in `app.js` | Section | What | |---|---| | `FL`, `pSatPure`, `vanLaar` | fluid table, vapour pressures, activity coefficients | | `updState` | enthalpy → temperature and phase | | `compFrame`, `mixFrame` | composition grid, bubble/dew points, K values | | `substep` | emitters, pumps, pair pass, integration, relaxation, collisions, ice | | `collideSolids` | walls, pipes, joints, contact heat | | `airStep`, `solidsStep` | air grid, solid conduction | | `buildFlowMap`, `buildInlineMap` | pump-driven flow through pipe networks | | `DEMOS` | the six demo scenes |