Rankine Notes

Dec 13Dec 14 Dec 15 Dec 16 Dec 17
Dec 20Dec 21 Dec 22Dec 23 Dec 24
...... .........
Jan 3Jan 4 Jan 5Jan 6 Jan 7
Jan 10Jan 11 Jan 12Jan 13 Jan 14
Jan 17Jan 18 Jan 19Jan 20 Jan 21
Jan 24Jan 25 Jan 26Jan 27 Jan 28
Jan 31Feb 1 Feb 2Feb 3 Feb 4
     

Mon Dec 13work in progress

Initial Information - Rankine (the source is in /usr/src/local/teach/rankine/) is written in fortran and uses a grasp-based GUI. It is vulnerable to OS-upgrades. The old version's beginning to go wrong even if we regress OS library upgrades.
Parameter limits -
  • The boiler pressure MUST be more than the condenser pressure!
  • Steam Turbines only work with Steam - Try boiling the water!
  • The condenser pressure MUST be less than the boiler pressure!
  • Negative pressures are a bit difficult!
  • The reheater pressure MUST be less than the boiler pressure!
  • The reheater pressure MUST be more than the condenser pressure!
  • The feed heater pressure must be below the critical pressure.
  • The feed heater pressure MUST be less than the boiler pressure!
  • The feed heater pressure MUST be more than the condenser pressure!
  • The boiler temperature and pressure may be varied between 0 and 800 degrees Celsius and 0 and 100 MP
  • The condenser pressure or temperature may be varied but since the program assumes that the fluid leaving the condenser will be saturated these are not independent.
  • The efficiencies of the turbines may be changed to investigate the consequences of irreversibilities in real cycles. The efficiency of the pumps cannot be changed since it has negligible effect on the overall cycle efficiency.
Work Done
  • ~tpl/matlab/rankine.m has taken about 9 hours. No maths, but diagrams/interface drawn. Scrollbars for input?

Thu Dec 16

steamlib.f is about 2000 lines of fortran. It's commented well. Some of the conversion can be semi-automated
  • Dealing with continuation lines
  • Dealing with comments
  • Replacing .GT., .OR., etc
  • Removing THEN. Replacing END IF by END
  • Dealing with single-line IF statements
  • Putting commands into lower case
  • Removing variable declarations
  • Removing DOUBLE PRECISION in function definitions
  • Changing function return syntax
  • Dealing with call by reference
  • Replacing GOTO
  • Using switch instead of multiple IFs
  • Replacing **
  • Replacing else if by elseif
  • Adding semicolons

Mon Dec 20

More than one routine in steamlib.f needs to be 'public', and the call tree isn't simple, so I've exploded the file, creating a steamlib sub-directory. 2 hours work. Calls still need to be changed to call by reference. Note: there are doubts in the original program when there are very low pressures that fall outside the normal steam table range.

Tue Dec 21

I've being trying some of the steamlib routines with random args - some "Divide by zero" errors but it's legal code. I'll try the other routines later once I know what the arg values should be, but first I'll convert the rankine.f code - this sits between steamlib and the interface. The non-graphic part is about 1000 lines long. I'll put the code into a rankinelib folder. 2 hours work.

Tue Jan 4

2 hour's conversion work done. I'm trying to make rkcalc work from the matlab prompt.

Wed Jan 5

The mission today is to find out how to set up the original program's default situation: One turbine and one pump. T=500, P=150, Condenser temperature 30. The simulator should then produce this output:
PointPressureTEnthalpyEntropyDryFlow
1.04230 125.7 0.436501
2150 30.3140.7 0.436501
7150 500 3310.66.348711
8.04230 1917.96.34870.73741
Rankine Efficiency=43.46. Turbine 1 work=1392.7. Pump 1 work=15. Boiler heat=3169.9

Globals

  • Y(14) IS MASS THROUGH GIVEN POINT PER KG THROUGH POINT 7 - i.e. flow?
  • P(14) is pressure
  • T(14) is temperature (in K)
  • V(14)
  • H(14) Enthalpy (I assume)
  • S(14) - entropy?
  • X(14) is dryness
  • TXT(14) IS THE NAME OF EACH POINT ON THE CYCLE
  • NIS(3) - TURBINE ISENTROPIC EFFICIENCY (0-1)
  • TWORK(3) - turbine work
  • PWORK(3) - pump work
  • EFFY - CYCLE EFFICIENCY
  • EFFZ - ORIGINAL EFFICIENCY
  • FDHEAT - number feeder heaters (one less than the number of pumps)
  • TSAT
  • QB - Boiler heat
  • QC - Condenser heat
