SEEPLOREBLOGTitles

BLOG · Air Conditioners Move Heat

Visualizing the refrigeration cycle: turning air conditioner physics into 3D

A devlog on calculating an R-32 air conditioner cycle with CoolProp and feeding that table into 3D dot colors, sizes, labels and card text, so 92 °C at the compressor reaches the screen untouched.

· Devlog · 5 min read

In Air Conditioners Move Heat, a 3D web documentary I built, the refrigerant leaving the compressor is at 92 °C. I didn't pick that number. It comes straight out of a calculation based on the refrigerant's real property tables. Here's how one Python run ends up driving the dot colors, the labels and even the sentences on the cards, using code from the project's repository.

Calculate once, in Python

Inside an air conditioner, the refrigerant travels around a loop of pipe. It boils, gets squeezed, turns back into a liquid, then squeezes through a tiny opening and cools down. That loop is called the refrigeration cycle. You could make up plausible temperatures and pressures and have a pretty picture in an afternoon, but then the numbers wouldn't agree with each other.

So I started with the physics. I used CoolProp (version 8.0.0), a library that knows the properties of real substances, with R-32 as the refrigerant. The example is a wall-mounted unit: room at 27 °C, outdoors at 35 °C, refrigerant boiling at 7 °C indoors and turning liquid at 45 °C outdoors, removing 2.5 kJ of heat from the room every second (2.5 kW). Here's the compressor step:

h2s = PropsSI('H', 'P', p_hi, 'S', s1, F)
h2 = h1 + (h2s - h1) / ETA
T2 = PropsSI('T', 'P', p_hi, 'H', h2, F) - K

h stands for enthalpy, roughly the energy carried by 1 kg of refrigerant. Line one asks what a perfect, loss-free compressor would do. Line two applies an efficiency of 0.70, so the real compressor has to put in more work. Line three works backward from that energy to a temperature: 92.14 °C.

The script saves everything to a file called cycle.json, which lives in the repository. The app in your browser never runs CoolProp. It only reads that saved table. Even the card text is a template, like `to about ${tHot} °C`, so if I change a condition and rerun the script, every number on screen updates together.

The loop, cut into 200 slices

A handful of key points isn't enough to color dots flowing through a pipe. So I unrolled the loop into a single position, s, from 0 to 1, and split it into sections: the indoor coil (the evaporator) runs from 0.07 to 0.36, the compressor from 0.42 to 0.50, the outdoor coil (the condenser) from 0.56 to 0.90, and the expansion valve from 0.97 to 1.00. Then I cut the whole loop into 200 slices and calculated temperature, pressure and gas fraction for each.

The valve section is my favorite. The energy stays the same while the pressure drops from 27.6 to 10.0 atmospheres. Suddenly the boiling point is far below the liquid's temperature, so about 21% of it boils on the spot, and the whole stream cools to 7 °C. It's the same reason water boils below 100 °C high up a mountain.

Enlarged model of the expansion valve: liquid at 40 °C and 28 atm before the tiny opening, liquid plus gas at 7 °C and 10 atm after it, with a bar showing 21% gas and 79% liquid
The expansion valve scene. The labels on both sides and the 21% in the bar all come from the same table. (Source: Air Conditioners Move Heat)

In the app, one function, at(s), reads that table. Give it a position and it blends the two nearest rows to return the values there. Every refrigerant dot in the 3D scene asks this function about its own position on every frame.

What one dot carries

const st = C.at(s);
s = (s + dt * base * (0.45 + 1.6 * st.vap)) % 1;
const gas = c.seed[i * 4] < st.vap;
c.col.set(C.tempRGB(st.T), i * 3);

Line two moves a dot faster when there's more gas (vap), a rough nod to the fact that light gas rushes through faster than liquid. One lap takes about 20 seconds, far slower than in a real unit. Line three compares a random number fixed for each dot with the gas fraction to decide whether it's a big dot (gas) or a small one (liquid). Where the refrigerant is 21% gas, about one dot in five is big.

The color in line four took some thought. Blend blue straight into red and the middle turns purple, which nobody reads as "medium." So the scale runs blue, sky blue, white, orange, red, and its ends lock automatically to the coldest (7 °C) and hottest (92 °C) values in the table.

The orange ring around a dot is the heat it's carrying. The dots are drawn by a shader, a small program the graphics chip runs for every dot, and I pass it one extra value, ld. It fills from 0 to 1 through the evaporator and drains back to 0 through the condenser. The center keeps the temperature color, so the two never get mixed up.

A piston that follows the table

Next to the compressor scene stands a glass cylinder, a simple model of what happens inside. The plate presses down for 3 seconds, then rises for 1. How far it has moved maps to a position inside the compressor section of the table, and the label and dot colors update from there. Shrinking the gas roughly in inverse proportion to pressure is a screen-only sketch, and the card notes that home units usually use rotary or scroll compressors rather than pistons.

Compressor scene with refrigerant dots glowing white in the outdoor coil and a glass cylinder labeled 21 °C, 11 atm, gas
Caught mid-stroke, the cylinder reads 21 °C and 11 atm. At the bottom of the stroke it reaches 92 °C and 28 atm. (Source: Air Conditioners Move Heat)

The story compares the refrigerant to a train that carries heat. At first a toy train rode on the real pipes, but feedback said it felt forced, so now it only appears in scene 4, on a separate circular track. What each scene shows isn't written as commands. Each scene lists target values for 18 "weights," one per visual element. GSAP slides the weights there over 1.6 seconds and sync() sets opacity from them, so jumping between scenes never leaves the picture in a broken state.

Does it add up, and what's left out

For each kilogram of refrigerant, 247.5 kJ of heat taken in indoors plus 59.8 kJ of compressor work equals 307.3 kJ of heat released outdoors. The cards show all three to one decimal place so rounding never makes the sum look wrong.

92 °CLeaving the compressor
10.0 → 27.6Pressure across it (atm)
21%Gas after the valve
4.1Heat moved per unit of electricity

Divide the heat taken in by the compressor work and you get the coefficient of performance (COP): 4.1. Pulling 2.5 kW out of the room takes 0.6 kW of electricity and dumps 3.1 kW outdoors.

Wide final scene with the room, indoor unit and outdoor unit, showing 4.1 in the top left and a box reading electricity used 1, heat moved 4.1
The full loop. The box in the top right shows 4.1 units of heat moved for every 1 unit of electricity. (Source: Air Conditioners Move Heat)

This is an idealized cycle, though. There's no pressure loss along the pipes and no heat leaking out, one efficiency number stands in for all the compressor's losses, and the fans' electricity isn't counted. A real air conditioner's numbers change with the weather and the settings.

To watch the calculation reach the screen, open the compressor scene in Air Conditioners Move Heat and keep an eye on the numbers on the glass cylinder. For another physics title in the series, Microwaves Shake Water follows the waves that shake water molecules in your food.

  • #RefrigerationCycle
  • #HowAirConditionersWork
  • #CoolProp
  • #threejs
  • #Shaders
  • #Devlog
  • #seeplore