Piston EnginesPiston EnginesOpen playground →

How the demos compute it

Every gauge, curve and cutaway in the Engine Room is computed live from a handful of equations — the ones in this course — evaluated at one master crank angle. This article opens the hood on that model: what it solves, in what order, and exactly where it stops being physics and starts being honest cartoon.

One angle drives everything

The entire engine state is a pure function of crank angle θ[0,720)\theta \in [0, 720^\circ). The animation loop advances θ\theta at the chosen rpm; piston position, valve lift, spark event, cylinder pressure and the PV point are all recomputed from scratch at each frame. Nothing is integrated forward in time, so nothing can drift: scrub backwards, jump, or change geometry mid-stroke and every panel stays exactly consistent. (The aerodynamics demo makes the same architectural choice for the same reason.)

  • Kinematics — the exact equations (1)–(2) of the kinematics article, radical included; velocity and acceleration are the exact analytic derivatives, not the λ-expansion.
  • Volume V(θ)=Vc+Ad(θ)V(\theta) = V_c + A\,d(\theta) with the clearance volume set from the compression ratio: Vc=Vs/(r1)V_c = V_s/(r-1).
  • Valves — lift follows a raised-sine bump sin2(πphase)\sin^2(\pi\,\text{phase}) across each open window of the timing table — a clean stand-in for a cam lobe.

The pressure model

With the valves closed, pressure follows the adiabat referenced to the intake state:

pmotored(θ)=pin(VmaxV(θ))γp_{\text{motored}}(\theta) = p_{\text{in}} \left(\frac{V_{\max}}{V(\theta)}\right)^{\gamma}(1)

Combustion multiplies this motored pressure by a factor that grows with the mass fraction burned, an S-curve known as the Wiebe function — the standard engineering fit for how a real charge burns:

xb(θ)=1exp ⁣[a(θθsparkΔθb)m+1],p=pmotored(1+(k1)xb)x_b(\theta) = 1 - \exp\!\left[-a\left(\frac{\theta - \theta_{\text{spark}}}{\Delta\theta_b}\right)^{m+1}\right], \qquad p = p_{\text{motored}}\,\bigl(1 + (k-1)\,x_b\bigr)(2)
a, ma,\ m
Wiebe shape constants (5 and 2 — textbook values) []
Δθb\Delta\theta_b
burn duration: 55° Otto, 50° two-stroke [deg]
kk
peak pressure multiplier (3.5 Otto, 3.2 two-stroke) []
pinp_{\text{in}}
intake pressure, 0.9 atm (a slight manifold depression) [Pa]

The Diesel model needs no Wiebe curve: it holds p=pTDCp = p_{\text{TDC}} constant from TDC until the cylinder volume reaches the cutoff V3=rcVTDCV_3 = r_c V_{\text{TDC}} (found by bisection on the exact volume function), then expands adiabatically from there — the textbook cycle of the Diesel article, computed literally. The two-stroke references its adiabat to the port-closing volume, which is how the effective-compression story appears in its PV loop. Around exhaust-valve opening, every cycle relaxes toward the exhaust back-pressure through a smoothstep blend — a stand-in for blowdown.

The balance model

The Cylinder Configurations demo evaluates, per cylinder, the exact acceleration at that cylinder’s phase offset, multiplies by the reciprocating mass (0.45 kg per cylinder), and projects along the bore direction of its bank:

Fnet(θ)=kma ⁣(θ+δk)u^k,M(θ)=kzkFk(θ)\vec F_{\text{net}}(\theta) = \sum_k m\,a\!\left(\theta + \delta_k\right)\hat u_k, \qquad M(\theta) = \sum_k z_k\,F_k(\theta)(3)

The rocking couple MM weights each force by its position zkz_k along the crank. The primary/secondary indices on the balance meter come from a harmonic decomposition of the same sum — the cosθ\cos\theta and cos2θ\cos 2\theta ledger of the balance article, but with the exact acceleration, so short-rod effects are included. All of it is normalised by one cylinder’s peak primary mrω2m r\omega^2, which is why the meter reads the same at any rpm.

What the model leaves out — deliberately

  • Heat transfer. Compression and expansion are treated as perfectly adiabatic with γ=1.4\gamma = 1.4 throughout. Real cylinders lose 15–25% of the fuel energy to the coolant, and hot burned gas has γ1.3\gamma \approx 1.3.
  • Gas exchange dynamics. Intake and exhaust run at fixed pressures (0.9 / 1.08 atm). There is no manifold acoustics, no volumetric-efficiency curve, so the model cannot show why torque peaks at a particular rpm.
  • Chemistry. The Wiebe curve and the peak-factor kk are imposed, not computed from fuel properties — no knock, no emissions, no mixture strength.
  • Friction. All pressures are indicated; the brake quantities of the torque article would need a friction model the demo does not carry.
  • Structure. Rods and cranks are rigid; the balance demo computes the forces the mounts must absorb, not how the block deforms under them.