Initialise as in the original using
T(1)=303.15;
T(7)=773.15;
P(7)=1.5D7;
P(2:6)=P(7);
P(1)=psat(T(1));
P(8)=P(1);
3 hours later (having fixed typos, call-by-ref issues, etc ...) I got this in the first error-free run
X=     0      0      0      0      0      0      1 0 0 0 0 0 0 0
S= 436.5  436.5  436.5  436.5  436.5  436.5 6348.7 0 0 0 0 0 0 0
T=303.15 303.49 303.49 303.49 303.49 303.49 773.15 0 0 0 0 0 0 0
P=0.0004 1.5000 1.5000 1.5000 1.5000 1.5000 1.5000 0.0004 0.0004 0.0004 0.0004 0.0004 0 0
EFFY =0.4346
TWORK(1)=1.3927e+06
PWORK(1)=1.5012e+04

If S is Entropy it might almost be right. I'm shocked. Things to do
  • Fix the bugs (the values in the 8th position are wrong)
  • Test other configurations from the command line (easy?)
  • Display output values in the GUI (done for the state-points)
  • Allow input via the GUI (awkward dealing with invalid input?)
  • Make the graph work

Thu Jan 6

Another 2 hours. rkinit currently calls rkcalc which in turn calls the display routines.
  • A graph is displayed, but only portions of it are correct.
  • Most output values (including the correct rankine efficiency) are now displayed
  • There's a problem in betak; it's sometimes called with THETA = 1 which causes a "divide by zero" condition.
I've added the rkchrh code to the turbine table callback, so that reheat stages can be added (maybe removed too). I've assumed that turbine 2's always added before turbine 3, and that turbine 3's removed before turbine 2.

I've archived the current version into ~/matlab/rankine1.

One reheater

With a reheater added (pressure 74.9, temperate 500C), the original program generates
PointPressureTEnthalpyEntropyDryFlow
1.04230 125.7 0.436501
2150 30.3140.7 0.436501
7150 500 3310.66.348711
874.9384.9 3109.96.348711
974.9500 3404.86.762311
10.04230 2043.46.76250.7891
Rankine Efficiency=44.65. Turbine 1 work=200.7. Turbine 2 work=1361.4. Pump 1 work=15. Boiler heat=3169.9. Reheater 1 heat = 294.9. Heat dissipated in condenser = 1917.7.

The first run for one reheater produced

PointPressureTEnthalpyEntropyDryFlow
1.042430 125.7 0.436501
2150 30.34140.7 0.436501
7150 500 3310.66.348711
874.97-273.15 3110.2001
974.97500 3404.76.761811
10.042-273.15 2043.2001
Rankine Efficiency=44.65. Turbine 1 work=200.4. Turbine 2 work=1361.49.

Two reheaters

With 2 reheater added (pressure 74.9, temperate 500C), the original program generates
PointPressureTEnthalpyEntropyDryFlow
1.04230 125.7 0.436501
2150 30.3140.7 0.436501
7150 500 3310.66.348711
874.9384.9 3109.96.348711
974.9500 3404.86.762511
1074.9500 3404.86.762511
1174.9500 3404.86.762511
12.04230 2043.46.76250.7891
Rankine Efficiency=44.65. Turbine 1 work=200.7. Turbine 2 work=XXXX. Turbine 3 work=1361.4. Reheater 1 heat = 294.9. Reheater 2 heat = 294.9.

The first run for 2 reheaters produced

PointPressureTEnthalpyEntropyDryFlow
1.042430 125.39 0.436501
2150 30.34140.4 0.436501
7150 500 3310.66.348711
874.97-273.15 3310.2001
974.975003404.7011
1074.97-273.15 3404.7001
1174.97500 3404.76.76011
12.042-273.15 2043.2001
Rankine Efficiency=44.65. Turbine 1 work=200.4. Turbine 2 work=0.00001 Turbine 3 work=1361.5.

(which took 3 more hours)

Next do a similar thing for pumps. Alas, it gets stuck in a while loop in rkcalc when feed pumps added. Also I need to remove unwanted output-table items when the table's redrawn.

Fri Jan 7

