S-Fuction Steam mixer design: How to use m-function in a C code
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maliha
am 24 Okt. 2014
Kommentiert: Maliha
am 2 Nov. 2014
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
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!