Recurring Error in Simulation

8 visualizaciones (últimos 30 días)
Annika Michel
Annika Michel el 27 de Jun. de 2024
Respondida: Umar el 1 de Jul. de 2024
So, I have a fairly complicated Simulink Model which run again and again, to generate different outputs. This has worked fine for several weeks, and now suddenly I have this Error. I didn't change anything in the model, only a random variable definition in the matlab script which initiates the simulation. The variable is not used in the model.
I was able to get the Model to run once by closing the window, reopening it and reloading some variables, but upon a second unaltered simulation it crashed again. The Error message I get is the following:
Error:An error occurred while running the simulation and the simulation was terminated
Caused by:
['My Model/Solver Configuration3']: Transient initialization at time 3.116414621485137e-05, solving for consistent states and modes, failed to converge.
Nonlinear solver: failed to converge, residual norm too large.
Here is the set of components with unconverged equations:
'My Model/Transmission Line3' % an ideal transmission line
Equation location is:
'C:\Program Files\MATLAB\R2023b\toolbox\physmod\elec\library\m\+ee\+passive\+lines\ideal_transmission_line.sscp'(no line number info)
'My Model/Simscape Component1' % this is a component I made myself by copying the Capacitor component and allowing negative capacitances
Equation location is:
'\\My Path\+NegativeCapacitor\NegativeCapacitor.ssc' (line 29)
Equation location is:
'\\My Path\+NegativeCapacitor\NegativeCapacitor.ssc' (line 29)
'My Model/Simscape Component' % same negative Capacitor
Equation location is:
'\\My Path\+NegativeCapacitor\NegativeCapacitor.ssc' (line 29)
Equation location is:
'\\My Path\+NegativeCapacitor\NegativeCapacitor.ssc' (line 29)
'My Model/Resistor3' % random resistor 1 Ohm
Equation location is:
'C:\Program Files\MATLAB\R2023b\toolbox\physmod\simscape\library\m\+foundation\+electrical\branch.ssc' (line 23)
'My Model/Resistor5' % random resistor ca 120 Ohm
Equation location is:
'C:\Program Files\MATLAB\R2023b\toolbox\physmod\simscape\library\m\+foundation\+electrical\branch.ssc' (line 23)
I've encountered this error several times before, the last time several months ago, but could so far avoid it by reloading previous versions of the file, or closing and opening again. My usual strategies aren't working this time and I'd like to know why this error occurs so I can fix it once and for all.
A similar question suggested checking for algebraic loops, but the Code
Simulink.BlockDiagram.getAlgebraicLoops('My Model')
did not find any algebraic loops.
I'm using Automatic Solver Selection with Variable Step. My model is pretty idealized, so abrupt jumps occur, however this has not been an issue in the past and I don't understand why it would be now, if this is why the error occurs (this has been suggested in another answer to a similar question). I have found that after a few microseconds the current in my circuit jumps to about 10^300, which is where the simulation stops, understandably. I just don't understand why the current would suddenly jump so high and why at that moment.
If anyone has any ideas on what is causing this error and how to fix it, I would greatly appreciate the help.

Respuesta aceptada

Umar
Umar el 27 de Jun. de 2024
Hi Annika,
To troubleshoot, check the component equations for inconsistencies, ensure proper initialization values, and verify the model's stability. Review the custom Simscape components for any unconventional behavior causing abrupt changes. Consider refining the solver settings or adjusting component parameters to prevent sudden spikes in values. Debugging the model step by step and monitoring key variables can help pinpoint the root cause of the convergence problem and facilitate a solution.
Hope this will help resolve your issue.
  3 comentarios
