Sizing a heat exchanger with the LMTD method is a standard heat transfer problem, but doing it by hand for several designs is slow. In this tutorial we write a short Python program that sizes a heat exchanger, compares parallel flow and counter flow, and plots the temperature of both fluids along the exchanger – the graph textbooks show, drawn from your own numbers.
Quick answer: The log mean temperature difference is LMTD = (ΔT1 − ΔT2) / ln(ΔT1/ΔT2), and the required area is A = Q / (U × LMTD). In this example a counter flow exchanger needs 6.63 m² while a parallel flow exchanger needs 8.33 m² for the same 126 kW duty – about 20% less area for counter flow.
The Problem
- Hot oil: 1.2 kg/s, cp = 2.1 kJ/kg·K, cooled from 120 °C to 70 °C
- Cold water: 1.0 kg/s, cp = 4.18 kJ/kg·K, entering at 25 °C
- Overall heat transfer coefficient U = 350 W/m²·K
Find the heat duty, the water outlet temperature, and the area needed for parallel flow and for counter flow.
Step 1: The Theory
Heat duty from the hot side: Q = ṁcpΔT = 1.2 × 2100 × (120 − 70) = 126 kW.
Water outlet temperature from the energy balance: Tc,out = 25 + 126 000 / (1.0 × 4180) = 55.1 °C.
End temperature differences depend on the arrangement:
- Parallel flow (both fluids enter at the same end): ΔT1 = 120 − 25 = 95 °C, ΔT2 = 70 − 55.1 = 14.9 °C → LMTD = 43.2 °C
- Counter flow (fluids enter at opposite ends): ΔT1 = 120 − 55.1 = 64.9 °C, ΔT2 = 70 − 25 = 45 °C → LMTD = 54.3 °C
Then A = Q / (U × LMTD) gives the area for each case.
Step 2: The Python Code
You need NumPy and Matplotlib (pip install numpy matplotlib). The temperature profiles use the analytical solution: the temperature difference between the fluids changes exponentially along the area, which lets us find how much heat has been transferred at every point.
import numpy as np
import matplotlib.pyplot as plt
# Hot fluid: oil, cold fluid: water (SI units)
m_h, cp_h = 1.2, 2100.0 # kg/s, J/kg·K
m_c, cp_c = 1.0, 4180.0 # kg/s, J/kg·K
Th_in, Th_out = 120.0, 70.0 # °C
Tc_in = 25.0 # °C
U = 350.0 # overall heat transfer coefficient, W/m²·K
C_h, C_c = m_h * cp_h, m_c * cp_c # heat capacity rates, W/K
Q = C_h * (Th_in - Th_out) # heat duty, W
Tc_out = Tc_in + Q / C_c # energy balance
def lmtd(dT1, dT2):
return (dT1 - dT2) / np.log(dT1 / dT2)
# End temperature differences for each arrangement
cases = {
"Parallel flow": (Th_in - Tc_in, Th_out - Tc_out),
"Counter flow": (Th_in - Tc_out, Th_out - Tc_in),
}
print(f"Heat duty Q = {Q/1000:.1f} kW")
print(f"Water outlet temperature = {Tc_out:.1f} °C")
areas = {}
for name, (dT1, dT2) in cases.items():
LMTD = lmtd(dT1, dT2)
A = Q / (U * LMTD)
areas[name] = A
print(f"{name}: LMTD = {LMTD:.1f} °C, area = {A:.2f} m²")
saving = 1 - areas["Counter flow"] / areas["Parallel flow"]
print(f"Counter flow needs {saving*100:.0f}% less area")
# Temperature profiles along the exchanger (analytical solution)
fig, axes = plt.subplots(1, 2, figsize=(11, 4), sharey=True)
for ax, (name, sign) in zip(axes, [("Parallel flow", +1), ("Counter flow", -1)]):
A = areas[name]
a = np.linspace(0, A, 200)
k = U * (1 / C_h + sign / C_c)
dT0 = cases[name][0]
q = U * dT0 * (1 - np.exp(-k * a)) / k # heat transferred up to a
Th = Th_in - q / C_h
Tc = Tc_in + q / C_c if sign > 0 else Tc_out - q / C_c
ax.plot(a / A, Th, label="Hot oil")
ax.plot(a / A, Tc, label="Cold water")
ax.set_title(f"{name} (A = {A:.2f} m²)")
ax.set_xlabel("Fraction of heat transfer area")
ax.grid(True, alpha=0.3)
axes[0].set_ylabel("Temperature (°C)")
axes[0].legend()
plt.tight_layout()
plt.savefig("heat_exchanger_profiles.png", dpi=150)
plt.show()
Step 3: The Results
Heat duty Q = 126.0 kW
Water outlet temperature = 55.1 °C
Parallel flow: LMTD = 43.2 °C, area = 8.33 m²
Counter flow: LMTD = 54.3 °C, area = 6.63 m²
Counter flow needs 20% less area
The values match the hand calculation in Step 1. The plot shows how the two fluid temperatures change along each exchanger:

