资源描述:
《华电潮流上机程序完整版》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、//flow.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#include#include#include"NEquation.h"#include"math.h"#include"config.h"voidtest()//测试程序{NEquationob1;ob1.SetSize(2);ob1.Data(0,0)=1;ob1.Data(0,1)=2;ob1.Data(1,0)=2;ob1.Data(1,1)=1;ob1.Value(0)=5;ob1.V
2、alue(1)=4;ob1.Run();printf("x1=%f",ob1.Value(0));printf("x2=%f",ob1.Value(1));}voidGetData()//数据读入{FILE*fp;inti;if((fp=fopen("E:\新建文件夹\flow\data\data.txt","r"))==NULL){printf("Cannotopenthefilenamed'data.txt'");return;}for(i=0;i<=Bus_Num-1;i++){fscanf(fp,"%d,%f,%f,%f,%f,%f,%f,%d",&gBus[i]
3、.No,&gBus[i].Voltage,&gBus[i].Phase,&gBus[i].GenP,&gBus[i].GenQ,&gBus[i].LoadP,&gBus[i].LoadQ,&gBus[i].Type);}for(i=0;i<=Line_Num-1;i++){fscanf(fp,"%d,%d,%d,%f,%f,%f,%f",&gLine[i].No,&gLine[i].No_I,&gLine[i].No_J,&gLine[i].R,&gLine[i].X,&gLine[i].B,&gLine[i].k);}fclose(fp);}voidGetYMatrix(){inti,j;
4、FILE*fp;//calculatetheYmatrixintbus1,bus2;floatr,x,d,g,b;for(i=0;i<=Bus_Num-1;i++){for(j=0;j<=Bus_Num-1;j++){gY_G[i][j]=0;gY_B[i][j]=0;}}for(i=0;i<=Line_Num-1;i++){bus1=gLine[i].No_I-1;bus2=gLine[i].No_J-1;r=gLine[i].R;//支路中的阻抗电阻x=gLine[i].X;//支路中的阻抗电纳d=r*r+x*x;g=r/d;//阻抗转化为导纳表示时的电导b=-x/d;//阻抗转化为导纳
5、表示时的电纳if(gLine[i].k==0)//不带变压器的普通支路{gY_G[bus1][bus1]=gY_G[bus1][bus1]+g;//下标相同的为自导纳,不同的为互导纳gY_G[bus2][bus2]=gY_G[bus2][bus2]+g;gY_G[bus1][bus2]=-g;//由于互导纳只涉及一个导纳,故直接等于支路导纳负值gY_G[bus2][bus1]=-g;gY_B[bus1][bus1]=gY_B[bus1][bus1]+b+gLine[i].B;gY_B[bus2][bus2]=gY_B[bus2][bus2]+b+gLine[i].B;gY_B[bus1][b
6、us2]=-b;gY_B[bus2][bus1]=-b;}else//带理想变压器的支路{gY_G[bus1][bus1]=gY_G[bus1][bus1]+g/gLine[i].k/gLine[i].k;gY_G[bus2][bus2]=gY_G[bus2][bus2]+g;gY_G[bus1][bus2]=-g/gLine[i].k;gY_G[bus2][bus1]=-g/gLine[i].k;gY_B[bus1][bus1]=gY_B[bus1][bus1]+b/gLine[i].k/gLine[i].k;gY_B[bus2][bus2]=gY_B[bus2][bus2]+b;gY_B
7、[bus1][bus2]=-b/gLine[i].k;gY_B[bus2][bus1]=-b/gLine[i].k;}}//outputtheYmatrixif((fp=fopen("E:\新建文件夹\flow\ymatrix.txt","w"))==NULL){printf("Cannotopenthefilenamed'ymatrix.txt'");return;}fprintf(fp,"---