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.
Related
I was trying to compare the performance of a microgrid between Simulink and Openmodelica. The microgrid has different VSC converters working in EMT average, synchronous generators, loads, lines and buses and the model obtains quite logical results, the problem is that when the same model is created with OpenModelica, the following error is obtained with DASSL solver and a step size of 2e-5 s:enter image description here . Also, the libraries used are Dynawo and the standard Modelica library. Does anybody knows what this error means and how can it be solved? If anybody wants to see the models or needs more information I could send it.
Thanks!
I tried to simplify the model the much as possible, using simple control techniques for the VSCs (no droops or LVRT) in Simulink and Modelica and I confirmed that the same values are used in both models. Also, I changed the tolerance, the step size and the solver.
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.
I used system identification tool to obtain a state space (order 2) and a process model (2 inputs, 1 output, 2nd order transfer function + delay each) of some data. The models show very nice fit to experimental data in the system identification model output window [Figure 1] but when I use the idmodel block in simulink to simulate the same data it does not look at all like it was on the tool.
I have used exactly the same block diagram with both fitted models. With the state-space fitted model the results are coherent with the system identification tool [Figures 2-3], meanwhile the process model it's totally different [Figures 4-5].
The state-space model only works well with certain experimental conditions, while the process model gives a good fit for all my experiments, that's the reason why I try to use it. The pictures below correspond to only 1 experiment.
I think the problem resides in that I can't set initial conditions to the idmodel block when using a process model instead of a state space model. I can get the initial conditions for the process model using findstates(model, data), but I don't know how to apply them. Any hints on how to set initial conditions for identified transfer function/process models in simulink? Maybe a possible workaround without simulink? I'm open to any solution or ideas.
Thank you.
Figure 1. System identification tool output for both state-space and process model
Figure 2. Simulink output of state-space model
Figure 3. idmodel block with state-space model: initial conditions parameter available
Figure 4. idmodel block with process model: initial conditions parameter NOT available
Figure 5. Simulink output of state-space model
After reaching matlab central and pointing me in the right direction I came up with a solution. Thanks to Rajiv Singh.
I first needed to convert the process model from idproc to idss using idss() instead of ss() -See this article-, then use compare() instead of findstates() to obtain the initial conditions and feed the initial conditions to the idmodel block in simulink. Graphically:
model=idss(T3s_2d);
[y,fit,x0]=compare(run_data_s{8}, model);
%T3s_2d is the identified process model (idproc) from system identification toolbox
%run_data_s is the iddata object with the experimental runs
I build a Modelica model, but when checking the model (Here is the model download link), it shows a local singularity like in the following screenshot.
so I delete the code showed in the error message.
h[3]=(hout+hl)/2
but although the model checks fine, there is a strong nonlinearity issue which causes the initialization failure.
So I try to delete the following code line:
h[1]=(hin+hv)/2
and the model not only checks but also there is no initialization issue.
My questions are:
When debugging the model singularity, the error message showed by Dymola might be not the singularity source of the model? Is there a general method to find the source of the singularity problem? Or I have to analyze the equations in the model manually?
How to minimize the nonlinearity of the Modelica model and ensure convergence? I found this problem exists in many fields, especially in the thermo-hydraulic models, I found that one way to deal with this problem is the way used in Thermao Power Library from Modelon and ThermoSysPro for EDF, these two libraries divide the models or connector into two types: flow and volume. To ensure convergence, it requires to use a staggered grid scheme like in the following screenshot.
So is there another method to deal with the nonlinearity problem in thermo-hydraulic models?
is there a common view on how to deal with the nonlinearity problem in thermo-hydraulic models?
Is there an alternative function to the sim() command oder a direct way executing a Simulink Model / a compiled version of it from Matlab without setting coder.extrinsic?
I want to execute a simulink model inside of an iterative Matlab-function. (Hence, speed matters dramatically). The used Simulink model contains a Dymola interface and hence, I cannot model it directly in Matlab. Another main Simulink model starts and iterates the Matlab functions and hence, simulating it leads the coder trying to compile it efficiently. By setting coder.extrinsic, of course I can use the sim command, but it is way too slow for its purpose. I thought about compiling the Simulink model as an alternative, but do not know if this would be a good approach
The structure looks as follows:
Simulink main model -> matlab functions -> simulink model
sim command needs MATLAB. So you need coder.extrinsic. There is no direct alternate way without coder.extrinsic to simulate a model. You can generate code from the model and call the generate code using coder.ceval functions. But if your goal is only to get more speed instead of getting stand-alone code you can set your model to run in accelerator mode and see whether that improves speed.