About 23 hours work so far. It looks like this
screendump
Numerical discrepancies are of 2 types
  • Errors of the order of 0.01% - Matlab works in double precision. I don't know whether all the Fortran does
  • Errors where values are wrongly 0 - How can so much be right if the Temperatures are sometimes so wrong? Maybe T is reset to 0 late in the calculations. Errors so far are at points 8, 10 and 12 - probably not a coincidence.
  • Resetting Errors? - adding then removing 2 turbines doesn't return the system to the initial conditions - rankine efficiency becomes 5.85%
Things done
  • Turbine efficiency, and boiler/condenser conditions can now be changed in the GUI (but it took an hour - callback ignorance). Previous efficiency shown.
  • Unwanted output-table items removed (sub-optimally) when the table's redrawn.
  • I'd only partly converted valph, valph3, valph4
  • I'd converted a fortran 'CONTINUE' loop wrongly in rkcalc. I can now add feed heaters.
With one feed heater, the original program gave
PointPressureTEnthalpyEntropyDryFlow
1.042430 125.7 0.436500.611
275 30.169133.179 0.436500.611
375 290.496 1292.6933.16601
4150293.457 1302.8963.16601
71505003310.5976.34911
80.04230 1917.9436.34870.73740.611
1375385.1 3110.36.34871.389
Rankine Efficiency=45.5.

The new program gives

PointPressureTEnthalpyEntropyDryFlow
1.042430 125.7 0.436500.525
275 30.169133.179 0.436500.525
375 290.496 1292.6933.16601
4150293.457 1302.8963.16601
71505003310.5976.34911
80.042-273.151917.943000.525
1375290.496 2572.1135.4350.8680.475
Rankine Efficiency=53.17.

Four hours work today.

Tue Jan 11

I've fixed some of the known bugs. Remaining work to do includes
  • Correcting the calculations - no improvement recently.
  • Correcting the graph - haven't looked at this recently, given that the graph depends on the calculations
  • Correcting the addition/removal of pumps and turbines so that they don't have to be added/removed in sequence
  • Tidying up the layout (easy!)
  • Checking the validity of user-input (easy!)
  • Improving the redraws so that existing objects aren't removed/created, only changed and moved.
1 hour of work today. Total of 28 hours.

Wed Jan 12

Spent 2 hours on the graph, adding more code. Matlab (unlike Grasp) has no concept of a 'current point' so I've changed the code a little. Some of the lines on the graph are believable but problems remain with values that are wrongly 0. Two thoughts -
  • In the original RKPLOT there's
          DO 10 I=1,21
            ...
            TEMP=(647.3D0-273.15D0)/20.*(I-1)+273.15D0
    
    In fortran or matlab is there ever a risk of the multiplication being done before the division, hence leading to division by 0?
  • Though the original program doesn't compile any more, the numerical part does (with pkc's help). It's in ~tpl/SRC/rankine. I'm now going to compare intermediate values in the old and new programs. valpt gives the same results in both programs.
I've made kelvin_zero a global. Sometimes -273.15 is used in the fortran, sometimes -273.16 is! I've used -273.15.

Thu Jan 13

Main calculation bug sorted out.
  • 1 turbine with 1, 2 or 3 pumps work ok - all values match those from the original program.
  • I've added feedheater/reheater information to the screen, with callbacks so that the information can be changed.
  • I've re-organised the screen so that there's no overlapping
The graph's just as wrong as before (maybe just a couple of points are wrongly given 0 coords).

Total now 34 hours.

Thu Jan 14

Problems
  • I've been trying to get the graph right. The old and new programs both produce the same numerical answers in the graphs section, but produce difference graphics when there are coords with value -1.
  • psat and betak are both suspect in their handling of singularities
As a break I'll check the validity of user-input.
PropertyStored asDisplayed asLimitsDone
Efficiency0-10-1000-100Yes
TemperatureKC0-800Crkint
Boiler TemperatureKCPressure must be okYes
Condenser TemperatureKCPressure must be okYes
Feedheater Temperature
Reheater TemperatureDone
PressureNewtons per Square Metre (or Pascals)bars0.0 - 1e8 Pa rkinp
Boiler PressureNewtons per Square Metre (or Pascals)barstemperature and Condenser pressure must be ok. done
Condenser PressureNewtons per Square Metre (or Pascals)barstemperature and Condenser pressure must be ok. done
Feedheater Pressurebelow the critical pressure, less than boiler, more than condenserdone
Reheater Pressuremore that condenserdone
Total now 40 hours.

