Ask Your Question
0

What is the API for generating the .qv files?

asked 2012-08-18 02:09:44 -0500

JervisW gravatar image

updated 2012-08-18 02:14:29 -0500

I've written my own QV curve generator (see here) but I'm curious, how would I create one of those .qv files.

A .qv file is the binary results file that PSSE saves the QV analysis results to.

(edit) I'm looking for the exact psspy commands that I should be using to

  1. load in a case
  2. run a QV curve analysis on a single bus and store the results in a binary .qv file
  3. (option) Bonus marks awarded if you can show how to get the results out of the .qv file into a Python array like this:

Example qv results array

# (Q,  V)
[(0.4,  0.99),
 (0.39, 0.98),
 (...)]
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2012-08-18 12:09:38 -0500

amaity gravatar image

updated 2012-08-18 12:11:23 -0500

I think I have the hang of the thing now:

import os,sys
import operator

PSSE_LOCATION = r"C:\Program Files\PTI\PSSE32\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' +  PSSE_LOCATION 

import psspy
import redirect
redirect.psse2py()
psspy.throwPsseExceptions = True

#--------------------------------
# PSS/E Saved case
casename = "MY_SYSTEM.sav"
CASE = os.path.join(os.path.abspath(dir[0]), casename)
psspy.psseinit(12000)
psspy.case(CASE)

busid = 44121
subfile = r"qvcase.sub"
f = open(subfile, "w+")
f.write("subsystem ABC\njoin group\nzone 44\nkvrange 100.0 300.\nend\nend\nend\n")
f.close()

monfile = r"qvcase.mon"
f = open(monfile, "w+")
f.write("monitor voltage range subsystem ABC 0.9\nend\n")
f.close()

confile = r"qvcase.con"
f = open(confile, "w+")
f.write("single line from bus %s\nend\nend\n" % busid)
f.close()

dfxfile = r"qvcase.dfx"
options = []
options.append(1) # 1-calculate distribution factors
options.append(1) # 1-sort monitored elements 
ierr = psspy.dfax(options, subfile, monfile, confile, dfxfile)

options = []
values  = []
options.append(0) # 0-disable tap adjustment
options.append(0) # 0-disable using tie line flows
options.append(0) # 0-disable phase shift adjustment
options.append(0) # 0-disable dc tap adjustment
options.append(0) # 0-disable switched shunt adjustment
options.append(1) # 1-enable non-divergent solution
options.append(0) # 0-FDNS
options.append(1) # 1-initially ignore: var limit code for the VHI power flow sol
options.append(0) # 
options.append(busid) # study bus number (no default allowed)
values.append(0.1) # Newton solution convergence tolerance, TOLN
values.append(1.1) # the initial (max) pu voltage setpoint at the study bus (VHI)
values.append(0.9) # the minimum pu voltage setpoint at the study bus (VLO)
values.append(0.01) # the pu voltage setpoint decrement (positive) 
ierr = psspy.qv_engine(options, values, dfxfile, accfile=r"test.qv")
edit flag offensive delete link more

Comments

Perfect! It seems "accept answer" is broken on the site. Will fix that and then check this as a "thanks answered the question"

JervisW gravatar imageJervisW ( 2012-08-18 15:13:14 -0500 )edit
1

answered 2012-08-20 16:00:19 -0500

waltterval gravatar image

Hi, This is a script that I use to do that task

You can use it with more than one case and get the curve for varius nodes

I get the .qv file, QV curves in .pdf file and the Mvar reserve in .csv files.


I didn't have time to translate the comments

# created by: Waltter Valdez
#Este script es para sacar las curvas QV de las contingencias

import sys, os
sys.path.insert(0, r"C:\Program Files\PTI\PSSE33\PSSBIN")
# xx --> substitute xx with Version Number here.
os.environ['PATH'] = r"C:\Program Files\PTI\PSSE33\PSSBIN" + ";" + os.environ['PATH']
import redirect
redirect.psse2py()
# this redirects PSS(R)E progress, report output to Python Shell/Console

import psspy
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
import pssarrays
import matplotlib.pyplot as plt
import csv

psspy.psseinit(50000)

Ruta = os.getcwd()
casos = ('ERT-MaxAbr12-UT_ST', 'ERT-MedAbr12-UT_ST', '')
"""No se debe quitar las comillas simples del final, estas permiten usar el
python incluso con un solo escenario """

