⚙️ 2D Carnot Cycle — P-V Diagram & Piston

PV = nRT · PV^γ = const · η = 1 − Tc/Th · work numerically integrated from the P-V loop

Reservoir Temperatures

Current Stage

▶ Isothermal Expansion (A→B)

Carnot Efficiency η = 1 − Tc/Th

η = 0%

Energy & Work

Qh absorbed (analytic)—
Qc rejected (analytic)—
W = Qh − Qc—
W (∮P dV, numeric)—
Integration error—

Current State Point

Volume V—
Pressure P—
Temperature T—
P Pause/Play   R Reset

Formulae

η = 1 − Tc/Th
P·V = n·R·T (ideal gas)
P·Vγ = const (adiabatic)
Qh = n·R·Th·ln(r)
W = ∮ P dV (numerically integrated)

⚙️ 2D Carnot Cycle — Real Ideal-Gas P-V Diagram & Piston

This 2D companion computes the same four Carnot stages as the 3D piston sim — isothermal expansion, adiabatic expansion, isothermal compression, adiabatic compression — directly from the ideal gas law PV = nRT and the adiabatic relation PVγ = const, then drives both the P-V curve and a synchronized piston-cylinder animation from that single set of numbers. Work per cycle is shown two ways: the analytic Qh − Qc, and a numerical trapezoidal integration of ∮P dV around the closed loop, so you can see the two independent calculations agree.

🔬 What It Demonstrates

Every corner point A, B, C, D is solved from PV = nRT and PVγ = const for the current Th, Tc and expansion ratio r. The piston's horizontal position is a direct linear map of the current volume V onto the cylinder — it is never an independent animation, so dragging any slider changes the P-V curve and the piston position from the same recomputed numbers in the same frame.

🎮 How to Use

Adjust hot/cold reservoir temperatures and the expansion ratio r to see how the enclosed P-V loop area, the Carnot efficiency η = 1 − Tc/Th, and the numerically integrated work per cycle all change together. Pause and step through with the keyboard shortcuts to inspect any single stage.

💡 Did You Know?

The two work figures — analytic Qh − Qc and the numerically integrated ∮P dV — should agree to a fraction of a percent; the small residual you see is genuine trapezoidal discretisation error from the 400 sub-steps per stage, not a fudge factor.

About this simulation

This 2D companion recomputes the Carnot cycle's four corner states every frame from PV = nRT and PVγ = const, drives a piston-cylinder animation directly from the resulting volume, and numerically integrates the enclosed P-V loop area for a genuine work-per-cycle figure alongside the analytic Qh − Qc result.

🔬 What it shows

State A is fixed at (VA, Th). B is found from isothermal expansion to VB = r·VA. C is found from the adiabatic relation T·Vγ−1 = const, cooling from Th to Tc. D is found from the same adiabatic relation so that the D→A leg closes the loop exactly back at A. The piston position is (V − Vmin)/(Vmax − Vmin) mapped onto the cylinder length — literally the same V used to plot the P-V curve.

🎮 How to use

Four sliders: hot reservoir Th, cold reservoir Tc, expansion ratio r, and animation speed. Watch the efficiency gauge, the two independent work figures (analytic and numerically integrated), and the live V/P/T readout all update together as the state point moves around the loop.

💡 Did you know?

The numerical work integral uses the trapezoidal rule with 400 sub-steps per stage. Because the analytic Qh − Qc and the numeric ∮P dV are computed by completely independent methods, their agreement (to well under 0.1% here) is a genuine self-check of the physics rather than a coincidence of how the sim was built.

Frequently asked questions

How does this differ from the 3D Carnot Cycle sim?

The 3D sim renders the piston-cylinder as a real Three.js/WebGL scene with orbit controls. This 2D companion uses only plain Canvas2D for both the P-V diagram and the piston view — same underlying thermodynamics (PV = nRT, PVγ = const, η = 1 − Tc/Th), but it adds a numerically integrated work-per-cycle figure computed independently of the analytic Qh − Qc formula.

Why do the two work values (analytic vs numeric) not match exactly?

The analytic value is Qh − Qc from the closed-form heat integrals; the numeric value is a trapezoidal-rule integration of ∮P dV over 1,600 discrete sub-steps around the loop. Any tiny residual between them is real discretisation error from the trapezoid approximation, and it shrinks further if you imagine subdividing the loop even more finely.

How is the piston position actually computed?

The current volume V comes from solving the ideal gas law or the adiabatic relation for whichever of the four stages is active. The piston's horizontal position is (V − Vmin)/(Vmax − Vmin), the same normalised value used to place the moving dot on the P-V diagram — so the piston and the P-V curve can never disagree about where the gas volume currently is.

Why does the expansion ratio r matter?

r = VB/VA sets how far the isothermal expansion travels before the adiabatic leg takes over. A larger r increases Qh = nRTh·ln(r) and therefore the work done per cycle, but it does not change the Carnot efficiency η = 1 − Tc/Th, which depends only on the two reservoir temperatures — a useful distinction to explore with the sliders.

What keeps the D→A leg a genuine adiabat?

VD is solved from the same adiabatic relation T·Vγ−1 = const applied between Tc and Th (the same exponent used for B→C), rather than being picked arbitrarily — so the loop closes exactly back onto state A with no seam or discontinuity in pressure or volume.