_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& a, const complex<long double>& b) { return powT(a, b); }
void Turbine_PSI_TMATS_body(double *y, const double *u, const double *CoolFlow, const Turbine_PSIStruct* prm) { double WIn = u[0]; /* Input Flow [pps] */ double htIn = u[1]; /* input enthalpy [BTU/lbm]*/ double TtIn = u[2]; /* Temperature Input [degR] */ double PtIn = u[3]; /* Pressure Input [psia] */ double FARcIn = u[4]; /* Compusted Fuel to Air Ratio [frac] */ double Nmech = u[5]; /* Mechancial Shaft Speed [rpm]*/ double psiMapIn = u[6]; /* PSI map [NA] */ double s_T_Nc = u[7]; /* Nc map scalar [NA] */ double s_T_Wc = u[8]; /* Wc map scalar [NA] */ double s_T_PR = u[9]; /* PR map scalar [NA] */ double s_T_Eff = u[10]; /* Eff map scalar [NA] */ int cfWidth = u[11]; /* Cooling Flow Vector Length */ /*--------Define Constants-------*/ double WOut, htOut, TtOut, PtOut, FARcOut, TorqueOut, NErrorOut; double WcCalcin, WcMap, theta,delta, Pwrout, PRin, htin; double Test, htIdealout, Sout, NcMap, Nc, EffMap, Eff; double dHcools1, dHcoolout, Wfcools1, Wfcoolout, Ws1in,hts1in, Tts1in, FARs1in; double Ss1in, Wcoolout, Wcools1, PRmapRead; double C_Eff, C_PR, C_Nc, C_Wc, TtOutIdeal; double WMap, psiMapI, delHtIdealMap, erT, erT_old, Ptoutg, Ptoutg_old; double TtOutIdealg, WpqAcrit, WoWMap, Ptoutg_new; int interpErr = 0; double Wcool[100]; double htcool[100]; double Ttcool[100]; double Ptcool[100]; double FARcool[100]; int Vtest, i; /* Verify input bleed vector is a multiple of 5 */ Vtest = cfWidth/5; if(5*Vtest != cfWidth && prm->CoolFlwEn > 0.5 && *(prm->IWork+Er1)==0){ #ifdef MATLAB_MEX_FILE printf("Error in %s, one or more of the cooling flow input vector eleements is missing(Vector form; 5x1: W,ht,Tt,Pt,FAR)\n",prm->BlkNm); #endif *(prm->IWork+Er1) = 1; } else if(prm->BldPosLeng != cfWidth/5 && prm->CoolFlwEn > 0.5 && *(prm->IWork+Er2)==0){ #ifdef MATLAB_MEX_FILE printf("Errorin %s, number of cooling flow inputs does not match the length of the Cooling flow postion vector in the mask\n",prm->BlkNm); #endif *(prm->IWork+Er2) = 1; } /* unpack CoolFlow vector */ for (i = 0; i < cfWidth/5; i++) { if (prm->CoolFlwEn < 0.5){ Wcool[i] = 0; htcool[i] = 0; Ttcool[i] = 0; Ptcool[i] = 0; FARcool[i] = 0; } else { Wcool[i] = CoolFlow[5*i]; Ttcool[i] = CoolFlow[5*i+2]; Ptcool[i] = CoolFlow[5*i+3]; FARcool[i] = CoolFlow[5*i+4]; htcool[i] = t2hc(Ttcool[i],FARcool[i]); } } /* Initialize cooling flow sum constants */ dHcools1 = 0; /* enthalpy * mass cooling flow rate at stage 1 of turbine */ dHcoolout = 0; /* enthalpy * mass cooling flow rate at exit of turbine */ Wcools1 = 0; /* total cooling flow at stage 1 of turbine*/ Wcoolout = 0; /* total cooling flow at output of turbine */ Wfcools1 = 0; /* combusted fuel flow in cooling at stage 1 of turbine */ Wfcoolout = 0; /* combusted fuel flow in cooling at exit of turbine */ /* calc cooling flow constants for stage 1 and output of the turbine */ for (i = 0; i < cfWidth/5; i++) { if ((prm->T_BldPos[i] > 1 || prm->T_BldPos[i] < 0) && prm->CoolFlwEn > 0.5 && *(prm->IWork+Er3)==0){ #ifdef MATLAB_MEX_FILE printf(" Error in %s, cooling flow postion element %i needs to be defined as a 0 or 1\n",prm->BlkNm,i+1); #endif *(prm->IWork+Er3) = 1; } /* calc mass flow for cooling flows */ Wcools1 = Wcools1 + Wcool[i]*(1-prm->T_BldPos[i]); Wcoolout = Wcoolout + Wcool[i]; /* calc fuel mass flow for cooling flows*/ Wfcools1 = Wfcools1 + FARcool[i]*Wcool[i]*(1-prm->T_BldPos[i])*divby(1+FARcool[i]); Wfcoolout = Wfcoolout + FARcool[i]*Wcool[i]*divby(1+FARcool[i]); } /*-- Compute Total Flow --------*/ Ws1in = WIn + Wcools1; /* mass flow at station 1 */ WOut = WIn + Wcoolout; /* mass flow at turbine exit */ /*-- Compute Fuel to Air Ratios ---*/ FARs1in = (FARcIn* WIn*divby(1+FARcIn) + Wfcools1)*divby(WIn*divby(1+FARcIn) + Wcools1- Wfcools1); FARcOut = (FARcIn* WIn*divby(1+FARcIn)+ Wfcoolout)*divby(WIn*divby(1+FARcIn) + Wcoolout- Wfcoolout); /* calc input enthalpy of cooling flow for stage 1 */ for (i = 0; i < cfWidth/5; i++) { /* Compute cooling flow dH at stage 1 */ dHcools1 = dHcools1 + htcool[i]*Wcool[i]*(1-prm->T_BldPos[i]); /* Compute cooling flow dH for the exit of the turbine assuming input htcool = htcoolout for turbine rear bleeds */ dHcoolout = dHcoolout + htcool[i]*Wcool[i]*prm->T_BldPos[i]; } /*-- Compute avg enthalpy at stage 1 --------*/ htin = t2hc(TtIn,FARcIn); hts1in = (htin* WIn + dHcools1)*divby(Ws1in); /*-- Compute stage 1 total temp--------*/ Tts1in = h2tc(hts1in,FARs1in); /*-- Compute Stage 1 entropy, assuming PtIn = Pts1in --------*/ Ss1in = pt2sc(PtIn,Tts1in,FARs1in); /*---- calculate misc. fluid condition related variables --------*/ delta = PtIn / C_PSTD; theta = TtIn / C_TSTD; /*------ Calculate corrected speed ---------*/ Nc = Nmech*divby(sqrtT(theta)); if(prm->IDes < 0.5) C_Nc = Nc*divby(prm->NcDes); else C_Nc = s_T_Nc; NcMap = Nc*divby(C_Nc); /* ---- Calculate output entropy ----*/ Sout = Ss1in; /*-- Compute Turbine Efficiency (from Turbine map) --------*/ psiMapI = interp2Ac(prm->X_T_PRpsiVec,prm->Y_T_NcpsiVec,prm->T_T_Map_psiArray,psiMapIn,NcMap,prm->B,prm->A,&interpErr); if (interpErr == 1 && *(prm->IWork+Er4)==0){ #ifdef MATLAB_MEX_FILE printf("Warning in %s, Error calculating psiMapI. Vector definitions may need to be expanded.\n", prm->BlkNm); #endif *(prm->IWork+Er4) = 1; } EffMap = psiMapIn*divby(psiMapI); if(prm->IDes < 0.5) C_Eff = prm->EffDes*divby(EffMap); else C_Eff = s_T_Eff; Eff = EffMap * C_Eff; /* ---- Ideal enthalpy ----*/ delHtIdealMap = psiMapI * (Nmech / 60)*(Nmech / 60); htIdealout = hts1in - delHtIdealMap * prm->s_T_hi; /* ensure enthalpy is >= 0 */ if(htIdealout < 0) { htIdealout = 0; } /* Determine Ideal exit temp */ TtOutIdeal = h2tc(htIdealout,FARs1in); /* Determine starting point for iteration to find PR */ Ptoutg = PtIn*powT((TtOutIdeal*divby(TtIn)),(prm->gamma_T*divby(prm->gamma_T-1))); TtOutIdealg = sp2tc(Sout,Ptoutg,FARs1in); erT = 100*fabs(TtOutIdealg - TtOutIdeal)*divby(TtOutIdeal); Ptoutg_new = Ptoutg; /* iterate to find Ptout when TtOutIdeal guess = TtOutIdeal */ while (fabs(erT) > 0.05) { erT_old = erT; Ptoutg_old = Ptoutg; if(fabs(Ptoutg - Ptoutg_new) < 0.02) Ptoutg = Ptoutg + 0.05; else Ptoutg = Ptoutg_new; Ptoutg = Ptoutg + 0.05; TtOutIdealg = sp2tc(Sout,Ptoutg,FARs1in); erT = 100*(TtOutIdealg - TtOutIdeal)*divby(TtOutIdeal); if (fabs(erT) > 0.05) { /* determine next guess pressure by secant algorithm */ Ptoutg_new = Ptoutg - erT *(Ptoutg - Ptoutg_old)*divby(erT - erT_old); } } PRin = PtIn*divby(Ptoutg); /*------ Compute pressure output --------*/ if(prm->IDes < 0.5) C_PR = (PRin - 1)*divby(prm->PRmapDes -1); else C_PR = s_T_PR; PRmapRead = (PRin -1)*divby(C_PR) + 1; PtOut = PtIn*divby(PRin); /*-- Compute Total Flow input (from Turbine map) --------*/ WoWMap = interp2Ac(prm->X_T_PRwowVec,prm->Y_T_NcwowVec,prm->T_T_Map_WoWArray,PRmapRead,NcMap,prm->D,prm->C,&interpErr); if (interpErr == 1 && *(prm->IWork+Er5)==0){ #ifdef MATLAB_MEX_FILE printf("Warning in %s, Error calculating WoWMap. Vector definitions may need to be expanded.\n", prm->BlkNm); #endif *(prm->IWork+Er5) = 1; } WpqAcrit = sqrtT((prm->gamma_T*C_GRAVITY)*divby(prm->Rt_T*JOULES_CONST))*divby(powT((1+(prm->gamma_T-1)/2),((prm->gamma_T+1)*divby(2*(prm->gamma_T-1))))); WMap = WoWMap * WpqAcrit * (PtIn*divby(sqrtT(Tts1in))); WcMap = WMap * sqrtT(theta)*divby(delta); if(prm->IDes < 0.5) C_Wc = Ws1in*sqrtT(theta)*divby(delta)*divby(WcMap); else C_Wc = s_T_Wc; WcCalcin = WcMap * C_Wc; /*-Compute power output only takes into account cooling flow that enters at front of engine (stage 1)-*/ Pwrout = ((hts1in - htIdealout)*Eff)*Ws1in * C_BTU_PER_SECtoHP; /* ---- enthalpy output ----*/ htOut = ((((htIdealout - hts1in)*Eff) + hts1in)*Ws1in + dHcoolout)*divby(WOut); /*------ Compute Temperature output (empirical) ---------*/ TtOut = h2tc(htOut,FARcOut); /*----- Compute output Torque to shaft ----*/ TorqueOut = C_HP_PER_RPMtoFT_LBF * Pwrout*divby(Nmech); /* ----- Compute Normalized Flow Error ----- */ if (prm->IDes < 0.5 && prm->NDes == 0) NErrorOut = 100; else if (prm->IDes < 0.5) NErrorOut = (Nmech - prm->NDes)*divby(prm->NDes); else if (Ws1in == 0) { NErrorOut = 100; } else { NErrorOut = (Ws1in*sqrtT(theta)*divby(delta)-WcCalcin)*divby(Ws1in*sqrtT(theta)*divby(delta)) ; } Test = Wcool[0]; /*------Assign output values------------ */ y[0] = WOut; /* Outlet Total Flow [pps] */ y[1] = htOut; /* Outlet Enthalpy [BTU/lbm]*/ y[2] = TtOut; /* Outlet Temperature [degR] */ y[3] = PtOut; /* Outlet Pressure [psia] */ y[4] = FARcOut; /* Outlet Fuel to Air Ratio [NA] */ y[5] = TorqueOut; /* Torque Output [lbf*ft] */ y[6] = NErrorOut; /* Normalized turbine Error [frac]*/ y[7] = C_Nc; /* Corrected Shaft Speed Scalar */ y[8] = C_Wc; /* Corrected Flow Scalar */ y[9] = C_PR; /* Pressure Ratio Scalar */ y[10] = C_Eff; /* Efficiency Scalar */ y[11] = Test; }
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>& z_in, int n) { return powT(z_in, n); }
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& a, const complex<float>& b) { return powT(a, b); }
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>& z_in, int n) { return powT(z_in, n); }
static void mdlOutputs(SimStruct *S, int_T tid) { /*--------Define Parameters-------*/ const real_T NcDes = *mxGetPr(NcDes_p(S)); const real_T PRmapDes = *mxGetPr(PRmapDes_p(S)); const real_T EffDes = *mxGetPr(EffDes_p(S)); const real_T NDes = *mxGetPr(NDes_p(S)); const real_T IDes = *mxGetPr(IDesign_p(S)); const real_T s_T_hi = *mxGetPr(s_T_hi_p(S)); const real_T gamma_T = *mxGetPr(gamma_T_p(S)); const real_T Rt_T = *mxGetPr(Rt_T_p(S)); const int_T BldPosLeng = *mxGetPr(BldPosLeng_p(S)); const int_T CoolFlwEn = *mxGetPr(CoolFlwEn_p(S)); /* vector & array data */ const real_T *Y_T_NcpsiVec = mxGetPr(Y_T_NcpsiVec_p(S)); const real_T *X_T_PRpsiVec = mxGetPr(X_T_PRpsiVec_p(S)); const real_T *Y_T_NcwowVec = mxGetPr(Y_T_NcwowVec_p(S)); const real_T *X_T_PRwowVec = mxGetPr(X_T_PRwowVec_p(S)); const real_T *T_T_Map_WoWArray = mxGetPr(T_T_Map_WoWArray_p(S)); const real_T *T_T_Map_psiArray = mxGetPr(T_T_Map_psiArray_p(S)); const real_T *T_BldPos = mxGetPr(T_BldPos_p(S)); /*------get dimensions of parameter arrays-------*/ const int_T A = mxGetNumberOfElements(Y_T_NcpsiVec_p(S)); const int_T B = mxGetNumberOfElements(X_T_PRpsiVec_p(S)); const int_T C = mxGetNumberOfElements(Y_T_NcwowVec_p(S)); const int_T D = mxGetNumberOfElements(X_T_PRwowVec_p(S)); /*---------Define Inputs--------*/ const real_T *u = (const real_T*) ssGetInputPortSignal(S,0); double WIn = u[0]; /* Input Flow [pps] */ double htIn = u[1]; /* input enthalpy [BTU/lbm]*/ double TtIn = u[2]; /* Temperature Input [degR] */ double PtIn = u[3]; /* Pressure Input [psia] */ double FARcIn = u[4]; /* Compusted Fuel to Air Ratio [frac] */ double Nmech = u[5]; /* Mechancial Shaft Speed [rpm]*/ double psiMapIn = u[6]; /* PSI map [NA] */ double s_T_Nc = u[7]; /* Nc map scalar [NA] */ double s_T_Wc = u[8]; /* Wc map scalar [NA] */ double s_T_PR = u[9]; /* PR map scalar [NA] */ double s_T_Eff = u[10]; /* Eff map scalar [NA] */ int cfWidth = u[11]; /* Cooling Flow Vector Length */ /*---------Define Inputs for input port 2--------*/ /* N 5x1 vectors consisting of W, ht, Tt, Pt and FAR, where N is the number of cooling flows */ const real_T *CoolFlow = ssGetInputPortRealSignal(S, 1); real_T *y = (real_T *)ssGetOutputPortRealSignal(S,0); /* Output Array */ /*--------Define Constants-------*/ double WOut, htOut, TtOut, PtOut, FARcOut, TorqueOut, NErrorOut; double WcCalcin, WcMap, theta,delta, Pwrout, PRin, htin; double TtIdealout, Test, htIdealout, Sout, NcMap, Nc, EffMap, Eff; double dHcools1, dHcoolout, Wfcools1, Wfcoolout, Ws1in,hts1in, Tts1in, Pts1in, FARs1in; double Ss1in, dHout, Wcoolout, Wcools1, PRmapRead; double C_Eff, C_PR, C_Nc, C_Wc, TtOutIdeal; double WMap, psiMapI, delHtIdealMap, erT, erT_old, Ptoutg, Ptoutg_old; double TtOutIdealg, WpqAcrit, WoWMap, Ptoutg_new; int interpErr = 0; double Wcool[100]; double htcool[100]; double Ttcool[100]; double Ptcool[100]; double FARcool[100]; int Vtest, i; /* ------- 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); /* Verify input bleed vector is a multiple of 5 */ Vtest = cfWidth/5; if(5*Vtest != cfWidth && CoolFlwEn > 0.5 && ssGetIWork(S)[Er1]==0){ printf("Error in %s, one or more of the cooling flow input vector eleements is missing(Vector form; 5x1: W,ht,Tt,Pt,FAR)\n",BlkNm); ssSetIWorkValue(S,Er1,1); } else if(BldPosLeng != cfWidth/5 && CoolFlwEn > 0.5 && ssGetIWork(S)[Er2]==0){ printf("Errorin %s, number of cooling flow inputs does not match the length of the Cooling flow postion vector in the mask\n",BlkNm); ssSetIWorkValue(S,Er2,1); } /* unpack CoolFlow vector */ for (i = 0; i < cfWidth/5; i++) { if (CoolFlwEn < 0.5){ Wcool[i] = 0; htcool[i] = 0; Ttcool[i] = 0; Ptcool[i] = 0; FARcool[i] = 0; } else { Wcool[i] = CoolFlow[5*i]; Ttcool[i] = CoolFlow[5*i+2]; Ptcool[i] = CoolFlow[5*i+3]; FARcool[i] = CoolFlow[5*i+4]; htcool[i] = t2hc(Ttcool[i],FARcool[i]); } } /* Initialize cooling flow sum constants */ dHcools1 = 0; /* enthalpy * mass cooling flow rate at stage 1 of turbine */ dHcoolout = 0; /* enthalpy * mass cooling flow rate at exit of turbine */ Wcools1 = 0; /* total cooling flow at stage 1 of turbine*/ Wcoolout = 0; /* total cooling flow at output of turbine */ Wfcools1 = 0; /* combusted fuel flow in cooling at stage 1 of turbine */ Wfcoolout = 0; /* combusted fuel flow in cooling at exit of turbine */ /* calc cooling flow constants for stage 1 and output of the turbine */ for (i = 0; i < cfWidth/5; i++) { if ((T_BldPos[i] > 1 || T_BldPos[i] < 0) && CoolFlwEn > 0.5 && ssGetIWork(S)[Er3]==0){ printf(" Error in %s, cooling flow postion element %i needs to be defined as a 0 or 1\n",BlkNm,i+1); ssSetIWorkValue(S,Er3,1); } /* calc mass flow for cooling flows */ Wcools1 = Wcools1 + Wcool[i]*(1-T_BldPos[i]); Wcoolout = Wcoolout + Wcool[i]; /* calc fuel mass flow for cooling flows*/ Wfcools1 = Wfcools1 + FARcool[i]*Wcool[i]*(1-T_BldPos[i])*divby(1+FARcool[i]); Wfcoolout = Wfcoolout + FARcool[i]*Wcool[i]*divby(1+FARcool[i]); } /*-- Compute Total Flow --------*/ Ws1in = WIn + Wcools1; /* mass flow at station 1 */ WOut = WIn + Wcoolout; /* mass flow at turbine exit */ /*-- Compute Fuel to Air Ratios ---*/ FARs1in = (FARcIn* WIn*divby(1+FARcIn) + Wfcools1)*divby(WIn*divby(1+FARcIn) + Wcools1- Wfcools1); FARcOut = (FARcIn* WIn*divby(1+FARcIn)+ Wfcoolout)*divby(WIn*divby(1+FARcIn) + Wcoolout- Wfcoolout); /* calc input enthalpy of cooling flow for stage 1 */ for (i = 0; i < cfWidth/5; i++) { /* Compute cooling flow dH at stage 1 */ dHcools1 = dHcools1 + htcool[i]*Wcool[i]*(1-T_BldPos[i]); /* Compute cooling flow dH for the exit of the turbine assuming input htcool = htcoolout for turbine rear bleeds */ dHcoolout = dHcoolout + htcool[i]*Wcool[i]*T_BldPos[i]; } /*-- Compute avg enthalpy at stage 1 --------*/ htin = t2hc(TtIn,FARcIn); hts1in = (htin* WIn + dHcools1)*divby(Ws1in); /*-- Compute stage 1 total temp--------*/ Tts1in = h2tc(hts1in,FARs1in); /*-- Compute Stage 1 entropy, assuming PtIn = Pts1in --------*/ Ss1in = pt2sc(PtIn,Tts1in,FARs1in); /*---- calculate misc. fluid condition related variables --------*/ delta = PtIn / C_PSTD; theta = TtIn / C_TSTD; /*------ Calculate corrected speed ---------*/ Nc = Nmech*divby(sqrtT(theta)); if(IDes < 0.5) C_Nc = Nc*divby(NcDes); else C_Nc = s_T_Nc; NcMap = Nc*divby(C_Nc); /* ---- Calculate output entropy ----*/ Sout = Ss1in; /*-- Compute Turbine Efficiency (from Turbine map) --------*/ psiMapI = interp2Ac(X_T_PRpsiVec,Y_T_NcpsiVec,T_T_Map_psiArray,psiMapIn,NcMap,B,A,&interpErr); if (interpErr == 1 && ssGetIWork(S)[Er4]==0){ printf("Warning in %s, Error calculating psiMapI. Vector definitions may need to be expanded.\n", BlkNm); ssSetIWorkValue(S,Er4,1); } EffMap = psiMapIn*divby(psiMapI); if(IDes < 0.5) C_Eff = EffDes*divby(EffMap); else C_Eff = s_T_Eff; Eff = EffMap * C_Eff; /* ---- Ideal enthalpy ----*/ delHtIdealMap = psiMapI * (Nmech / 60)*(Nmech / 60); htIdealout = hts1in - delHtIdealMap * s_T_hi; /* ensure enthalpy is >= 0 */ if(htIdealout < 0) { htIdealout = 0; } /* Determine Ideal exit temp */ TtOutIdeal = h2tc(htIdealout,FARs1in); /* Determine starting point for iteration to find PR */ Ptoutg = PtIn*powT((TtOutIdeal*divby(TtIn)),(gamma_T*divby(gamma_T-1))); TtOutIdealg = sp2tc(Sout,Ptoutg,FARs1in); erT = 100*fabs(TtOutIdealg - TtOutIdeal)*divby(TtOutIdeal); Ptoutg_new = Ptoutg; /* iterate to find Ptout when TtOutIdeal guess = TtOutIdeal */ while (fabs(erT) > 0.05) { erT_old = erT; Ptoutg_old = Ptoutg; if(fabs(Ptoutg - Ptoutg_new) < 0.02) Ptoutg = Ptoutg + 0.05; else Ptoutg = Ptoutg_new; Ptoutg = Ptoutg + 0.05; TtOutIdealg = sp2tc(Sout,Ptoutg,FARs1in); erT = 100*(TtOutIdealg - TtOutIdeal)*divby(TtOutIdeal); if (fabs(erT) > 0.05) { /* determine next guess pressure by secant algorithm */ Ptoutg_new = Ptoutg - erT *(Ptoutg - Ptoutg_old)*divby(erT - erT_old); } } PRin = PtIn*divby(Ptoutg); /*------ Compute pressure output --------*/ if(IDes < 0.5) C_PR = (PRin - 1)*divby(PRmapDes -1); else C_PR = s_T_PR; PRmapRead = (PRin -1)*divby(C_PR) + 1; PtOut = PtIn*divby(PRin); /*-- Compute Total Flow input (from Turbine map) --------*/ WoWMap = interp2Ac(X_T_PRwowVec,Y_T_NcwowVec,T_T_Map_WoWArray,PRmapRead,NcMap,D,C,&interpErr); if (interpErr == 1 && ssGetIWork(S)[Er5]==0){ printf("Warning in %s, Error calculating WoWMap. Vector definitions may need to be expanded.\n", BlkNm); ssSetIWorkValue(S,Er5,1); } WpqAcrit = sqrtT((gamma_T*C_GRAVITY)*divby(Rt_T*JOULES_CONST))*divby(powT((1+(gamma_T-1)/2),((gamma_T+1)*divby(2*(gamma_T-1))))); WMap = WoWMap * WpqAcrit * (PtIn*divby(sqrtT(Tts1in))); WcMap = WMap * sqrtT(theta)*divby(delta); if(IDes < 0.5) C_Wc = Ws1in*sqrtT(theta)*divby(delta)*divby(WcMap); else C_Wc = s_T_Wc; WcCalcin = WcMap * C_Wc; /*-Compute power output only takes into account cooling flow that enters at front of engine (stage 1)-*/ Pwrout = ((hts1in - htIdealout)*Eff)*Ws1in * C_BTU_PER_SECtoHP; /* ---- enthalpy output ----*/ htOut = ((((htIdealout - hts1in)*Eff) + hts1in)*Ws1in + dHcoolout)*divby(WOut); /*------ Compute Temperature output (empirical) ---------*/ TtOut = h2tc(htOut,FARcOut); /*----- Compute output Torque to shaft ----*/ TorqueOut = C_HP_PER_RPMtoFT_LBF * Pwrout*divby(Nmech); /* ----- Compute Normalized Flow Error ----- */ if (IDes < 0.5 && NDes == 0) NErrorOut = 100; else if (IDes < 0.5) NErrorOut = (Nmech - NDes)*divby(NDes); else if (Ws1in == 0) { NErrorOut = 100; } else { NErrorOut = (Ws1in*sqrtT(theta)*divby(delta)-WcCalcin)*divby(Ws1in*sqrtT(theta)*divby(delta)) ; } Test = Wcool[0]; /*------Assign output values------------ */ y[0] = WOut; /* Outlet Total Flow [pps] */ y[1] = htOut; /* Outlet Enthalpy [BTU/lbm]*/ y[2] = TtOut; /* Outlet Temperature [degR] */ y[3] = PtOut; /* Outlet Pressure [psia] */ y[4] = FARcOut; /* Outlet Fuel to Air Ratio [NA] */ y[5] = TorqueOut; /* Torque Output [lbf*ft] */ y[6] = NErrorOut; /* Normalized turbine Error [frac]*/ y[7] = C_Nc; /* Corrected Shaft Speed Scalar */ y[8] = C_Wc; /* Corrected Flow Scalar */ y[9] = C_PR; /* Pressure Ratio Scalar */ y[10] = C_Eff; /* Efficiency Scalar */ y[11] = Test; }
static void mdlOutputs(SimStruct *S, int_T tid) { /*--------Define Parameters-------*/ 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] */ double FARcbyIn = u[3]; /* Bypass combusted fuel to air ratio [frac] */ double VlvPosIn = u[4]; /* Valve Position [frac, 0-1] */ double WmfpIn = u[5]; /* Main flow path flow rate [pps] */ 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)[Er1]==0){ printf("Flow rates must be nonzero !!"); ssSetIWorkValue(S,Er1,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)[Er2]==0){ printf("Warning in %s, Error calculating Rb. Vector definitions may need to be expanded.\n", BlkNm); ssSetIWorkValue(S,Er2,1); } gamb = interp2Ac(X_V_FAR_vec,Y_V_Tt_vec,T_V_gamma_array,FARcmfpIn,TtmfpIn,A1,B1,&interpErr); if (interpErr == 1 && ssGetIWork(S)[Er3]==0){ printf("Warning in %s, Error calculating gamb. Vector definitions may need to be expanded.\n", BlkNm); ssSetIWorkValue(S,Er3,1); } Cpb = Rb*gamb*divby(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 = sqrtT(2*divby(gamb-1)*(powT(Pe*divby(PtmfpIn), (1-gamb)*divby(gamb))-1)); Tcr_o_Te = (2*divby(gamb+1))*(1 + 0.5*(gamb-1)*Me*Me); Ae_o_Acr = powT(Tcr_o_Te, (gamb+1)*divby(2*(gamb-1)))*divby(Me); /* obtain throat to critical area ratio */ Ath_o_Acr = Ae_o_Acr*Ath*divby(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*divby(gamb+1))*(1 + 0.5*(gamb-1)*Mth0*Mth0); Tcr_o_Tth1 = (2*divby(gamb+1))*(1 + 0.5*(gamb-1)*Mth1*Mth1); Ath_o_Acr0 = powT(Tcr_o_Tth0, (gamb+1)*divby(2*(gamb-1)))*divby(Mth0); Ath_o_Acr1 = powT(Tcr_o_Tth1, (gamb+1)*divby(2*(gamb-1)))*divby(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)*divby(err0 - err1); if (Mth > 1.0) Mth = 1.0; /* compute error to drive solution towards specified area ratio */ Tcr_o_Tth_it = (2*divby(gamb+1))*(1 + 0.5*(gamb-1)*Mth*Mth); Ath_o_Acr_it = powT(Tcr_o_Tth_it, (gamb+1)*divby(2*(gamb-1)))*divby(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*divby(gamb+1); Tth_o_T0 = 1*divby(1 + 0.5*(gamb-1)*Mth*Mth); if (Tth_o_T0 < Tcr_o_T0) Tth_o_T0 = Tcr_o_T0; Tth = TtmfpIn*Tth_o_T0; Pth = PtmfpIn*powT(Tth_o_T0, gamb*divby(gamb-1)); /* recompute the actual flow rate, assume no pressure loss */ rhoth = Pth*144*divby(Rb*JOULES_CONST*Tth); /* [lb/ft^3] */ Vth = sqrtT(2*Cpb*C_GRAVITY*JOULES_CONST*(TtmfpIn - Tth)); /* [ft/s] */ Wth = rhoth*Ath/144*Vth; /* [lb/s] */ Mth = Vth*divby(sqrtT(gamb*Rb*C_GRAVITY*JOULES_CONST*Tth)); } else { Wth = 0; Mth = 0; } WthOut = Wth; Test = Vth; /*------Assign output values------------*/ y[0] = WthOut; /* Valve throat flow [pps] */ y[1] = MthOut; /* Mach no. at throat */ y[2] = Test; /* Output Test Point */ }