Is it possible to stop the simulation on purpose from a c++ module

I am handling exceptions inside a c++ module. I am printing an error message to the console (include stdio.h and use printf). By the nature of my module, this exception could happen multiple times during simulation, but I would like to keep the console “tidy” by showing only the first occurrence.

One solution is to stop the simulation at the first exception occurrence:
Is there a global method that could be called from within the dll to accomplish that? If yes, how to make the call?

Hi @Egrana, you can include <stdlib.h> and use the command exit(3); (not 0 because even if it works, usually it is used to tell the operating system that there was no error) to stop the simulation.

1 Like

@LoicL.TPS ,

I’ve tried exit(3). It does work.

However … sometimes, my sim ends with sim plot data thrown to the window, sometimes it doesn’t. I want the plot data up until the point of stopping the sim.

Any ideas?

Update: The .qraw is created. If I open the file, it shows “(Trouble plotting data)”
My guess is ending the sim in this case prevented the .qraw from closing properly. Plot data corrupt?
The .qraw file size is about 6KB.

I use notepad to look into the .qraw file. I shows data after “Binary:”.
However “No. Points: 0” is the response.

Update:
If I stop the sim <5.04 secs ==> no plot window.
If I stop the sim > 5.04 secs ==> plot window shows up.

IMPORTANT UPDATE!!!:
I believe I may found found the reason for why stopping the sim too early might prevent plot data…

The short answer: At least 517 simulation iteration points must be computed. This was found with multiple test sims.
The long answer is that my simulation was using a MAXSTEP=0.1 seconds. When the sim didn’t plot out as requested, less than 517 iteration points were computed. Once I tested for the iteration point count exceeding 516 point before the stopping, I get the plotting I requested up to the stopping time.

Len

1 Like