Skip to content

Commit

Permalink
Code comment update
Browse files Browse the repository at this point in the history
a few typos were found in the coding comments.  These were corrected.
  • Loading branch information
chapman178 committed Feb 4, 2014
1 parent 1654161 commit 896f89d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions Trunk/TMATS_Library/MEX/C_code/Ambient_TMATS.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ static void mdlOutputs(SimStruct *S, int_T tid)
char * BlkNm;
int_T buflen;
int_T status;

/* Get name of block from dialog parameter (string) */
buflen = mxGetN(BN_p(S))*sizeof(mxChar)+1;
BlkNm = mxMalloc(buflen);
status = mxGetString(BN_p(S), BlkNm, buflen);

/* Static Temperature */
TsStDayOut = interp1Ac(X_A_AltVec,T_A_TsVec,AltIn,A,&interpErr);
if (interpErr == 1 && ssGetIWork(S)[0]==0){
Expand Down Expand Up @@ -136,7 +136,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
y[0] = TtOut; /* Total Temperature [degR] */
y[1] = PtOut; /* Total Pressure [psia] */
y[2] = PsOut; /* Static Pressure [psia] */
y[3] = TsOut; /* Static Pressure [degR] */
y[3] = TsOut; /* Static Temperature [degR] */
y[4] = VengOut; /* Engine Velocity [ft/sec] */

}
Expand Down
2 changes: 1 addition & 1 deletion Trunk/TMATS_Library/MEX/C_code/Burner_TMATS.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
y[2] = TtOut; /* Output Temperature [degR]*/
y[3] = PtOut; /* Output Pressure [psia] */
y[4] = FARcOut; /* Output Combusted Fuel to Air Ratio [frac] */
y[5] = Test; /* Output Test Piont */
y[5] = Test; /* Output Test Point */

}

Expand Down
74 changes: 37 additions & 37 deletions Trunk/TMATS_Library/MEX/C_code/ValvePHY_TMATS.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ static void mdlInitializeSizes(SimStruct *S)
/* Return if number of expected != number of actual parameters */
return;
}

for (i = 0; i < NPARAMS; i++)
ssSetSFcnParamTunable(S, i, 0);

ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);

if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 9);
ssSetInputPortRequiredContiguous(S, 0, true);
ssSetInputPortDirectFeedThrough(S, 0, 1);

if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);

ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 3);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);

ssSetOptions(S,
SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_EXCEPTION_FREE_CODE |
Expand Down Expand Up @@ -88,21 +88,21 @@ static void mdlOutputs(SimStruct *S, int_T tid)
const real_T s_V_Ae_vlv = *mxGetPr(s_V_Ae_vlv_p(S));
const real_T s_V_Ae_byp = *mxGetPr(s_V_Ae_byp_p(S));
const real_T s_V_Ae_th = *mxGetPr(s_V_Ae_th_p(S));

/*-------- vector & array data -------*/
const real_T *X_V_FAR_vec = mxGetPr(X_V_FAR_vec_p(S));
const real_T *T_V_Rt_vec = mxGetPr(T_V_Rt_vec_p(S));
const real_T *Y_V_Tt_vec = mxGetPr(Y_V_Tt_vec_p(S));
const real_T *T_V_gamma_array = mxGetPr(T_V_gamma_array_p(S));

/*------get dimensions of parameter arrays-------*/
const int_T A1 = mxGetNumberOfElements(X_V_FAR_vec_p(S));
const int_T B1 = mxGetNumberOfElements(Y_V_Tt_vec_p(S));

/*---------Define Inputs--------*/
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);


double WbyIn = u[0]; /* Bypass flow path flow rate [pps] */
double TtbyIn = u[1]; /* Bypass Temperature [degR] */
double PtbyIn = u[2]; /* Bypass disch. pressure [psia] */
Expand All @@ -112,39 +112,39 @@ static void mdlOutputs(SimStruct *S, int_T tid)
double TtmfpIn = u[6]; /* Main flow path Temprature [degR] */
double PtmfpIn = u[7]; /* Main flow path Pressure Input [psia] */
double FARcmfpIn= u[8]; /* Main flow path combusted fuel to air ratio [frac] */

real_T *y = (real_T *)ssGetOutputPortRealSignal(S,0); /* Output Array */

