How to compute Rankine cycle efficiency in Python
CoolProp gives you real steam properties in one line each, so you can skip the interpolation in your textbook. On a Small awx computer, you can calculate a whole Rankine cycle, plot its T–s diagram and run a sweep of boiler pressures in five seconds. The sweep helps explain why power plants reheat their steam.
Step 1: a computer and CoolProp
Create a Small computer in awx. We called ours rankine-steam. Open its Terminal tab and run the commands below to install CoolProp, the open-source library we’ll use to find fluid properties. The installation took 31 seconds.
python3 -m venv ~/thermo
~/thermo/bin/pip install CoolProp numpy matplotlib
Step 2: steam properties in one line
To find a property with PropsSI, give the function the property you want, then any two properties you know and their values, and finally the fluid. Use SI units throughout, including Pa, K, J/kg, and J/(kg·K) for entropy. Keep the distinction between J and the kJ used in most tables in mind. Try these calls at the prompt opened by ~/thermo/bin/python, since plain python3 does not have CoolProp.
from CoolProp.CoolProp import PropsSI
PropsSI("H", "P", 8e6, "T", 773.15, "Water") # enthalpy at 8 MPa, 500 °C: 3399.5 kJ/kg (in J/kg)
PropsSI("H", "P", 10e3, "Q", 0, "Water") # saturated liquid at 10 kPa: 191.8 kJ/kg
PropsSI("Q", "P", 10e3, "S", 6724, "Water") # quality (dryness) after an isentropic expansion: 0.810
The values agree with the steam tables in your thermodynamics book, and you can get them without interpolating.
Step 3: the four states
Follow the water around the ideal Rankine cycle. The pump raises the liquid to boiler pressure, and the boiler heats it to superheated steam. The steam then expands through the turbine before the condenser turns it back into liquid. The cycle itself takes a dozen lines in rankine.py. The excerpt below uses F = "Water", p_boiler, T_in and p_cond, all set at the top of the full script.
h1 = PropsSI("H", "P", p_cond, "Q", 0, F) # 1: saturated liquid out of the condenser
v1 = 1 / PropsSI("D", "P", p_cond, "Q", 0, F) # its specific volume, for the pump
w_pump = v1 * (p_boiler - p_cond); h2 = h1 + w_pump # 2: after the pump (w = v Δp)
h3 = PropsSI("H", "P", p_boiler, "T", T_in, F) # 3: superheated steam out of the boiler
s3 = PropsSI("S", "P", p_boiler, "T", T_in, F)
h4 = PropsSI("H", "P", p_cond, "S", s3, F) # 4: after an isentropic turbine
x4 = PropsSI("Q", "P", p_cond, "S", s3, F) # how dry the steam is at the turbine exit
eta = ((h3 - h4) - w_pump) / (h3 - h2)
Step 4: the numbers
Download the script to your home folder, then run it to see the results.
cd ~ && curl -sO https://awanbox.com/blog/files/rankine-cycle/rankine.py
~/thermo/bin/python rankine.py
Here is what the script prints for a boiler at 8 MPa and 500 °C and a condenser at 10 kPa.
Boiler 8 MPa, 500 °C; condenser 10 kPa
h1 = 191.8 kJ/kg
h2 = 199.9 kJ/kg
h3 = 3399.5 kJ/kg
h4 = 2130.2 kJ/kg
turbine work 1269.3 kJ/kg, pump work 8.1 kJ/kg, heat in 3199.6 kJ/kg
thermal efficiency 39.4 %, back work ratio 0.64 %, turbine exit quality 0.810
Carnot between the same temperatures: 58.7 %
First compare the pump work with the turbine work. The pump uses less than 1% of the turbine’s work because pumping a liquid takes so little work. That is the Rankine cycle’s big advantage. Now look at the turbine exit quality. The steam leaves only 81% dry, and the rest is water droplets.
Step 5: change the boiler pressure
As you raise the boiler pressure, the cycle takes in heat at a higher average temperature, so its efficiency rises. Now follow the expansion line on the T–s diagram. It moves left and ends deeper inside the dome, so the steam leaves the turbine wetter.
Boiler pressure sweep (500 °C in, 10 kPa out):
2 MPa efficiency 33.9 % exit quality 0.905
4 MPa efficiency 36.8 % exit quality 0.859 too wet (< 0.88)
6 MPa efficiency 38.4 % exit quality 0.831 too wet (< 0.88)
8 MPa efficiency 39.4 % exit quality 0.810 too wet (< 0.88)
10 MPa efficiency 40.2 % exit quality 0.793 too wet (< 0.88)
12 MPa efficiency 40.8 % exit quality 0.779 too wet (< 0.88)
15 MPa efficiency 41.4 % exit quality 0.760 too wet (< 0.88)
When the steam falls below about 88 to 90% dryness, the water droplets erode the last turbine blades. A designer therefore wants to gain the efficiency of high boiler pressure while keeping the steam dry enough at the exit.
Step 6: the fix, reheat
With reheat, the steam first expands only as far as 2 MPa. It then returns to the boiler, where it heats back up to 500 °C before expanding the rest of the way.
With reheat at 2 MPa back to 500 °C: efficiency 41.0 % (was 39.4 %), exit quality 0.905 (was 0.810)
Compare both results with the original cycle. Efficiency rises by 1.6 points, and the steam at the turbine exit is dry enough again. That is why large steam plants reheat their steam, some of them twice.
The result
The script saves rankine.png in the same folder as the script. Open the chart from the computer’s Files tab. For your own assignment, you can change the boiler pressure and temperature, the condenser pressure and the reheat pressure at the top of the script. Use isentropic efficiencies to model a real turbine and pump. The real turbine produces less work than the ideal one, so use h4 = h3 − η_t (h3 − h4s). The real pump needs more work, so use w_pump = v Δp / η_p.
Common questions
Is CoolProp accurate enough for coursework?
Yes. By default, CoolProp uses the IAPWS-95 formulation for water, which is the basis for modern steam tables. Its values usually agree with your textbook's tables to the last digit they print. If your tables use an older formulation, that last digit can differ slightly.
Why is the Carnot efficiency so much higher?
The Carnot cycle takes in all its heat at the top temperature. In a Rankine cycle, the water starts heating at about 46 °C and warms from there. Its average temperature during heat addition is therefore much lower, which accounts for the lower efficiency.
Can I use it for refrigerants like R134a?
Yes. To get the properties of another fluid, use the same PropsSI calls and replace "Water" with "R134a", "R410A", "Ammonia", "CO2" or one of more than a hundred others. In a refrigeration cycle, you write the four states in the same way as for the Rankine cycle, using the evaporator exit, compressor, condenser exit and throttle valve.
Do I need to install anything on my laptop?
No. Everything runs on the awx computer through your browser. If you want a copy of the chart or script on your laptop, you can download it from the computer’s Files tab.
Keep reading
- How to find natural frequency from vibration data in Python
- How to run an OpenFOAM simulation overnight, laptop closed
- How to learn Python and Linux with a tutor beside you
Getting started
Sign in with your Google account and ask to join. Once your request is approved, you can create a Small computer and work through the steps above.
Awi, signing off.