Ask Your Question
0

What is the correct way to finish a simulation

asked 2019-05-16 04:14:45 -0500

toderesa97 gravatar image

I have some simulations and was wondering what is the best way (instructions using psspy) to finish successfully a simulation. I don't know if it is a silly or useless question, but have searched on this site and have not found anything, so if someone could shed some light on this, I'd really appreciate it.

The way I currently finish a simulation is by executing these set of instructions:

psspy.delete_all_plot_channels()
psspy.dynamicsmode(0)
ierr_close_line = psspy.close_powerflow()
ierr_del_tmpfiles = psspy.deltmpfiles()
ierr_halt = psspy.pssehalt_2()

Thanks, Tomás.

edit retag flag offensive close merge delete

7 answers

Sort by » oldest newest most voted
2

answered 2019-05-17 00:06:59 -0500

perolofl gravatar image

updated 2019-06-22 12:19:58 -0500

There is nothing needed to ”finish a simulation”. You don’t need those lines. What do you want to do?

EDIT: Too many people believe it is necessary to stop PSSE before doing the next dynamic simualtion.

You only need to:

1: Open a saved case

2: Open a snapshot

3: Convert generators and loads

4: Initialise dynamic simulation (STRT)

5: Perform the steps in the simulation (RUN and disturbances). The last RUN performed will define the "end of simulation"!

edit flag offensive delete link more

Comments

that's what I've thought as well. There is no need to execute anything particular.. At least, that's what I've been doing all these years long..!

Pasnos gravatar imagePasnos ( 2021-01-11 14:29:20 -0500 )edit

In some simulations I have found it necessary to se the above process to ensure the following simulation runs PSSINIT cleanly. And if PSSINIT is not run then the system may be incorrectly loaded with with previous model definitions.

Tassie Dave gravatar imageTassie Dave ( 2023-10-23 20:46:30 -0500 )edit
1

answered 2020-12-31 03:13:47 -0500

bobby34 gravatar image

If you are running just one simulation the lines of code you mentioned would probably be sufficient. Although in my experience if you are running multiple studies (e.g. using a for loop) then the saved case may not get closed properly prior to the next one being opened etc.

In case you are running many studies in your script then you may also have to re-write the same lines of code again. Here is an alternative way using Python's with statement and a context manager function from the built-in contextlib library to start and finish each run appropriately.

from contextlib import contextmanager

@contextmanager
def open_savedcase(filepath):
    try:
        psspy.case(filepath)
        yield
    finally:
        psspy.delete_all_plot_channels()
        psspy.dynamicsmode(0)
        ierr_close_line = psspy.close_powerflow()
        ierr_del_tmpfiles = psspy.deltmpfiles()
        ierr_halt = psspy.pssehalt_2()

Then to run a study you can type

with open_savedcase(filepath):
    # Study code here

Once you switch back to the initial indentation level the code to finalise the study will get run automatically. You can also run multiple studies with the following code

case_filepaths = ['case1.sav',' case2.sav', 'case3.sav']

for case in case_filepaths:
    with open_savedcase(case):
        # Study code here

Another benefit to using a context manager is that in case an error or exception occurs in your script part way through running a simulation then the finish code will still run because of Python's finally statement.

edit flag offensive delete link more
1

answered 2021-01-06 05:48:13 -0500

jfconroy gravatar image

You should always finish a simulation with a smile on your face.

edit flag offensive delete link more

Comments

Always! 8)

Alex P gravatar imageAlex P ( 2023-05-17 07:29:15 -0500 )edit
0

answered 2023-05-17 07:28:13 -0500

Alex P gravatar image

Normally you don't need to do anything...you can just finish with your last run command.
In rare cases, I've needed to force output buffers to be flushed with ioflush.
And in very rare cases, with problematic user written models, I've needed to unload dlls and reload them before the next run to properly reset the model memory.

dropmodellibrary(full model dll path),
then
addmodellibrary(just file name, assuming the working directory has been set correctly)

edit flag offensive delete link more
0

answered 2023-05-09 02:19:54 -0500

I am running multiple simulations with the same model, the same case and the same conditions. Obviously the result of each simulation should be exactly the same. The best results that I get is by means of finishing each simulation using the instructions:

psspy.deltmpfiles() # Delete closed temporary files psspy.pssehalt_2() # end the operation of PSSE

I see that If I don´t use them the result of each simulation may not fit at all.

thanks for the contributions done in this threat.

edit flag offensive delete link more

Comments

Just read my answer... It is not necessary to stop PSSE.

perolofl gravatar imageperolofl ( 2023-05-09 03:24:06 -0500 )edit
0

answered 2021-01-07 20:10:49 -0500

JbFord gravatar image

Just use psspy.pssehalt_2() at the end of your script. It is important if you are using hourly dongles and if you don't want PSSE drains all your hours left on the counter. If you have a perpetual licence it is up to you wether to add it our now but it is a good practice to halt PSSE after finishing your simulation. Otherwise, you may face with memory management issue in case of long simulations.

edit flag offensive delete link more
0

answered 2019-06-21 11:46:23 -0500

boat14 gravatar image

updated 2019-06-21 11:47:00 -0500

You can just terminate with the psspy.pssehalt_2() command.

psspy.delete_all_plot_channels()         # this clears the channels, not required because you're not saving the .snp file.
psspy.dynamicsmode(0)                    # not required, as you're not doing any more operations.
ierr_close_line = psspy.close_powerflow()# not required, as you're not doing any more operations.
ierr_del_tmpfiles = psspy.deltmpfiles()  # not required, I'm pretty sure temp files get cleared when PSS/e terminates
edit flag offensive delete link more

Comments

API psspy.pssehalt_2 will stop PSSE. The question is "How to finish a simulation".

perolofl gravatar imageperolofl ( 2019-06-22 12:12:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2019-05-16 04:14:45 -0500

Seen: 2,393 times

Last updated: May 17 '23