简体   繁体   English

Python和PSS / E

[英]Python and PSS/E

I am trying to have the bus loads in PSS/E to change by using python program. 我正在尝试通过使用python程序来更改PSS / E中的总线负载。 So I am trying to write a script in python where I could change loads to different values between two buses in PSS/E. 所以我试图用python编写脚本,在其中我可以将PSS / E中两条总线之间的负载更改为不同的值。

You can use API routine called "LOAD_CHNG_4" (search for this routin in API.pdf documentation). 您可以使用称为“ LOAD_CHNG_4”的API例程(在API.pdf文档中搜索此例程)。 This routine belongs to the set of load data specification functions. 该例程属于负载数据规范功能集。 It can be used to modify the data of an existing load in the working case. 在工作案例中,它可用于修改现有负载的数据。

Look at chapter II of the PSSE python API. 查看PSSE python API的第二章。 It completely covers changing power flow data. 它完全涵盖了不断变化的潮流数据。 Load data can be referenced with the bus number and load ID. 可以使用总线号和负载ID引用负载数据。 You can change all the parameters you see in the nameplate when you manually enter in the load data itself. 手动输入载荷数据本身时,可以更改在铭牌上看到的所有参数。 Use this function below to change the load: 在下面使用此功能更改负载:

ierr = psspy.load_chang(bus_number, load_id, intgar,realar)

See page 728 of the API manual for more info. 有关更多信息,请参见API手册的第728页。

I wrote this class to handle loads in PSSE...It originally sent with SQL alchemy so it has some extras which I removed: 我写了这个类来处理PSSE中的负载...最初是随SQL炼金术一起发送的,所以它有一些我删除的附加功能:

class Load():

    def __init__(self,busnumber,loadID):
        # Initialize the Branch Class Instance Variables to a Default 0; Except for the From,To and Circuit ID
        self.bus = Bus(busnumber)
        self.busI = busnumber
        self.loadID = loadID
        self.status = 0
        self.Pload = 0.0
        self.Qload = 0.0

        self.errorList = []
        self.init()
    def init(self):
        # Setup the load from the case
        # Check to see if bus exists
        busOk = self.bus.init()
        if not busOk[0]: 
            return (False,self.bus.number,"The bus number %d is invalid or does not exist..." % self.bus.number)
        if psspy.loddt2(self.bus.number,self.loadID,'TOTAL','ACT')[0] != 0:
            return (False,False)
        Scomplex = self.check(psspy.loddt2(self.bus.number,self.loadID,'TOTAL','ACT'),'loddt2','ACT')               # Grab the S vector/phasor from the power flow case for the load specified at the BUS number
        self.Pload = Scomplex.real
        self.Qload = Scomplex.imag
        self.status = self.check(psspy.lodint(self.bus.number,self.loadID,'STATUS'),'lodint','STATUS')              # Grab the Status of the Load

        return (True,self.bus.number)

    def check(self,tuple,funName,subFun):
        # Define Error Messages that should be accesable by the end-user and developer
        loddt2 = {
            0:'No error; P and Q or CMPVAL returned',
            1:'Bus not found; P and Q or CMPVAL unchanged.',
            2:'Load not found; P and Q or CMPVAL unchanged.',
            3:'Bus type code is not 1, 2 or 3; P and Q or CMPVAL returned.',
            4:'Load out-of-service; P and Q or CMPVAL returned.',
            5:'Invalid value of STRING1 or STRING2; P and Q or CMPVAL unchanged.'
        }   

        lodint = {
            0:'No error; IVAL returned.',
            1:'Bus not found; IVAL unchanged.',
            2:'Load not found; IVAL unchanged.',
            3:'Bus type code is not 1, 2 or 3; IVAL returned.',
            4:'Load out-of-service; IVAL returned.',
            5:'Invalid value of STRING; IVAL unchanged.'
        }       

        funDic = {
            'loddt2':loddt2,
            'lodint':lodint
        }

        # Retrieve the Right Error Message
        list = funDic[funName]
        msg = list[tuple[0]]
        if tuple[0] > 0:
            logging.debug("Function Name:  %s  Sub Function Name:  %s   Error Message: %s"%(funName,subFun,msg))

        return tuple[1]

    def setLoad(self,loadP):
        self.Pload = loadP
    def updateCase(self):

        # Setup Defaults
        _i = psspy.getdefaultint()
        _f = psspy.getdefaultreal()
        cDef = psspy.getdefaultchar()
        psspy.load_data_3(self.bus.number,self.loadID,[self.status,_i,_i,_i,_i],[self.Pload, self.Qload,_f,_f,_f,_f])

    # To String Method 
    def __repr__(self):
        return "%d %s %d %d" %(self.bus.number,self.loadID,self.Pload,self.Qload)

    # printf Statement that Dumps information to CMD line...Homeage to C and C++
    def printf(self):
        print "\n Bus: %d \n Load ID: %s \n MW Value: %d \n MVAR Value: %d \n" % (self.bus.number,self.loadID,self.Pload,self.Qload)

If you call the function named, "updateCase" it will take what ever values are stored in the load object and refresh the PSSE case. 如果调用名为“ updateCase”的函数,它将使用存储在装入对象中的所有值,并刷新PSSE的情况。

http://www.whit.com.au/blog/2011/07/run-psse-from-python-and-not-other-way/ http://www.whit.com.au/blog/2011/07/run-psse-from-python-and-not-other-way/

I found this blog post about how to run Python command from PSSE. 我找到了有关如何从PSSE运行Python命令的博客文章。 I don't think that your question has anything to do with ASP.NET though. 我认为您的问题与ASP.NET没有任何关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM