A Byte of PhysicsLogo

Thermodynamic processes

A thermodynamic state is described by macroscopic variables such as pressure, volume, temperature, composition, and internal energy. A process is a path through those states. Names such as isothermal, isobaric, isochoric, and adiabatic state which quantity or transfer is constrained; they do not fully specify every real process.

State variables are constrained

For \(n\) moles of an ideal gas,

\[pV=nRT\]

where \(p\), \(V\), \(T\), and \(R\) describe an equilibrium state. Once \(n\) is fixed, only two of \(p\), \(V\), and \(T\) can be chosen independently.

The ideal-gas law is a model for dilute gases. It is not a process equation and does not say how much heat or work occurred. Two paths can connect the same endpoint states while having different heat and work.

This lesson uses heat into the gas as positive and work done by the gas as positive:

\[\Delta U=Q-W\]

For an ideal gas, internal energy depends only on temperature. If molar heat capacity at constant volume \(C_V\) is constant over the range,

\[\Delta U=nC_V(T_f-T_i)\]

Isochoric: constant volume

An isochoric process keeps \(V\) fixed. There is no pressure–volume boundary work:

\[W=\int p_{\mathrm{ext}}\,dV=0\]

Therefore \(Q=\Delta U\) under the chosen convention when no other work mode is present. For an ideal gas at fixed amount and volume, pressure is proportional to absolute temperature:

\[\frac{p_f}{p_i}=\frac{T_f}{T_i}\]

The formula requires kelvin. Celsius ratios do not preserve the ideal-gas proportionality.

Isobaric: constant pressure

An isobaric quasistatic process keeps pressure \(p\) fixed. Its pressure–volume work is

\[W=p(V_f-V_i)\]

At fixed amount of ideal gas, \(V/T\) is constant. Heating usually raises both internal energy and volume, so

\[Q=\Delta U+W=nC_P(T_f-T_i)\]

when \(C_P\) is constant and pressure–volume work is the only work. For an ideal gas, \(C_P-C_V=R\).

Isothermal: constant temperature

An isothermal process keeps \(T\) fixed. For an ideal gas, \(\Delta U=0\). Along a reversible or quasistatic path,

\[p(V)=\frac{nRT}{V}\]

and the work done by the gas is

\[W=nRT\ln\left(\frac{V_f}{V_i}\right)\]

The first law then gives \(Q=W\). During expansion, the gas absorbs heat to replace the work it performs. This conclusion is specific to ideal-gas internal energy and constant temperature. A real gas can have interaction energy that changes during an isothermal volume change.

Adiabatic: no heat transfer

An adiabatic process has \(Q=0\). It does not necessarily have constant temperature. The first law becomes

\[\Delta U=-W\]

A quasistatic reversible ideal-gas process with constant heat capacities obeys

\[pV^\gamma=\mathrm{constant},\qquad TV^{\gamma-1}=\mathrm{constant},\qquad \gamma=\frac{C_P}{C_V}\]

Expansion cools the gas and compression heats it under these assumptions. The work can be written

\[W=\frac{p_iV_i-p_fV_f}{\gamma-1}=nC_V(T_i-T_f)\]

These formulas are not consequences of \(Q=0\) alone. Free expansion into a vacuum can be adiabatic with zero external pressure and therefore zero work. For an ideal gas, the first law then gives no temperature change, even though the process is irreversible and does not follow \(pV^\gamma=\mathrm{constant}\).

Quasistatic and reversible are not synonyms

A quasistatic process proceeds slowly enough that the system passes through states close to equilibrium, allowing a path to be drawn in equilibrium state space. Reversible is stronger: the process must be restorable by an infinitesimal change without net entropy production in system plus surroundings.

Friction, viscosity, finite temperature differences, unrestrained expansion, electrical resistance, and mixing make processes irreversible. Moving slowly can reduce some departures from equilibrium, but it does not remove dry friction or diffusion.

When work is evaluated from a quasistatic gas path, gas pressure approximates external pressure. For a rapid irreversible process, work still depends on external force or pressure, but one uniform gas pressure may not exist.

Reading a pressure–volume diagram

A point on a pressure–volume diagram represents an equilibrium state only when the system is describable by one pressure and volume. An oriented curve represents a process. The signed work done by the gas is the area under the path:

\[W=\int_{V_i}^{V_f}p_{\mathrm{ext}}\,dV\]

Vertical paths have zero pressure–volume work. A clockwise closed loop has positive net work by the gas under the usual axes; a counterclockwise loop has negative net work. Area is energy because \(\mathrm{Pa\,m^3}=\mathrm J\).

Building a process path

import numpy as np

amount, gas_constant, temperature = 1.0, 8.314462618, 300.0
volumes = np.linspace(0.01, 0.02, 1001)
pressures = amount * gas_constant * temperature / volumes
assert np.allclose(pressures * volumes, amount * gas_constant * temperature)
work_by = np.trapezoid(pressures, volumes)
internal_energy_change = 0.0  # Isothermal ideal gas.
heat_in = internal_energy_change + work_by
exact = amount * gas_constant * temperature * np.log(volumes[-1] / volumes[0])
print(f"Work and heat: {work_by:.3f} J; exact work: {exact:.3f} J")

The last line is the first law rearranged under the chosen convention. It does not identify the microscopic heat-transfer mechanism; it infers net heat only after the other energy terms are valid.

Comparing paths with the same endpoints

Take an ideal gas from one equilibrium state to another. One route might first heat at constant volume and then expand at constant pressure. Another might follow a curved isothermal or polytropic path. If the endpoint temperatures match, both routes have the same \(\Delta U\). Their work and heat generally differ.

This makes a strong code test. Generate two valid ordered paths with identical endpoints, integrate work on each, and compute heat from the first law. Require internal-energy change to agree while allowing transfer terms to differ.

Numerical and physical checks

At every point, verify the equation of state and positivity of absolute pressure, volume, and temperature. For an isochoric fixture, require zero pressure–volume work. For an isothermal ideal-gas expansion, check that pressure falls inversely with volume, work is positive, and \(Q=W\). For a reversible adiabatic fixture, check both invariant forms and compare work with the internal energy change.

Refine path sampling. A trapezoidal work estimate should converge for a smooth path. Do not sort samples by volume: a real process can reverse direction, and sorting destroys its orientation and loop area. Report residuals and uncertainty rather than forcing endpoint data to fit an assumed path.

Real processes can include phase transitions, reactions, leaks, changing composition, spatial gradients, turbulence, radiation, surface tension, and nonideal equations of state. A named textbook process is a controlled model, not a complete description of a machine.

A worked Python notebook

Trace an isothermal process for one mole of ideal gas at 300 kelvin. The question for this calculation is precise: how does isothermal pressure change when we change volume, while keeping the other choices fixed? The earlier sections explain the physical relationship. Here we turn one part of that relationship into a calculation that you can run, inspect, and change in Google Colab.

An adiabatic process follows a different pressure-volume relation. Keep that sentence beside the results. A formula can return a number outside its useful range, and a plotting library will usually draw that number without asking whether the physical assumptions still hold. The selected interval is from 0.005 to 0.03 m^3. It gives us a specific domain to discuss instead of leaving the graph's range to a software default.

Use the notebook link above the lesson, run the setup cell, and then run the cells in order. The code below is also included there. NumPy handles the arrays of numerical values, SymPy keeps the equation symbolic, and Matplotlib draws the results. If these libraries or notebook cells are unfamiliar, start with Your first physics notebook.

State the relationship before choosing a graph

In this small example, q stands for volume, expressed in m^3. The output is isothermal pressure, expressed in Pa. The equation below uses the numerical values in those units. Any fixed coefficients therefore carry the units needed to make the relation consistent. A value supplied in another unit must be converted before it enters this expression.

\[f(q) = \frac{2494.3387854}{q}\]

This is a function of one changing input. It is not a statement that the physical system has only one variable. We deliberately hold the other inputs fixed so that one cause of variation is visible. Changing several inputs at once would make it harder to tell which change produced the output difference. Write down the held-fixed choices before trying a different experiment.

At 0.01 m^3, the expression gives 249434 Pa. This is our reference calculation. It is a prediction of the stated example, not a new measurement. Its displayed digits help us compare implementations. They should not be read as a claim that physical inputs are known to six significant figures.

import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

q = sp.Symbol("q", real=True)
expression = sp.sympify("8.314462618*300/q", locals={"q": q})
reference_input = 0.01
reference_output = float(expression.subs(q, reference_input))
print("Input:", reference_input, "m^3")
print("Predicted isothermal pressure:", reference_output, "Pa")

sp.Symbol declares a mathematical symbol. It does not assign a numerical measurement to that symbol. subs then replaces the symbol with our chosen input, and float converts the resulting symbolic number into a standard Python numerical value. Keeping these steps separate lets us inspect the equation before numerical substitution. It also prevents a later plot from becoming the only surviving record of the model.

Compare a few cases you can explain

