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.

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

One way I can think of is to use SimState. You can let the model with faster run at sample time of 21s. You can make the simulation stop at a certain point and take a snapshot of the relevant data. Once the other model reaches the desired point, you can restart the simulation for this model using the snapshot.
You can read more about it using this link:
Hi Archit Dhanani,
Thank you for your comment.
I just want to remind you that the 2 models have 2 variables calculated and exchanged between them during the whole duration of the simulation time. (The variables NE and PTQ, see the attached images of the overviews of Model 1 and Model 2)
Model 1.PNG
Model 2.PNG
Model 1 is the model with slow execution time: sample time = 0.001s.
Model 2 is the model with fast execution time: sample time = 21s.
So, as far as ı understood from your comment I have to run the fast model (Model 2) and to stop the simulation at a certain time in order to take the snapshot.
The problem is that Model 2 can not run alone, it must run in parallel with the slow model (Model 1), because Model 2 uses variables calculated in Model 1( Variables NE and PTQ in the attached images of the models).
So if I try to run the 2 models in parallel in order to take a snapshot of the fast model (Model 2), the values of the data taken will not be correct because if I stop the fast model at any time, always the value of that simulation time will be far more than the value of the simulation time that the slow model (Model 1) has reached.
If my understanding is incorrect, please give more clarifications.
Thank you again.
Instead of complicating things by using MATLAB function blocks and data store to transmit data between two blocks running at different rates, have you tried using Rate Transition block?
Yes,I have used rate transition block. It did not work.
Can you elaborate why it did not work or what errors you got? I am asking this because I have used rate transition blocks for similar cases and it has worked.
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.
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
@ 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)

Categories

Products

Release

R2019a

Asked:

on 23 Jul 2019

Commented:

Raj
on 26 Jul 2019

Community Treasure Hunt

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

Start Hunting!