S-Fuction Steam mixer design: How to use m-function in a C code

조회 수: 4 (최근 30일)
Maliha
Maliha 2014년 10월 24일
댓글: Maliha 2014년 11월 2일
Hi, for my project I have to design this mixer in S-function, and the primary code is below. Problem is for this I need to use the XSteam.m function to get the enthalpy. How do I do that? Any kind of help would be appreciated. Also let me know if i can improve the code in any way
#define S_FUNCTION_NAME MMM #define S_FUNCTION_LEVEL 2
/* * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ #include "simstruc.h" #include stdio.h #include math.h
/*====================* * S-function methods ====================*/
static void mdlInitializeSizes(SimStruct *S) {
ssSetNumSFcnParams(S, 1); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 5)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 2)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
/* Specify the sim state compliance to be same as a built-in block */
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, 0);
}
static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */ #if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif /* MDL_INITIALIZE_CONDITIONS */
#define MDL_START /* Change to #undef to remove function */ #if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
}
#endif /* MDL_START */
static void mdlOutputs(SimStruct S, int_T tid) { double *Mpgin = ( double)ssGetInputPortRealSignal(S,0); double Tpgin = ( double)ssGetInputPortSignal(S,1); double Mis = (double)ssGetInputPortSignal(S,2); double Tis = (double)ssGetInputPortSignal(S,3); double Ppg = ( double)ssGetInputPortSignal(S,4); double *Mpgout = ssGetOutputPortSignal(S,0); double *Tpgout = ssGetOutputPortSignal(S,1);
double Hpgin, Qpgin, His, Qis, Qpgout, Hpgout;
Mpgout[0] = Mpgin[0]+ Mis[0];
Hpgin = XSteam('h_pt',Ppg[0],Tpgin[0]);
Qpgin = Hpgin*Mpgin[0];
His = XSteam('h_pt',Ppg[0],Tis[0]);
Qis = His*Mis[0];
Qpgout = Qis + Qpgin;
Hpgout = Qpgout/Mpgout[0];
*Tpgout = XSteam('t_ph',Ppg[0],Hpgout) ;
}
#define MDL_UPDATE /* Change to #undef to remove function */ #if defined(MDL_UPDATE)
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif /* MDL_UPDATE */
#define MDL_DERIVATIVES /* Change to #undef to remove function */ #if defined(MDL_DERIVATIVES)
static void mdlDerivatives(SimStruct *S)
{
}
#endif /* MDL_DERIVATIVES */
*/
static void mdlTerminate(SimStruct *S)
{
}
/*======================================================* * See sfuntmpl_doc.c for the optional S-function methods ======================================================*/
/*=============================* * Required S-function trailer =============================*/
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? / #include "simulink.c" / MEX-file interface mechanism / #else #include "cg_sfun.h" / Code generation registration function */ #endif

채택된 답변

Kaustubha Govind
Kaustubha Govind 2014년 11월 2일
  댓글 수: 1
Maliha
Maliha 2014년 11월 2일
thanks, I solved the problem on my own. Now I am having issues with another code. Help will be appreciated :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by