MATLAB Answers

How to make 2 different models running in parallel to be executed at the same speed from the beginning to the end of the simulation.

7 views (last 30 days)
kamal kiki
kamal kiki on 23 Jul 2019
Commented: Raj on 26 Jul 2019
Hi everyone,
I have 2 Simulink models.
Both models run with Automatic solver selction and a solver of the Fixed step type and a Fixed-step size set to Auto.
Both models have the same simulation stop time equal to: 1050s.
The sample time used by Simulink with the 1st model when it is run separately is: 0.001s (so this model is executed very slowly).
The sample time used by Simulink with the 2nd model when it is run separately is: 21s (so this model is executed very quickly).
I managed to use Data Store Memory and MATLAB Function blocks to run the two models at the same time (in parallel) in order to exchange some variables calculated betweeen the two models.
The problem is that after starting both models at the same time the model with sample time equal to 21s executes very quickly and stops but the other model with sample time equal to 0.001s continues running.
I know that all this is normal given the different sample times of the two models but I am wondering whether there is a way to make the two models have the same length of the execution time (fast or slow) so that the data exchanged betweeen the two models is correct during the whole simulation time.
Note:
The 1st model can not run successfully when its sample time is set to 21s.
The 2nd model can not run successfully when its sample time is set to 0.001s.
Every little tip is welcome.
Many thanks to all the contributors of MATLAB Central.

  8 Comments

Show 5 older comments
kamal kiki
kamal kiki on 25 Jul 2019
Hi Raj,
Thanks a lot for your follow up to my question.
Here is what I did to try the Rate Transition block:
I copied the two plants (Plant 1 from Model 1, and Plant 2 from Model 2) in a single Combined Model.
The Combined Model solver has the following setting:
*Solver type: Fixed step
*Solver: Automatic Solver Selection
*Solver Fixed-step size: Auto
*simulation stop time: 1050s.
Please see the attached image for an overview of the Combined Model.
Combined Model.PNG
In the block Rate Transition 1 I set the Output port sample time to: 21
In the block Rate Transition 2 I set the Output port sample time to: 0.001
When I run the simulation of the Combined Model all the values of the variables of the model reached very high values and I had the error message below:
Evaluation of expression resulted in an invalid output. Only finite double vector or matrix outputs are supported
I have the same error when I try to run Plant 2 separately with a fixed step size of 0.001.
But, separately, Plant 2 can run successfully when the fixed step size of its solver is set to Auto or 21.
Archit Dhanani
Archit Dhanani on 25 Jul 2019
Hi Kamal,
The issue seems to be else where. Here is a similar model below. Const1 is set to sample time = 0.001 and Const2 = 21. You can check the legend to see the rates for all the blocks. I used the same solver settings. The model works fine. (The atomic subsystems just adds the two numbers.)
answers1.png
Raj
Raj on 26 Jul 2019
@ kamal kiki "all the values of the variables of the model reached very high values" - Since the model is running, it means the rate transition block is doing its job. Model becoming unstable maybe a sign of design issues. Individual systems can run perfectly without any issues but combining them creates a totally new system with its own characteristics.

Sign in to comment.

Answers (0)


Translated by