MATLAB error handling of SIMULINK (sim) due to external component - matlab

My problem is that I am running a sweep study with some parameters. I change them in MATLAB and then run a simulation in MATLAB with the sim command. The simulation in SIMULINK contains an external software component from COMSOL with an FEM behind it. In some cases where the configuration is unfavorable (rapid changes in the feedback loop of the controlled system), the FEM tool is not able to converge in finite time, resulting in an error after a few simulation seconds/minutes/hours. The simulation command is inside a try-catch section to avoid that the program is stopped and the next study step starts to process the acquired data.
The problem is that in case the simulation has a convergence problem, the data generated up to this error is not sent to the workspace, but would be valid, and so I cannot find out from the data what was the reason for the convergence problem.
As additional information, I have been using the ToWorkspace block to send the data to my workspace where I do my post processing, and that works fine when the simulation is complete.
If any of you have any ideas on how to solve this problem, maybe you can help me.
Thank you in advance.

Related

Challenges faced in resolving Algebraic Loops in SIMULINK models

Problem Faced:
I have a SIMULINK model that has got two algebraic loops.
In order to overcome this I have set the model configuration properties as "warning".
The model runs well and has got the expected dynamics as shown in below image.
enter image description here
Now I need to convert this model to .exe which will be accessed by a GUI.
In order to do so I have to break this algebraic loop by using a unit delay block else the build process does not execute EVEN IF the configuration properties of the simulation model has been set to "none/warning".
But in the process of using a unit delay block, entire dynamics of the solution changes which shows that its a numerical error as shown in below image..
enter image description here
I request, somebody please suggest a suitable solution in dissolving this algebraic loop error without changing the dynamics of the model.
In many situations Simulink is capable of solving algebraic loops and provide a solution, but it can not generate code (see "Implications of Algebraic Loops in a Model" at the end). If I assume your implicit goal of creating an exe is to run it on systems without Simulink, that is not possible.

How to speed up simulation of Simscape based Physical model?

I am working on modeling and controlling of a hydraulic system. Modeling of the system is modeled in Matlab simscape in simulink environment which is looks like this
and for basic controlling to control the piston position (Piston Pos in figure) I have established simple feedback to check the position.
While I run the simulation when this comes to control the position Simulation takes too much time. For example if I gave desired piston position 300 mm than while output comes to around 290-294 mm simulation time reaches at around 5.18sec than it is stuck on that for longer time.
I want to know that, is there any way to speed up the simulation ?
I am using Matlab simulink solver ode23t due to simscape modeling.
Speeding up simulations in general is vast subject. It seems the issue here is an event which triggers multiple small time-step in the variable step solver.
This can be perfectly normal, for example a clutch engaging, or a valve opening.
To check whether or nor this is the case you can execute (make sure time-logging is enabled):
semilogy(tout(2:end), diff(tout))
Sharp downward spikes indicate small time-steps were taken. For a more in-depth analysis you can use the Solver Profiler:
https://www.mathworks.com/help/simulink/ug/examine-solver-behavior-using-solver-profiler.html
This will give you detailed information as to which components are causing solver resets.
Such behavior can be difficult to debug if you're not used to the tool. I'd highly recommend getting in touch with MathWorks tech support if the behavior persists. They'll be able to look at your model and diagnose the issue.

a nonstop Running of my Simulink model

In order to plot the Eb/N0 versus BER performance of my model Simulink and bring out the output (which is a vector of bits) from simulink to workspace, I need to the complete simulation of my model. But, the simulation doesn't stop, it runs hours und hours without stop. Actually, I haven't unterstand this problem as a beginner in Matlab-simulink. But, I am quiet sure that I need to see the end of my work to be able to analyse the performance and then correct if there is a problem.
Thanks in advance
This might be what you want to access data during simulation:
http://www.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html

Where does Simulink start execution from?

I believe that it is possible to transfer MATLAB codes to Simulink. When we program in MATLAB, I know that it will execute from top to bottom line by line. On the other hand, Simulink deals with blocks that are connected to each others. There might be feedback signals. There might be subsystems whose outputs are inputs to other blocks and so on...Suppose we have 3 subsystem blocks connected to each other and the last block's output is fed into the first, which block does Simulink start with?
My question might be a foolish one especially after this long of playing with MATLAB and Simulink but I've not come to know the answer for this yet!
This depends on the actual simulation model. Before the simulation starts, Simulink analyzes the model (which blocks are connected in which direction, are there algebraic loops, etc.). The result is the so-called sorted order of the blocks, which is then used to actually execute the blocks' code.
See the documentation for details.

Plotting in Matlab using Real Time data from Simulink

I'm trying to solve a problem of simulating in real time in Simulink (This is solved) but plotting (real time) in Matlab ?
Details:
I want to be able to run a Simulink simulation (which is running in real time) and be able to turn on / off manual switches while the simulation is happening. This works well when I'm using the built in Scopes in Simulink but now I want to export that data to Matlab in real time as well (To make a custom looking graph).
So is there a way, to export this data (it can be sampled if that is necessary) to Matlab and make a plot that is constantly updating. Meanwhile I can still manipulate the switches in Simulink and influence the simulation manually ?
Simulink is effectively running continuously until I stop it.
Thanks for the help!
There should be some kind of notification going when simulink updates the data to be visualized. Maybe this is the linkdata feature.
Another, worse, solution is the drawnow command to redraw the graphs continously (the latter could be unnescessary costly for you program).