A surprising number of bugs I‘ve debugged in "non-physics" software came from a quiet assumption about matter. A sensor pipeline assumes a fluid can‘t compress. A robotics stack assumes a payload keeps its shape under acceleration. A game effect assumes smoke behaves like a liquid. Even in everyday engineering decisions (packaging, piping, HVAC, lab work), the difference between solid, liquid, and gas is the difference between "this model holds" and "this model fails in production."
When you understand these three states as constraints (shape, volume, compressibility), plus what‘s happening at the particle level (spacing, forces, motion), you can reason about real-world behavior without memorizing a pile of exceptions. I‘m going to walk you through the differences in a way that maps cleanly to how we model systems: what stays constant, what changes under stress, and which approximations are safe.
Along the way, I‘ll also show a couple of runnable code examples: one that simulates "solid-ish vs liquid-ish vs gas-ish" behavior using a simple particle model, and one that classifies a material state from measured properties (the same kind of logic you might use in IoT or lab automation).
Why States of Matter Show Up in Software
When I say "state of matter," I‘m not trying to turn you into a chemist. I‘m giving you a mental model for constraints:
- If something is solid, you can usually assume shape stability (within limits) and near-constant volume.
- If something is liquid, you can usually assume volume stability but shape adaptability (it takes the container‘s shape).
- If something is gas, you should assume shape adaptability and volume adaptability, with behavior tied strongly to pressure and temperature.
These assumptions sneak into code in a lot of places:
- Robotics and controls: Grippers, suction cups, fluid-filled actuators, pneumatic systems.
- Rendering and simulation: Rigid bodies vs fluids vs volumetric effects.
- Manufacturing and QA: Dispensing adhesives (liquid-ish), powders (granular solids), compressed air (gas).
- Data modeling: "Does this quantity scale with container volume?" is basically "is it gas-like?"
A practical programming analogy I use: solids, liquids, and gases are like different levels of "schema rigidity." Solids have a strict schema (shape + volume). Liquids relax shape but keep volume. Gases relax both and shift the rules into an equation-of-state world (pressure, temperature, moles).
One more software analogy that helps when you‘re designing systems: think in terms of invariants.
- Solid invariant: adjacency relationships between particles mostly stay fixed (structure is stable).
- Liquid invariant: particles stay near each other (cohesion), but neighbors change (rearrangement is easy).
- Gas invariant: there is no persistent neighborhood; collisions are brief and state depends on container + boundary conditions.
When you translate that into engineering: solids carry load through structure, liquids transmit pressure, gases store energy in compression.
The Particle-Level Story: Spacing, Forces, Motion
Macroscopic properties (shape, flow, compressibility) come from microscopic behavior. The simplest mental model is: particles are always moving, and the average spacing and strength of attraction between particles changes across states.
Solid
In a solid, particles are tightly packed and strongly attracted. They don‘t sit perfectly still; they vibrate around relatively fixed positions.
- Intermolecular (or interparticle) forces: strong
- Typical spacing: small
- Motion: vibration around a stable arrangement
Analogy: people packed into assigned seats in a theater. You can shift a little, but you don‘t rearrange the whole seating plan without a lot of effort.
A detail that matters when you model solids: "strong attraction" isn‘t the only thing. The shape stability of solids depends heavily on resisting shear (sideways deformation), not just resisting compression.
Liquid
In a liquid, particles are still close, but they have enough energy to slide past each other. Attractions exist, but they‘re not strong enough to lock particles into fixed positions.
- Intermolecular forces: moderate
- Typical spacing: small-to-intermediate
- Motion: sliding and rearranging while staying close
Analogy: people moving around in a crowded pool. You‘re near others, you bump, you drift, but you can change neighbors.
Liquids are "structured" in the sense that particles remain close (so density stays high), but they don‘t maintain long-lived lattice order.
Gas
In a gas, particles are far apart relative to their size and interact weakly most of the time. Motion is fast, and collisions dominate the behavior.
- Intermolecular forces: weak (except during collisions)
- Typical spacing: large
- Motion: rapid, free movement with frequent collisions
Analogy: people scattered across a huge gym, running in random directions and occasionally bumping.
The "far apart" piece is the root of gas compressibility: there is room to squeeze particles closer before strong repulsion kicks in.
Energy and kinetic energy (a subtle but important point)
When people talk about "energy" in states of matter, they often mix up categories. On average:
- Kinetic energy of particles increases from solid -> liquid -> gas (because particles move more freely and faster).
- Strength of binding/attraction is strongest in solids, weaker in liquids, weakest in gases.
So you can‘t treat "energy" as a single slider without specifying what you mean. For engineering intuition, the "freedom to rearrange" is the key: solids resist rearrangement, liquids allow it, gases basically live in rearrangement.
If you want a clean mental model that scales to real work: temperature mostly controls the "random motion" term, while intermolecular attraction controls the "sticking" term. The state is the regime where one term dominates.
Shape and Volume: The Constraints You Can Count On
This is the core difference most people remember, and it‘s the one I map directly to system constraints.
Solid: definite shape, definite volume
A solid keeps its own shape and volume under normal conditions.
- Put a brick on a table: it stays brick-shaped.
- Move it into a box: it doesn‘t become box-shaped.
In code terms: you can usually represent a solid as a rigid body with a fixed mesh/geometry and treat volume as constant.
But "definite shape" has a footnote: solids can be elastic (spring back), plastic (permanently deform), or brittle (fracture). The state-of-matter label alone doesn‘t tell you which. If you‘re doing physical modeling, you often need a constitutive model (elastic/plastic/fracture), not just "solid."
Liquid: no definite shape, definite volume
A liquid does not keep a fixed shape; it takes the shape of its container, but the amount of liquid (and therefore its volume) stays roughly constant.
- Pour water into a cup: cup-shaped surface.
- Pour it into a bowl: bowl-shaped surface.
In code terms: a liquid is "container-driven geometry." You keep volume constant (unless temperature/pressure changes matter), and you let shape be a result of boundaries and gravity.
A practical modeling note: liquids also create free surfaces (like the top of water in a glass) governed by gravity, surface tension, and contact angle. That free surface is where many "liquid" bugs hide (spills, sloshing, capillary action).
Gas: no definite shape, no definite volume
A gas expands to fill the container.
- Air in a balloon: balloon-shaped, and its volume changes if you squeeze it.
- Air in a room: room-shaped.
In code terms: for gases, container size is part of the state. Volume isn‘t just an output; it‘s a variable tied to pressure and temperature.
Another practical note: gases don‘t typically have a "free surface" like liquids. In a gravity field, gas density can vary with height (a pressure gradient), but you don‘t get a stable flat boundary without a phase change.
Quick comparison table
Solid
Gas
—
—
Definite
Takes container‘s shape
Definite
Expands/contracts to fit container
Small
Large
Strong
Weak
No (as a bulk fluid)
Yes
Very low
High
Very low
High
High
LowIf you remember one line: liquids keep volume but not shape; gases keep neither.
Compressibility, Density, and Pressure: What Actually Changes
Compressibility is where real systems get interesting.
Solids: "incompressible" is a useful approximation, not a law
Most solids resist compression strongly. If you apply enough force, they will compress a little (and then possibly yield or fracture), but compared to liquids and gases, the volume change is tiny.
Practical implication: For many mechanical designs, I treat solids as constant-volume unless I‘m doing stress/strain calculations.
If you are doing stress/strain calculations, the key quantities are:
- Bulk modulus (K): resistance to uniform compression (volume change).
- Shear modulus (G): resistance to shear deformation (shape change).
The reason solids keep their shape is mostly high shear modulus. That‘s a big hint for classification later: a solid is the state where shear stress produces bounded deformation instead of continuous flow.
Liquids: nearly incompressible, but not perfectly
Liquids are often treated as incompressible in everyday engineering. That‘s a good approximation in many regimes.
Where it breaks:
- High-pressure hydraulics: "nearly incompressible" still matters.
- Water hammer in pipes: pressure waves propagate and can cause damage.
- Acoustics: sound transmission depends on compressibility.
In software terms, if you‘re simulating or controlling fluid systems under high pressure, you should allow small density/volume changes instead of assuming a hard constant.
A developer-ish way to think about it: "incompressible" is like using a float for a quantity that is technically rational. It works until you care about the small differences.
Gases: compressibility is the main event
Gases compress easily because particles are far apart.
- Squeeze a syringe of air: volume drops, pressure rises.
- Heat a sealed container: pressure rises.
A common approximation for many gases at everyday conditions is the ideal gas law:
- PV = nRT
You don‘t need to compute it constantly unless your system depends on pressure/temperature changes. But conceptually, it explains why gases behave so differently: volume is not "owned" by the gas; it‘s negotiated with the container and environment.
One important modeling rule: for gases, you almost never get away with ignoring temperature. Compression heats, expansion cools. That becomes relevant the moment you move beyond slow, gentle flows.
Density differences: why "same container" doesn‘t mean "same mass"
A 1-liter container filled with steel vs water vs air has wildly different mass. That matters for:
- payload calculations
- buoyancy
- energy costs in transport
- thermal inertia
As a rule of thumb:
- solids are dense because particles pack tightly and attractions are strong
- liquids are also fairly dense, but packing is less rigid
- gases are sparse, so density is low and highly variable
The "highly variable" part is the key software trap: if you‘re using gas density anywhere (mass flow, buoyancy, energy calculations), you need to know whether you can treat it as constant or whether you need pressure/temperature compensation.
Flow and Diffusion: Viscosity Isn‘t Just a Chemistry Word
"Flow" is the most visible behavioral difference between a solid and a fluid (liquid or gas).
Why liquids flow
Liquids flow because particles can rearrange. Apply a shear force (like stirring), and layers can slide.
Key idea: liquids resist flow via viscosity. Honey flows slowly, water flows quickly.
A subtle point that saves time in real modeling: viscosity is not just a property of "what it is," it‘s a property of temperature (and sometimes shear rate). If you‘re dispensing adhesives or oils, viscosity swings can be large with temperature.
Why gases flow differently
Gases also flow, but because they‘re compressible and low-density, they behave differently:
- they expand to fill space
- they form strong pressure-driven flows
- they mix quickly
In many everyday settings, a gas can appear "more fluid" than a liquid because it moves with tiny pressure gradients.
Diffusion: why smells spread
Diffusion is the spontaneous mixing due to random motion.
- In solids, diffusion is very slow (particles are locked in place).
- In liquids, diffusion happens at a noticeable but moderate rate.
- In gases, diffusion is fast (large spacing and high motion).
Analogy: imagine shuffling a deck of cards.
- solid: cards are glued together; shuffling is almost impossible
- liquid: cards slide but still touch; shuffling takes time
- gas: cards are scattered; mixing happens quickly as they move
Engineering takeaway: if you care about "how quickly does this mix or spread," you should immediately ask whether your medium is gas-like or liquid-like.
A practical add-on: diffusion is only half the story. In many real systems, convection (bulk flow) dominates mixing. Gases are especially convection-friendly because small density differences create buoyancy-driven circulation.
A Better Mental Model: Bulk vs Shear (Why Solids Keep Shape)
If you only memorize "shape and volume," you can still get surprised by materials that sort of hold shape but also sort of flow. The deeper discriminator is how the material responds to shear stress.
- Solid: apply a small shear stress, it deforms a bit, then reaches a new equilibrium (bounded deformation). Remove the stress, it may spring back (elastic) or stay deformed (plastic), but it does not keep flowing forever under that same constant stress.
- Liquid: apply a constant shear stress, it keeps deforming (it flows). The relationship is often described by viscosity.
- Gas: also flows under shear stress, but with the added twist of compressibility and strong coupling to temperature.
This bulk vs shear framing is extremely practical because:
- It explains why liquids can transmit pressure (bulk response) while not holding shape (shear response).
- It explains why a gel can "feel solid" at rest but "flow" when squeezed.
- It maps nicely to simulation choices (rigid body constraints vs Navier-Stokes-like solvers).
If you‘re building a classifier or making modeling decisions, "shear behavior" is usually more diagnostic than "does it pour?".
Phase Changes and Edge Cases That Break Simple Labels
The three-state model is powerful, but reality has boundary cases that matter when you‘re building robust systems.
Phase changes: same substance, different constraints
A single substance (water is the standard example) can be solid, liquid, or gas depending on temperature and pressure.
- melting: solid -> liquid
- freezing: liquid -> solid
- boiling/evaporation: liquid -> gas
- condensation: gas -> liquid
- sublimation: solid -> gas (dry ice is a classic)
- deposition: gas -> solid
What‘s happening physically: you‘re changing how much energy is available to overcome attractions between particles.
A detail people miss: during melting or boiling, the temperature can stay nearly constant while energy goes into changing the phase (latent heat). If you‘re modeling heating systems, that plateau is not optional; it‘s often the dominant behavior.
Pressure matters more than most people think
Everyday intuition is mostly built at "normal" pressure, so it‘s easy to forget that pressure shifts phase boundaries.
- Lower pressure makes boiling easier (boiling point decreases).
- Higher pressure can keep a substance liquid at temperatures where it would normally boil.
This is why vacuum chambers, pressure cookers, and high-altitude environments create so many "wait, why did it do that" moments.
Common mistakes I see (and how I correct them)
- Mistake: "Liquids have a definite shape."
Correction: liquids have a definite volume but take the shape of their container.
- Mistake: "Gases have low energy."
Correction: gas particles typically have higher kinetic energy than liquids and solids at the same temperature regime.
- Mistake: "Incompressible" means "cannot compress."
Correction: it often means "compression is small enough to ignore for this design," not that it‘s physically impossible.
- Mistake: "Gas fills the container instantly."
Correction: it fills quickly in many cases, but the time scale depends on diffusion, convection, and geometry. A long, thin tube can make "filling" surprisingly slow.
- Mistake: "If it pours, it‘s a liquid."
Correction: powders and grains pour too. Bulk granular flow is a separate category that behaves liquid-ish in some ways and solid-ish in others.
Materials that don‘t behave like the textbook picture
If you build systems, you will encounter these:
- Glass: looks like a solid and behaves like one in daily life, but structurally it‘s an amorphous solid (no crystal lattice). For most engineering, treat it as solid.
- Gels and pastes: toothpaste, yogurt, gels. They can flow like a liquid under enough stress but hold shape at rest. This is a "non-Newtonian" world.
- Granular materials: sand, rice, powders. Individual grains are solid, but the bulk can pour like a liquid. This trips up naive collision and friction models.
- Foams: shaving foam, whipped cream. A foam is gas trapped in a liquid/solid matrix. Behavior depends on bubble size, drainage, and collapse.
- Aerosols and smoke: tiny solid/liquid particles suspended in gas. Treating smoke as a liquid is usually a bug.
- Supercritical fluids: at high temperature and pressure, the boundary between liquid and gas disappears. Density can be liquid-like while diffusion is gas-like.
My rule: when the label is ambiguous, fall back to the behavior you care about (shape retention, compressibility, flow under shear, mixing rate) and model that.
Practical Scenarios: Which Assumptions Are Safe (And When They Break)
I like to turn the state-of-matter ideas into quick "if-then" rules you can use in design reviews.
Robotics: gripping, acceleration, and payload modeling
- Solid payload (rigid): treat geometry as fixed; forces map cleanly to motion; center-of-mass is stable.
- Liquid payload in a container: volume fixed, but center-of-mass moves (sloshing). If you accelerate, you can get delayed motion and oscillations.
- Gas payload (compressed): mass is there, but volume depends on pressure; pressure changes can create force changes that look like springs.
Common failure mode: using a rigid-body model for a container partially filled with liquid. The slosh can destabilize control loops.
Piping and HVAC
- Liquids: pressure drop and flow are often modeled assuming incompressibility. Good for many water lines.
- Gases: compressibility means density changes along the pipe; temperature can change; you may need a compressible flow model.
Common failure mode: treating compressed air like water in mass flow calculations.
Sensors: what your measurement actually represents
- Level sensors: for liquids, "height" often maps to volume. For gases, "height" isn‘t a meaningful filling metric in the same way.
- Pressure sensors: for liquids in static conditions, pressure correlates with depth. For gases, pressure can correlate with temperature and amount of gas, not just depth.
Common failure mode: interpreting gas pressure changes as "more gas" without temperature compensation.
Packaging and storage
- Solids: shape stability; stacking is straightforward.
- Liquids: need seals; pressure changes can bulge containers.
- Gases: containers behave like springs; temperature swings cause pressure swings.
Common failure mode: ignoring headspace gas expansion when shipping sealed containers.
Cooking and lab work (yes, this shows up in engineering too)
- Heating a liquid through a phase change can hold temperature nearly constant while absorbing energy.
- Evaporation cools surfaces (liquid -> gas pulls energy from surroundings).
Common failure mode: assuming temperature rises linearly with heater power even during boiling.
Modeling Solids, Liquids, and Gases in Code
When I implement these ideas, I don‘t start with a "state" enum. I start with constraints and interactions.
- solid-ish: strong attractions + limited rearrangement
- liquid-ish: moderate attractions + rearrangement allowed
- gas-ish: weak attractions + free movement + collisions
Below are two runnable examples you can copy into a terminal.
Example 1: A tiny particle simulation (Python)
This is not a physics engine. It‘s a teaching model that shows how changing attraction strength and noise produces "solid-ish," "liquid-ish," and "gas-ish" clustering and motion.
What to look for when you run it:
- solid: particles form a clump that jitters but mostly holds shape
- liquid: particles clump but constantly rearrange; the outline changes
- gas: particles spread out and bounce around the box
import random
import math
import time
Simple 2D particle toy model.
- Particles repel at very short range (avoid collapse)
- Particles attract within a mid range (cohesion)
- Random motion ("thermal" noise) pushes them to rearrange
- Boundary walls keep particles in a box
WIDTH = 80
HEIGHT = 24
N = 30
STEPS = 250
DT = 0.06
def clamp(x, lo, hi):
return max(lo, min(hi, x))
def dist(a, b):
dx = a[0] - b[0]
dy = a[1] - b[1]
return math.sqrt(dx dx + dy dy) + 1e-9
def render(particles, step, mode):
grid = [[‘ ‘ for in range(WIDTH)] for in range(HEIGHT)]
# Draw border
for x in range(WIDTH):
grid[0][x] = ‘-‘
grid[HEIGHT - 1][x] = ‘-‘
for y in range(HEIGHT):
grid[y][0] = ‘|‘
grid[y][WIDTH - 1] = ‘|‘
grid[0][0] = ‘+‘
grid[0][WIDTH - 1] = ‘+‘
grid[HEIGHT - 1][0] = ‘+‘
grid[HEIGHT - 1][WIDTH - 1] = ‘+‘
# Plot particles
for x, y in particles:
ix = int(clamp(round(x), 1, WIDTH - 2))
iy = int(clamp(round(y), 1, HEIGHT - 2))
grid[iy][ix] = ‘o‘
header = f‘mode={mode} step={step}/{STEPS}‘
header = header[: max(0, WIDTH - 2)]
for i, ch in enumerate(header):
if 1 + i < WIDTH - 1:
grid[0][1 + i] = ch
# Clear screen + print
print(‘\x1b[H\x1b[2J‘, end=‘‘)
for row in grid:
print(‘‘.join(row))
def simulate(mode=‘solid‘, sleep=0.02, show=True):
# Tuned parameters per "state".
# Increase attract => more cohesion (solid/liquid).
# Increase noise => more rearrangement/escape (liquid/gas).
if mode == ‘solid‘:
attract = 2.2
noise = 0.02
elif mode == ‘liquid‘:
attract = 1.3
noise = 0.10
elif mode == ‘gas‘:
attract = 0.15
noise = 0.25
else:
raise ValueError("mode must be ‘solid‘, ‘liquid‘, or ‘gas‘")
repel = 2.0
attract_radius = 6.0
repel_radius = 2.0
# Initialize particles near the center.
particles = []
velocities = []
cx, cy = WIDTH / 2.0, HEIGHT / 2.0
for _ in range(N):
particles.append([cx + random.uniform(-5, 5), cy + random.uniform(-3, 3)])
velocities.append([random.uniform(-0.2, 0.2), random.uniform(-0.2, 0.2)])
for step in range(STEPS):
ax = [0.0 for _ in range(N)]
ay = [0.0 for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
d = dist(particles[i], particles[j])
dx = particles[j][0] - particles[i][0]
dy = particles[j][1] - particles[i][1]
ux = dx / d
uy = dy / d
# Short-range repulsion
if d < repel_radius:
f = repel * (repel_radius - d)
ax[i] -= f * ux
ay[i] -= f * uy
ax[j] += f * ux
ay[j] += f * uy
# Mid-range attraction
elif d < attract_radius:
# Pull together more gently the farther apart they are (within range)
f = attract * (d - repelradius) / (attractradius - repel_radius)
ax[i] += f * ux
ay[i] += f * uy
ax[j] -= f * ux
ay[j] -= f * uy
# Integrate velocity + position
for i in range(N):
# Add random motion
ax[i] += random.uniform(-noise, noise)
ay[i] += random.uniform(-noise, noise)
velocities[i][0] = 0.92 velocities[i][0] + ax[i] DT
velocities[i][1] = 0.92 velocities[i][1] + ay[i] DT
particles[i][0] += velocities[i][0]
particles[i][1] += velocities[i][1]
# Bounce off walls
if particles[i][0] < 1:
particles[i][0] = 1
velocities[i][0] *= -0.9
if particles[i][0] > WIDTH - 2:
particles[i][0] = WIDTH - 2
velocities[i][0] *= -0.9
if particles[i][1] < 1:
particles[i][1] = 1
velocities[i][1] *= -0.9
if particles[i][1] > HEIGHT - 2:
particles[i][1] = HEIGHT - 2
velocities[i][1] *= -0.9
if show:
render(particles, step, mode)
time.sleep(sleep)
return particles
if name == ‘main‘:
# Try: solid, liquid, gas
simulate(‘solid‘)
time.sleep(0.6)
simulate(‘liquid‘)
time.sleep(0.6)
simulate(‘gas‘)
Why this toy model works as an intuition pump:
- Cranking up attract makes particles "want" to stay near each other, mimicking cohesion.
- Cranking up noise makes them rearrange more, mimicking thermal motion.
- The same code produces three regimes without changing the structure of the system, which mirrors real physics: the rules don‘t fundamentally change, the parameters do.
Performance considerations (practical note): this uses an O(N^2) pair loop. For N=30 it‘s fine. If you scale it to thousands of particles, you‘ll want a spatial hash / grid / k-d tree to avoid checking every pair.
Example 2: Classify a material state from measured properties
In real systems you rarely get a magical "state" label. You get sensor readings: density, compressibility, viscosity, temperature, pressure, maybe a shear response.
So here‘s a practical heuristic classifier. It‘s intentionally simple: it turns "solid vs liquid vs gas" into a set of threshold-based rules.
- Gas: high compressibility OR very low density in typical conditions.
- Solid: significant shear modulus (resists shear without continuous flow).
- Liquid: low compressibility (compared to gas) + negligible shear modulus (flows under shear) + moderate-to-high density.
This is the kind of logic you might embed in a pipeline that decides which downstream model to use.
from dataclasses import dataclass
@dataclass
class Measured:
# Values are intentionally unit-agnostic; you should keep units consistent.
# In real code, I like to wrap these in a unit system.
density: float # e.g., kg/m^3
compressibility: float # relative or 1/Pa-like; higher means easier to compress
shear_modulus: float # Pa-like; higher means holds shape under shear
viscosity: float # Pa*s-like; higher means flows slowly
def classify_state(m: Measured) -> str:
# Heuristic thresholds. Tune per domain.
# The goal isn‘t perfect physics; it‘s choosing a safe modeling assumption.
# Gas-like if it compresses easily or density is extremely low.
if m.compressibility > 1e-4 or m.density < 10:
return ‘gas‘
# Solid-like if it resists shear strongly.
if m.shear_modulus > 1e7:
return ‘solid‘
# Otherwise treat as liquid-like.
return ‘liquid‘
if name == ‘main‘:
samples = {
‘steel-ish‘: Measured(density=7850, compressibility=1e-12, shear_modulus=8e10, viscosity=1e20),
‘water-ish‘: Measured(density=1000, compressibility=5e-10, shear_modulus=0.0, viscosity=1e-3),
‘air-ish‘: Measured(density=1.2, compressibility=1e-5, shear_modulus=0.0, viscosity=1.8e-5),
‘honey-ish‘: Measured(density=1400, compressibility=5e-10, shear_modulus=0.0, viscosity=10.0),
‘gel-ish‘: Measured(density=1100, compressibility=5e-10, shear_modulus=5e5, viscosity=5.0),
}
for name, m in samples.items():
print(name, ‘->‘, classify_state(m))
How I‘d use this in production:
- Treat the label as a routing decision, not a ground truth.
- Log the raw features and classification so you can tune thresholds.
- Add an "unknown" or "mixed" state when your data routinely lands in boundary regions (gels, foams, granular flows).
A common extension: include temperature and pressure so your classifier can flip a material between regimes when conditions change.
Common Pitfalls (Developer Edition)
These are failure patterns I‘ve seen repeatedly, phrased as "what assumption snuck into the code."
Pitfall 1: Modeling a liquid as truly incompressible
Usually fine for low-pressure water flow. Not fine for:
- pressure spikes (water hammer)
- fast valve closures
- long pipes with elastic walls
Symptom in code: you get unrealistically infinite propagation speed for pressure changes.
Pitfall 2: Treating gas density as constant
For small temperature/pressure changes, maybe. For compressed air systems, HVAC, or altitude changes, it breaks.
Symptom in code: mass flow calculations drift, energy estimates are wrong, control loops behave oddly.
Pitfall 3: Treating powders as liquids
Powders pour, so people model them as liquids. But granular materials can:
- jam
- form arches
- behave solid-like under load
- segregate by particle size
Symptom in code: simulations that never jam, feeders that "should work" but don‘t.
Pitfall 4: Treating smoke/steam as a liquid in rendering
Smoke is gas + particles. Steam can condense. Treating it as a simple liquid flow often looks wrong and behaves wrong.
Symptom in code: effects that pool on the ground, or don‘t expand to fill space.
Pitfall 5: Forgetting that phase change can dominate energy balance
During boiling or melting, energy goes into changing phase, not raising temperature.
Symptom in code: predicted temperature spikes that never happen in real systems.
Alternative Approaches: Different Levels of Modeling Fidelity
I like to choose the simplest model that is safe for the question I‘m answering.
Option A: Constraint-based modeling (fast, robust)
- Solid: rigid body constraints
- Liquid: incompressible approximation + volume constraint
- Gas: ideal-gas-like coupling (pressure/temperature/volume)
Best when you‘re doing controls, planning, and high-level estimation.
Option B: Continuum mechanics (more accurate)
- Solids: elasticity/plasticity models
- Fluids: Navier-Stokes (incompressible or compressible)
Best when geometry, turbulence, or stresses matter.
Option C: Particle methods (intuitive, expensive)
- Smoothed particle hydrodynamics (SPH) for fluids
- Molecular dynamics-like models for micro regimes
Best when free surfaces and splashes matter (and you can afford it).
The real trick is to avoid mixing levels incorrectly. For example, a particle-based "gas" model can be overkill for HVAC control, while an incompressible model can be dangerously wrong for compressed air.
Practical Rules of Thumb (When You‘re Under Time Pressure)
If you need a quick decision for a system design or a code path:
- If volume changes noticeably when you squeeze it, treat it gas-like.
- If it holds shape at rest and resists shear, treat it solid-like.
- If it flows under shear but doesn‘t noticeably change volume, treat it liquid-like.
And if you‘re unsure:
- ask what happens under shear (stirring, sliding, vibration)
- ask what happens under compression (pressure change)
- ask whether temperature swings are expected
Those three questions usually narrow the right model faster than arguing about labels.
Quick Reference Cheatsheet
Solid
Gas
—
—
Yes (usually)
No
Yes (nearly)
No
No
Yes
Often
Often not
Sometimes
Often
Rigid/elastic body
Compressible fluid / equation of stateIf you internalize just one idea: solid/liquid/gas are not trivia labels; they‘re modeling regimes. The regime tells you what you can treat as constant, what becomes boundary-driven, and what variables you must track (especially pressure and temperature for gases).


