潮流上机课程设计报告1华电文档格式.docx
《潮流上机课程设计报告1华电文档格式.docx》由会员分享,可在线阅读,更多相关《潮流上机课程设计报告1华电文档格式.docx(28页珍藏版)》请在冰豆网上搜索。
简单系统如下图所示,支路数据如下:
节点数据如下:
//2014.cpp:
定义控制台应用程序的入口点。
//
#include"
stdafx.h"
structLine//线路结构体
{
intNum,NumI,NumJ;
//线路号左节点名右节点名
floatR,X,B,K;
//电阻电抗电纳变比(K等于1为普通支路,不等于1为变压器支路的变比)
};
structBus//节点结构体
intNum;
floatVolt,Phase,GenP,GenQ,LoadP,LoadQ;
intType;
#include"
stdio.h"
string.h"
math.h"
stdlib.h"
#defineNBUS4//
#defineNLINE4
/*Globalvariables*/
intnL,nB,nVA,nSH;
floatX[NBUS];
intL;
doubledef[2*NBUS];
doubleawe[100];
int_tmain(intargc,_TCHAR*argv[])
{
FILE*fp;
FILE*fpout;
inti,j,l,h,n,k;
inti1=0,i2=0,i3=0,kp,kq;
doublea,b,k1;
doubleH=0,N=0,J=0,L=0,R=0,S=0;
floatd1=0,d2=0,d3=0,d4=0,d5=0,d6=0,r,x,g,b1,b2,g1,g2,tt,LL,e,ps=0,qs=0,shsh,m;
structLinesL[NLINE];
structBussB[NBUS];
floatYG[NBUS+1][NBUS+1],YB[NBUS+1][NBUS+1];
doubleu[50][2],p[50],da,db,pp[50],ppl[50],Q[10][10],gJaccobi[50][50],sP[10][10],sQ[10][10],WP=0.0,WQ=0.0;
for(i=0;
i<
NBUS;
i++)
{if((fp=fopen("
H:
\\2014\\2014\\in.txt"
"
r"
))==NULL)
{printf("
Cannotopenthefilenamed'
in.txt'
\n"
);
exit(0);
}
fscanf(fp,"
%d,%d,%d"
&
nB,&
nL,&
nSH);
}
nB;
i++){
sB[i].Num=sB[i].Type=0;
sB[i].Volt=1.0;
sB[i].Phase=sB[i].GenP=sB[i].GenQ=sB[i].LoadP=sB[i].LoadQ=0.0;
fscanf(fp,"
%d,%f,%f,%f,%f,%f,%f,%d"
i1,&
d1,&
d2,&
d3,&
d4,&
d5,&
d6,&
i2);
sB[i].Num=i1;
sB[i].Volt=d1;
sB[i].Phase=d2;
sB[i].GenP=d3;
sB[i].GenQ=d4;
sB[i].LoadP=d5,sB[i].LoadQ=d6;
sB[i].Type=i2;
nL;
sL[i].Num=sL[i].NumI=sL[i].NumJ=0;
sL[i].R=sL[i].X=sL[i].B=0.0;
sL[i].K=1.0;
%2d%3d%3d%f%f%f%f"
i2,&
i3,&
d4);
sL[i].Num=i1;
sL[i].NumI=i2;
sL[i].NumJ=i3;
sL[i].R=d1;
sL[i].X=d2;
sL[i].B=d3;
sL[i].K=d4;
if(fp!
=NULL)fclose(fp);
/*MakeYMatrix*/
for(i=1;
nB+1;
for(j=1;
j<
j++){
YG[i][j]=0.0;
YB[i][j]=0.0;
for(l=0;
l<
l++){
i=sL[l].NumI;
j=sL[l].NumJ;
r=sL[l].R;
x=sL[l].X;
d1=r*r+x*x;
g=r/d1;
b=-x/d1;
m=sL[l].K;
if(fabs(sL[l].K-1.0)<
0.000001)//普通支路
YG[i][i]=YG[i][i]+g;
YG[j][j]=YG[j][j]+g;
YB[i][i]=YB[i][i]+b+sL[l].B;
YB[j][j]=YB[j][j]+b+sL[l].B;
YG[i][j]=YG[i][j]-g;
YG[j][i]=YG[j][i]-g;
YB[i][j]=YB[i][j]-b;
YB[j][i]=YB[j][i]-b;
else//变压器支路
YB[i][i]=YB[i][i]+b;
YG[j][j]=YG[j][j]+g/(m*m);
YB[j][j]=YB[j][j]+b/(m*m);
YG[i][j]=YG[i][j]-g/m;
YG[j][i]=YG[j][i]-g/m;
YB[i][j]=YB[i][j]-b/m;
YB[j][i]=YB[j][i]-b/m;
/*ChecktheYmatrix*/
if((fp=fopen("
GGBB.txt"
w"
))==NULL){
printf("
GGBB.txt'
exit(0);
}
fprintf(fp,"
---YMatrix---\n"
j++)
if(fabs(YB[i][j]-0.0)>
0.000001)
Y(%3d,%-3d)=(%10.5f,%10.5f)\n"
i,j,YG[i][j],YB[i][j]);
for(i=1;
if(sB[i-1].Type==2)
{
u[i][0]=sB[i-1].Volt*cos(sB[i-1].Phase);
u[i][1]=sB[i-1].Volt*sin(sB[i-1].Phase);
}
elseif(sB[i-1].Type==1)
{u[i][0]=sB[i-1].Volt*cos(sB[i-1].Phase);
u[i][1]=0.0;
elseif(sB[i-1].Type==0)
u[i][0]=1.0;
u[i][1]=0.0;
fp=fopen("
电压初值.txt"
if(fp==NULL)
printf("
电压初值.txt'
exit(0);
fprintf(fp,"
---电压初值---\n"
fprintf(fp,"
e(%d)=%10.5f;
f(%d)=%10.5f\n"
i,u[i][0],i,u[i][1]);
if(fp!
printf("
赋予的电压初值为(e+if):
\n"
%lf+i%lf\n"
u[i][0],u[i][1]);
/*循环迭代*/
/*求偏移量*/
doubleP_P[5];
doubleP_Q[5];
doubleP_UU[5];
intv;
for(v=1;
;
v++)
{if(sB[i-1].Type==2)
{P_P[i]=0.0;
P_Q[i]=0.0;
P_UU[i]=0.0;
if(sB[i-1].Type==0)//0为PQ节点,1为PV节点
{doubletempP=0.0;
doubletempQ=0.0;
for(j=1;
tempP+=YG[i][j]*u[j][1]+YB[i][j]*u[j][0];
tempQ+=YG[i][j]*u[j][0]-YB[i][j]*u[j][1];
P_P[i]=(sB[i-1].GenP-sB[i-1].LoadP)-tempP*u[i][1]-tempQ*u[i][0];
P_Q[i]=(sB[i-1].GenQ-sB[i-1].LoadQ)+tempP*u[i][0]-tempQ*u[i][1];
}
if(sB[i-1].Type==1)
for(j=1;
{tempP+=YG[i][j]*u[j][1]+YB[i][j]*u[j][0];
}
P_P[i]=(sB[i-1].GenP-sB[i-1].LoadP)-tempP*u[i][1]-tempQ*u[i][0];
P_UU[i]=sB[i-1].Volt*sB[i-1].Volt-(u[i][0]*u[i][0]+u[i][1]*u[i][1]);
}}
/*偏移量阵*/
doubleP_PQ[6];
intc=0;
for(i=2;
{
if(sB[i-1].Type==0)
P_PQ[c]=P_P[i];
c=c+2;
if(sB[i-1].Type==1)
{P_PQ[c]=P_P[i];
c=c+2;
c=1;
{P_PQ[c]=P_Q[i];
{if(sB[i-1].Type==1)
{P_PQ[c]=P_UU[i];
c=c+2;
/*输出偏移量*/
输出偏移量\n"
偏移量.txt"
))==NULL)
{
偏移量.txt'
---偏移量---\n"
c-1;
i++)
P_PQ(%2d)=(%10.5f)\n"
i,P_PQ[i]);
for(i=0;
2*(nB-1);
P_PQ[%2d]=(%10.5f)\n"
//形成雅克比矩阵
for(i=2;
for(j=2;
if(sB[i-1].Type==0)//PQ节点
{
if(i!
=j)//非对角元素
{
H=-YB[i][j]*u[i][0]+YG[i][j]*u[i][1];
N=YG[i][j]*u[i][0]+YB[i][j]*u[i][1];
J=-N;
L=H;
}
else//对角元素
a=0;
b=0;
for(k=1;
k<
k++)//u[i][]从i=1开始
{
a=a+(YG[i][k]*u[k][0]-YB[i][k]*u[k][1]);
b=b+(YG[i][k]*u[k][1]+YB[i][k]*u[k][0]);
}
H=+YG[i][i]*u[i][1]-YB[i][i]*u[i][0]+b;
N=+YG[i][i]*u[i][0]+YB[i][i]*u[i][1]+a;
J=-YG[i][i]*u[i][0]-YB[i][i]*u[i][1]+a;
L=YG[i][i]*u[i][1]-YB[i][i]*u[i][0]-b;
gJaccobi[2*(i-2)][2*(j-2)]=H;
gJaccobi[2*(i-2)][2*(j-2)+1]=N;
gJaccobi[2*(i-2)+1][2*(j-2)]=J;
gJaccobi[2*(i-2)+1][2*(j-2)+1]=L;
else//PV节点
H=-YB[i][j]*u[i][0]+YG[i][j]*u[i][1];
R=0;
S=0;
a=b=0;
k++)
a=a+(YG[i][k]*u[k][0]-YB[i][k]*u[k][1]);
H=YG[i][i]*u[i][1]-YB[i][i]*u[i][0]+b;
N=YG[i][i]*u[i][0]+YB[i][i]*u[i][1]+a;
R=2*u[i][1];
S=2*u[i][0];
gJaccobi[2*(i-2)+1][2*(j-2)]=R;
gJaccobi[2*(i-2)+1][2*(j-2)+1]=S;
//outputtheJaccobi
fp=fopen("
雅克比.txt"
雅克比.txt'
---雅克比矩阵---\n"
i++)//
for(j=0;
Jaccobi(%d,%d)=(%10.5lf)\b"
i+1,j+1,gJaccobi[i][j]);
//雅克比矩阵从i=0开始
fprintf(fp,"
voidGauss(doublea[50][50],doubleb[6],intn);
intNN=6;
Gauss(gJaccobi,P_PQ,NN);
//调用高斯函数
6;
awe[%d]=%lf\n"
i,awe[i]);
\n开始计算电压新值\n"
for(i=2,j=0;
=nB,j<
i++,j=j+2)//i=1是平衡节点不放入
u[i][1]+=awe[j];
u[i][0]+=awe[j+1];
u[%d][0]=%10.5lf,u[%d][1]=%10.5lf\n"
电压新值.txt"
/*路径*/
电压新值.txt'
---电压新值---\n"
=3;
i++)//
ge[%d]=%10.5f,gf[%d]=%10.5f\n"
doublemax;
max=0.0;
if(fabs(awe[i])>
max)
max=fabs(awe[i]);
if(max<
=0.00001)
break;
循环次数v=%d\n"
v);
//计算平衡节点功率
doubletempP=0.0;
ps=0;
qs=0;
NBUS+1;
if(sB[i-1].Type==2)
{
ps=tempP*u[i][1]+tempQ*u[i][0];
qs=-tempP*u[i][0]+tempQ*u[i][1];
//计算线路流动功率
j++)
sP[i][j]=0;
sQ[i][j]=0;
l++)
b1=sL[l].B;
0.000001)
{//普通支路
sP[i][j]=u[i][0]*((u[i][0]-u[j][0])*g-(u[i][1]-u[j][1])*b)+u[i][1]*((u[i][1]-u[j][1])*g+(u[i][0]-u[j][0])*b);
sQ[i][j]=-u[i][0]*((u[i][0]-u[j][0])*b+(u[i][1]-u[j][1])*g)+u[i][1]*((u[i][0]-u[j][0])*g-(u[i][1]-u[j][1])*b)-(u[i][0]*u[i][0]+u[i][1]*u[i][1])*b1;
sP[j][i]=u[j][0]*((u[j][0]-u[i][0])*g-(u[j][1]-u[i][1])*b)+u[j][1]*((u[j][1]-u[i][1])*g+(u[j][0]-u[i][0])*b);
sQ[j][i]=-u[j][0]*((u[j][0]-u[i][0])*b+(u[j][1]-u[i][1])*g)+u[j][1]*((u[j][0]-u[i][0])*g-(u[j][1]-u[i][1])*b)-(u[j][0]*u[j][0]+u[j][1]*u[j][1])*b1;
else
{//abnormaltransformerratio
k1=sL[l].K;
r=sL[l].R;
g1=(k1-1)/k1*g;
g2=(1-k1)/(k1*k1)*g;
b1=(k1-1)/k1*b;
b2=(1-k1)/(k1*k1)*b;
//sP[i][j]=u[i][0]*((u[i][0]-u[j][0])*g-(u[i][1]-u[j][1])*b-u[i][1]*b1)+u[i][1]*((u[i][0]-u[j][0])*b+(u[i][1]-u[j][1])*g+u[i][0]*b1);
//sP[j][i]=u[j][0]*((u[j][0]-u[i][0])*g-(u[j][1]-u[i][1])*b-u[j]