Mon Jan 17

Remaining Work
  • Checking that things are reset when reheaters/feedheaters removed
  • Dealing with possibility that Turbine 2 might be removed before Turbine 3, etc
  • The Graph's wrong. I'll worry about that today again...
  • Tidying up the Info window. Adding the original copyrights to the steamlib files.
  • Testing...
In the fortran code the "saturation line" (Red) is drawn as follows
  • For I=1,21 and drynes=0, TEMP=(647.3-273.15)/20.*(I-1)+273.15. Then PRESS=PSAT(TEMP) is calculated and VALPT called. The resulting (ENTROP, TEMP) values are used as line coordinates - 20 lines
  • The same is done for drynes=1 - 20 lines
  • Then with PRESS=1000, TEMP=TSAT(PRESS) and drynes=0, VALPT called. It's called again with the same values except that drynes=1. A line is drawn between the (ENTROP, TEMP) values returned.
Results from the fortran version are
I T PRESS ENTRP, drynes=0
1 273.1499938964844 610.8003577211135 -0.15449010656674
2 291.8574829101562 2155.94993201653 277.8157054417007
3 310.5650024414062 6417.192022476914 537.4847362244958
4 329.2724914550781 16607.30634622461 782.0053996242245
5 347.97998046875 38275.51547517449 1013.396326509618
6 366.6875 80074.77326086957 1233.301707560369
7 385.3949890136719 154414.6874515113 1443.196062736537
8 404.1024780273438 277920.7351780301 1644.419960924145
9 422.8099975585938 471673.140416795 1838.178330645096
10 441.5175170898438 761250.1910413107 2025.554587796701
11 460.2250061035156 1176635.641651147 2207.550641502597
12 478.9324951171875 1752059.545784051 2385.143500541253
13 497.6400146484375 2525829.832965319 2559.347264555384
14 516.3475341796875 3540204.303777279 2731.280771722549
15 535.0549926757812 4841372.815457007 2902.259190491513
16 553.7625122070312 6479719.375600124 3073.955736086386
17 572.469970703125 8510694.442966441 3248.716287460297
18 591.177490234375 10997377.14876794 3430.239193303234
19 609.885009765625 14016562.28530682 3625.275465137544
20 628.592529296875 17672071.05957778 3855.081255803374
21 647.300048828125 -1.0 0.0
I T PRESS ENTRP, drynes=1
1 273.1499938964844 610.8003577211135 9157.728719408567
2 291.8574829101562 2155.94993201653 8697.428561514449
3 310.5650024414062 6417.192022476914 8307.431997217245
4 329.2724914550781 16607.30634622461 7973.921174999745
5 347.97998046875 38275.51547517449 7685.970272575441
6 366.6875 80074.77326086957 7434.871196649116
7 385.3949890136719 154414.6874515113 7213.625716889211
8 404.1024780273438 277920.7351780301 7016.531835410638
9 422.8099975585938 471673.140416795 6838.85345218616
10 441.5175170898438 761250.1910413107 6676.574865115113
11 460.2250061035156 1176635.641651147 6526.240845514364
12 478.9324951171875 1752059.545784051 6384.849552110396
13 497.6400146484375 2525829.832965319 6249.721629409879
14 516.3475341796875 3540204.303777279 6118.262813326486
15 535.0549926757812 4841372.815457007 5987.601148787282
16 553.7625122070312 6479719.375600124 5854.168602866126
17 572.469970703125 8510694.442966441 5713.436059922235
18 591.177490234375 10997377.14876794 5559.689537516721
19 609.885009765625 14016562.28530682 5379.244920759154
20 628.592529296875 17672071.05957778 5137.222870250577
21 647.300048828125 -1.0 0.0
(3.77356696128845 0.0) (3.77356696128845 0.0)