/*--------Define Constants-------*/
double Ath, Rb, gamb, Cpb, Pe, Me, Tcr_o_Te, Ae_o_Acr, Ath_o_Acr;
double Mth0, Mth1, Tcr_o_Tth0, Tcr_o_Tth1, Ath_o_Acr0, Ath_o_Acr1, err0, err1, err;
double Mth, Tcr_o_Tth_it, Ath_o_Acr_it, Tcr_o_T0, Tth_o_T0, Tth, Pth, rhoth, Vth, Wth, Wbyp_noz, Whpc;
double MthOut, Test, WthOut;

int interpErr = 0;
int count;

/* ------- get strings -------------- */
char * BlkNm;
int_T buflen;
int_T status;

/* Get name of block from dialog parameter (string) */
buflen = mxGetN(BN_p(S))*sizeof(mxChar)+1;
BlkNm = mxMalloc(buflen);
status = mxGetString(BN_p(S), BlkNm, buflen);

/* Input validation */
if ((WbyIn <= 0 || WmfpIn <= 0) && ssGetIWork(S)[0]==0){
printf("Flow rates must be nonzero !!");
ssSetIWorkValue(S,0,1);
}

if (VlvPosIn > 0){
if (VlvPosIn < 0.001)
VlvPosIn = 0.001;
Ath = VlvPosIn*s_V_Ae_th; /* throat area [in^2] */

/* define gas constants for booster discharge air */
Rb = interp1Ac(X_V_FAR_vec,T_V_Rt_vec,FARcmfpIn,A1,&interpErr);
if (interpErr == 1 && ssGetIWork(S)[1]==0){
Expand All @@ -157,54 +157,54 @@ static void mdlOutputs(SimStruct *S, int_T tid)
ssSetIWorkValue(S,2,1);
}
Cpb = Rb*gamb/(gamb-1);

/* determine static pressure at the exit plane (entering fan); */
/* assume bypass flow >> bleed flow */
Pe = calc_Pstatic(PtbyIn,TtbyIn,WbyIn,s_V_Ae_byp,X_V_FAR_vec,T_V_Rt_vec,Y_V_Tt_vec,T_V_gamma_array,FARcbyIn,A1,B1);

/* compute exit to critical area ratio */
Me = sqrt(2/(gamb-1)*(pow(Pe/PtmfpIn, (1-gamb)/gamb)-1));
Tcr_o_Te = (2/(gamb+1))*(1 + 0.5*(gamb-1)*Me*Me);
Ae_o_Acr = pow(Tcr_o_Te, (gamb+1)/(2*(gamb-1)))/Me;

/* obtain throat to critical area ratio */
Ath_o_Acr = Ae_o_Acr*Ath/s_V_Ae_vlv;

/* determine throat Mach no. iteratively; initialize guesses, errors */
Mth0 = 0.1; /* subsonic guess values */
Mth1 = 0.2;

Tcr_o_Tth0 = (2/(gamb+1))*(1 + 0.5*(gamb-1)*Mth0*Mth0);
Tcr_o_Tth1 = (2/(gamb+1))*(1 + 0.5*(gamb-1)*Mth1*Mth1);
Ath_o_Acr0 = pow(Tcr_o_Tth0, (gamb+1)/(2*(gamb-1)))/Mth0;
Ath_o_Acr1 = pow(Tcr_o_Tth1, (gamb+1)/(2*(gamb-1)))/Mth1;
err0 = Ath_o_Acr - Ath_o_Acr0;
err1 = Ath_o_Acr - Ath_o_Acr1;

err = 100;
count = 0;

while (fabs(err) > 0.002 && (err0 - err1) != 0 && count < 100){

/* compute new Mach no. guess */
Mth = Mth0 - err0*(Mth0 - Mth1)/(err0 - err1);
if (Mth > 1.0)
Mth = 1.0;

/* compute error to drive solution towards specified area ratio */
Tcr_o_Tth_it = (2/(gamb+1))*(1 + 0.5*(gamb-1)*Mth*Mth);
Ath_o_Acr_it = pow(Tcr_o_Tth_it, (gamb+1)/(2*(gamb-1)))/Mth;
err = Ath_o_Acr - Ath_o_Acr_it;

/* propagate errors & guesses */
Mth1 = Mth0;
err1 = err0;
Mth0 = Mth;
err0 = err;

count++;
}

/* compute throat static pressure, temperature and Mach no.; */
/* modify if choked */
Tcr_o_T0 = 2/(gamb+1);
Expand All @@ -213,7 +213,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
Tth_o_T0 = Tcr_o_T0;
Tth = TtmfpIn*Tth_o_T0;
Pth = PtmfpIn*pow(Tth_o_T0, gamb/(gamb-1));

/* recompute the actual flow rate, assume no pressure loss */
rhoth = Pth*144/(Rb*JOULES_CONST*Tth); /* [lb/ft^3] */
Vth = sqrt(2*Cpb*C_GRAVITY*JOULES_CONST*(TtmfpIn - Tth)); /* [ft/s] */
Expand All @@ -224,16 +224,16 @@ static void mdlOutputs(SimStruct *S, int_T tid)
Wth = 0;
Mth = 0;
}