Before drawing hundreds of points, calculate three. The lower endpoint gives 498868 Pa. The midpoint, at 0.0175 m^3, gives 142534 Pa. The upper endpoint gives 83144.6 Pa. Read these together with the assumptions: they describe different choices of volume within the same example, with the other inputs held fixed.

These three values are a useful first check, but they do not establish the shape between them. Two endpoints can be equal even when the curve bends or oscillates in between. Likewise, a large change between endpoints does not tell us whether the relationship is linear. We need the equation and intermediate samples to answer those questions.

evaluate = sp.lambdify(q, expression, modules="numpy")
inputs = np.array([0.005, 0.017499999999999998, 0.03])
outputs = np.asarray(evaluate(inputs), dtype=float)
outputs = np.broadcast_to(outputs, inputs.shape)
for input_value, output_value in zip(inputs, outputs):
    print(f"{input_value:.6g} m^3 -> {output_value:.6g} Pa")
assert np.all(np.isfinite(outputs))

lambdify turns the symbolic expression into a numerical function. We explicitly select NumPy as its numerical backend so it can accept an array. The same expression now has two useful forms: one for algebra and one for calculating many cases. The assertion checks that the chosen inputs produce finite outputs. It would catch an infinity or an undefined numerical result, but a finite value can still be physically inappropriate.

Make a graph that answers the question

The horizontal axis shows volume; the vertical axis shows isothermal pressure. Every plotted point is a prediction of the same expression. We mark the reference case separately so that a reader can connect the earlier printed value to its place on the curve. The axis labels include units because a shape without a scale cannot tell us the size of a physical effect.

input_grid = np.linspace(0.005, 0.03, 301)
output_grid = np.asarray(evaluate(input_grid), dtype=float)
output_grid = np.broadcast_to(output_grid, input_grid.shape)
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot(input_grid, output_grid, label="Stated model")
ax.scatter([reference_input], [reference_output], label="Reference case", zorder=3)
ax.set_xlabel("Volume (m^3)")
ax.set_ylabel("Isothermal pressure (Pa)")
ax.legend()
ax.grid(alpha=0.25)
fig.tight_layout()
plt.show()

Look for a sign change, a turning point, or a region where the curve becomes steep. Connect each feature to the expression rather than to the colour of the line. If the curve has a minimum or maximum, changing the input in opposite directions may have similar effects on the output near that point. If it is nearly straight over a short interval, a local linear approximation may be useful even when the complete expression is nonlinear.

Increasing the number of samples makes the line smoother and may reveal features that a coarse grid missed. It does not improve the physical inputs or enlarge the model's validity range. For quantities that can take only discrete values, use the line as a guide to the relationship and interpret only the allowed input values. A plotting function does not enforce such restrictions for you.

Measure the local sensitivity

A derivative asks a more specific question than the whole graph: how quickly does isothermal pressure change near the reference input? Its units are the output unit divided by the input unit. For this calculation, the derivative at 0.01 m^3 is -2.49434e+07 in those ratio units. Locally, the output decreases as the input increases. This statement is local; the sign or size of the slope can be different elsewhere on the curve.

