📄 main.cpp
字号:
#include <cstdio>
#include <boost/timer.hpp>
#include "Flow.h"
int main( int argc, char* argv[] )
{
int grid_id = 4; // 算例选择
char* infile = NULL;
char* outfile = NULL;
char* grid_name = NULL;
switch (grid_id) {
case 0: {
grid_name = "潮流计算测试数据";
infile = "../InputData/AC-DC3.dat";
outfile = "../OutputData/AC-DC3_Result.dat";
break;
}
case 1: {
grid_name = "IEEE 14节点算例";
infile = "../InputData/IEEE_14.dat";
outfile = "../OutputData/IEEE_14_Result.dat";
break;
}
case 2: {
grid_name = "IEEE 24节点算例";
infile = "../InputData/IEEE_24.dat";
outfile = "../OutputData/IEEE_24_Result.dat";
break;
}
case 3: {
grid_name = "IEEE 30节点算例";
infile = "../InputData/IEEE_30.dat";
outfile = "../OutputData/IEEE_30_Result.dat";
break;
}
case 4: {
grid_name = "IEEE 57节点算例";
infile = "../InputData/IEEE_57_DC.dat";
outfile = "../OutputData/IEEE_57_DCResult.dat";
break;
}
case 5: {
grid_name = "IEEE 118节点算例";
infile = "../InputData/IEEE_118.dat";
outfile = "../OutputData/IEEE_118_Result.dat";
break;
}
case 6: {
grid_name = "西北电网冬大";
infile = "./InputData/西北电网冬大.dat";
outfile = "./OutputData/西北电网冬大_Result.dat";
break;
}
case 7: {
grid_name = "西北电网夏小";
infile = "../InputData/西北电网夏小.dat";
outfile = "../OutputData/西北电网夏小_Result.dat";
break;
}
case 8: {
grid_name = "2005华东电网冬大";
infile = "../InputData/2005hddd.dat";
outfile = "../OutputData/2005华东电网冬大_Result.dat";
break;
}
case 9: {
grid_name = "2007华东电网夏大";
infile = "../InputData/2007华东电网夏大.dat";
outfile = "../OutputData/2007华东电网夏大_Result.dat";
break;
}
default: {
std::cerr << "No grid is selected for load flow calculation!" << std::endl;
return 1;
}
}
std::cout << setiosflags(ios::fixed) //设置浮点数以固定的小数位数显示
<< setiosflags(ios::right) //OutputData右对齐
<< setprecision(6);//设置实数的精度为n位
Flow::Method method_id = Flow::NR_METHOD;
boost::timer t;//Timer(定时器)库提供了timer类来测量时间的流逝
t.restart();
Flow flow;
if ( !flow.ReadData(infile,outfile) ) {
std::cerr << " Reading input data failed! " << std::endl;
return 1;
}
std::size_t iter = 0;
std::size_t const max_iter = 10;
bool converged = false;
bool violated = false;
bool refresh = true;
do {
refresh = !(iter++);
// Step 1. Calculate DC load flow.
flow.PrepareDCLoadFlow(refresh);
converged = flow.CalculateDCLoadFlow(refresh);
if ( !converged ) {
std::cerr << "DC load flow calculation failed to converge!" << std::endl;
return 1;
}
// Step 2. Calculate AC load flow with the DC system equivalent to loads and generations.
flow.PrepareACLoadFlow(method_id,refresh);
converged = flow.CalculateACLoadFlow(method_id);
if ( !converged ) {
std::cerr << "AC load flow calculation failed to converge!" << std::endl;
return 1;
}
// Step 3. Check commutating transformer taps.
violated = flow.CheckDCTapViolation();
} while ( violated && iter <= max_iter );
bool success = !violated && iter <= max_iter;
if ( success ) {
std::cout << "Alternative iteration count: " << iter << '\n';
std::cout << "Alternative iteration time: " << t.elapsed() << "s\n";
// std::cout << "Nodal voltage or generation violations: " << LoadFlow.GetVQViolation() << '\n';
flow.OutputResult(grid_name);
flow.CalcBranchPQ();
} else {
std::cout << "Alternative iteration failed to converge." << std::endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -