Hi all. I’m trying to run a some code where I am intentionally pushing a differential equations solver that’s called inside a dynamic systems modeling package to fail to converge. I’m trying to explore the boundaries of when this failure happens and the system behavior near the boundary. When the solver fails I get an error that stops my code from advancing, which is fine, except it means I have to change my operating points manually which is time consuming.
I’m testing different combinations of variables which are in nested for loops, and I’d like the inner loop to run until the solver fails to converge in which case the code breaks to the outer loop to test the next set of conditions. Something like:
set_a = [3.0, 2.0, 1.0]
set_b = [0.25, 0.2, 0.15]
for apples in set_a
for bananas in set_b
sys = (system, limit=bananas) # Define the system being studied
sim = Simulation( # Establish the length and scenario of the simulation to run
ResidualModel, #Type of model used
sys, # system
(0.0, 40.0), # time span
Disturbance(1.0, apples, :P, 0.9);
)
try
execute!(sim, IDA(); abstol = 1e-8) # Command which runs the simulation
catch
break
else
continue
end
plot(read_results(sim))
end
end
However, this seems to break both loops since when I hit a condition I know will cause a convergence error (say 2.0 and 0.2 from above) the normal error message is displayed and the code stops advancing. Does anyone have any ideas on how to resolve this?