WthOut = Wth;

Test = WthOut;

/*------Assign output values------------*/
y[0] = WthOut; /* Valve throat flow [pps] */
y[1] = MthOut; /* Mach no. at throat */
y[2] = Test; /* Output Test Piont */
y[2] = Test; /* Output Test Point */

}

static void mdlTerminate(SimStruct *S)
Expand Down
46 changes: 23 additions & 23 deletions Trunk/TMATS_Library/MEX/C_code/Valve_TMATS.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ static void mdlInitializeSizes(SimStruct *S)
/* Return if number of expected != number of actual parameters */
return;
}

for (i = 0; i < NPARAMS; i++)
ssSetSFcnParamTunable(S, i, 0);

ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);

if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 5);
ssSetInputPortRequiredContiguous(S, 0, true);
ssSetInputPortDirectFeedThrough(S, 0, 1);

if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 2);

ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 1);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);

ssSetOptions(S,
SS_OPTION_WORKS_WITH_CODE_REUSE |
SS_OPTION_EXCEPTION_FREE_CODE |
Expand Down Expand Up @@ -79,42 +79,42 @@ static void mdlOutputs(SimStruct *S, int_T tid)
const real_T VlvfullyOpen = *mxGetPr(VlvfullyOpen_p(S));
const real_T VlvdeadZone = *mxGetPr(VlvdeadZone_p(S));
const real_T Valve_Ae = *mxGetPr(Valve_Ae_p(S));

/*-------- vector & array data -------*/
const real_T *X_V_PRVec = mxGetPr(X_V_PRVec_p(S));
const real_T *T_V_WcVec = mxGetPr(T_V_WcVec_p(S));

/*------get dimensions of parameter arrays-------*/
const int_T A = mxGetNumberOfElements(X_V_PRVec_p(S));

/*---------Define Inputs--------*/
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);

double PtbyIn = u[0]; /* Bypass disch. pressure [psia] */
double VlvPosIn = u[1]; /* Valve Position [frac, 0-1] */
double WmfpIn = u[2]; /* Main flow path flow rate [pps] */
double TtmfpIn = u[3]; /* Main flow path Temprature [degR] */
double PtmfpIn = u[4]; /* Main flow path Pressure Input [psia] */


real_T *y = (real_T *)ssGetOutputPortRealSignal(S,0); /* Output Array */

/*--------Define Constants-------*/
double ValveFrac, ValvePR, WthOut, Valve_active_Ae;
double bleedFlxCr, Test;

int interpErr = 0;

/* ------- get strings -------------- */
char * BlkNm;
int_T buflen;
int_T status;

/* Get name of block from dialog parameter (string) */
buflen = mxGetN(BN_p(S))*sizeof(mxChar)+1;
BlkNm = mxMalloc(buflen);
status = mxGetString(BN_p(S), BlkNm, buflen);

/* Compute Valve open fraction */
ValveFrac = (VlvPosIn-VlvdeadZone)/(VlvfullyOpen-VlvdeadZone);

Expand All @@ -124,14 +124,14 @@ static void mdlOutputs(SimStruct *S, int_T tid)
/* Determine flow properties of the valve */
if ((ValveFrac <= 0) || (ValvePR <= 1.0)) /* dead zone or one-way valve */
{

WthOut = 0; /* Valve throat flow [pps] */
}
else /* the valve is open and flow is moving */
{
/*------ Compute Active Area ---------*/
Valve_active_Ae = ValveFrac*Valve_Ae;

/* compute corrected flow based on pressure ratio */
bleedFlxCr = interp1Ac(X_V_PRVec,T_V_WcVec,ValvePR,A,&interpErr);
if (interpErr == 1 && ssGetIWork(S)[0]==0){
Expand All @@ -145,13 +145,13 @@ static void mdlOutputs(SimStruct *S, int_T tid)
WthOut = WmfpIn;
}
}

Test = WthOut;

/*------Assign output values------------*/
y[0] = WthOut; /* Valve throat flow [pps] */
y[1] = Test; /* Output Test Piont */
y[1] = Test; /* Output Test Point */

}

static void mdlTerminate(SimStruct *S)
Expand Down

0 comments on commit 896f89d

Please sign in to comment.