PCL.cpp
资源名称:PCL.rar [点击查看]
上传用户:hyjxc386
上传日期:2021-09-01
资源大小:2k
文件大小:7k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Visual C++
- #include<iostream.h>
- #include<iomanip.h>
- #include<math.h>
- #include<fstream.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define N 50
- void guss(double **a,int n)
- {
- int i,j,k;double c;
- for(k=0;k<n-1;k++)
- {
- c=a[k][k];
- for(j=k;j<=n;j++) a[k][j]/=c;
- for(i=k+1;i<n;i++)
- {
- c=a[i][k];
- for(j=k;j<=n;j++) a[i][j]-=c*a[k][j];
- }
- }
- a[n-1][n]/=a[n-1][n-1];
- for(k=n-2;k>=0;k--)
- for(j=k+1;j<n;j++) a[k][n]-=a[k][j]*a[j][n];
- }
- void main()
- {
- ifstream pfile;
- pfile.open("test.txt");
- if (!pfile)
- {cout<<"can't open!n"<<endl;}
- cout<<"%%%%%%潮流计算%%%%%%"<<endl;
- int n=1,m,sum,sumPQ=0,sumPV=0,sumdetaV=0;
- double k;
- int type[N];
- type[0]=0;
- double V[N],P[N],Q[N],P1[50];
- double x[50][50],r[N][N],bb[N][N],K[N][N],B1[N][N],mo[N][N],G1[N][N],KK[N][N];
- for(int i=0;i<=N;i++)
- {P[i]=0;Q[i]=0;P1[i]=0;V[i]=1;}
- for(i=0;i<N;i++)
- for(int j=0;j<N;j++)
- {x[i][j]=0;r[i][j]=0;bb[i][j]=0;K[i][j]=1;KK[i][j]=1;B1[i][j]=0;G1[i][j]=0;mo[i][j]=1;}
- i=1;
- for(n=1;n!=0;)
- {
- pfile>>n;
- if(n)
- {
- pfile>>type[n];
- if(type[n]==1)
- {pfile>>P[n]>>Q[n];sumPQ++;}
- if(type[n]==2)
- {pfile>>P[n]>>k;sumPV++;}
- if(type[n]==3)
- {pfile>>k>>k;sumdetaV++;}
- sum=i++;
- }
- }
- for(n=1;n!=0;)
- {
- pfile>>n;
- if(type[n]==2) pfile>>P1[n]>>V[n];
- if(type[n]==3) pfile>>k>>V[n];
- }
- for(n=1;n!=0;)
- {
- pfile>>n;
- if(n)
- {
- pfile>>m;
- pfile>>r[n][m]>>x[n][m]>>bb[n][m]>>K[m][n];
- r[m][n]=r[n][m];x[m][n]=x[n][m];KK[n][m]=K[m][n];
- bb[m][n]=bb[n][m];
- }
- }
- for(n=1;n<=sum;n++)
- for(m=1;m<=sum;m++)
- {
- mo[n][m]=x[n][m]*x[n][m]+r[n][m]*r[n][m];
- if(mo[n][m]==0) mo[n][m]=1;
- }
- for(n=1;n<=sum;n++)
- for(m=1;m<=sum;m++)
- {
- B1[n][n]+=bb[n][m]-x[n][m]*K[n][m]*K[n][m]/mo[n][m];
- G1[n][n]+=r[n][m]*K[n][m]*K[n][m]/mo[n][m];
- }
- for(n=1;n<=sum;n++)
- for(m=1;m<=sum;m++)
- if(K[n][m]==1) {K[n][m]=K[m][n];KK[m][n]=-1;}
- for(n=1;n<=sum;n++)
- for(m=1;m<=sum;m++)
- {
- if(m!=n)
- {
- B1[n][m]+=x[n][m]*K[n][m]/mo[n][m];
- G1[n][m]+=-r[n][m]*K[n][m]/mo[n][m];
- }
- }
- double deta[N],detaP[N],detaV[N],PS[N],Pi[N],Ddeta[N],detaQ[N],Qi[N];
- double aa[N][N],cc[N][N];
- for(n=1;n<=sum;n++)
- {deta[n]=0;detaP[n]=0;PS[n]=0;Pi[n]=0;detaQ[n]=0;Qi[n]=0;}
- for(n=1;n<=sum-1;n++)
- PS[n]=-P[n]+P1[n];
- int Kp=1,Kq=1,maxP=0,maxQ=0;
- k=0;
- cout<<"**********************************************************************"<<endl;
- P:for(n=1;n<=sum-1;n++)
- {
- for(m=1;m<=sum;m++)
- Pi[n]+=V[m]*(G1[n][m]*cos(deta[n]-deta[m])+B1[n][m]*sin(deta[n]-deta[m]));
- Pi[n]*=V[n];
- }
- double maxdetaP=0,maxdetaQ=0;
- for(n=1;n<=sum-1;n++)
- {
- detaP[n]=PS[n]-Pi[n];
- Pi[n]=0;
- }
- for(n=0;n<sum-1;n++)
- for(m=0;m<sum-1;m++) aa[n][m]=-B1[n+1][m+1];
- for(n=0;n<sum;n++)
- aa[n][sum-1]=detaP[n+1]/V[n+1];
- double *a[N];
- for (n=0;n<sum-1;n++)
- a[n]=aa[n];
- for(n=1;n<=sum-1;n++)
- if(fabs(maxdetaP)<fabs(detaP[n])) {maxdetaP=detaP[n];maxP=n;}
- if(fabs(maxdetaP)<1e-5)
- {
- Kp=0;
- if(Kq==0) goto R;
- if(Kq!=0) goto Q;
- }
- guss(a,sum-1);
- for(n=0;n<sum-1;n++)
- {Ddeta[n+1]=aa[n][sum-1]/V[n+1];deta[n+1]=deta[n+1]+Ddeta[n+1];}
- Kq=1;
- Q:for(n=1;n<=sumPQ;n++)
- {
- for(m=1;m<=sum;m++)
- Qi[n]+=V[m]*(G1[n][m]*sin(deta[n]-deta[m])-B1[n][m]*cos(deta[n]-deta[m]));
- Qi[n]*=V[n];
- }
- for(n=1;n<=sumPQ;n++)
- {
- detaQ[n]=-Q[n]-Qi[n];
- Qi[n]=0;
- }
- for(n=0;n<sumPQ;n++)
- for(m=0;m<sumPQ;m++) cc[n][m]=-B1[n+1][m+1];
- for(n=0;n<sumPQ;n++)
- cc[n][sumPQ]=detaQ[n+1]/V[n+1];
- for(n=1;n<=sumPQ;n++)
- ;
- double *c[N];
- for (n=0;n<sumPQ;n++)
- c[n]=cc[n];
- for(n=1;n<=sumPQ;n++)
- if(fabs(maxdetaQ)<fabs(detaQ[n])) {maxdetaQ=detaQ[n];maxQ=n;}
- if(fabs(maxdetaQ)<1e-5)
- {
- Kq=0;
- if(Kp==0) goto R;
- if(Kq!=0) goto T;
- }
- guss(c,sumPQ);
- for(n=0;n<sumPQ;n++)
- {detaV[n+1]=cc[n][sumPQ];V[n+1]=V[n+1]+detaV[n+1];}
- T: if(fabs(maxdetaQ)<fabs(maxdetaP)) {maxdetaQ=maxdetaP;maxQ=maxP;
- cout<<"第"<<k<<"次迭代后误差:"<<setw(15)<<maxdetaQ<<" 最大的功率误差在节点:"<<maxQ<<" 最大误差是detaP"<<endl;}
- else
- cout<<"第"<<k<<"次迭代后误差:"<<setw(15)<<maxdetaQ<<" 最大的功率误差在节点:"<<maxQ<<" 最大误差是detaQ"<<endl;
- k=k+1;
- goto P;
- R:cout<<"*******************************************************************************"<<endl;
- cout<<"节点数据:"<<endl;
- for(n=1;n<=sum;n++)
- {
- cout<<"节点:"<<n<<"电压:"<<setw(10)<<V[n]<<" 相角:"<<setw(12)<<deta[n]*180/3.1415926;//转换为角度制
- if(type[n]==1) cout<<"发电有功:"<<setw(10)<<"0.0"<<" 发电无功:"<<setw(10)<<"0.0"<<"负荷有功:"<<setw(10)<<-PS[n]<<" 负荷无功:"<<setw(10)<<Q[n]<<endl;//PQ节点
- else if(type[n]==2)
- {
- for(m=1;m<=sum;m++)
- Q[n]+=V[m]*(G1[n][m]*sin(deta[n]-deta[m])-B1[n][m]*cos(deta[n]-deta[m]));
- Q[n]*=V[n];
- cout<<"发电有功:"<<setw(10)<<PS[n]<<" 发电无功:"<<setw(10)<<Q[n]<<"负荷有功:"<<setw(10)<<"0.0"<<" 负荷无功:"<<setw(10)<<"0.0"<<endl;
- }
- else
- {
- for(m=1;m<=sum;m++)
- PS[n]+=V[m]*(G1[n][m]*cos(deta[n]-deta[m])+B1[n][m]*sin(deta[n]-deta[m]));
- PS[n]*=V[n];
- for(m=1;m<=sum;m++)
- Q[n]+=V[m]*(G1[n][m]*sin(deta[n]-deta[m])-B1[n][m]*cos(deta[n]-deta[m]));
- Q[n]*=V[n];
- cout<<"发电有功:"<<setw(10)<<PS[n]<<" 发电无功:"<<setw(10)<<Q[n]<<"负荷有功:"<<setw(10)<<"0.0"<<" 负荷无功:"<<setw(10)<<"0.0"<<endl;//输出浮点型的0.0
- }
- }
- cout<<"-------------------------------------------------------------------------------"<<endl;
- cout<<"支路数据:"<<endl;
- double LP[N][N],LQ[N][N];
- for(n=1;n<N;n++)
- for(m=n;m<N;m++)
- LP[n][m]=LP[m][n]=LQ[n][m]=LQ[m][n]=0;
- cout<<"支路功率流动"<<endl;
- for(n=1;n<=sum;n++)
- for(m=1;m<=sum;m++)
- {
- if(r[n][m]||x[n][m]||bb[n][m])
- {
- LP[n][m]=-V[n]*V[n]*((1-K[n][m])*G1[n][m]/KK[n][m])-V[n]*cos(deta[n])*(G1[n][m]*(V[n]*cos(deta[n])-V[m]*cos(deta[m]))-B1[n][m]*(V[n]*sin(deta[n])-V[m]*sin(deta[m])))
- -V[n]*sin(deta[n])*(G1[n][m]*(V[n]*sin(deta[n])-V[m]*sin(deta[m]))+B1[n][m]*(V[n]*cos(deta[n])-V[m]*cos(deta[m])));
- LQ[n][m]=V[n]*V[n]*(-bb[n][m]+(1-K[n][m])*B1[n][m]/KK[n][m])-V[n]*sin(deta[n])*(G1[n][m]*(V[n]*cos(deta[n])-V[m]*cos(deta[m]))-B1[n][m]*(V[n]*sin(deta[n])-V[m]*sin(deta[m])))
- -V[n]*cos(deta[n])*(-G1[n][m]*(V[n]*sin(deta[n])-V[m]*sin(deta[m]))-B1[n][m]*(V[n]*cos(deta[n])-V[m]*cos(deta[m])));
- cout<<n<<"到"<<m<<"的有功:"<<setw(10)<<LP[n][m]<<" ";
- cout<<n<<"到"<<m<<"的无功:"<<setw(10)<<LQ[n][m]<<endl;
- }
- }
- cout<<"支路功率损耗"<<endl;
- for(n=1;n<=sum;n++)
- for(m=n+1;m<=sum;m++)
- {
- if(LP[n][m]&&LP[m][n]) cout<<"节点"<<n<<"到"<<"节点"<<m<<"有功损耗"<<setw(15)<<fabs(LP[n][m]+LP[m][n])<<" ";
- if(LQ[n][m]&&LQ[m][n]) cout<<"节点"<<n<<"到"<<"节点"<<m<<"无功损耗"<<setw(15)<<fabs(LQ[n][m]+LQ[m][n])<<endl;
- }
- cout<<"-------------------------------------------------------------------------------"<<endl;
- cout<<"全网数据:"<<endl;
- double GenerateP=0,LoadP=0,LossP,MaxV=0,MinV=100000;
- int NumbermaxV=1,NumberminV=1;
- for(n=1;n<=sum;n++)
- {
- if(type[n]!=1) GenerateP+=PS[n];
- else LoadP+=-PS[n];
- if(V[n]>MaxV) {MaxV=V[n];NumbermaxV=n;}
- else if(V[n]<MinV) {MinV=V[n];NumberminV=n;}
- }
- LossP=GenerateP-LoadP;
- cout<<"发电有功:"<<GenerateP<<" 负荷有功:"<<LoadP<<" 有功损耗:"<<LossP<<" 最高电压:"<<MaxV<<" 最高电压节点号:"<<NumbermaxV<<" 最低电压:"<<MinV<<" 最低电压节点号:"<<NumberminV<<endl;
- }