Problem when two Simulink models are combined.

Hi everyone,
I developped in MATLAB 2019a version, separately, two Simulink models.
They work perfectly when they are run separately.
The simulation using one of the models is very fast and the simulation using the other model is very slow but both simulations run perfectely during the simulation time which is the same for the two models.
Both of the models are configured to run with an Automatic solver selection of a solver of the Fixed-step type and a fixed step size set to Auto.
The problems start when I copy one of the models into the other model and try to run the obtained combined model: Even without connecting the inputs and the outputs of the two models the simulation is failing: it runs for a fraction of a second and then stops with the error:
An error occurred while running the simulation and the simulation was terminated
Caused by:
During one of the attempts to solve the problem I have used the Rate transition block to connects the inputs and the outputs of the two models but it did not solve the problem.
Please, can anyone help with this problem???
Every little hint is welcome.
Thank you very much in advance.

回答(1 个)

In the two separate models, can you run simulation and log the time? Take a look at the resulting fixed-step size. Do the same for the combined model. That might give a clue.
Some times a bigger-than-appropriate step size could cause the simulation unstable (causing nan). Knowing the step size for all above three scenerio, you could duplicate the error in one of the separate modles by specifying the step size. Then you can take a look at the response and figure out a way.

8 个评论

Hi Fangjun Jiang,
Thank you so much for your answer.
As I have said in the first posting of the question, both models are configured to run with an Automatic solver selection of a solver of the Fixed-step type and a fixed step size set to Auto and the simulation time is equal to 1050s.
I did exactly what you have said:
The sample time of the fast model is 21s.
The sample time of the slow model is 0.001s.
In my combined model I copied the slow model inside the the fast model and I found out that the sample time used by Simulink in the combined model is 0.001s.
Note: ( when the models are run Separately)
*When the fast model fixed step size is changed from Auto to 0.001s the simulation does not work.
*When the slow model fixed step size is changed from Auto to 21s the simulation does not work.
I think this is the cause of the problem: the two models, separately, have different sample times and when they are combined the new sample time automatically choosen by Simulink (0.001s) is convenient for the slow model but not for the fast model.
Many thanks.
Use function-call triggered subsystem to wrap these two subsystems and put them together. Use function-call generator to specify the rate as 0.001 and 20 second.
Hi Fangjun Jiang,
I am very sorry for my late reply to your posting, but I just have had time to try what you said today.
I have built the new combined model according to your guidance (please see the attached image).
Capture.PNG
I have set the value of the sample time in the function call generator of subsystem 1 to 0.001s and the value of the sample time in the function call generator of subsystem 2 to 21s.
When I run the simulation I had the error below:
Derivative has sample time 0. Only constant (inf) or inherited (-1) sample times are allowed in function call subsystem 1.
It seems that I have to find another way.
Many thanks.
That means that you need to make some changes inside the function-call triggered subsystems. You can't specify any sample time other than inf (for constant) and -1 (for inherited).
Sample time of 0 means continuous. I thought your original model runs at a fixed step size. You need to discretize that "Derivative" (with sample time as 0) block.
Hi Fangjun Jiang,
Thank you a lot for your reply.
The sample times 0.001s and 21s are just the sample times used automatically by Simulink when each model is run separately.
I knew these 2 values of the sample times of each model only by logging some of the signals in each model.
But in terms of the blocks used inside each model, I have too many many blocks and their sample times are set to different values: For example in the slow model, some blocks have the sample time -1 (inherited), some blocks have the sample time 0.001s.
The point is that now the two subsystems are triggered by functioncall generators (one at 0.001s and the other at 21s), then there shouldn't be any other sample times inside the two subsystems (other than inf or -1).
Hi Fangjun Jiang,
Okay, I will try to check all the blocks of the models.
If each model can work separately with the new setting of the sample times of all its blocks, then I will try again your plan with the function-call triggered subsystems.
I will let you know about the outcome, I just need time to check all the sample times of all the blocks in the 2 models.
Many thanks for your continuous support.
Hi, did you get hepl on this? I need your assistance.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Modeling 的更多信息

产品

版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by