The corresponding values in the new programs are
I T PRESS ENTRP, drynes=0
1 2.731500e+02 6.108006e+02 -1.543959e-01
2 2.918575e+02 2.155952e+03 2.778160e+02
3 3.105650e+02 6.417191e+03 5.374847e+02
4 3.292725e+02 1.660731e+04 7.820055e+02
5 3.479800e+02 3.827555e+04 1.013397e+03
6 3.666875e+02 8.007477e+04 1.233302e+03
7 3.853950e+02 1.544147e+05 1.443196e+03
8 4.041025e+02 2.779209e+05 1.644420e+03
9 4.228100e+02 4.716732e+05 1.838178e+03
10 4.415175e+02 7.612499e+05 2.025554e+03
11 4.602250e+02 1.176635e+06 2.207551e+03
12 4.789325e+02 1.752060e+06 2.385144e+03
13 4.976400e+02 2.525829e+06 2.559347e+03
14 5.163475e+02 3.540202e+06 2.731280e+03
15 5.350550e+02 4.841373e+06 2.902259e+03
16 5.537625e+02 6.479718e+06 3.073956e+03
17 5.724700e+02 8.510698e+06 3.248717e+03
18 5.911775e+02 1.099738e+07 3.430239e+03
19 6.098850e+02 1.401656e+07 3.625275e+03
20 6.285925e+02 1.767206e+07 3.625275e+03
21 6.473000e+02 22120000 0
I T PRESS ENTRP, drynes=1
1 2.731500e+02 6.108006e+02 9.157729e+03
2 2.918575e+02 2.155952e+03 8.697428e+03
3 3.105650e+02 6.417191e+03 8.307432e+03
4 3.292725e+02 1.660731e+04 7.973921e+03
5 3.479800e+02 3.827555e+04 7.685970e+03
6 3.666875e+02 8.007477e+04 7.434871e+03
7 3.853950e+02 1.544147e+05 7.213626e+03
8 4.041025e+02 2.779209e+05 7.016532e+03
9 4.228100e+02 4.716732e+05 6.838853e+03
10 4.415175e+02 7.612499e+05 6.676575e+03
11 4.602250e+02 1.176635e+06 6.526241e+03
12 4.789325e+02 1.752060e+06 6.384850e+03
13 4.976400e+02 2.525829e+06 6.249722e+03
14 5.163475e+02 3.540202e+06 6.118263e+03
15 5.350550e+02 4.841373e+06 5.987601e+03
16 5.537625e+02 6.479718e+06 5.854169e+03
17 5.724700e+02 8.510698e+06 5.713436e+03
18 5.911775e+02 1.099738e+07 5.559689e+03
19 6.098850e+02 1.401656e+07 5.379245e+03
20 6.285925e+02 1.767206e+07 5.379245e+03
21 6.473000e+02 22120000 0
(1.060405e+02 2.801327e+02) (8.976668e+03 2.801327e+02)

Problems are reported for the i=21 values - "problem in betak, Divide by zero. Theta=1"

2 issues

  • Note that the final TEMP value in the fortran is 647.300048828125 whereas the matlab equivalent produces exactly 647.3. The fortran PSAT routine begins with
          IF (TEMP.LE.647.3D0)
    
    So the fortran and matlab loop arithmetic produce different values for TEMP and hence for PRESSURE, but matlab's PRESSURE value seems viable. Besides, the ENTROP value is being used for plotting and that's the same in both versions. So why isn't the 0 ENTROP value causing trouble when used as an x coord in the fortran?
  • The ENTROP value for I=19 and I=20 are the same in the matlab version, but not the fortran version.
4 more hours.

Tue Jan 18

I've found why some lines on the graph had coords erroneously set to 0. It's because in one routine I'd erroneously set TEMP to 0. Sad. This removes the divide-by-0 errors I've been getting. Just one bogus point on the graph remains.

Found the bug - a missing "e-8". It's time to install. 3 hours today. 47 hours to produce this first release. 6034 lines of Fortran.

Thu Jan 27

Several typos fixed. A "recalculate" button added. Colours and layout adjusted. Took 2 hours. Re-installed.

Wed Feb 2

More bugs fixed. A bug in the fortran code too
         IF (RHT.EQ.1) THEN
            IF (REHEAT.EQ.0) THEN
              P(8)=P(1)
              P(9)=P(1)
            ELSE
              P(8)=P(10)
              P(9)=P(11)
              T(9)=T(11)
              P(10)=P(1)
              P(11)=P(1)
            END IF
         ELSE IF (RHT.EQ.1) THEN
            P(10)=P(1)
            P(11)=P(1)
         END IF
Surely the 2 "IF( RHT..." conditions shouldn't be the same. 1 hour. Re-installed. The new version has date-of-installation on the title window frame and can be started from the unix command line by typing "newrankine".
Updated February 2005
Tim Love