Unknown error using DWork Vector
古いコメントを表示
Hi,
I get an error for using DWork vector. The error occurs when I run the simulink model second time. Running for the first time goes smooth but when I run again, Matlab just shuts down. I suspected it to be some memory management problem. Can you give me an advice to make it better. I put the part of the code below where DWork Vectors are defined and used. The complete codes are also attached.
...
#define NDWORKS 3
// DWork 1
#define DWORK_0_NAME combState
#define DWORK_0_WIDTH 1
#define DWORK_0_DTYPE real_T
#define DWORK_0_COMPLEX COMPLEX_NO
// DWork 2
#define DWORK_1_NAME phiIg
#define DWORK_1_WIDTH 1
#define DWORK_1_DTYPE real_T
#define DWORK_1_COMPLEX COMPLEX_NO
// DWork 3
#define DWORK_2_NAME mqf
#define DWORK_2_WIDTH 1
#define DWORK_2_DTYPE real_T
#define DWORK_2_COMPLEX COMPLEX_NO
static void mdlInitializeSizes(SimStruct *S)
{
...
/*initialzation of sizes related to DWork Vectors*/
ssSetNumDWork(S,NDWORKS);
/*DWork vector 1*/
ssSetDWorkWidth(S, 0, DWORK_0_WIDTH);
ssSetDWorkDataType(S, 0, SS_DOUBLE);
/*DWork vector 2*/
ssSetDWorkWidth(S, 1, DWORK_1_WIDTH);
ssSetDWorkDataType(S, 1, SS_DOUBLE);
/*DWork vector 3*/
ssSetDWorkWidth(S, 2, DWORK_2_WIDTH);
ssSetDWorkDataType(S, 2, SS_DOUBLE);
...
}
...
static void mdlInitializeConditions(SimStruct *S)
{
#define MDL_INITIALIZE_CONDITIONS
/* Function: mdlInitializeConditions ============================
* Abstract:
* Initialize both continuous states to zero
*/
real_T *x1 = (real_T*) ssGetDWork(S,0);
real_T *x2 = (real_T*) ssGetDWork(S,1);
real_T *x3 = (real_T*) ssGetDWork(S,2);
/* Initialize the dwork to 0 */
x1[0] = 0; // combustion state
x2[0] = 0; // ignition delay
x3[0] = 0; // mass of fuel injected
}
...
static void mdlOutputs(SimStruct *S, int_T tid)
{
const real_T *phi = (const real_T*) ssGetInputPortSignal(S,0);
const real_T *phiInj = (const real_T*) ssGetInputPortSignal(S,1);
const real_T *uGov = (const real_T*) ssGetInputPortSignal(S,2);
const real_T *omega = (const real_T*) ssGetInputPortSignal(S,3);
const real_T *p = (const real_T*) ssGetInputPortSignal(S,4);
const real_T *temp = (const real_T*) ssGetInputPortSignal(S,5);
real_T *combStateO = (real_T *)ssGetOutputPortRealSignal(S,0);
real_T *phiComb = (real_T *)ssGetOutputPortRealSignal(S,1);
real_T *phiIgO = (real_T *)ssGetOutputPortRealSignal(S,2);
real_T *mqfO = (real_T *)ssGetOutputPortRealSignal(S,3);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const int_T p_width1 = mxGetNumberOfElements(PARAM_DEF1(S));
const real_T *mqfCycMax = (const real_T *)mxGetData(PARAM_DEF0(S));
const real_T *wiebePara = (const real_T *)mxGetData(PARAM_DEF1(S));
const real_T *combState = (const real_T*) ssGetDWork(S,0);
const real_T *phiIg = (const real_T*) ssGetDWork(S,1);
const real_T *mqf = (const real_T*) ssGetDWork(S,2);
combState_Outputs_wrapper(phi, phiInj, uGov, omega, temp, p, combState,
phiIg, mqf, combStateO, phiComb, phiIgO, mqfO, mqfCycMax,
p_width0, wiebePara, p_width1);
}
...
static void mdlUpdate(SimStruct *S, int_T tid)
{
const real_T *phi = (const real_T*) ssGetInputPortSignal(S,0);
const real_T *phiInj = (const real_T*) ssGetInputPortSignal(S,1);
const real_T *uGov = (const real_T*) ssGetInputPortSignal(S,2);
const real_T *omega = (const real_T*) ssGetInputPortSignal(S,3);
const real_T *p = (const real_T*) ssGetInputPortSignal(S,4);
const real_T *temp = (const real_T*) ssGetInputPortSignal(S,5);
const real_T *combStateO = (const real_T *)ssGetOutputPortRealSignal(S,0);
const real_T *phiComb = (const real_T *)ssGetOutputPortRealSignal(S,1);
const real_T *phiIgO = (const real_T *)ssGetOutputPortRealSignal(S,2);
const real_T *mqfO = (const real_T *)ssGetOutputPortRealSignal(S,3);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const int_T p_width1 = mxGetNumberOfElements(PARAM_DEF1(S));
const real_T *mqfCycMax = (const real_T *)mxGetData(PARAM_DEF0(S));
const real_T *wiebePara = (const real_T *)mxGetData(PARAM_DEF1(S));
real_T *combState = (real_T*) ssGetDWork(S,0);
real_T *phiIg = (real_T*) ssGetDWork(S,1);
real_T *mqf = (real_T*) ssGetDWork(S,2);
/*
combState_Update_wrapper(phi, phiInj, uGov, omega, temp, p, combState,
phiIg, mqf, combStateO, phiComb, phiIgO, mqfO, mqfCycMax,
p_width0, wiebePara, p_width1);
*/
*combState = *combStateO;
*mqf = *mqfO;
*phiIg = *phiIgO;
}
...
1 件のコメント
Geoff Hayes
2014 年 7 月 26 日
Koosup - Please include the error message that you observe from the second run of the model.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Configure C/C++ S-Function Features についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!