Work is energy transfer by organized forces through displacement; heat is transfer associated with a temperature difference. A simulation needs separate channels for both before it can claim energy accounting. They are transfer modes, not amounts permanently stored inside an object.
With this convention, positive Q enters the system and positive W leaves through work done by the system. Adding 10 J of heat with 3 J of expansion work gives ΔU = 7 J. If the system is compressed, W by the system is negative, so the same algebra increases U. Another convention can be correct, but mixing conventions between components produces a false energy error.
For a quasi-static gas, work is the path integral W = ∫p dV; it depends on how volume changed, whereas U is a state change once the system model is fixed. Store a sequence of pressure/volume samples and a named quadrature rule rather than estimating work from initial/final values only. Heat needs its own event/source model rather than being inferred from a color-temperature display.
Prediction: Adding heat with no work raises internal energy by that heat; adiabatic expansion with positive work lowers it.
Write two unit tests: Q = 10 J, W = 0 and Q = 0, W = 3 J. State expected ΔU for each, then reverse work direction for compression. Finally list the event metadata a sampled p–V work integrator must preserve.Use an explicit signed ledger for heat and work, preserve boundary and path metadata, then test the first law after each modeled process. Treat a nonzero residual as a diagnostic requiring explanation, not as rounding to hide.
Heat: energy transfer from temperature difference.
Work: energy transfer from generalized force and displacement.
Sign convention: declared meaning of positive values.
State function: quantity determined by state rather than path.
Path integral: accumulated quantity whose value depends on intermediate states.
Adiabatic: no heat transfer across the declared boundary.
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Work and Heat in Simulations, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Temperature and the First Law, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Work and Heat in Simulations as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Use signed heat and work events to test first-law accounting in a state update.