Menu

Stopping Simulation

Andy
2022-11-25
2022-11-27
  • Andy

    Andy - 2022-11-25

    I am running a simulation using ngspice.dll and I feed in the netlist using circbyline. When I feed in .end then the simulation starts.

    My simulation could take a couple of minutes to run. If the user chooses to stop the simulation how can I cleanly do this?

    Thanks, Andy

     
  • Holger Vogt

    Holger Vogt - 2022-11-25

    Standard ngspice simulation can be stopped only via an interrupt.

    When the simulation is running in the main thread, shared ngspice may be stopped by interrupting one of the callback functions SendStat or SendData.

    It then depends on what the user wants to do:

    Completely stopping probably will require to send 'quit' for freeing memory, then unloading, loading again and initializing shared ngspice to then have a fresh simulator available.

    There may be other ways, but then data and allocated memory remain, and it may be not sure if the next simulation will be unaffected.

    If the user wants to move on with the simulation after stopping, the program has to continue inside of the callback function.

    If you have sent the netlist as an array via ngSpice_Circ and started simulation in a second (background) thread by sending command bg_run, you may stop it by sending bg_halt from the main thread. The simulation may be continued by sending bg_resume.

     
    • Andy

      Andy - 2022-11-25

      Thanks. If I send the command 'quit' from the SendData callback it immediately corrupts memory inside ngspice.dll and crashes the application. I don't want to pause and resume, just stop the simulation.

       
    • Andy

      Andy - 2022-11-26

      If I call ngSpice_Circ it runs automatically just the same as using the command circbyline - so I don't get a chance to send bg_run. If I miss off '.end' then I get an error from ngSpice_Circ that '.end' is missing. Sending bg_run anyway gives an error that there are no circuits loaded.

       
      • Holger Vogt

        Holger Vogt - 2022-11-26

        This depends on what you send to ngspice.

        If you send a plain netlist without any simulation command, it will wait for command 'tran'. If you send a netlist + .tran command, it will wait for 'run' (primary thread) or 'bg_run' (background thread). If you send a netlist + .control section, it will do what the .control section prescribes, if it contains 'run' or 'tran', it will do that.

         

        Last edit: Holger Vogt 2022-11-26
        • Andy

          Andy - 2022-11-27

          Thanks. I call ngSpice_Circ and pass the netlist witthout a .tran or .control. I then send the command circbyline .tran xxxxx. I then send the command bg_run and nothing happens - simulation doesn't start.

          Do you have an example sequence for using bg_run?

          Thanks, Andy

           
  • dick freebird

    dick freebird - 2022-11-25

    Are there classes of "interrupts"? Thinking about Big Iron tool suites where I have been able to "stop simulation" via the GUI, and have the engine do so cleanly (saving end-time and the results to that point, etc.).

    A behavior which (say) took the first ctrl-C as a "soft stop, clean, don't quit all the way" and subsequent ones as "I meant -now-, screw the data" could be neat.

    But I am imagining that these "domesticated" simulators have made use of some specific "SIGNAL" to get them to play nice inside a larger assembly?

     

    Last edit: dick freebird 2022-11-25
  • Andy

    Andy - 2022-11-25

    There is a return value for the SendData callback - what does that do? I am returning zero. Is there a value that can be returned to stop the simulation cleanly?

     

Log in to post a comment.