├── .gitattributes ├── .gitignore ├── PowerFlowCalculation ├── PowerFlowCalculation.sln ├── PowerFlowCalculation.v12.suo └── PowerFlowCalculation │ ├── DrawConvergenceGraph.py │ ├── Graphes and outputs │ ├── 2.5timesDivergence.png │ ├── 2.5timesDivergence.txt │ ├── 2.5timesDivergence局部放大图——底部起伏处.png │ ├── 3timesDivergence.png │ ├── 3timesDivergence.txt │ ├── 3timesDivergence局部放大图——底部起伏处.png │ ├── timesResultComparison.png │ ├── timesResultComparison.txt │ ├── timesResultComparison局部放大图——收敛转折处.png │ ├── 牛拉法与PQ对比图_1.png │ └── 牛拉法与PQ对比图_2.png │ ├── PowerFlowCalculation.py │ ├── PowerFlowCalculation.pyc │ ├── PowerFlowCalculation.pyproj │ ├── drawTimesComparisonGraph.py │ ├── globalVariable.py │ ├── globalVariable.pyc │ ├── input.txt │ ├── input1.txt │ ├── makeInput.py │ ├── makeInput.pyc │ ├── output.txt │ └── timesResultComparison.txt └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | *.publishproj 131 | 132 | # NuGet Packages Directory 133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 134 | #packages/ 135 | 136 | # Windows Azure Build Output 137 | csx 138 | *.build.csdef 139 | 140 | # Windows Store app package directory 141 | AppPackages/ 142 | 143 | # Others 144 | sql/ 145 | *.Cache 146 | ClientBin/ 147 | [Ss]tyle[Cc]op.* 148 | ~$* 149 | *~ 150 | *.dbmdl 151 | *.[Pp]ublish.xml 152 | *.pfx 153 | *.publishsettings 154 | 155 | # RIA/Silverlight projects 156 | Generated_Code/ 157 | 158 | # Backup & report files from converting an old project file to a newer 159 | # Visual Studio version. Backup files are not needed, because we have git ;-) 160 | _UpgradeReport_Files/ 161 | Backup*/ 162 | UpgradeLog*.XML 163 | UpgradeLog*.htm 164 | 165 | # SQL Server files 166 | App_Data/*.mdf 167 | App_Data/*.ldf 168 | 169 | ############# 170 | ## Windows detritus 171 | ############# 172 | 173 | # Windows image file caches 174 | Thumbs.db 175 | ehthumbs.db 176 | 177 | # Folder config file 178 | Desktop.ini 179 | 180 | # Recycle Bin used on file shares 181 | $RECYCLE.BIN/ 182 | 183 | # Mac crap 184 | .DS_Store 185 | 186 | 187 | ############# 188 | ## Python 189 | ############# 190 | 191 | *.py[cod] 192 | 193 | # Packages 194 | *.egg 195 | *.egg-info 196 | dist/ 197 | build/ 198 | eggs/ 199 | parts/ 200 | var/ 201 | sdist/ 202 | develop-eggs/ 203 | .installed.cfg 204 | 205 | # Installer logs 206 | pip-log.txt 207 | 208 | # Unit test / coverage reports 209 | .coverage 210 | .tox 211 | 212 | #Translations 213 | *.mo 214 | 215 | #Mr Developer 216 | .mr.developer.cfg 217 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PowerFlowCalculation", "PowerFlowCalculation\PowerFlowCalculation.pyproj", "{56087C25-23D2-4881-9819-22CB2FE7C15D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {56087C25-23D2-4881-9819-22CB2FE7C15D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {56087C25-23D2-4881-9819-22CB2FE7C15D}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation.v12.suo -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/DrawConvergenceGraph.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # Name: DrawConvergenceGraph.py 4 | # Func: To draw the convergence graph of this project, this can be the startup file of this project too. 5 | # Author: Maples7 6 | # Addr: EE of SDU, China 7 | # Time: 2015-04-10 8 | # Link: http://www.cnblogs.com/maples7/ 9 | 10 | from PowerFlowCalculation import * 11 | 12 | import pylab as pl 13 | 14 | # main 15 | #y_down = 0 16 | #y_up = 0.6 17 | floatResBit = 7 18 | 19 | plot = [] 20 | pl.title('Convergence Graph') 21 | pl.xlabel('Times of Iteration') 22 | pl.ylabel('Maximum Power Error') 23 | pl.grid(True) 24 | #pl.ylim(y_down, y_up) 25 | 26 | # draw Newton-Raphson method 27 | draw = pl.plot(x_axis, y_axis, 'blue', label='Newton-Raphson Method') 28 | plot.append(draw) 29 | 30 | for i in range(len(x_axis)): # show points' data text 31 | pl.text(x_axis[i], y_axis[i], str(round(y_axis[i], floatResBit))) 32 | 33 | 34 | # draw PQ decomposition method, The Data is from Page 115 in Reference book 35 | # for comparison 36 | #x_axis = [1, 2, 3, 4, 5, 6, 7] 37 | #y_axis = [0.55580, 0.07135, 0.00715, 0.00078, 0.00020, 0.00005, 0.00001] 38 | #draw = pl.plot(x_axis, y_axis, 'red', label='PQ Decomposition Method') 39 | #plot.append(draw) 40 | 41 | #for i in range(len(x_axis)): # show points' data text 42 | # pl.text(x_axis[i], y_axis[i], str(round(y_axis[i], floatResBit))) 43 | 44 | 45 | pl.legend() 46 | pl.show() -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/2.5timesDivergence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/2.5timesDivergence.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/2.5timesDivergence.txt: -------------------------------------------------------------------------------- 1 | Times of iteration: 1 The maximum power error: 0.500000 2 | Times of iteration: 2 The maximum power error: 0.109161 3 | Times of iteration: 3 The maximum power error: 0.040712 4 | Times of iteration: 4 The maximum power error: 0.012056 5 | Times of iteration: 5 The maximum power error: 0.003419 6 | Times of iteration: 6 The maximum power error: 0.001202 7 | Times of iteration: 7 The maximum power error: 0.001498 8 | Times of iteration: 8 The maximum power error: 0.001053 9 | Times of iteration: 9 The maximum power error: 0.002979 10 | Times of iteration: 10 The maximum power error: 0.001091 11 | Times of iteration: 11 The maximum power error: 0.002326 12 | Times of iteration: 12 The maximum power error: 0.000995 13 | Times of iteration: 13 The maximum power error: 0.007418 14 | Times of iteration: 14 The maximum power error: 0.002077 15 | Times of iteration: 15 The maximum power error: 0.000968 16 | Times of iteration: 16 The maximum power error: 0.049906 17 | Times of iteration: 17 The maximum power error: 0.013126 18 | Times of iteration: 18 The maximum power error: 0.003682 19 | Times of iteration: 19 The maximum power error: 0.001262 20 | Times of iteration: 20 The maximum power error: 0.001318 21 | Times of iteration: 21 The maximum power error: 0.001234 22 | Times of iteration: 22 The maximum power error: 0.001390 23 | Times of iteration: 23 The maximum power error: 0.001139 24 | Times of iteration: 24 The maximum power error: 0.001815 25 | Times of iteration: 25 The maximum power error: 0.000967 26 | Times of iteration: 26 The maximum power error: 0.044394 27 | Times of iteration: 27 The maximum power error: 0.010089 28 | Times of iteration: 28 The maximum power error: 0.002933 29 | Times of iteration: 29 The maximum power error: 0.001078 30 | Times of iteration: 30 The maximum power error: 0.002518 31 | Times of iteration: 31 The maximum power error: 0.001023 32 | Times of iteration: 32 The maximum power error: 0.004225 33 | 34 | 35 | The power flow is Divergence. -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/2.5timesDivergence局部放大图——底部起伏处.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/2.5timesDivergence局部放大图——底部起伏处.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/3timesDivergence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/3timesDivergence.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/3timesDivergence.txt: -------------------------------------------------------------------------------- 1 | Times of iteration: 1 The maximum power error: 0.500000 2 | Times of iteration: 2 The maximum power error: 0.151220 3 | Times of iteration: 3 The maximum power error: 0.109714 4 | Times of iteration: 4 The maximum power error: 12.081385 5 | Times of iteration: 5 The maximum power error: 0.988150 6 | Times of iteration: 6 The maximum power error: 4982.244794 7 | Times of iteration: 7 The maximum power error: 1255.732251 8 | Times of iteration: 8 The maximum power error: 314.127600 9 | Times of iteration: 9 The maximum power error: 78.650899 10 | Times of iteration: 10 The maximum power error: 19.798282 11 | Times of iteration: 11 The maximum power error: 4.991243 12 | Times of iteration: 12 The maximum power error: 1.121875 13 | Times of iteration: 13 The maximum power error: 0.273683 14 | Times of iteration: 14 The maximum power error: 0.382010 15 | Times of iteration: 15 The maximum power error: 0.361991 16 | Times of iteration: 16 The maximum power error: 0.201135 17 | Times of iteration: 17 The maximum power error: 0.129419 18 | Times of iteration: 18 The maximum power error: 0.503540 19 | Times of iteration: 19 The maximum power error: 0.169849 20 | Times of iteration: 20 The maximum power error: 0.116798 21 | Times of iteration: 21 The maximum power error: 1.417613 22 | Times of iteration: 22 The maximum power error: 0.375510 23 | Times of iteration: 23 The maximum power error: 0.152368 24 | Times of iteration: 24 The maximum power error: 0.123493 25 | Times of iteration: 25 The maximum power error: 0.449738 26 | Times of iteration: 26 The maximum power error: 0.155678 27 | Times of iteration: 27 The maximum power error: 0.126302 28 | Times of iteration: 28 The maximum power error: 0.381496 29 | Times of iteration: 29 The maximum power error: 0.140491 30 | Times of iteration: 30 The maximum power error: 0.148528 31 | Times of iteration: 31 The maximum power error: 0.155663 32 | Times of iteration: 32 The maximum power error: 0.119018 33 | 34 | 35 | The power flow is Divergence. -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/3timesDivergence局部放大图——底部起伏处.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/3timesDivergence局部放大图——底部起伏处.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/timesResultComparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/timesResultComparison.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/timesResultComparison.txt: -------------------------------------------------------------------------------- 1 | 0.01 7 2 | 1 26.984655 3 | 2 1.225535 4 | 3 0.275823 5 | 4 0.147840 6 | 5 0.026819 7 | 6 0.000590 8 | 7 0.000001 9 | 10 | 0.1 5 11 | 1 2.087818 12 | 2 0.472366 13 | 3 0.031669 14 | 4 0.000180 15 | 5 0.000000 16 | 17 | 0.5 4 18 | 1 0.500000 19 | 2 0.096659 20 | 3 0.002861 21 | 4 0.000003 22 | 23 | 2 5 24 | 1 0.500000 25 | 2 0.076128 26 | 3 0.013866 27 | 4 0.000467 28 | 5 0.000000 29 | 30 | 2.2 5 31 | 1 0.500000 32 | 2 0.083610 33 | 3 0.021742 34 | 4 0.001587 35 | 5 0.000009 36 | 37 | 2.3 6 38 | 1 0.500000 39 | 2 0.092169 40 | 3 0.026931 41 | 4 0.003006 42 | 5 0.000046 43 | 6 0.000000 44 | 45 | 2.4 6 46 | 1 0.500000 47 | 2 0.100684 48 | 3 0.033181 49 | 4 0.005876 50 | 5 0.000303 51 | 6 0.000001 52 | 53 | 2.5 32 54 | 1 0.500000 55 | 2 0.109161 56 | 3 0.040712 57 | 4 0.012056 58 | 5 0.003419 59 | 6 0.001202 60 | 7 0.001498 61 | 8 0.001053 62 | 9 0.002979 63 | 10 0.001091 64 | 11 0.002326 65 | 12 0.000995 66 | 13 0.007418 67 | 14 0.002077 68 | 15 0.000968 69 | 16 0.049906 70 | 17 0.013126 71 | 18 0.003682 72 | 19 0.001262 73 | 20 0.001318 74 | 21 0.001234 75 | 22 0.001390 76 | 23 0.001139 77 | 24 0.001815 78 | 25 0.000967 79 | 26 0.044394 80 | 27 0.010089 81 | 28 0.002933 82 | 29 0.001078 83 | 30 0.002518 84 | 31 0.001023 85 | 32 0.004225 86 | 87 | 3 32 88 | 2 0.151220 89 | 3 0.109714 90 | 4 12.081385 91 | 5 0.988150 92 | 6 4982.244794 93 | 7 1255.732251 94 | 8 314.127600 95 | 9 78.650899 96 | 10 19.798282 97 | 11 4.991243 98 | 12 1.121875 99 | 13 0.273683 100 | 14 0.382010 101 | 15 0.361991 102 | 16 0.201135 103 | 17 0.129419 104 | 18 0.503540 105 | 19 0.169849 106 | 20 0.116798 107 | 21 1.417613 108 | 22 0.375510 109 | 23 0.152368 110 | 24 0.123493 111 | 25 0.449738 112 | 26 0.155678 113 | 27 0.126302 114 | 28 0.381496 115 | 29 0.140491 116 | 30 0.148528 117 | 31 0.155663 118 | 32 0.119018 119 | 120 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/timesResultComparison局部放大图——收敛转折处.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/timesResultComparison局部放大图——收敛转折处.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/牛拉法与PQ对比图_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/牛拉法与PQ对比图_1.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/牛拉法与PQ对比图_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/Graphes and outputs/牛拉法与PQ对比图_2.png -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/PowerFlowCalculation.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # Name: PowerFlowCalculation.py 4 | # Func: To calc the power flow of elecrtcal grid using Newton-Raphson method, this is the main file of this project 5 | # Author: Maples7 6 | # Addr: EE of SDU, China 7 | # Time: 2015-04-07 8 | # Link: http://www.cnblogs.com/maples7/ 9 | 10 | import globalVariable as gv 11 | import numpy as np 12 | from math import sin, cos, fabs, pi 13 | 14 | # const 15 | MAX_ITER = 30 # max iter times 16 | DIVERGENCE_ERROR = 1.0e4 17 | 18 | from makeInput import * 19 | 20 | if inputFile in locals().keys(): 21 | inputFile = "input.txt" 22 | 23 | def read_data(): 24 | """ 25 | Read Data from input.txt, the global variables are in the globalVariable.py 26 | """ 27 | global inputFile 28 | try: 29 | fp = open(inputFile, "r+") 30 | 31 | firstLine = fp.readline().split(" ") 32 | gv.num_node = int(firstLine[0]) 33 | gv.num_line = int(firstLine[1]) 34 | gv.num_tran = int(firstLine[2]) 35 | gv.num_gene = int(firstLine[3]) 36 | gv.num_load = int(firstLine[4]) 37 | gv.error_max = float(firstLine[5]) 38 | 39 | gv.line = [None] 40 | for i in range(gv.num_line): 41 | nLine = fp.readline().split(" ") 42 | temp = gv.Line(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 43 | gv.line.append(temp) 44 | 45 | nLine = fp.readline() 46 | gv.tran = [None] 47 | for i in range(gv.num_tran): 48 | nLine = fp.readline().split(" ") 49 | temp = gv.Tran(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 50 | gv.tran.append(temp) 51 | 52 | nLine = fp.readline() 53 | gv.gene = [None] 54 | for i in range(gv.num_gene): 55 | nLine = fp.readline().split(" ") 56 | temp = gv.Gene(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 57 | gv.gene.append(temp) 58 | 59 | nLine = fp.readline() 60 | gv.load = [None] 61 | for i in range(gv.num_load): 62 | nLine = fp.readline().split(" ") 63 | temp = gv.Load(int(nLine[0]), float(nLine[1]), float(nLine[2])) 64 | gv.load.append(temp) 65 | 66 | fp.close() 67 | except: 68 | print "Error: Can't read Data from "+inputFile+". (function read_data() error)" 69 | exit() 70 | 71 | def output_file_ready(): 72 | """ 73 | make output.txt file ready to store output result 74 | """ 75 | global fou 76 | try: 77 | fou = open("output.txt", "w+") 78 | except: 79 | print "Error: Can't create output.txt. (function output_file_ready() error)" 80 | exit() 81 | 82 | def admt_matrix(): 83 | """ 84 | Create admittance matrix 85 | """ 86 | global Y 87 | Y = np.zeros((gv.num_node+1, gv.num_node+1), dtype = complex) 88 | for lineNum in range(1, gv.num_line+1): 89 | i = gv.line[lineNum].i 90 | j = gv.line[lineNum].j 91 | r = gv.line[lineNum].a 92 | x = gv.line[lineNum].b 93 | comp = 1/complex(r, x) 94 | if i==j: 95 | Y[i][i] += comp 96 | else: 97 | c = gv.line[lineNum].c 98 | Y[i][j] -= comp 99 | Y[j][i] = Y[i][j] 100 | Y[i][i] += (comp + complex(0, c)) 101 | Y[j][j] += (comp + complex(0, c)) 102 | for tranNum in range(1, gv.num_tran+1): 103 | i = gv.tran[tranNum].i 104 | j = gv.tran[tranNum].j 105 | r = gv.tran[tranNum].a 106 | x = gv.tran[tranNum].b 107 | c = gv.tran[tranNum].c 108 | comp = 1/complex(r, x) 109 | Y[i][i] += comp 110 | Y[i][j] -= comp/c 111 | Y[j][i] = Y[i][j] 112 | Y[j][j] += comp/c/c 113 | 114 | 115 | def Um_and_Ua(): 116 | """ 117 | Set the amplitude and phase angle of voltage 118 | """ 119 | global Um 120 | global Ua 121 | Um = np.ones(gv.num_node+1) 122 | Ua = np.zeros(gv.num_node+1) 123 | for i in range(1, gv.num_gene+1): 124 | if gv.gene[i].j <= 0: 125 | Um[gv.gene[i].i] = gv.gene[i].c 126 | 127 | def form_Jacobian(): 128 | """ 129 | Form Jacobian Matrix & Calc the Power error 130 | """ 131 | global Um 132 | global Ua 133 | global Jacob 134 | global P 135 | global Q 136 | global Y 137 | 138 | n2 = 2*gv.num_node 139 | nu = n2 + 1 140 | for i in range(1, gv.num_node+1): 141 | vi = Um[i] 142 | di = Ua[i] 143 | dp = 0.0 144 | dq = 0.0 145 | for j in range(1, gv.num_node+1): 146 | if j != i: # when i <> j, off-diagonal elements 147 | g = Y[i][j].real # G 148 | b = Y[i][j].imag # B 149 | vj = Um[j] 150 | dj = Ua[j] 151 | dij = di - dj # diff of Phase Angle 152 | Hij = -Um[i] * Um[j] * (g*sin(dij) - b*cos(dij)) 153 | Lij = Hij 154 | Jacob[i][j] = Hij 155 | Jacob[i+gv.num_node][j+gv.num_node] = Lij 156 | Nij = -Um[i]*Um[j]*(g*cos(dij)+b*sin(dij)) 157 | Mij = -Nij 158 | Jacob[i][j+gv.num_node]=Nij 159 | Jacob[i+gv.num_node][j] = Mij 160 | p = Um[j]*(g*cos(dij)+b*sin(dij)) 161 | q = Um[j]*(g*sin(dij)-b*cos(dij)) 162 | dp += p 163 | dq += q 164 | g = Y[i][i].real 165 | b = Y[i][i].imag 166 | Hii = vi*dq 167 | Nii = -vi*dp - 2*vi*vi*g 168 | Mii = -vi*dp 169 | Lii = -vi*dq + 2*vi*vi*b 170 | Jacob[i][i] = Hii 171 | Jacob[i][i+gv.num_node] = Nii 172 | Jacob[i+gv.num_node][i] = Mii 173 | Jacob[i+gv.num_node][i+gv.num_node] = Lii 174 | Jacob[i][nu] = -vi*(dp+vi*g) 175 | Jacob[i+gv.num_node][nu] = -vi*(dq-vi*b) 176 | P[i] = vi * (dp+vi*g) 177 | Q[i] = vi * (dq-vi*b) 178 | for i in range(1, gv.num_load+1): 179 | kk = gv.load[i].i 180 | lp = gv.load[i].a 181 | lq = gv.load[i].b 182 | Jacob[kk][nu] += -lp 183 | Jacob[kk+gv.num_node][nu] += -lq 184 | for i in range(1, gv.num_gene+1): 185 | kk = gv.gene[i].i 186 | gp = gv.gene[i].a 187 | gq = gv.gene[i].b 188 | Jacob[kk][nu] += gp 189 | Jacob[kk+gv.num_node][nu] += gq 190 | for k in range(1, gv.num_gene+1): 191 | ii = gv.gene[k].i 192 | kk = gv.gene[k].j 193 | if kk == 0: # Balance nodes 194 | for j in range(1, n2+1): 195 | Jacob[ii][j] = 0.0 196 | Jacob[gv.num_node+ii][j] = 0.0 197 | Jacob[j][ii] = 0.0 198 | Jacob[j][gv.num_node+ii] = 0.0 199 | Jacob[ii][ii] = 1.0 200 | Jacob[gv.num_node+ii][gv.num_node+ii] = 1.0 201 | Jacob[ii][nu] = 0.0 202 | Jacob[gv.num_node+ii][nu] = 0.0 203 | if kk < 0: # PV nodes 204 | for j in range(1, n2+1): 205 | Jacob[gv.num_node+ii][j] = 0.0 206 | Jacob[j][gv.num_node+ii] = 0.0 207 | Jacob[gv.num_node+ii][gv.num_node+ii] = 1.0 208 | Jacob[gv.num_node+ii][nu] = 0.0 209 | 210 | def node_flow(): 211 | """ 212 | output the power flow of nodes 213 | """ 214 | global fou 215 | global P 216 | global Q 217 | global Um 218 | global Ua 219 | fou.write("\n\n\n\t\t* - * - * - Rasult of Power Flow Calculation * - * - * -") 220 | fou.write("\n\n\t\t\t\t-------power flow of nodes-------") 221 | fou.write("\n\n\tno.i\t Um\t\t\tUa\t\t\tPG\t\t QG\t\t PL\t\t\tQL\n\n") 222 | for i in range(1, gv.num_node+1): 223 | b1,b2,c1,c2 = 0.0, 0.0, 0.0, 0.0 224 | for j in range(1, gv.num_gene+1): 225 | ii = gv.gene[j].i 226 | kk = gv.gene[j].j 227 | if i == ii and kk == 0: # Balance nodes 228 | b1 = P[ii] 229 | b2 = Q[ii] 230 | for k in range(1, gv.num_load+1): 231 | ii = gv.load[k].i 232 | if i == ii: 233 | c1 = gv.load[k].a 234 | c2 = gv.load[k].b 235 | b1 += c1 236 | b2 += c2 237 | break 238 | if i == ii and kk == -1: # PV nodes 239 | b1 = gv.gene[j].a 240 | b2 = Q[ii] 241 | for k in range(1, gv.num_load+1): 242 | ii = gv.load[k].i 243 | if i == ii: 244 | c1 = gv.load[k].a 245 | c2 = gv.load[k].b 246 | b2 += c2 247 | break 248 | for j in range(1, gv.num_load+1): 249 | ii = gv.load[j].i 250 | if i == ii: 251 | c1 = gv.load[j].a 252 | c2 = gv.load[j].b 253 | break 254 | fou.write(" %6d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f\n" %(i, Um[i], Ua[i]*180.0/pi, b1, b2, c1, c2)) 255 | 256 | def branch_flow(): 257 | """ 258 | output the power flow of branches 259 | """ 260 | global Um 261 | global Ua 262 | fou.write("\n\n\t\t\t\t-------power flow of branches-------") 263 | fou.write("\n\n\ti\t j\t\tPij\t\t Qij\t\t Pji\t\t Qji\t\t dP\t\t dQ\n\n") 264 | ph, qh = 0.0, 0.0 265 | for p in gv.line: 266 | if p == None: 267 | continue 268 | i = p.i 269 | j = p.j 270 | r = p.a 271 | x = p.b 272 | b = r*r + x*x 273 | if i == j: 274 | vi = Um[i] 275 | b = vi*vi/b 276 | pij = r*b 277 | qij = x*b 278 | pji = 0.0 279 | qji = 0.0 280 | dpb = pij 281 | ph += dpb 282 | dqb = qij 283 | qh += dqb 284 | else: 285 | r = r/b 286 | x = -x/b 287 | b = p.c 288 | dij = Ua[i] - Ua[j] 289 | vi = Um[i] 290 | vj = Um[j] 291 | vij = vi*vj 292 | vi *= vi 293 | vj *= vj 294 | cd = vij * cos(dij) 295 | sd = vij * sin(dij) 296 | pij = vi*r - r*cd - x*sd 297 | pji = vj*r - r*cd + x*sd 298 | dpb = pij + pji 299 | ph += dpb 300 | qij = -vi*(b+x) + x*cd - r*sd 301 | qji = -vj*(b+x) + x*cd + r*sd 302 | dqb = qij + qji 303 | qh += dqb 304 | fou.write(" %3d %3d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f\n" %(i, j, pij, qij, pji, qji, dpb, dqb)) 305 | for p in gv.tran: 306 | if p == None: 307 | continue 308 | i = p.i 309 | j = p.j 310 | r = p.a 311 | x = p.b 312 | t = p.c 313 | b = t*(r*r+x*x) 314 | r /= b 315 | x /= -b 316 | b = t - 1.0 317 | ri = r*b 318 | xi = x*b 319 | rj = -ri/t 320 | xj = -xi/t 321 | vi = Um[i] 322 | vj = Um[j] 323 | vij = vi*vj 324 | vi *= vi 325 | vj *= vj 326 | dij = Ua[i] - Ua[j] 327 | cd = vij * cos(dij) 328 | sd = vij * sin(dij) 329 | pij = vi*(ri+r) - r*cd - x*sd 330 | pji = vj*(rj+r) - r*cd + x*sd 331 | dpb = pij + pji 332 | ph += dpb 333 | qij = -vi*(xi+x) + x*cd - r*sd 334 | qji = -vj*(xj+x) + x*cd + r*sd 335 | dqb = qij + qji 336 | qh += dqb 337 | fou.write(" %3d %3d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f\n" %(i, j, pij, qij, pji, qji, dpb, dqb)) 338 | fou.write("\n\n The total loss of the system: - Active power:%8.5f\t\tReactive power:%8.5f" %(ph, qh)) 339 | 340 | def solv_Eqn(): 341 | """ 342 | solve the Modified Equations 343 | """ 344 | global Jacob 345 | n2 = 2*gv.num_node 346 | nu = n2 + 1 347 | for i in range(1, n2+1): 348 | i1 = i+1 349 | d = 1.0/Jacob[i][i] 350 | for j in range(i1, nu+1): 351 | e = Jacob[i][j] 352 | if e != 0.0: 353 | Jacob[i][j] = e*d 354 | if i != n2: 355 | for j in range(i1, n2+1): 356 | e = Jacob[j][i] 357 | if e != 0.0: 358 | for k in range(i1, nu+1): 359 | Jacob[j][k] -= Jacob[i][k]*e 360 | for k in range(2, n2+1): 361 | i = n2 - k + 1 362 | i1 = i + 1 363 | for j in range(i1, n2+1): 364 | Jacob[i][nu] = Jacob[i][nu] - Jacob[i][j]*Jacob[j][nu] 365 | 366 | def close_file(): 367 | """ 368 | close output.txt 369 | """ 370 | global fou 371 | try: 372 | fou.close() 373 | except: 374 | print "Error: Close Files Error. (function close_file() error)" 375 | exit() 376 | 377 | # main 378 | read_data() 379 | output_file_ready() 380 | admt_matrix() 381 | Um_and_Ua() 382 | 383 | Jacob = np.zeros((2*gv.num_node+1, 2*gv.num_node+2)) 384 | P = np.zeros(gv.num_node+1) 385 | Q = np.zeros(gv.num_node+1) 386 | 387 | iter = 0 388 | x_axis = [] # for drawing graph 389 | y_axis = [] # for drawing graph 390 | while True: 391 | form_Jacobian() 392 | error = 0.0 393 | for i in range(1, 2*gv.num_node+1): 394 | if fabs(Jacob[i][2*gv.num_node+1]) > error: 395 | error = fabs(Jacob[i][2*gv.num_node+1]) 396 | fou.write("Times of iteration: %2d\t\tThe maximum power error: %11.6f\n" %(iter+1, error)) 397 | #fou.write("%d %.6f\n" %(iter+1, error)) 398 | x_axis.append(iter+1) # for drawing graph 399 | y_axis.append(error) # for drawing graph 400 | if error < gv.error_max: 401 | node_flow() 402 | branch_flow() 403 | break 404 | if iter > MAX_ITER or error > DIVERGENCE_ERROR: 405 | fou.write("\n\n\t\tThe power flow is Divergence.") 406 | break 407 | solv_Eqn() 408 | for i in range(1, gv.num_node+1): 409 | a = Jacob[i][2*gv.num_node+1] 410 | Ua[i] += -a 411 | a = Jacob[gv.num_node+i][2*gv.num_node+1] 412 | Um[i] *= 1-a 413 | iter += 1 414 | 415 | close_file() 416 | 417 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/PowerFlowCalculation.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/PowerFlowCalculation.pyc -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/PowerFlowCalculation.pyproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | 2.0 6 | 56087c25-23d2-4881-9819-22cb2fe7c15d 7 | . 8 | DrawConvergenceGraph.py 9 | 10 | 11 | . 12 | . 13 | PowerFlowCalculation 14 | PowerFlowCalculation 15 | 16 | 17 | true 18 | false 19 | 20 | 21 | true 22 | false 23 | 24 | 25 | 26 | Code 27 | 28 | 29 | Code 30 | 31 | 32 | Code 33 | 34 | 35 | Code 36 | 37 | 38 | 39 | 40 | 10.0 41 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets 42 | 43 | 44 | 45 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/drawTimesComparisonGraph.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # Name: PowerFlowCalculation.py 4 | # Func: Change times of input Data to look into the regular pattern, this can be the startup file of this project too. 5 | # Author: Maples7 6 | # Addr: EE of SDU, China 7 | # Time: 2015-04-13 8 | # Link: http://www.cnblogs.com/maples7/ 9 | 10 | import pylab as pl 11 | 12 | result = {} 13 | 14 | # Read Data 15 | try: 16 | fp = open("timesResultComparison.txt", "r+") 17 | while True: 18 | try: 19 | line = fp.readline().split(" ") 20 | times = float(line[0]) 21 | loopTimes = int(line[1]) 22 | result[times] = [] 23 | for i in range(loopTimes): 24 | line = fp.readline().split(" ") 25 | result[times].append(line[1]) 26 | line = fp.readline() 27 | except: 28 | print "End of Read Data." 29 | break 30 | 31 | fp.close() 32 | except: 33 | print "Error: Can't read Data." 34 | exit() 35 | 36 | # Draw Graph 37 | plot = [] 38 | y_down = 0 39 | y_up = 0.55 40 | pl.title('Convergence Graph Comparison') 41 | pl.xlabel('Times of Iteration') 42 | pl.ylabel('Maximum Power Error') 43 | pl.grid(True) 44 | pl.ylim(y_down, y_up) 45 | 46 | for times in sorted(result.keys()): 47 | x_axis = [e+1 for e in range(len(result[times]))] 48 | y_axis = result[times][:] 49 | draw = pl.plot(x_axis, y_axis, label=str(times)+' times') 50 | plot.append(draw) 51 | 52 | pl.legend() 53 | pl.show() -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/globalVariable.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # Name: globalVariable.py 4 | # Func: To state the all global variables of this project 5 | # Author: Maples7 6 | # Addr: EE of SDU, China 7 | # Time: 2015-04-07 8 | # Link: http://www.cnblogs.com/maples7/ 9 | 10 | # totle number of nodes 11 | num_node = 0 12 | 13 | # totle number of lines and parallel capacitors 14 | num_line = 0 15 | 16 | # totle number of transformer branches 17 | num_tran = 0 18 | 19 | # totle number of generator nodes 20 | num_gene = 0 21 | 22 | # totle number of load buses 23 | num_load = 0 24 | 25 | # admissible error of the unbalance of node power 26 | error_max = 0.0 27 | 28 | 29 | # obj of lines and parallel capacitors 30 | class Line: 31 | def __init__(self, i, j, a, b, c): 32 | self.i = i 33 | self.j = j 34 | self.a = a 35 | self.b = b 36 | self.c = c 37 | line = [] 38 | 39 | # obj of transformer branches 40 | class Tran: 41 | def __init__(self, i, j, a, b, c): 42 | self.i = i 43 | self.j = j 44 | self.a = a 45 | self.b = b 46 | self.c = c 47 | tran = [] 48 | 49 | # obj of generator nodes 50 | class Gene: 51 | def __init__(self, i, j, a, b, c): 52 | self.i = i 53 | self.j = j 54 | self.a = a 55 | self.b = b 56 | self.c = c 57 | gene = [] 58 | 59 | # obj of load buses 60 | class Load: 61 | def __init__(self, i, a, b): 62 | self.i = i 63 | self.a = a 64 | self.b = b 65 | load = [] 66 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/globalVariable.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/globalVariable.pyc -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/input.txt: -------------------------------------------------------------------------------- 1 | 4 4 1 2 2 0.00001 2 | 4 3 0.260331 0.495868 0.025864 3 | 1 4 0.173554 0.330579 0.017243 4 | 2 2 0.000000 -20.000000 0.000000 5 | 3 1 0.130165 0.247934 0.012932 6 | 7 | 1 2 0.000000 0.166667 1.128205 8 | 9 | 4 0 0.0 0.0 1.05 10 | 3 -1 0.2 0.0 1.05 11 | 12 | 2 0.5 0.3 13 | 4 0.15 0.1 -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/input1.txt: -------------------------------------------------------------------------------- 1 | 4 4 1 2 2 1e-05 2 | 4 3 0.260331 0.495868 0.025864 3 | 1 4 0.173554 0.330579 0.017243 4 | 2 2 0.0 -20.0 0.0 5 | 3 1 0.130165 0.247934 0.012932 6 | 7 | 1 2 0.0 0.166667 1.128205 8 | 9 | 4 0 0.0 0.0 1.05 10 | 3 -1 0.2 0.0 1.05 11 | 12 | 2 0.5 0.3 13 | 4 0.15 0.1 14 | 15 | -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/makeInput.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | 3 | # Name: PowerFlowCalculation.py 4 | # Func: To make input Data of this project, this can be the startup file of this project too. 5 | # Author: Maples7 6 | # Addr: EE of SDU, China 7 | # Time: 2015-04-13 8 | # Link: http://www.cnblogs.com/maples7/ 9 | 10 | import globalVariable as gv 11 | 12 | # Read init Data 13 | orignalInputFile = "input.txt" 14 | try: 15 | fp = open(orignalInputFile, "r+") 16 | 17 | firstLine = fp.readline().split(" ") 18 | gv.num_node = int(firstLine[0]) 19 | gv.num_line = int(firstLine[1]) 20 | gv.num_tran = int(firstLine[2]) 21 | gv.num_gene = int(firstLine[3]) 22 | gv.num_load = int(firstLine[4]) 23 | gv.error_max = float(firstLine[5]) 24 | 25 | gv.line = [] 26 | for i in range(gv.num_line): 27 | nLine = fp.readline().split(" ") 28 | temp = gv.Line(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 29 | gv.line.append(temp) 30 | 31 | nLine = fp.readline() 32 | gv.tran = [] 33 | for i in range(gv.num_tran): 34 | nLine = fp.readline().split(" ") 35 | temp = gv.Tran(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 36 | gv.tran.append(temp) 37 | 38 | nLine = fp.readline() 39 | gv.gene = [] 40 | for i in range(gv.num_gene): 41 | nLine = fp.readline().split(" ") 42 | temp = gv.Gene(int(nLine[0]), int(nLine[1]), float(nLine[2]), float(nLine[3]), float(nLine[4])) 43 | gv.gene.append(temp) 44 | 45 | nLine = fp.readline() 46 | gv.load = [] 47 | for i in range(gv.num_load): 48 | nLine = fp.readline().split(" ") 49 | temp = gv.Load(int(nLine[0]), float(nLine[1]), float(nLine[2])) 50 | gv.load.append(temp) 51 | 52 | fp.close() 53 | except: 54 | print "Error: Can't read Data from "+orignalInputFile+"." 55 | exit() 56 | 57 | # output Created Data 58 | inputFile = "input1.txt" 59 | try: 60 | fou = open(inputFile, "w+") 61 | except: 62 | print "Error: Can't create "+inputFile+"." 63 | exit() 64 | 65 | fou.write(str(gv.num_node)+' '+str(gv.num_line)+' '+str(gv.num_tran)+' '+str(gv.num_gene)+' '+str(gv.num_load)+' '+str(gv.error_max)+'\n') 66 | 67 | for e in gv.line: 68 | times = 1 # change the var to look into the regular pattern 69 | fou.write(str(e.i)+' '+str(e.j)+' '+str(e.a*times)+' '+str(e.b*times)+' '+str(e.c*times)) 70 | fou.write('\n') 71 | fou.write('\n') 72 | 73 | for e in gv.tran: 74 | times = 1 75 | fou.write(str(e.i)+' '+str(e.j)+' '+str(e.a*times)+' '+str(e.b*times)+' '+str(e.c*times)) 76 | fou.write('\n') 77 | fou.write('\n') 78 | 79 | for e in gv.gene: 80 | times = 1 81 | fou.write(str(e.i)+' '+str(e.j)+' '+str(e.a*times)+' '+str(e.b*times)+' '+str(e.c*times)) 82 | fou.write('\n') 83 | fou.write('\n') 84 | 85 | for e in gv.load: 86 | times = 1 87 | fou.write(str(e.i)+' '+str(e.a*times)+' '+str(e.b*times)) 88 | fou.write('\n') 89 | fou.write('\n') 90 | 91 | try: 92 | fou.close() 93 | except: 94 | print "Error: Close Files Error." 95 | exit() -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/makeInput.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Maples7/PowerFlowCalculation/16f72c0412af6c616077f88b29fae7764214d3bd/PowerFlowCalculation/PowerFlowCalculation/makeInput.pyc -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/output.txt: -------------------------------------------------------------------------------- 1 | Times of iteration: 1 The maximum power error: 0.500000 2 | Times of iteration: 2 The maximum power error: 0.052346 3 | Times of iteration: 3 The maximum power error: 0.001633 4 | Times of iteration: 4 The maximum power error: 0.000002 5 | 6 | 7 | 8 | * - * - * - Rasult of Power Flow Calculation * - * - * - 9 | 10 | -------power flow of nodes------- 11 | 12 | no.i Um Ua PG QG PL QL 13 | 14 | 1 0.96950 -3.87378 0.00000 0.00000 0.00000 0.00000 15 | 2 1.03877 -9.23044 0.00000 0.00000 0.50000 0.30000 16 | 3 1.05000 -1.84120 0.20000 0.19687 0.00000 0.00000 17 | 4 1.05000 0.00000 0.47769 0.14430 0.15000 0.10000 18 | 19 | 20 | -------power flow of branches------- 21 | 22 | i j Pij Qij Pji Qji dP dQ 23 | 24 | 4 3 0.05647 -0.05702 -0.05553 0.00179 0.00094 -0.05523 25 | 1 4 -0.25735 -0.11014 0.27121 0.10132 0.01386 -0.00882 26 | 2 2 0.00000 -0.05395 0.00000 0.00000 0.00000 -0.05395 27 | 3 1 0.25553 0.19508 -0.24265 -0.19696 0.01288 -0.00187 28 | 1 2 0.50000 0.30710 -0.50000 -0.24605 0.00000 0.06105 29 | 30 | 31 | The total loss of the system: - Active power: 0.02769 Reactive power:-0.05883 -------------------------------------------------------------------------------- /PowerFlowCalculation/PowerFlowCalculation/timesResultComparison.txt: -------------------------------------------------------------------------------- 1 | 0.01 7 2 | 1 26.984655 3 | 2 1.225535 4 | 3 0.275823 5 | 4 0.147840 6 | 5 0.026819 7 | 6 0.000590 8 | 7 0.000001 9 | 10 | 0.1 5 11 | 1 2.087818 12 | 2 0.472366 13 | 3 0.031669 14 | 4 0.000180 15 | 5 0.000000 16 | 17 | 0.5 4 18 | 1 0.500000 19 | 2 0.096659 20 | 3 0.002861 21 | 4 0.000003 22 | 23 | 2 5 24 | 1 0.500000 25 | 2 0.076128 26 | 3 0.013866 27 | 4 0.000467 28 | 5 0.000000 29 | 30 | 2.2 5 31 | 1 0.500000 32 | 2 0.083610 33 | 3 0.021742 34 | 4 0.001587 35 | 5 0.000009 36 | 37 | 2.3 6 38 | 1 0.500000 39 | 2 0.092169 40 | 3 0.026931 41 | 4 0.003006 42 | 5 0.000046 43 | 6 0.000000 44 | 45 | 2.4 6 46 | 1 0.500000 47 | 2 0.100684 48 | 3 0.033181 49 | 4 0.005876 50 | 5 0.000303 51 | 6 0.000001 52 | 53 | 2.5 32 54 | 1 0.500000 55 | 2 0.109161 56 | 3 0.040712 57 | 4 0.012056 58 | 5 0.003419 59 | 6 0.001202 60 | 7 0.001498 61 | 8 0.001053 62 | 9 0.002979 63 | 10 0.001091 64 | 11 0.002326 65 | 12 0.000995 66 | 13 0.007418 67 | 14 0.002077 68 | 15 0.000968 69 | 16 0.049906 70 | 17 0.013126 71 | 18 0.003682 72 | 19 0.001262 73 | 20 0.001318 74 | 21 0.001234 75 | 22 0.001390 76 | 23 0.001139 77 | 24 0.001815 78 | 25 0.000967 79 | 26 0.044394 80 | 27 0.010089 81 | 28 0.002933 82 | 29 0.001078 83 | 30 0.002518 84 | 31 0.001023 85 | 32 0.004225 86 | 87 | 3 32 88 | 1 0.500000 89 | 2 0.151220 90 | 3 0.109714 91 | 4 12.081385 92 | 5 0.988150 93 | 6 4982.244794 94 | 7 1255.732251 95 | 8 314.127600 96 | 9 78.650899 97 | 10 19.798282 98 | 11 4.991243 99 | 12 1.121875 100 | 13 0.273683 101 | 14 0.382010 102 | 15 0.361991 103 | 16 0.201135 104 | 17 0.129419 105 | 18 0.503540 106 | 19 0.169849 107 | 20 0.116798 108 | 21 1.417613 109 | 22 0.375510 110 | 23 0.152368 111 | 24 0.123493 112 | 25 0.449738 113 | 26 0.155678 114 | 27 0.126302 115 | 28 0.381496 116 | 29 0.140491 117 | 30 0.148528 118 | 31 0.155663 119 | 32 0.119018 120 | 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerFlowCalculation 2 | 电力系统潮流计算 using Python through Newton-Raphson method 3 | 4 | 参考 《电力系统分析(第二版)》(夏道止 主编,中国电力出版社)附录 5 | 6 | * 输入输出: 7 | 输入输出均采用文件方式, 8 | 输入数据格式与要求均与上述附录相同,注意数据块之间的空行严格为一行。 9 | 10 | * 画收敛图 DrawConvergenceGraph.py: 11 | 程序在计算之后画出了迭代收敛图, 12 | 横坐标为 迭代次数,纵坐标为 最大功率误差。 13 | 同时与PQ分解法的收敛图对比,硬编码在程序中的数据来自于与 input.txt 默认数据相同的测例,可参考上述书籍 Page 115。 14 | 一般可作为该项目的入口文件。 15 | 16 | * makeInput.py: 17 | 基于原始的输入数据input.txt,通过改变输入倍数(times)等其他因素生成新的输入数据存入input1.txt。 18 | 在设置好times等参数后可直接运行DrawConvergenceGraph.py(作为入口文件运行),全自动化得出基于input1.txt输入数据的输出。 19 | 20 | * drawTimesComparisonGraph.py: 21 | timesResultComparison.txt来自于几次对makeInput.py中输入线路(gv.line)times的更改而生成的输入数据对应的数据结果的整理。 22 | 基于此txt用该py画出了其对比图分析线路参数与其收敛的情况。 23 | --------------------------------------------------------------------------------