2
votes

I have a model with some inputs that are fed into a CMEX S-Function via the Memory block, and the S-Function provides outputs based on these inputs, and those inputs are fed back into the S-Function. Classic algebraic loop scenario. I was using a memory block to prevent this because our solver is usually variable-time step

According to the Mathworks documentation the Memory Block, and the Unit Delay block also, are fixed in minor time step in terms of their outputs. I realize that the inputs can be either discrete or continuous, but the output will only be continuous in the major time step, and fixed in the minor one.

Now, for various reasons, it is important to us that everything in the model get updated in the minor and major time steps. I came up with a way of using the PWork vector to store the previous value of state points and forward them to the CMEX S-Function that we use. This prevents algebraic loops from occuring and also ensures continuous in minor time step, but is not as elegant as I would like.

Does anyone have any alternative suggestions?

PS: As an aside, I believe that it is better to use the Memory block regardless of if my solver is Fixed Step or Variable Step, because it will internally just become a Unit Delay block for Fixed Step solvers. Is this assumption correct?

1
NOTE: Since asking this question, I have spoken to engineers at Mathworks, who have informed me that it is not possible to have an alternative that isn't fixed in the minor time step. We tried a range of options: using mdlUpdate to update values (however, it gets called only in the major steps), creating our own s-function that imitates the memory block, but in the minor time step (simulink does not give access to us to update the imitation-block's states in the minor steps). In the end, it was concluded that we have to live with this inconvenience.user2215426

1 Answers

0
votes

According to this article, using fast-response transfer function may achieve similar result without going into minor step.