/[ascend]/trunk/models/johnpye/fprops/combinedcycle_fprops.a4c
ViewVC logotype

Contents of /trunk/models/johnpye/fprops/combinedcycle_fprops.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2693 - (show annotations) (download) (as text)
Tue Mar 5 05:23:34 2013 UTC (9 years, 3 months ago) by jpye
File MIME type: text/x-ascend
File size: 9122 byte(s)
Modified test case for bug 564 slightly, now able to access the error via valgrind as well. Valgrind output gives:

solvers/qrslv/qrslv.c:3373 (structural_analysis): In QRSlv, got vused = 219...
==28310== Invalid read of size 8
==28310==    at 0x4EFCF76: CalcResidGivenValue (relation_util.c:4037)
==28310==    by 0x4EFD90C: zbrent (rootfind.c:84)
==28310==    by 0x4EFD235: RootFind (relation_util.c:4120)
==28310==    by 0x4EFAB80: RelationFindRoots (relation_util.c:3210)
==28310==    by 0x4F4C59E: relman_directly_solve_new (relman.c:1039)
==28310==    by 0x4F509D7: slv_direct_solve (slv_common.c:208)
==28310==    by 0x70324C6: qrslv_iterate (qrslv.c:3842)
==28310==    by 0x70336E5: qrslv_solve (qrslv.c:4175)
==28310==    by 0x4F60CB1: slv_solve (solver.c:364)
==28310==    by 0x42F607: test_bug564 (test_qrslv.c:244)
==28310==    by 0x61587A3: run_single_test (TestRun.c:1129)
==28310==    by 0x6156161: CU_run_selected_tests (TestRun.c:473)
==28310==  Address 0x100793d338 is not stack'd, malloc'd or (recently) free'd
==28310== 
==28310== 
==28310== Process terminating with default action of signal 11 (SIGSEGV)
==28310==  Access not within mapped region at address 0x100793D338
==28310==    at 0x4EFCF76: CalcResidGivenValue (relation_util.c:4037)
==28310==    by 0x4EFD90C: zbrent (rootfind.c:84)
==28310==    by 0x4EFD235: RootFind (relation_util.c:4120)
==28310==    by 0x4EFAB80: RelationFindRoots (relation_util.c:3210)
==28310==    by 0x4F4C59E: relman_directly_solve_new (relman.c:1039)
==28310==    by 0x4F509D7: slv_direct_solve (slv_common.c:208)
==28310==    by 0x70324C6: qrslv_iterate (qrslv.c:3842)
==28310==    by 0x70336E5: qrslv_solve (qrslv.c:4175)
==28310==    by 0x4F60CB1: slv_solve (solver.c:364)
==28310==    by 0x42F607: test_bug564 (test_qrslv.c:244)
==28310==    by 0x61587A3: run_single_test (TestRun.c:1129)
==28310==    by 0x6156161: CU_run_selected_tests (TestRun.c:473)
==28310==  If you believe this happened as a result of a stack
==28310==  overflow in your program's main thread (unlikely but
==28310==  possible), you can try to increase the size of the
==28310==  main thread stack using the --main-stacksize= flag.
==28310==  The main thread stack size used in this run was 8388608.
==28310== 