Umar
Umar el 27 de Jun. de 2024
Also, another issue lies in the line where the capacitance parameter is defined as C = { 1, 'F' };. The value of the capacitance is set to 1 Farad, which might lead to numerical instability during the simulation, especially when the frequency of operation is high. To address the bug and improve the stability of the simulation, it is recommended to adjust the initial capacitance value to a more reasonable value. You can modify the capacitance parameter initialization as follows:
C = { 1e-6, 'F' }; % Set the initial capacitance to 1 microfarad
By setting the initial capacitance to a smaller value (1 microfarad in this case), the simulation is less likely to encounter numerical issues, especially at higher frequencies.
Step by Step guidance
Step by Step:
Save the text from NegativeCapacitor.txt as a .ssc file.
Create a folder named +NegativeCapacitor and place the .ssc file and the corresponding .jpg file in it.
Add the folder to the Matlab path.
Run InitFunc.m to initialize the necessary functions and variables.
Define the frequency variable by executing freqHz = 200000; in the Matlab console.
Experiment with different frequency values between 1e5 and 1e6 to observe the system behavior.
Run the simulation to analyze the performance of the NegativeCapacitor component at the specified frequency.
By following these steps and adjusting the initial capacitance value, you can enhance the stability and accuracy of the simulation process in Matlab.
Annika Michel
Annika Michel el 1 de Jul. de 2024
First of all, thanks for your answer! I'm going a little crazy with this and I'm very glad your trying to help.
You wrote above that I could try adjusting the solver settings. What settings would you recommend? I have tried lowering the max step time, however this didn't fix the issue and the simulation got of course much slower. I don't know the Solvers well enough to know how they differ, so if you can recommend one that is better than the auto selection, I would be glad to know.
As for the variables in the block parameters: Those all check out. I've checked them, and again, this exact simulation ran like this for months with these exact parameters. I don't know where you see a capacitance defined as 1F, in my model all capacitances are of the order 1e-8F or lower. My custom component is of course a bit of a wildcard, but since I literally changed only "C>0" to "abs(C>0)" in the capacitor for this I don't think it is the source of the issue. Again, I have been using this simulation in this form for months and never had an issue.
I may try upgrading to 2024a and see if that helps, if you have any specific advice beyond "check everything again" I'd be glad to hear it.
Thanks again for your answer!

Iniciar sesión para comentar.

Más respuestas (2)

Umar
Umar el 1 de Jul. de 2024
Hi Annika,
No problem, so I will try to tackle your questions by providing solutions to them to best of my knowledge. So, your first question was
What settings would you recommend? I have tried lowering the max step time, however this didn't fix the issue and the simulation got of course much slower. I don't know the Solvers well enough to know how they differ, so if you can recommend one that is better than the auto selection, I would be glad to know.
In my opinion, default solver selection is usually reliable, but for specific cases, manual selection might be beneficial. Here are some common solvers and their characteristics:
ode45: A good general-purpose solver for non-stiff problems. ode15s: Ideal for stiff systems where fast transients are present. ode23: Balances efficiency and accuracy for medium-sized problems. You can manually select a solver using the odeset function. For instance:
options = odeset('RelTol',1e-5,'AbsTol',1e-8); [t,y] = ode45(@odefun,tspan,y0,options);
As for the variables in the block parameters: Those all check out. I've checked them, and again, this exact simulation ran like this for months with these exact parameters. I don't know where you see a capacitance defined as 1F, in my model all capacitances are of the order 1e-8F or lower. My custom component is of course a bit of a wildcard, but since I literally changed only "C>0" to "abs(C>0)" in the capacitor for this I don't think it is the source of the issue. Again, I have been using this simulation in this form for months and never had an issue.
If you suspect a custom component might be causing the issue, it's essential to scrutinize its implementation. Verify the changes made, especially the alteration from "C>0" to "abs(C>0)" in the capacitor. Ensure that this modification aligns with the expected behavior and doesn't introduce unintended consequences.
I may try upgrading to 2024a and see if that helps, if you have any specific advice beyond "check everything again" I'd be glad to hear it.
That is a valid option because newer versions often come with bug fixes and performance enhancements. Before upgrading, ensure compatibility with your existing codebase and any specific features you rely on.
While you have validated the parameters and settings, a systematic troubleshooting approach can help pinpoint the root cause. Check for any recent changes, unexpected interactions, or boundary conditions that might have been overlooked.
Let me know if I can assist further.
  1 comentario
Annika Michel
Annika Michel el 1 de Jul. de 2024
Thanks for your help! I saved all the workspace variables in a working iteration and then with the error and compared them one by one. And I found my mistake. I was accidentally using a variable name twice, so I overwrote a gain value with a much higher number. This explains why I suddenly had an incredibly high current, and also why it worked when I ran the model outside of my iterating code.
So yeah, my mistake and thanks for your help :D I am an idiot.

Iniciar sesión para comentar.


Umar
Umar el 1 de Jul. de 2024
Hi Annika,
Glad to help out. People make mistakes but when we work as a team together, problems get resolved. I am glad that you are happy and problem is resolved. Good luck with your future endeavors.

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by