archSub = Ruta + '\\' + 'subsistemas_QV.sub'
archMon = Ruta + '\\' + 'monitoreo_QV.mon'
archCon = Ruta + '\\' + 'contingencias_QV.con'

nodos = (28161, 28181, 27421, 27461)
"""# En nodos se debe introducir los numeros de los buses en los cuales
se desea obtener las curvas QV"""

psspy.progress_output(2, 'reportePro', [2, 0])
# Crea casos y QV por gobernador
for casoN in casos:
    if casoN != '':
        carpeta = Ruta + '\\' + casoN
        if not os.path.isdir(carpeta):
            os.makedirs(carpeta)
        caso = Ruta + '\\' + casoN + '.sav'
        Difaxx = carpeta + '\\' + 'Difaxx-' + casoN + '.dfx'
        progreso = carpeta + '\\' + 'Progreso_' + casoN + '.txt'
        psspy.progress_output(2, progreso, [2, 0])
        psspy.case(caso)
        psspy.branch_data(27371, 27372, r"""1""",
             [_i, _i, _i, _i, _i, _i], [0.1E-05, _f, _f, _f, _f, _f, _f, _f,
                 _f, _f, _f, _f, _f, _f, _f])
        """Do it if you have Zero branch..."""
        psspy.fnsl([1, 0, 0, 1, 1, 0, 0, 0])
        psspy.dfax([1, 1], archSub, archMon, archCon, Difaxx)
        for nodo in nodos:
            nodo1 = str(nodo)
            archivoqv = carpeta + '\\' + 'QV_' + nodo1
            ierr2 = psspy.qv_engine([0, 0, 0, 0, 0, 0, 1, 0, 0, nodo],
            [0.5, 1.2, 0.5, 0.01], Difaxx, "", archivoqv)
            if ierr2 != 0:
                continue
            # Change these values as required.
            qvfile = 'QV_' + nodo1 + ".qv"
            qvfile1 = carpeta + '\\''QV_' + nodo1 + ".qv"
            contingencias = pssarrays.qv_summary(qvfile1).colabel
            reserva = ["Reserva (Mvars)"]
            contingencia = ["Contingencias"]
            plt.cla()
            ierr, cval = psspy.notona(nodo)
            for colabel in contingencias:
                rlst = pssarrays.qv_solution(qvfile1, colabel)
                v = rlst.vsetpoint
                q = rlst.mgenmvar
                contingencia.append(colabel)
                reserva.append(min(rlst.mgenmvar)[0])
                plt.plot(v, q)

            reporteReserva = carpeta + '\\' + 'Reporte_Reserva_' + qvfile + '.csv'
            csv_out = open(reporteReserva, 'wb')
            mywriter = csv.writer(csv_out)
            rows = zip(contingencia, reserva)
            mywriter.writerows(rows)
            csv_out.close()

            plt.legend(contingencias, loc='upper right')
            plt.title(qvfile[0:-3] + "_" + cval[0:-7])
            plt.ylabel('MVAr')
            plt.xlabel('Voltaje(p.u.)')
            plt.grid(True)
            plt.savefig(carpeta + '\\' + qvfile[0:-3] + '.pdf', format=None, orientation='portrait')
edit flag offensive delete link more

Comments

@waltterval thanks for sharing the script. After I few scans I find that I can't understand some of the stuff in your script, for example, why are you adding a zero impedance branch?

amaity gravatar imageamaity ( 2012-08-20 20:33:06 -0500 )edit

@amaity I'm not adding a zero impedance branch (ZIB), what I did is change parameters in ZIB to be treated as a normal branch, This is becuase the API dosn't permit get QV curve if the bus is joined with a ZIB

waltterval gravatar imagewaltterval ( 2012-08-21 11:23:33 -0500 )edit

@waltterval is that in the documentation?

amaity gravatar imageamaity ( 2012-08-21 11:46:01 -0500 )edit

@amaity Not, I was trying to do a QV curve in node with ZIB and got an error, then asked to PSSE and told me that.

waltterval gravatar imagewaltterval ( 2012-08-21 11:55:11 -0500 )edit

Aha! @waltterval that's a big help. By the way, I posted a question in the bus reactor section a few minutes back. Any ideas?

amaity gravatar imageamaity ( 2012-08-21 12:03:55 -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

Stats

Asked: 2012-08-18 02:09:44 -0500

Seen: 2,593 times

Last updated: Aug 20 '12