1 (* ASCEND modelling environment
2 Copyright (C) 2010 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *)(*
17 This file contains a model of a combined-cycle power station, with
18 a gas turbine (Brayton) cycle running as the 'topping' cycle and a steam
19 turbine (Rankine) cycle running as the 'bottoming' cycle. Initially the
20 model is being based on Example 9.13 from Moran & Shapiro, 'Fundamentals of
21 Engineering Thermodynamics', 4th Ed, Wiley, 2000.
22
23 See also Example 10-9 from the book Çengel & Boles
24 'Thermodynamcs: An Engineering Approach, 6th Ed, McGraw-Hill, 2008.
25
26 This file was based on models/johnpye/combinedcycle.a4c which originally
27 made use of the external library 'freesteam' for calculation of steam
28 properties in the bottoming cycle. This version has been modified to make
29 use of FPROPS for the property calculations, allowing the model to be
30 adapted for use with various different fluids.
31
32 Author: John Pye
33 *)
34 REQUIRE "johnpye/fprops/rankine_fprops.a4c";
35 REQUIRE "johnpye/brayton.a4c";
36
37 MODEL air_stream_heat_exchanger REFINES air_equipment;
38 inlet_cold, outlet_cold IS_A stream_node;
39 inlet.p, outlet.p ARE_THE_SAME;
40 inlet_cold.p, outlet_cold.p ARE_THE_SAME;
41 inlet_cold.mdot, outlet_cold.mdot ARE_THE_SAME;
42 inlet_cold.cd, outlet_cold.cd ARE_THE_SAME;
43
44 mdot_cold ALIASES inlet_cold.mdot;
45 cd_cold ALIASES inlet_cold.cd;
46
47 (* some very simplistics checks that temperatures are feasible: not totally safe! *)
48 DT_1, DT_2 IS_A delta_temperature;
49 DT_1 = inlet.T - outlet_cold.T;
50 DT_2 = outlet.T - inlet_cold.T;
51
52 (* some intermediate temperatures for plotting *)
53 n IS_A integer_constant;
54 n :== 20;
55 H[0..n] IS_A air_node;
56 H[0..n].p, inlet.p ARE_THE_SAME;
57 H[0..n].mdot, inlet.mdot ARE_THE_SAME;
58 H[0].h, inlet.h ARE_THE_SAME;
59 H[n].h, outlet.h ARE_THE_SAME;
60 FOR i IN [1..n-1] CREATE
61 H[i].h = H[0].h + (H[n].h - H[0].h)/n * i;
62 END FOR;
63
64 Qdot IS_A energy_rate;
65 (* Strange, but the following form solves better than the obvious form,
66 Could maybe be something to do with scaling. *)
67 outlet.h - inlet.h = Qdot/inlet.mdot;
68 outlet_cold.h = inlet_cold.h - Qdot/inlet_cold.mdot;
69 METHODS
70 METHOD default_self;
71 RUN inlet_cold.default_self;
72 RUN outlet_cold.default_self;
73 DT_1.lower_bound := 0 {K};
74 DT_2.lower_bound := 0 {K};
75 END default_self;
76 METHOD heat_exchanger_plot;
77 EXTERNAL air_stream_heat_exchanger_plot(SELF);
78 END heat_exchanger_plot;
79 END air_stream_heat_exchanger;
80
81
82 MODEL air_stream_heat_exchanger_test REFINES air_stream_heat_exchanger;
83 cd_cold.component :== 'water';
84 METHODS
85 METHOD on_load;
86 RUN default_self;
87 FIX inlet_cold.p; inlet_cold.p := 50 {bar};
88 FIX inlet_cold.h; inlet_cold.h := 200 {kJ/kg};
89 FIX inlet.p; inlet.p := 1 {bar};
90 FIX inlet.T; inlet.T := 700 {K};
91 FIX mdot; mdot := 1 {kg/s};
92 FIX mdot_cold; mdot_cold := 0.1 {kg/s};
93 FIX Qdot; Qdot := 10 {kW};
94 END on_load;
95 END air_stream_heat_exchanger_test;
96
97 (* --- whole cycle models --- *)
98
99 MODEL combinedcycle_fprops_common;
100 (* define the blocks *)
101 GC IS_A compressor;
102 BU IS_A combustor;
103 GT IS_A gas_turbine;
104 HE IS_A air_stream_heat_exchanger;
105 DI IS_A dissipator;
106 TU IS_A turbine_simple;
107 CO IS_A condenser_simple;
108 PU IS_A pump_simple;
109
110 (* wire up the model *)
111 GC.outlet, BU.inlet ARE_THE_SAME;
112 BU.outlet, GT.inlet ARE_THE_SAME;
113 GT.outlet, HE.inlet ARE_THE_SAME;
114 HE.outlet, DI.inlet ARE_THE_SAME;
115 DI.outlet, GC.inlet ARE_THE_SAME;
116
117 HE.outlet_cold, TU.inlet ARE_THE_SAME;
118 TU.outlet, CO.inlet ARE_THE_SAME;
119 CO.outlet, PU.inlet ARE_THE_SAME;
120 PU.outlet, HE.inlet_cold ARE_THE_SAME;
121
122 cd_rankine ALIASES TU.inlet.cd;
123
124 Wdot, Wdot_gas, Wdot_vap IS_A energy_rate;
125 Wdot_gas = GC.Wdot + GT.Wdot;
126 Wdot_vap = TU.Wdot + PU.Wdot;
127 Wdot = Wdot_gas + Wdot_vap;
128
129 braytonpowerfraction IS_A fraction;
130 braytonpowerfraction = Wdot_gas / Wdot;
131
132 Qdot_H ALIASES BU.Qdot;
133 Qdot_HE ALIASES HE.Qdot;
134 Qdot_DI ALIASES DI.Qdot;
135
136 eta IS_A fraction;
137 eta = Wdot / Qdot_H;
138
139 massflowratio IS_A factor;
140 massflowratio = TU.mdot / GT.mdot;
141
142 braytonpressureratio IS_A positive_factor;
143 braytonpressureratio * GC.inlet.p = GC.outlet.p;
144
145 METHODS
146 METHOD default_self;
147 RUN TU.default_self;
148 RUN PU.default_self;
149 RUN CO.default_self;
150 RUN HE.default_self;
151 END default_self;
152 METHOD specify;
153 (* these values should be independent of the fluid we choose to use *)
154 FIX GC.eta; GC.eta := 0.84;
155 FIX GT.eta; GT.eta := 0.88;
156 FIX TU.eta; TU.eta := 0.85;
157 FIX PU.eta; PU.eta := 0.8;
158 FIX CO.outlet.x; CO.outlet.x := 1e-6;
159 FIX BU.eta; BU.eta := 1;
160 END specify;
161 METHOD cycle_plot;
162 EXTERNAL cycle_plot_ccgt(SELF);
163 END cycle_plot;
164 END combinedcycle_fprops_common;
165
166
167 MODEL combinedcycle_toluene REFINES combinedcycle_fprops_common;
168 TU.inlet.cd.component :== 'toluene';
169 HE.outlet.T = PU.outlet.T + 40 {K};
170 HE.outlet_cold.T = GT.outlet.T - 20 {K};
171 Tmax_rankine ALIASES HE.outlet_cold.T;
172 METHODS
173 METHOD default_self;
174 RUN combinedcycle_fprops_common::default_self;
175 (* starting guess, for easy solving *)
176 HE.outlet_cold.h := 400 {kJ/kg};
177 CO.outlet.h := 400 {kJ/kg};
178 END default_self;
179 METHOD on_load;
180 RUN ClearAll;
181 RUN default_self;
182 RUN combinedcycle_fprops_common::specify;
183 FIX Wdot; Wdot := 100 {MW};
184
185 (* ambient conditions *)
186 FIX GC.inlet.T, GC.inlet.p;
187 GC.inlet.T := 30 {K} + 273.15 {K};
188 GC.inlet.p := 1 {bar};
189
190 (* Brayton parameters *)
191 FIX braytonpressureratio; braytonpressureratio := 10.9; (* optimise this *)
192 FIX BU.outlet.T; BU.outlet.T := 970 {K} + 273.15 {K};
193
194 (* Rankine cycle condenser *)
195 CO.outlet.p := 8 {kPa};
196 FIX CO.outlet.T; CO.outlet.T := 40 {K} + 273.15 {K};
197 FIX TU.inlet.p; TU.inlet.p := 150 {bar};
198
199 (* optimisable *)
200
201 (* heat exchange cycle *)
202 (* FIX HE.outlet.T; HE.outlet.T := 60 {K} + 273.15 {K};
203 FIX HE.outlet_cold.T; HE.outlet_cold.T := 470 {K} + 273.15 {K};
204 *)
205 SOLVER QRSlv;
206 OPTION convopt 'RELNOM_SCALE';
207 END on_load;
208 END combinedcycle_toluene;
209
210
211 MODEL combinedcycle_water REFINES combinedcycle_fprops_common;
212 TU.inlet.cd.component :== 'water';
213 x_turb_out ALIASES TU.outlet.x;
214 (* the difference values in these formula have to be corrected by looking
215 at the heat exchanger temperature profiles; haven't thoroughly modelled
216 this bit yet! *)
217 HE.outlet.T = PU.outlet.T + 130 {K};
218 HE.outlet_cold.T = GT.outlet.T - 20 {K};
219 METHODS
220 METHOD default_self;
221 RUN combinedcycle_fprops_common::default_self;
222 (* starting guess, for easy solving *)
223 HE.outlet_cold.h := 3000 {kJ/kg};
224 TU.inlet.h := 4000 {kJ/kg};
225 END default_self;
226 METHOD on_load;
227 RUN ClearAll;
228 RUN default_self;
229 RUN combinedcycle_fprops_common::specify;
230 FIX Wdot; Wdot := 100 {MW};
231
232 (* ambient conditions *)
233 FIX GC.inlet.T, GC.inlet.p;
234 GC.inlet.T := 30 {K} + 273.15 {K};
235 GC.inlet.p := 1 {bar};
236
237 (* Brayton parameters *)
238 FIX braytonpressureratio; braytonpressureratio := 7.2; (* optimise this *)
239 FIX BU.outlet.T; BU.outlet.T := 970 {K} + 273.15 {K};
240
241 (* Rankine cycle condenser *)
242 CO.outlet.p := 8 {kPa};
243 FIX CO.outlet.T; CO.outlet.T := 40 {K} + 273.15 {K};
244 FIX TU.inlet.p; TU.inlet.p := 150 {bar};
245
246 SOLVER QRSlv;
247 OPTION convopt 'RELNOM_SCALE';
248 END on_load;
249 METHOD set_x_limit;
250 FREE PU.outlet.p;
251 PU.outlet.p.upper_bound := 150 {bar};
252 FIX TU.outlet.x; TU.outlet.x := 0.9;
253 END set_x_limit;
254
255 END combinedcycle_water;
256
257 MODEL combinedcycle_water_opt REFINES combinedcycle_water;
258 MAXIMIZE eta;
259 METHODS
260 METHOD on_load;
261 RUN combinedcycle_water::on_load;
262 braytonpressureratio.lower_bound := 8;
263 braytonpressureratio.upper_bound := 20;
264 END on_load;
265 END combinedcycle_water_opt;
266
267
268
269 MODEL combinedcycle_ammonia REFINES combinedcycle_fprops_common;
270 TU.inlet.cd.component :== 'ammonia';
271 HE.outlet.T = PU.outlet.T + 15 {K};
272 HE.outlet_cold.T = GT.outlet.T - 12 {K};
273 METHODS
274 METHOD default_self;
275 RUN combinedcycle_fprops_common::default_self;
276 (* starting guess, for easy solving *)
277 HE.outlet_cold.h := 400 {kJ/kg};
278 CO.outlet.h := 400 {kJ/kg};
279 END default_self;
280 METHOD on_load;
281 RUN ClearAll;
282 RUN default_self;
283 RUN combinedcycle_fprops_common::specify;
284 FIX Wdot; Wdot := 100 {MW};
285
286 (* ambient conditions *)
287 FIX GC.inlet.T, GC.inlet.p;
288 GC.inlet.T := 30 {K} + 273.15 {K};
289 GC.inlet.p := 1 {bar};
290
291 (* Brayton parameters *)
292 FIX braytonpressureratio; braytonpressureratio := 11.2; (* optimise this *)
293 FIX BU.outlet.T; BU.outlet.T := 970 {K} + 273.15 {K};
294
295 (* Rankine cycle condenser *)
296 CO.outlet.p := 8 {kPa};
297 FIX CO.outlet.T; CO.outlet.T := 40 {K} + 273.15 {K};
298 FIX TU.inlet.p; TU.inlet.p := 150 {bar};
299
300 SOLVER QRSlv;
301 OPTION convopt 'RELNOM_SCALE';
302 END on_load;
303 END combinedcycle_ammonia;
304
305 (*
306 the combinedcycle_co2 model is removed, because it wasn't viable due to the
307 location of the CO2 critical point.
308 *)

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22