What the Graph Tells You
- Parallel flow starts with a very large temperature difference (95 °C) that collapses to 14.9 °C at the exit. Most of the heat is transferred in the first part of the exchanger, and the last part works poorly.
- Counter flow keeps the difference between 45 °C and 65 °C along the whole length, so every square metre does useful work. That is why its LMTD is higher and its area is smaller.
- In counter flow the cold outlet (55.1 °C) can approach the hot inlet. In parallel flow the cold outlet can never exceed the hot outlet – a key limit to mention in your viva.
Common Mistakes
- Swapping ΔT1 and ΔT2 between arrangements – always write which end each difference belongs to.
- Mixing kJ and J – keep cp in J/kg·K so Q comes out in watts.
- Equal end differences – the formula divides by ln(1) = 0; handle that case separately (LMTD = ΔT).
- Forgetting the correction factor – shell-and-tube and cross flow exchangers need an LMTD correction factor F.
Try It Yourself: Extend the Code
- Add the effectiveness–NTU method and check it gives the same outlet temperatures.
- Plot required area against U from 100 to 1000 W/m²·K.
- Replace water with a nanofluid using its property values and compare the area.
- Add an LMTD correction factor for a 1-shell, 2-pass exchanger.
- Compare your Python results with a CFD model of a double pipe heat exchanger.
Steps 3 to 5 lead naturally into a final year project – see our heat exchanger projects and the beam deflection in Python tutorial for another worked example.
Next tutorial: how to plot CFD and FEA results with Python Matplotlib – mesh study and validation graphs for your report.
Learn Python for Mechanical Engineering
We teach Python to mechanical and aerospace students through problems from heat transfer, strength of materials and machine design. In our Python for mechanical engineers classes you learn NumPy, Matplotlib and data handling step by step, in live screen-share sessions or recorded videos, and write the code yourself.
Frequently Asked Questions
How do you calculate LMTD in Python?
Find the two end temperature differences for your flow arrangement, then compute LMTD = (ΔT1 − ΔT2) / ln(ΔT1 / ΔT2) with NumPy’s log function. The heat transfer area is then A = Q / (U × LMTD).
Why does a counter flow heat exchanger need less area?
In counter flow the temperature difference between the two fluids stays more uniform along the exchanger, so the log mean temperature difference is higher. A higher LMTD means less area is needed for the same heat duty – about 20% less in this example.
When should I use the NTU method instead of LMTD?
Use LMTD when the inlet and outlet temperatures are known and you need the area (sizing). Use the effectiveness–NTU method when the area is known and you need to predict the outlet temperatures (rating).
Can the LMTD formula fail in Python?
Yes. If the two end temperature differences are equal, ln(ΔT1/ΔT2) is zero and the formula divides by zero; in that case LMTD equals ΔT. If any temperature difference is negative, the temperatures are not physically possible for that arrangement and the inputs must be checked.
Is this useful for a heat exchanger final year project?
Yes. A Python sizing tool is a quick way to check CFD or experimental results, compare fluids and flow arrangements, and produce clean graphs for your report and viva.
Start Learning
Tell us your branch and what you want to build. Message us on WhatsApp or use the enquiry form on our home page.
Interested in this project? Get the details, files and guidance from our team.
Enquire on WhatsApp