\[f'(q) = - \frac{2494.3387854}{q^{2}}\]

For a small input change, multiply the derivative by that change to estimate the output change. Then compare that estimate with a fresh evaluation of the full expression. The distinction between these two calculations matters: the derivative gives a tangent approximation, while substitution evaluates the chosen expression at the new point.

slope_expression = sp.diff(expression, q)
slope_at_reference = float(slope_expression.subs(q, reference_input))
changed_input = 0.010125
linear_prediction = reference_output + slope_at_reference * (
    changed_input - reference_input
)
full_prediction = float(evaluate(changed_input))
print("Symbolic derivative:", slope_expression)
print("Tangent prediction:", linear_prediction, "Pa")
print("Full expression:", full_prediction, "Pa")
print("Approximation difference:", full_prediction - linear_prediction, "Pa")

Here the changed input is 0.010125 m^3. The tangent estimate is 246316 Pa, while the full expression gives 246354 Pa. If the two values are close, it means the chosen input change is small enough for this local approximation at this point. It does not mean the entire model is linear. If the slope is zero, a quadratic or higher-order term may supply the leading change instead.

This is also the beginning of uncertainty propagation. If the input has a small stated standard uncertainty, the magnitude of the slope times that uncertainty estimates one contribution to output uncertainty. Do not automatically use the same rule for a wide interval, a discontinuity, a turning point with zero first derivative, or several correlated uncertain inputs. Those situations need more of the model than one slope.

Check the derivative with numerical differences

We can estimate the same slope from values on either side of the reference point. Subtract the lower output from the upper output and divide by twice the input step. Parentheses are essential: the entire output difference must be divided by the entire input interval. Without them, Python can execute a different mathematical expression while still producing a plausible number.

The calculation below uses three decreasing step sizes. Each estimate is compared with the symbolic derivative, so the reference is independent of the numerical difference formula. Near an endpoint, it is acceptable here to evaluate a small extension only because the displayed mathematical expression is smooth there; such a check does not assert that extrapolated values describe additional physical cases.

input_span = 0.024999999999999998
for fraction in [1e-2, 1e-3, 1e-4]:
    step = input_span * fraction
    upper = float(evaluate(reference_input + step))
    lower = float(evaluate(reference_input - step))
    numerical_slope = (upper - lower) / (2 * step)
    difference = numerical_slope - slope_at_reference
    print(f"step={step:.6g}: slope={numerical_slope:.6g}, difference={difference:.6g}")

For a smooth function, reducing the step often reduces the approximation error at first. Very small steps can eventually make subtraction of nearly equal floating-point values less reliable. Therefore “smaller” is not an unlimited guarantee of “better.” Compare the observed behaviour over a useful range of steps instead of choosing the smallest number the computer can represent.

An absolute slope difference is useful when the expected slope is near zero. A relative difference would divide by a very small reference and could look enormous even when the absolute discrepancy is tiny. Away from zero, a relative difference can help compare quantities with very different scales. The tolerance should reflect the question and the numerical method, rather than a universal decimal threshold copied into every test.

Change the example and preserve the reasoning

Make one copy of the reference calculation before editing it. Choose a second value of volume inside the stated interval, predict whether isothermal pressure will rise or fall, and then evaluate the expression. Place the prediction and the result in a text cell. If they disagree, identify whether the mistake was in the sign, the unit conversion, the algebra, or the assumption about how the curve behaves.

Next choose a shorter plotting interval around the reference point. Compare the local curve with its tangent approximation. Then widen the interval again. The difference shows why a useful local estimate need not describe the whole range. Keep the axis labels and numerical scale visible when comparing the plots; automatic axis limits can make two different effects appear equally large.

Finally, return to the physical limit stated at the start: An adiabatic process follows a different pressure-volume relation. Describe one change to the setup that would violate that limit. State what new input, equation, or observation would be needed before trusting an answer in the changed situation. This last step connects the Python experiment to the physics instead of treating successful execution as the only criterion for a useful result.

Before saving, restart the runtime and run all cells in order. A result that depends on an earlier, now-deleted input cell is not reproducible from the saved notebook. Keep unrounded values for later calculations, round only the reported output, and label any new data as measured, assumed, or generated. The graph and printed values should remain traceable to the same expression and the same choices of inputs.

Recover the output change by integrating the slope

There is another way to check that the expression and its derivative describe the same relationship. Add up the small output changes predicted by the slope across the chosen input interval. In the continuous limit, this integral equals the output at the upper endpoint minus the output at the lower endpoint. The result has units of Pa: the input unit in the integration cancels the input unit in the denominator of the slope.

This statement is about the mathematics of this particular relationship. It does not assign a new physical meaning to an arbitrary area under a graph. For example, an area under force versus distance represents work, while an area under a different pair of quantities may represent something else or have no standard name. Always carry the axis units through the calculation before naming an integral.

slope_function = sp.lambdify(q, slope_expression, modules="numpy")
endpoint_change = float(evaluate(0.03) - evaluate(0.005))
for points in [101, 201, 401]:
    grid = np.linspace(0.005, 0.03, points)
    slopes = np.asarray(slope_function(grid), dtype=float)
    slopes = np.broadcast_to(slopes, grid.shape)
    integrated_change = np.trapezoid(slopes, grid)
    print(
        points,
        "integrated change:",
        integrated_change,
        "endpoint change:",
        endpoint_change,
    )

The trapezoidal rule joins neighbouring slope samples with straight segments and adds their signed areas. A negative contribution remains negative; replacing every slope by its magnitude would calculate a different quantity. Increasing the sample count provides a practical refinement check. If the values do not settle toward the endpoint difference, first inspect the interval, singularities, and array ordering.

Do not conclude that two agreeing calculations prove the model is physically complete. Both use the same selected relationship, so an omitted effect would be omitted from both. Their agreement is evidence that the numerical tools implement that relationship consistently. Comparing with an independent experiment or a more appropriate physical model is a separate test.

Keep this comparison in the notebook when you change the expression. It is particularly useful after adding a coefficient, changing a sign convention, or converting an input unit. A code cell that produces a smooth graph can conceal these mistakes; a second calculation of the same output change gives you another place to notice them.

Sources


Share to: