《潮流计算代码c++(共37页).docx》由会员分享,可在线阅读,更多相关《潮流计算代码c++(共37页).docx(37页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上电力系统潮流上机课程设计报告 院 系:电气与电子工程学院 班 级: 电气1405 学 号: 学生姓名: 指导教师: 孙英云 设计周数: 两周 成 绩: 日期:2017年7月5日专心-专注-专业一、课程设计的目的与要求培养学生的电力系统潮流计算机编程能力,掌握计算机潮流计算的相关知识二、 设计正文1 掌握计算机潮流计算的原理:a) 复习电力系统分析基础中潮流的计算机算法一章,重点掌握节点分类、潮流算法介绍b) 详细阅读牛拉法部分,掌握潮流方程(极坐标、直角坐标)的写法,掌握雅可比矩阵的公式及排列顺序和潮流方程、变量顺序的关系,掌握迭代法收敛条件及迭代法的基本原理c) 设
2、计程序框图,划分功能模块、并对每个模块的输入输出量进行细化。2 编写计算机潮流计算程序a) 学习了解IEEE标准格式数据,学习掌握C/C+读取数据的方法b) 设计计算机数据存储母线、支路数据的结构,并将所读取的数据存放于所设计的结构当中c) 学习节点排序、节点导纳阵计算方法,编写节点导纳阵生成模块d) 编写潮流方程不平衡量计算模块e) 编写雅可比矩阵生成子模块f) 利用给定的pfMatrix类,编写修正量计算模块g) 实现潮流计算主程序,并利用IEEE标准节点数据进行校验,要求能够输出计算结果、支路潮流等必要信息3 思考题1潮流计算的方法有哪些?各有何特点?答:潮流计算分为简单电力网络的手算和
3、复杂电力网络的机算两大类,其中机算又有高斯-赛德尔法、牛顿-拉夫逊法和P-Q分解法。各方法特点如下所示:手算求解潮流一般只用于简单的网络中,计算量大,对于多节点的网络用手算一般难以解决问题。但是通过手算可以对物理概念的理解,还可以在运用计算机计算前由手算的形式求取某些原始数据。方法高斯-赛德尔法牛顿-拉夫逊法P-Q分解法初值要求不高高高迭代次数多少多收敛速度慢较快最快精度三者一样应用早期应用多,现在较少广泛应用应用较多2如果交给你一个任务,请你用已有的潮流计算软件计算北京城市电网的潮流,你应该做哪些工作?(收集哪些数据,如何整理,计算结果如何分析)答:.所需要收集的数据:A.电网中所有节点的数
4、据:a各节点的类型,包括平衡节点、PV节点、PQ节点b.对于平衡节点要了解节点的电压大小相位、及节点所能提供的最大最小有功无功功率c.PV节点要知道节点电压大小注入有功功率及节点所能提供的最大和最小无功功.率d.PQ节点要知道节点的注入有功和无功功率B电网中所有支路的数据:a.各支路类型,即是否含有变压器b.各支路的电阻、电感、电纳c.各变压器的变比。数据整理:将上述数据资料进行分类整理,并为每个节点及支路编上编号。将整理的结果写成本实验中所要求的格式(原始数据的txt文档),再用本实验所编制的程序进行求解,得到各节点电压、相位,各线路传输功率、损耗,平衡节点注入功率等数值。.计算结果分析:考
5、虑PQ节点的电压是否过高或过低;分析PV节点的电压幅值是否正常及无功功率是否超出范围;分析平衡节点有功、无功功率是否在节点所能提供的范围之内;分析给定之路的功率,看是否超出线路的最大传输容量;分析整个系统的网损是否达到标准。3设计中遇到的问题和解决的办法。c+好久没用,有些生疏。经过复习与百度,渐渐回忆起来。潮流计算机解法已经遗忘,经过复习查书,很快熟悉起来。对老师的思路不是很理解,经过与同学一起探讨,得到了正确答案。三、 课程设计总结或结论2016下半年学历电力系统潮流计算,当时并没有编程实践,就背了背矩阵公式。现在真让我们上手实践,感觉还是略有难度,很有挑战性,毕竟平时没多少机会接触程序。
6、通过这两周的摸索与交流,最终完成了潮流的编程计算。由于是在老师的工作基础上进行补充与改造,所以要读懂老师的代码。我觉得老师的注释还是太少,而且还是英文(虽然英语也能看懂,但还是觉得中文环境用中文好)。在对节点数据的处理上,我们对老师的思路并不能感到理解,因此在后面雅克比矩阵生成与不平衡量计算模块绕了些许弯路,我最后还是没采用老师的办法。除了算法的设计外,最恼人的当属开发工具了,机房是vs2010,而我电脑上是vc+6.0与vs2015,一开始用vc写,然后出了一个迷之bug,换到了vs2010才解决。但我电脑装上vs2010却因为2015的存在无法运行,vs2015也无法运行我在2010下写好
7、的程序。不想卸掉花老长时间才装上的巨大2015,为此浪费了许多时间,很令人生气。能够亲手实践电力系统潮流的计算机计算,还是学到了很多知识,对潮流计算那一部分知识又有了更深的印象。四、参考文献1. 电力系统稳态分析,陈珩,中国电力出版社,2007年,第三版;2. 高等电力网络分析,张伯明,陈寿孙,严正,清华大学出版社,2007年,第二版3. 电力系统计算:电子数字计算机的应用,西安交通大学等合编。北京:水利电力出版社;4. 现代电力系统分析,王锡凡主编,科学出版社; 二、 程序Example.cpp#include #include #include #include pf.husing nam
8、espace std;void main()pf A;A.readDataFromFile(009ieee.dat);A.initPFData(); A.makeYMatrix();A.makeJacobi();A.solveLF();A.outputResult();system(pause);Pf.cpp#include pf.husing namespace std;pf:pf(void)m_Line = NULL;m_Bus = NULL;m_Bus_newIdx = NULL;m_pv_Num = 0;m_sw_Num = 0;m_pq_Num = 0;pf:pf(void)if (
9、m_Line!=NULL) delete m_Line;if (m_Bus!=NULL) delete m_Bus;if (m_Bus_newIdx!=NULL) delete m_Bus_newIdx;int pf:readDataFromFile(string fileName)int i;string strLine,strTemp;ifstream fin;/ open file to read;fin.open(fileName.c_str();if(!fin.fail()/ 1. read SBase;getline(fin,strLine);strTemp.assign(strL
10、ine,31,6);m_SBase = atof(strTemp.c_str();/ 2. read Bus Data here ; / 2.1 read Bus num;getline(fin,strLine);size_t pos_begin, pos_end;pos_begin = strLine.find(FOLLOWS);pos_begin = pos_begin + size_t(10);pos_end = strLine.find(ITEM);strTemp = strLine.substr(pos_begin, pos_end - pos_begin);m_Bus_Num =
11、atoi(strTemp.c_str(); / 2.2 read each bus data here/ allocate memory for m_Busm_Bus = new Busm_Bus_Num;m_Bus_newIdx = new intm_Bus_Num;for (int i = 0; im_Bus_Num; i+)getline(fin,strLine);strTemp = strLine.substr(0,4);/ read bus numm_Busi.Num = atoi(strTemp.c_str();/ read bus Name;strTemp = strLine.s
12、ubstr(5,7);m_Busi.Name = strTemp;/ read bus type PQ: Type = 1; PV: Type = 2; swing: Type = 3;/判断条件YYstrTemp = strLine.substr(24,2);if (atoi(strTemp.c_str()=1)m_Busi.Type = 1; m_pq_Num +;else if(atoi(strTemp.c_str()=2)m_Busi.Type = 2;m_pv_Num +;else if(atoi(strTemp.c_str()=3)m_Busi.Type = 3;m_sw_Num
13、+;/read bus VoltagestrTemp = strLine.substr(27,6);m_Busi.V = atof(strTemp.c_str();/read bus anglestrTemp = strLine.substr(33,7);m_Busi.theta = atof(strTemp.c_str()/180*3.;/read bus Load PstrTemp = strLine.substr(40,9);m_Busi.LoadP = atof(strTemp.c_str()/m_SBase;/read bus Load QstrTemp = strLine.subs
14、tr(49,10);m_Busi.LoadQ = atof(strTemp.c_str()/m_SBase;/read bus Gen PstrTemp = strLine.substr(59,8);m_Busi.GenP = atof(strTemp.c_str()/m_SBase;/read bus Gen Q strTemp = strLine.substr(67,8);m_Busi.GenQ = atof(strTemp.c_str()/m_SBase;/read bus Shunt conductance G strTemp = strLine.substr(106,8);/read
15、 bus Shunt susceptance B strTemp = strLine.substr(114,8);/ 3. read Line Data here ;/ 3.1 read Line num;getline(fin,strLine);getline(fin,strLine);pos_begin = strLine.find(FOLLOWS);pos_begin = pos_begin + size_t(10);pos_end = strLine.find(ITEM);strTemp = strLine.substr(pos_begin, pos_end - pos_begin);
16、m_Line_Num = atoi(strTemp.c_str();/ 3.2 read each line data;m_Line = new Linem_Line_Num;for (i = 0;i m_Line_Num;i+)getline(fin,strLine);/read Tap bus numberstrTemp = strLine.substr(0,4);m_Linei.NumI = atoi(strTemp.c_str();/read Z bus numberstrTemp = strLine.substr(5,4);m_Linei.NumJ = atoi(strTemp.c_
17、str();/read line typestrTemp = strLine.substr(18,1);m_Linei.Type = atoi(strTemp.c_str();/read line resistance RstrTemp = strLine.substr(19,10);m_Linei.R = atof(strTemp.c_str();/read line reactance XstrTemp = strLine.substr(29,11);m_Linei.X = atof(strTemp.c_str();/read line charging BstrTemp = strLin
18、e.substr(40,10);m_Linei.B = atof(strTemp.c_str();/read transformer ratiostrTemp = strLine.substr(76,6);m_Linei.K = atof(strTemp.c_str(); / 4. close the file;fin.close();elsecoutfile open fail!endl;return 0;int pf:initPFData()/ according to Page 132 of ref book 3,/ reindex the bus num ase the sequenc
19、e PQ PV SW;int iPQ,iPV,iSW;iPQ = 0;iPV = 0;iSW = 0;int i;for( i = 0; im_Bus_Num; i+)/按PQPVSW排序switch (m_Busi.Type)case 1:m_Bus_newIdxi = iPQ;iPQ+;break;case 2:m_Bus_newIdxi = iPV + m_pq_Num;iPV+;break;case 3:m_Bus_newIdxi = iSW + m_pq_Num + m_pv_Num;iSW+;break;for (i =0; im_Bus_Num; i+)coutm_Bus_new
20、Idxiendl;/ here we give the size of Jacobi matrix;m_Jacobi.setSize(2*m_pq_Num+m_pv_Num,2*m_pq_Num+m_pv_Num);m_Matrix_G.setSize(m_Bus_Num,m_Bus_Num);m_Matrix_B.setSize(m_Bus_Num,m_Bus_Num);return 0;int pf:getBusIdx(int busNum)/ return the index of bus from busNumint i,idx = -1;for (i = 0; im_Bus_Num;
21、 i+)if (m_Busi.Num = busNum)idx = i;return idx;int pf:makeYMatrix()/ TO DOint i;float Line_G;float Line_B;for(i = 0;i m_Line_Num;i+)Line_G = m_Linei.R/(m_Linei.R*m_Linei.R+m_Linei.X*m_Linei.X); Line_B = -m_Linei.X/(m_Linei.R*m_Linei.R+m_Linei.X*m_Linei.X);if(m_Linei.Type != 2)/m_Matrix_G.DumpInfo(he
22、re); m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) = m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) + Line_G; m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumJ) += -Line_G; m_Matrix_G(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumI) += -Line_G; m_Matrix_G(getBusIdx(m_
23、Linei.NumJ),getBusIdx(m_Linei.NumJ) = m_Matrix_G(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) + Line_G; m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) = m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) + Line_B + m_Linei.B/2; m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Li
24、nei.NumJ) += -Line_B; m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumI) += -Line_B; m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) = m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) + Line_B + m_Linei.B/2; else m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI)
25、 = m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) + Line_G/(m_Linei.K*m_Linei.K); m_Matrix_G(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumJ) += -Line_G/m_Linei.K; m_Matrix_G(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumI) += -Line_G/m_Linei.K; m_Matrix_G(getBusIdx(m_Linei.NumJ),getBusIdx
26、(m_Linei.NumJ) = m_Matrix_G(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) + Line_G; m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) = m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumI) + Line_B/(m_Linei.K*m_Linei.K); m_Matrix_B(getBusIdx(m_Linei.NumI),getBusIdx(m_Linei.NumJ) +=
27、-Line_B/m_Linei.K; m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumI) += -Line_B/m_Linei.K; m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) = m_Matrix_B(getBusIdx(m_Linei.NumJ),getBusIdx(m_Linei.NumJ) + Line_B; m_Matrix_G.outputMatrixtoFile(G.txt);/实部m_Matrix_B.outputMatrixtoFile(
28、B.txt);/虚部return 0;int pf:makeJacobi()int equNum = 2*m_pq_Num+m_pv_Num;int i,j,k;double H,J,N,L;/ init Jacobi matrix;for(i = 0;i equNum;i+)for(j = 0;j equNum;j+)m_Jacobi(i,j) = 0.0;for(i = 0; i m_Bus_Num; i+)for(j = 0; jm_Bus_Num; j+)H=0.0;J=0.0;L=0.0;N=0.0;if(i=j)for(int k=0;km_Bus_Num;k+)if(i!=k)/
29、H+=-m_Busi.V*m_Busk.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*sin(m_Busi.theta-m_Busk.theta)-m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*cos(m_Busi.theta-m_Busk.theta);/J+= m_Busi.V*m_Busk.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*cos(m_Busi.theta-m_Busk.th
30、eta)+m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*sin(m_Busi.theta-m_Busk.theta);/N+= m_Busi.V*m_Busk.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*cos(m_Busi.theta-m_Busk.theta)+m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*sin(m_Busi.theta-m_Busk.theta);/L+=m_Busi.V*
31、m_Busk.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*sin(m_Busi.theta-m_Busk.theta)-m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busk.Num)*cos(m_Busi.theta-m_Busk.theta);H+=-m_Busi.V*m_Busk.V*(m_Matrix_G(i,k)*sin(m_Busi.theta-m_Busk.theta)-m_Matrix_B(i,k)*cos(m_Busi.theta-m_Busk.theta);J
32、+= m_Busi.V*m_Busk.V*(m_Matrix_G(i,k)*cos(m_Busi.theta-m_Busk.theta)+m_Matrix_B(i,k)*sin(m_Busi.theta-m_Busk.theta);N+= m_Busi.V*m_Busk.V*(m_Matrix_G(i,k)*cos(m_Busi.theta-m_Busk.theta)+m_Matrix_B(i,k)*sin(m_Busi.theta-m_Busk.theta);L+=m_Busi.V*m_Busk.V*(m_Matrix_G(i,k)*sin(m_Busi.theta-m_Busk.theta
33、)-m_Matrix_B(i,k)*cos(m_Busi.theta-m_Busk.theta);/N+=2*m_Busi.V*m_Busi.V*m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busi.Num);/L+=-2*m_Busi.V*m_Busi.V*m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busi.Num);N+=2*m_Busi.V*m_Busi.V*m_Matrix_G(i,i);L+=-2*m_Busi.V*m_Busi.V*m_Matrix_B(i,i);else/H = m_Bu
34、si.V*m_Busj.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busj.Num)*sin(m_Busi.theta-m_Busj.theta)-m_Matrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busj.Num)*cos(m_Busi.theta-m_Busj.theta);/J= -m_Busi.V*m_Busj.V*(m_Matrix_G(getBusIdx(m_Busi.Num),getBusIdx(m_Busj.Num)*cos(m_Busi.theta-m_Busj.theta)+m_M
35、atrix_B(getBusIdx(m_Busi.Num),getBusIdx(m_Busj.Num)*sin(m_Busi.theta-m_Busj.theta);/N=-J;/L=H;H = m_Busi.V*m_Busj.V*(m_Matrix_G(i,j)*sin(m_Busi.theta-m_Busj.theta)-m_Matrix_B(i,j)*cos(m_Busi.theta-m_Busj.theta);J= -m_Busi.V*m_Busj.V*(m_Matrix_G(i,j)*cos(m_Busi.theta-m_Busj.theta)+m_Matrix_B(i,j)*sin
36、(m_Busi.theta-m_Busj.theta);N=-J;L=H;/雅可比矩阵int a,b;switch(m_Busi.Type)case 1: / PQ bus;switch(m_Busj.Type)case 1: / PQ bus/ H N J L four elementsm_Jacobi(2*m_Bus_newIdxi,2*m_Bus_newIdxj) = H;m_Jacobi(2*m_Bus_newIdxi,2*m_Bus_newIdxj+1) = N;m_Jacobi(2*m_Bus_newIdxi+1,2*m_Bus_newIdxj) = J;m_Jacobi(2*m_
37、Bus_newIdxi+1,2*m_Bus_newIdxj+1) = L;break;case 2: / PV bus/ H J two elementsm_Jacobi(2*m_Bus_newIdxi,m_Bus_newIdxj+m_pq_Num) = H;m_Jacobi(2*m_Bus_newIdxi+1,m_Bus_newIdxj+m_pq_Num) = J;break;case 3: / SW busbreak;break;case 2: / PV bus;switch(m_Busj.Type)case 1: / PQ bus/ H N two elementsm_Jacobi(m_
38、Bus_newIdxi+m_pq_Num,2*m_Bus_newIdxj) = H;m_Jacobi(m_Bus_newIdxi+m_pq_Num,2*m_Bus_newIdxj+1) = N;break;case 2: / PV bus/ H, one elementm_Jacobi(m_Bus_newIdxi+m_pq_Num,m_Bus_newIdxj+m_pq_Num) = H;break;case 3: / SW busbreak;break;case 3: / SW bus;break;ofstream fout(J.txt);for(int i=0;iequNum;i+)for(
39、int j=0;jequNum;j+)foutsetw(12)m_Jacobi(i,j) ;foutendl;fout.close();return 0;int pf:solveLF()/ TODOint i;int equNum = 2*m_pq_Num + m_pv_Num;double * bph = new doubleequNum;/ 1. initializefor ( i = 0; im_Bus_Num; i+)switch (m_Busi.Type)case 1: /PQ nodem_Busi.V = 1;m_Busi.theta = 0;break;case 2: /PV nodem_Busi.theta = 0;break;case 3: /SW nodebreak; / 2. iterateint maxIter = 20;int p,k;for (i = 0; imaxIter; i+)/ 2.1 calDeltaSif(calcDeltaS(bph)=1) /判断是否收敛cout一共迭代i+1
限制150内