Skip to content

Commit 3d2cfd8

Browse files
committed
iDes Nc scalar correction for v1.0.0
1 parent 01abfe7 commit 3d2cfd8

File tree

2 files changed

+138
-138
lines changed

2 files changed

+138
-138
lines changed

Releases/TMATS_v1_0_0/TMATS_Library/MEX/C_code/Compressor_TMATS.c

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,38 @@ static void mdlInitializeSizes(SimStruct *S)
5454
/* Return if number of expected != number of actual parameters */
5555
return;
5656
}
57-
57+
5858
for (i = 0; i < NPARAMS; i++)
5959
ssSetSFcnParamTunable(S, i, 0);
60-
60+
6161
ssSetNumContStates(S, 0);
6262
ssSetNumDiscStates(S, 0);
63-
63+
6464
if (!ssSetNumInputPorts(S, 3)) return;
6565
ssSetInputPortWidth(S, 0, 7);
6666
ssSetInputPortRequiredContiguous(S, 0, true);
6767
ssSetInputPortDirectFeedThrough(S, 0, 1);
68-
68+
6969
ssSetInputPortWidth(S, 1, DYNAMICALLY_SIZED);
7070
ssSetInputPortRequiredContiguous(S, 1, true);
7171
ssSetInputPortDirectFeedThrough(S, 1, 1);
72-
72+
7373
ssSetInputPortWidth(S, 2, DYNAMICALLY_SIZED);
7474
ssSetInputPortRequiredContiguous(S, 2, true);
7575
ssSetInputPortDirectFeedThrough(S, 2, 1);
76-
76+
7777
if (!ssSetNumOutputPorts(S, 3)) return;
7878
ssSetOutputPortWidth(S, 0, 13);
7979
ssSetOutputPortWidth(S, 1, DYNAMICALLY_SIZED);
8080
ssSetOutputPortWidth(S, 2, DYNAMICALLY_SIZED);
81-
81+
8282
ssSetNumSampleTimes(S, 1);
8383
ssSetNumRWork(S, 0);
8484
ssSetNumIWork(S, 6);
8585
ssSetNumPWork(S, 0);
8686
ssSetNumModes(S, 0);
8787
ssSetNumNonsampledZCs(S, 0);
88-
88+
8989
ssSetOptions(S,
9090
SS_OPTION_WORKS_WITH_CODE_REUSE |
9191
SS_OPTION_EXCEPTION_FREE_CODE |
@@ -145,58 +145,58 @@ static void mdlOutputs(SimStruct *S, int_T tid)
145145
const real_T IDes = *mxGetPr(IDesign_p(S));
146146
const real_T CustBldEn = *mxGetPr(CustBldEn_p(S));
147147
const real_T FBldEn = *mxGetPr(FBldEn_p(S));
148-
148+
149149
/* vector & array data */
150150
const real_T *Y_C_NcVec = mxGetPr(Y_C_NcVec_p(S));
151151
const real_T *X_C_RlineVec = mxGetPr(X_C_RlineVec_p(S));
152152
const real_T *T_C_Map_WcArray = mxGetPr(T_C_Map_WcArray_p(S));
153153
const real_T *T_C_Map_PRArray = mxGetPr(T_C_Map_PRArray_p(S));
154154
const real_T *T_C_Map_EffArray = mxGetPr(T_C_Map_EffArray_p(S));
155-
155+
156156
const real_T *FracCusBldht = mxGetPr(FracCusBldht_p(S));
157157
const real_T *FracCusBldPt = mxGetPr(FracCusBldPt_p(S));
158158
const real_T *FracBldht = mxGetPr(FracBldht_p(S));
159159
const real_T *FracBldPt = mxGetPr(FracBldPt_p(S));
160-
160+
161161
const real_T *X_C_WcSurgeVec = mxGetPr(X_C_WcSurgeVec_p(S));
162162
const real_T *T_C_PRSurgeVec = mxGetPr(T_C_PRSurgeVec_p(S));
163-
163+
164164
/*------get dimensions of parameter arrays-------*/
165165
const int_T A = mxGetNumberOfElements(Y_C_NcVec_p(S));
166166
const int_T B = mxGetNumberOfElements(X_C_RlineVec_p(S));
167167
const int_T C = mxGetNumberOfElements(X_C_WcSurgeVec_p(S));
168-
168+
169169
/*---------Define Inputs for input port 1--------*/
170170
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
171-
171+
172172
double WIn = u[0]; /* Input Flow [pps] */
173173
double htIn = u[1]; /* Input Enthalpy [BTU/lbm] */
174174
double TtIn = u[2]; /* Temperature Input [degR] */
175175
double PtIn = u[3]; /* Pressure Input [psia] */
176176
double FARcIn = u[4]; /* Combusted Fuel to Air Ratio [frac] */
177177
double Nmech = u[5]; /* Mechancial Shaft Speed [rpm] */
178178
double Rline = u[6]; /* Rline [NA] */
179-
179+
180180
/*---------Define Inputs for input port 2--------*/
181181
const real_T *Wcust = ssGetInputPortRealSignal(S, 1);
182182
int uWidth1 = ssGetCurrentInputPortDimensions(S, 1, 0);
183-
183+
184184
/*---------Define Inputs for input port 3--------*/
185185
const real_T *FracWbld = ssGetInputPortSignal(S,2);
186186
int uWidth2 = ssGetCurrentInputPortDimensions(S, 2, 0);
187-
187+
188188
real_T *y = (real_T *)ssGetOutputPortRealSignal(S,0); /* Output Array port 1 */
189189
real_T *y1 = (real_T *)ssGetOutputPortRealSignal(S,1); /* Output Array port 2 */
190190
real_T *y2 = (real_T *)ssGetOutputPortRealSignal(S,2); /* Output Array port 3 */
191-
191+
192192
/*--------Define Constants-------*/
193193
double WOut, htOut, TtOut, PtOut, FARcOut, TorqueOut, NErrorOut;
194194
double C_Nc, C_Wc, C_PR, C_Eff;
195195
double htin, Sin, Wcin, WcCalcin, WcMap, theta,delta, Pwrout, Wbleeds, Wsumbleed;
196196
double TtIdealout, htIdealout, Test, Sout, NcMap, Nc, PRMap, PR, EffMap, Eff;
197197
double Wb4bleed, Pwrb4bleed, PwrBld;
198198
double SPR, SMavail;
199-
199+
200200
/* Define Arrays for bleed calcs */
201201
int MaxNumberBleeds = 100;
202202
double WcustOut[500];
@@ -209,116 +209,116 @@ static void mdlOutputs(SimStruct *S, int_T tid)
209209
double TtbldOut[500];
210210
double htbldOut[500];
211211
double htcustOut[500];
212-
212+
213213
int interpErr = 0;
214214
int i;
215-
215+
216216
/* ------- get strings -------------- */
217217
char * BlkNm;
218218
int_T buflen;
219219
int_T status;
220-
220+
221221
/* Get name of block from dialog parameter (string) */
222222
buflen = mxGetN(BN_p(S))*sizeof(mxChar)+1;
223223
BlkNm = mxMalloc(buflen);
224224
status = mxGetString(BN_p(S), BlkNm, buflen);
225-
225+
226226
/*-- Compute output Fuel to Air Ratio ---*/
227227
FARcOut = FARcIn;
228-
228+
229229
/*-- Compute Input enthalpy --------*/
230-
230+
231231
htin = t2hc(TtIn,FARcIn);
232-
232+
233233
/*-- Compute Input entropy --------*/
234-
234+
235235
Sin = pt2sc(PtIn,TtIn,FARcIn);
236-
236+
237237
/*---- calculate misc. fluid condition related variables and corrected Flow --*/
238238
delta = PtIn / C_PSTD;
239239
theta = TtIn / C_TSTD;
240240
Wcin = WIn*sqrt(theta)/delta;
241-
241+
242242
/*------ Calculate corrected speed ---------*/
243243
Nc = Nmech/sqrt(theta);
244244
if (IDes > 0.5)
245245
C_Nc = Nc / NcDes ;
246246
else
247247
C_Nc = s_C_Nc;
248-
249-
NcMap = Nc / s_C_Nc;
248+
249+
NcMap = Nc / C_Nc;
250250

251251
/*-- Compute Total Flow input (from Compressor map) --------*/
252-
252+
253253
WcMap = interp2Ac(X_C_RlineVec,Y_C_NcVec,T_C_Map_WcArray,Rline,NcMap,B,A,&interpErr);
254254
if (interpErr == 1 && ssGetIWork(S)[0]==0){
255255
printf("Warning in %s, Error calculating WcMap. Vector definitions may need to be expanded.\n", BlkNm);
256256
ssSetIWorkValue(S,0,1);
257257
}
258-
258+
259259
if (IDes > 0.5)
260260
C_Wc = Wcin / WcMap;
261261
else
262262
C_Wc = s_C_Wc;
263-
263+
264264
WcCalcin = WcMap * C_Wc;
265-
265+
266266
/*-- Compute Pressure Ratio (from Compressor map) --------*/
267-
267+
268268
PRMap = interp2Ac(X_C_RlineVec,Y_C_NcVec,T_C_Map_PRArray,Rline,NcMap,B,A,&interpErr);
269269
if (interpErr == 1 && ssGetIWork(S)[1]==0){
270270
printf("Warning in %s, Error calculating PRMap. Vector definitions may need to be expanded.\n", BlkNm);
271271
ssSetIWorkValue(S,1,1);
272272
}
273-
273+
274274
if (IDes > 0.5)
275275
C_PR = (PRDes -1) / (PRMap-1);
276276
else
277277
C_PR = s_C_PR;
278-
278+
279279
PR = C_PR*(PRMap - 1) + 1 ;
280-
280+
281281
/*-- Compute Efficiency (from Compressor map) ---*/
282-
282+
283283
EffMap = interp2Ac(X_C_RlineVec,Y_C_NcVec,T_C_Map_EffArray,Rline,NcMap,B,A,&interpErr);
284284
if (interpErr == 1 && ssGetIWork(S)[2]==0){
285285
printf("Warning in %s, Error calculating EffMap. Vector definitions may need to be expanded.\n", BlkNm);
286286
ssSetIWorkValue(S,2,1);
287287
}
288-
288+
289289
if (IDes > 0.5)
290290
C_Eff = EffDes / EffMap;
291291
else
292292
C_Eff = s_C_Eff;
293-
293+
294294
Eff = EffMap * C_Eff;
295-
295+
296296
/*------ Compute pressure output --------*/
297-
297+
298298
PtOut = PtIn*PR;
299-
300-
299+
300+
301301
/*------ enthalpy calculations ---------*/
302-
302+
303303
/* ---- Ideal enthalpy ----*/
304304
Sout = Sin;
305305
TtIdealout = sp2tc(Sout,PtOut,FARcIn);
306306
htIdealout = t2hc(TtIdealout,FARcIn);
307-
308-
307+
308+
309309
/* ---- Final enthalpy output ----*/
310-
310+
311311
htOut = ((htIdealout - htin)/Eff) + htin;
312-
312+
313313
/*------ Compute Temperature output ---------*/
314-
314+
315315
TtOut = h2tc(htOut,FARcIn);
316-
317-
316+
317+
318318
/* initalize Bleed sums components */
319319
Wbleeds = 0;
320320
PwrBld = 0;
321-
321+
322322
/* compute customer Bleed components */
323323
for (i = 0; i < uWidth1; i++)
324324
{
@@ -345,9 +345,9 @@ static void mdlOutputs(SimStruct *S, int_T tid)
345345
ssSetIWorkValue(S,3,1);
346346
}
347347
}
348-
348+
349349
/*----Disable Fractional bleed when requested----*/
350-
350+
351351
for (i = 0; i < uWidth2; i++)
352352
{
353353
if (FracWbld[i] <= 0 || FBldEn < 0.5 ){
@@ -357,7 +357,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
357357
TtbldOut[i] = 0;
358358
PtbldOut[i] = 0;
359359
}
360-
360+
361361
else {
362362
/*-- Compute sum of Fractional Bleed Flow output --------*/
363363
Wbleeds = Wbleeds + FracWbld[i]*WIn; /* add to total bleed value */
@@ -373,19 +373,19 @@ static void mdlOutputs(SimStruct *S, int_T tid)
373373
ssSetIWorkValue(S,4,1);
374374
}
375375
}
376-
376+
377377
/*-- Compute Flows --------*/
378378
Wb4bleed = WIn;
379379
WOut = WIn - Wbleeds;
380-
380+
381381
/*------ Compute Powers ---------*/
382-
382+
383383
Pwrb4bleed = Wb4bleed * (htin - htOut) * C_BTU_PER_SECtoHP;
384384
Pwrout = Pwrb4bleed - PwrBld;
385-
385+
386386
/*----- Compute output Torque to shaft ----*/
387387
TorqueOut = C_HP_PER_RPMtoFT_LBF * Pwrout/Nmech;
388-
388+
389389
/* ----- Compute Normalized Flow Error ----- */
390390
if (IDes > 0.5 && Rline == 0)
391391
NErrorOut = 100;
@@ -395,18 +395,18 @@ static void mdlOutputs(SimStruct *S, int_T tid)
395395
NErrorOut = 100;
396396
else
397397
NErrorOut = (Wcin - WcCalcin)/Wcin ;
398-
398+
399399
/* Compute Stall Margin */
400400
SPR = interp1Ac(X_C_WcSurgeVec,T_C_PRSurgeVec,Wcin,C,&interpErr);
401401
if (interpErr == 1 && ssGetIWork(S)[5]==0){
402402
printf("Warning in %s, Error calculating SPR. Vector definitions may need to be expanded.\n", BlkNm);
403403
ssSetIWorkValue(S,5,1);
404404
}
405405
SMavail = (SPR - PR)/PR * 100;
406-
406+
407407
/* Test variable */
408408
Test = PRMap;
409-
409+
410410
/*------Assign output values port1------------*/
411411
y[0] = WOut; /* Outlet Total Flow [pps] */
412412
y[1] = htOut; /* Output Enthalpy [BTU/lbm] */
@@ -421,7 +421,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
421421
y[10] = C_PR; /* Pressure Ratio scalar */
422422
y[11] = C_Eff; /* Efficiency scalar */
423423
y[12] = Test;
424-
424+
425425
/*------Assign output values port2------------*/
426426
/* Customer or flow based bleed*/
427427
for (i = 0; i < uWidth1; i++)
@@ -432,7 +432,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
432432
*y1++ = PtcustOut[i];
433433
*y1++ = FARcustOut[i];
434434
}
435-
435+
436436
/*------Assign output values port3------------*/
437437
/* fractional bleed, typically used for turbine cooling flow */
438438
for (i = 0; i < uWidth2; i++)
@@ -443,7 +443,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
443443
*y2++ = PtbldOut[i];
444444
*y2++ = FARbldOut[i];
445445
}
446-
446+
447447
}
448448

449449
static void mdlTerminate(SimStruct *S)

0 commit comments

Comments
 (0)