@@ -54,38 +54,38 @@ static void mdlInitializeSizes(SimStruct *S)
54
54
/* Return if number of expected != number of actual parameters */
55
55
return ;
56
56
}
57
-
57
+
58
58
for (i = 0 ; i < NPARAMS ; i ++ )
59
59
ssSetSFcnParamTunable (S , i , 0 );
60
-
60
+
61
61
ssSetNumContStates (S , 0 );
62
62
ssSetNumDiscStates (S , 0 );
63
-
63
+
64
64
if (!ssSetNumInputPorts (S , 3 )) return ;
65
65
ssSetInputPortWidth (S , 0 , 7 );
66
66
ssSetInputPortRequiredContiguous (S , 0 , true);
67
67
ssSetInputPortDirectFeedThrough (S , 0 , 1 );
68
-
68
+
69
69
ssSetInputPortWidth (S , 1 , DYNAMICALLY_SIZED );
70
70
ssSetInputPortRequiredContiguous (S , 1 , true);
71
71
ssSetInputPortDirectFeedThrough (S , 1 , 1 );
72
-
72
+
73
73
ssSetInputPortWidth (S , 2 , DYNAMICALLY_SIZED );
74
74
ssSetInputPortRequiredContiguous (S , 2 , true);
75
75
ssSetInputPortDirectFeedThrough (S , 2 , 1 );
76
-
76
+
77
77
if (!ssSetNumOutputPorts (S , 3 )) return ;
78
78
ssSetOutputPortWidth (S , 0 , 13 );
79
79
ssSetOutputPortWidth (S , 1 , DYNAMICALLY_SIZED );
80
80
ssSetOutputPortWidth (S , 2 , DYNAMICALLY_SIZED );
81
-
81
+
82
82
ssSetNumSampleTimes (S , 1 );
83
83
ssSetNumRWork (S , 0 );
84
84
ssSetNumIWork (S , 6 );
85
85
ssSetNumPWork (S , 0 );
86
86
ssSetNumModes (S , 0 );
87
87
ssSetNumNonsampledZCs (S , 0 );
88
-
88
+
89
89
ssSetOptions (S ,
90
90
SS_OPTION_WORKS_WITH_CODE_REUSE |
91
91
SS_OPTION_EXCEPTION_FREE_CODE |
@@ -145,58 +145,58 @@ static void mdlOutputs(SimStruct *S, int_T tid)
145
145
const real_T IDes = * mxGetPr (IDesign_p (S ));
146
146
const real_T CustBldEn = * mxGetPr (CustBldEn_p (S ));
147
147
const real_T FBldEn = * mxGetPr (FBldEn_p (S ));
148
-
148
+
149
149
/* vector & array data */
150
150
const real_T * Y_C_NcVec = mxGetPr (Y_C_NcVec_p (S ));
151
151
const real_T * X_C_RlineVec = mxGetPr (X_C_RlineVec_p (S ));
152
152
const real_T * T_C_Map_WcArray = mxGetPr (T_C_Map_WcArray_p (S ));
153
153
const real_T * T_C_Map_PRArray = mxGetPr (T_C_Map_PRArray_p (S ));
154
154
const real_T * T_C_Map_EffArray = mxGetPr (T_C_Map_EffArray_p (S ));
155
-
155
+
156
156
const real_T * FracCusBldht = mxGetPr (FracCusBldht_p (S ));
157
157
const real_T * FracCusBldPt = mxGetPr (FracCusBldPt_p (S ));
158
158
const real_T * FracBldht = mxGetPr (FracBldht_p (S ));
159
159
const real_T * FracBldPt = mxGetPr (FracBldPt_p (S ));
160
-
160
+
161
161
const real_T * X_C_WcSurgeVec = mxGetPr (X_C_WcSurgeVec_p (S ));
162
162
const real_T * T_C_PRSurgeVec = mxGetPr (T_C_PRSurgeVec_p (S ));
163
-
163
+
164
164
/*------get dimensions of parameter arrays-------*/
165
165
const int_T A = mxGetNumberOfElements (Y_C_NcVec_p (S ));
166
166
const int_T B = mxGetNumberOfElements (X_C_RlineVec_p (S ));
167
167
const int_T C = mxGetNumberOfElements (X_C_WcSurgeVec_p (S ));
168
-
168
+
169
169
/*---------Define Inputs for input port 1--------*/
170
170
const real_T * u = (const real_T * ) ssGetInputPortSignal (S ,0 );
171
-
171
+
172
172
double WIn = u [0 ]; /* Input Flow [pps] */
173
173
double htIn = u [1 ]; /* Input Enthalpy [BTU/lbm] */
174
174
double TtIn = u [2 ]; /* Temperature Input [degR] */
175
175
double PtIn = u [3 ]; /* Pressure Input [psia] */
176
176
double FARcIn = u [4 ]; /* Combusted Fuel to Air Ratio [frac] */
177
177
double Nmech = u [5 ]; /* Mechancial Shaft Speed [rpm] */
178
178
double Rline = u [6 ]; /* Rline [NA] */
179
-
179
+
180
180
/*---------Define Inputs for input port 2--------*/
181
181
const real_T * Wcust = ssGetInputPortRealSignal (S , 1 );
182
182
int uWidth1 = ssGetCurrentInputPortDimensions (S , 1 , 0 );
183
-
183
+
184
184
/*---------Define Inputs for input port 3--------*/
185
185
const real_T * FracWbld = ssGetInputPortSignal (S ,2 );
186
186
int uWidth2 = ssGetCurrentInputPortDimensions (S , 2 , 0 );
187
-
187
+
188
188
real_T * y = (real_T * )ssGetOutputPortRealSignal (S ,0 ); /* Output Array port 1 */
189
189
real_T * y1 = (real_T * )ssGetOutputPortRealSignal (S ,1 ); /* Output Array port 2 */
190
190
real_T * y2 = (real_T * )ssGetOutputPortRealSignal (S ,2 ); /* Output Array port 3 */
191
-
191
+
192
192
/*--------Define Constants-------*/
193
193
double WOut , htOut , TtOut , PtOut , FARcOut , TorqueOut , NErrorOut ;
194
194
double C_Nc , C_Wc , C_PR , C_Eff ;
195
195
double htin , Sin , Wcin , WcCalcin , WcMap , theta ,delta , Pwrout , Wbleeds , Wsumbleed ;
196
196
double TtIdealout , htIdealout , Test , Sout , NcMap , Nc , PRMap , PR , EffMap , Eff ;
197
197
double Wb4bleed , Pwrb4bleed , PwrBld ;
198
198
double SPR , SMavail ;
199
-
199
+
200
200
/* Define Arrays for bleed calcs */
201
201
int MaxNumberBleeds = 100 ;
202
202
double WcustOut [500 ];
@@ -209,116 +209,116 @@ static void mdlOutputs(SimStruct *S, int_T tid)
209
209
double TtbldOut [500 ];
210
210
double htbldOut [500 ];
211
211
double htcustOut [500 ];
212
-
212
+
213
213
int interpErr = 0 ;
214
214
int i ;
215
-
215
+
216
216
/* ------- get strings -------------- */
217
217
char * BlkNm ;
218
218
int_T buflen ;
219
219
int_T status ;
220
-
220
+
221
221
/* Get name of block from dialog parameter (string) */
222
222
buflen = mxGetN (BN_p (S ))* sizeof (mxChar )+ 1 ;
223
223
BlkNm = mxMalloc (buflen );
224
224
status = mxGetString (BN_p (S ), BlkNm , buflen );
225
-
225
+
226
226
/*-- Compute output Fuel to Air Ratio ---*/
227
227
FARcOut = FARcIn ;
228
-
228
+
229
229
/*-- Compute Input enthalpy --------*/
230
-
230
+
231
231
htin = t2hc (TtIn ,FARcIn );
232
-
232
+
233
233
/*-- Compute Input entropy --------*/
234
-
234
+
235
235
Sin = pt2sc (PtIn ,TtIn ,FARcIn );
236
-
236
+
237
237
/*---- calculate misc. fluid condition related variables and corrected Flow --*/
238
238
delta = PtIn / C_PSTD ;
239
239
theta = TtIn / C_TSTD ;
240
240
Wcin = WIn * sqrt (theta )/delta ;
241
-
241
+
242
242
/*------ Calculate corrected speed ---------*/
243
243
Nc = Nmech /sqrt (theta );
244
244
if (IDes > 0.5 )
245
245
C_Nc = Nc / NcDes ;
246
246
else
247
247
C_Nc = s_C_Nc ;
248
-
249
- NcMap = Nc / s_C_Nc ;
248
+
249
+ NcMap = Nc / C_Nc ;
250
250
251
251
/*-- Compute Total Flow input (from Compressor map) --------*/
252
-
252
+
253
253
WcMap = interp2Ac (X_C_RlineVec ,Y_C_NcVec ,T_C_Map_WcArray ,Rline ,NcMap ,B ,A ,& interpErr );
254
254
if (interpErr == 1 && ssGetIWork (S )[0 ]== 0 ){
255
255
printf ("Warning in %s, Error calculating WcMap. Vector definitions may need to be expanded.\n" , BlkNm );
256
256
ssSetIWorkValue (S ,0 ,1 );
257
257
}
258
-
258
+
259
259
if (IDes > 0.5 )
260
260
C_Wc = Wcin / WcMap ;
261
261
else
262
262
C_Wc = s_C_Wc ;
263
-
263
+
264
264
WcCalcin = WcMap * C_Wc ;
265
-
265
+
266
266
/*-- Compute Pressure Ratio (from Compressor map) --------*/
267
-
267
+
268
268
PRMap = interp2Ac (X_C_RlineVec ,Y_C_NcVec ,T_C_Map_PRArray ,Rline ,NcMap ,B ,A ,& interpErr );
269
269
if (interpErr == 1 && ssGetIWork (S )[1 ]== 0 ){
270
270
printf ("Warning in %s, Error calculating PRMap. Vector definitions may need to be expanded.\n" , BlkNm );
271
271
ssSetIWorkValue (S ,1 ,1 );
272
272
}
273
-
273
+
274
274
if (IDes > 0.5 )
275
275
C_PR = (PRDes - 1 ) / (PRMap - 1 );
276
276
else
277
277
C_PR = s_C_PR ;
278
-
278
+
279
279
PR = C_PR * (PRMap - 1 ) + 1 ;
280
-
280
+
281
281
/*-- Compute Efficiency (from Compressor map) ---*/
282
-
282
+
283
283
EffMap = interp2Ac (X_C_RlineVec ,Y_C_NcVec ,T_C_Map_EffArray ,Rline ,NcMap ,B ,A ,& interpErr );
284
284
if (interpErr == 1 && ssGetIWork (S )[2 ]== 0 ){
285
285
printf ("Warning in %s, Error calculating EffMap. Vector definitions may need to be expanded.\n" , BlkNm );
286
286
ssSetIWorkValue (S ,2 ,1 );
287
287
}
288
-
288
+
289
289
if (IDes > 0.5 )
290
290
C_Eff = EffDes / EffMap ;
291
291
else
292
292
C_Eff = s_C_Eff ;
293
-
293
+
294
294
Eff = EffMap * C_Eff ;
295
-
295
+
296
296
/*------ Compute pressure output --------*/
297
-
297
+
298
298
PtOut = PtIn * PR ;
299
-
300
-
299
+
300
+
301
301
/*------ enthalpy calculations ---------*/
302
-
302
+
303
303
/* ---- Ideal enthalpy ----*/
304
304
Sout = Sin ;
305
305
TtIdealout = sp2tc (Sout ,PtOut ,FARcIn );
306
306
htIdealout = t2hc (TtIdealout ,FARcIn );
307
-
308
-
307
+
308
+
309
309
/* ---- Final enthalpy output ----*/
310
-
310
+
311
311
htOut = ((htIdealout - htin )/Eff ) + htin ;
312
-
312
+
313
313
/*------ Compute Temperature output ---------*/
314
-
314
+
315
315
TtOut = h2tc (htOut ,FARcIn );
316
-
317
-
316
+
317
+
318
318
/* initalize Bleed sums components */
319
319
Wbleeds = 0 ;
320
320
PwrBld = 0 ;
321
-
321
+
322
322
/* compute customer Bleed components */
323
323
for (i = 0 ; i < uWidth1 ; i ++ )
324
324
{
@@ -345,9 +345,9 @@ static void mdlOutputs(SimStruct *S, int_T tid)
345
345
ssSetIWorkValue (S ,3 ,1 );
346
346
}
347
347
}
348
-
348
+
349
349
/*----Disable Fractional bleed when requested----*/
350
-
350
+
351
351
for (i = 0 ; i < uWidth2 ; i ++ )
352
352
{
353
353
if (FracWbld [i ] <= 0 || FBldEn < 0.5 ){
@@ -357,7 +357,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
357
357
TtbldOut [i ] = 0 ;
358
358
PtbldOut [i ] = 0 ;
359
359
}
360
-
360
+
361
361
else {
362
362
/*-- Compute sum of Fractional Bleed Flow output --------*/
363
363
Wbleeds = Wbleeds + FracWbld [i ]* WIn ; /* add to total bleed value */
@@ -373,19 +373,19 @@ static void mdlOutputs(SimStruct *S, int_T tid)
373
373
ssSetIWorkValue (S ,4 ,1 );
374
374
}
375
375
}
376
-
376
+
377
377
/*-- Compute Flows --------*/
378
378
Wb4bleed = WIn ;
379
379
WOut = WIn - Wbleeds ;
380
-
380
+
381
381
/*------ Compute Powers ---------*/
382
-
382
+
383
383
Pwrb4bleed = Wb4bleed * (htin - htOut ) * C_BTU_PER_SECtoHP ;
384
384
Pwrout = Pwrb4bleed - PwrBld ;
385
-
385
+
386
386
/*----- Compute output Torque to shaft ----*/
387
387
TorqueOut = C_HP_PER_RPMtoFT_LBF * Pwrout /Nmech ;
388
-
388
+
389
389
/* ----- Compute Normalized Flow Error ----- */
390
390
if (IDes > 0.5 && Rline == 0 )
391
391
NErrorOut = 100 ;
@@ -395,18 +395,18 @@ static void mdlOutputs(SimStruct *S, int_T tid)
395
395
NErrorOut = 100 ;
396
396
else
397
397
NErrorOut = (Wcin - WcCalcin )/Wcin ;
398
-
398
+
399
399
/* Compute Stall Margin */
400
400
SPR = interp1Ac (X_C_WcSurgeVec ,T_C_PRSurgeVec ,Wcin ,C ,& interpErr );
401
401
if (interpErr == 1 && ssGetIWork (S )[5 ]== 0 ){
402
402
printf ("Warning in %s, Error calculating SPR. Vector definitions may need to be expanded.\n" , BlkNm );
403
403
ssSetIWorkValue (S ,5 ,1 );
404
404
}
405
405
SMavail = (SPR - PR )/PR * 100 ;
406
-
406
+
407
407
/* Test variable */
408
408
Test = PRMap ;
409
-
409
+
410
410
/*------Assign output values port1------------*/
411
411
y [0 ] = WOut ; /* Outlet Total Flow [pps] */
412
412
y [1 ] = htOut ; /* Output Enthalpy [BTU/lbm] */
@@ -421,7 +421,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
421
421
y [10 ] = C_PR ; /* Pressure Ratio scalar */
422
422
y [11 ] = C_Eff ; /* Efficiency scalar */
423
423
y [12 ] = Test ;
424
-
424
+
425
425
/*------Assign output values port2------------*/
426
426
/* Customer or flow based bleed*/
427
427
for (i = 0 ; i < uWidth1 ; i ++ )
@@ -432,7 +432,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
432
432
* y1 ++ = PtcustOut [i ];
433
433
* y1 ++ = FARcustOut [i ];
434
434
}
435
-
435
+
436
436
/*------Assign output values port3------------*/
437
437
/* fractional bleed, typically used for turbine cooling flow */
438
438
for (i = 0 ; i < uWidth2 ; i ++ )
@@ -443,7 +443,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
443
443
* y2 ++ = PtbldOut [i ];
444
444
* y2 ++ = FARbldOut [i ];
445
445
}
446
-
446
+
447
447
}
448
448
449
449
static void mdlTerminate (SimStruct * S )
0 commit comments