📄 flow.h
字号:
#ifndef FLOW_H
#define FLOW_H
#include <fstream>
#include <map>
#include <vector>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/lu.hpp>
#include "Bus.h"
#include "Branch.h"
#include "SparseMatrix.h"
#include "FactorTableForNR.h"
#include "FactorTableForPQ.h"
namespace ublas = boost::numeric::ublas;
// 发电机节点的无功出力限值
// struct QLimit { double QMax,QMin; };
//----------2008.10.27----------------------------------------------
// 为处理小阻抗和R/X比值较大的支路而增加的类,目的是为了提高收敛性能
class ParallelCompensBranch { //支路并联补偿
public:
int nBranchOrder;
int NodeI,NodeJ;
int BranchType;
double K;
double B_2;
double Gn,Bn; // 表示具有正常阻抗值和合理R/X比的支路,以此支路参加导纳阵的形成
double Gc,Bc; // 表示并列支路的导纳值,以此导纳计算注入电流或功率参加潮流计算的迭代
double Pi,Qi; // 等效注入的功率
double Pj,Qj;
};
/*
//-------------------[3/27/2006 ZQfalcon更改]-------------------------------------
struct CShuntLoad { //为处理BPA格式的并联导纳负荷而设立的结构体
public:
int i; //节点号
double ShuntP,ShuntQ; //并联导纳负荷
};
//-------------------[3/27/2006 ZQfalcon更改]-------------------------------------
*/
class Flow {
// 2009.04.15 The data and functions for dealing with the DC network.
private:
// Predefined constants for the DC load flow algorithm.
static double const ktheta; // kγ.
static double const kgamma; // kθ.
private:
// Type definitions of the necessary data structures.
typedef ublas::compressed_matrix<
double,
ublas::row_major
> Matrix;
typedef ublas::vector<
typename Matrix::value_type
> Vector;
typedef ublas::permutation_matrix<
typename Matrix::size_type
> PermMat;
private:
int dc_bus_count;
int dc_branch_count;
std::vector<DCBus> dc_buses;
std::vector<DCBranch> dc_branches;
std::map<int,int> id2index;
std::map<int,int> index2id;
// Because the unknown variables in the nodal voltage equations of the DC
// network may be both voltages and currents, and the constant power constraints
// may exist, the equations are modified into the following form:
// M * [ Vd, Id ]' = [0, Vds, Ids, Pds ]'
// where M is the coefficient matrix M. The 1st order differential coefficient
// matrix J of the equation set is built in the following matrix so that a
// certain iterative algorithm could be used.
Matrix dc_correction_mat;
// Because of the high similarity of matrix M and matrix J, matrix M is stored
// to facilitate the construction of matrix J.
Matrix dc_coefficient_mat;
// The vector at the right hand side of the above equation set is constant,
// so it's better to store it in advance to facilitate the construction of the
// error vector. The following vector is for this purpose.
Vector dc_constant_vec;
// Pivot selection is necessary for solving the nonlinear equation set
// M * [ Vd, Id ]' = [0, Vds, Ids, Pds ]'
// by a certain iterative algorithm because its 1st order coefficient matrix J
// is always singular. The following vector records the pivot permutation.
PermMat dc_correction_perm;
public:
void PrepareDCLoadFlow( bool refresh = true );
bool CalculateDCLoadFlow( bool rebuild = true );
bool CheckDCTapViolation();
private:
void InitializeDCBusValues( bool rebuild = true );
template < class Mat >
void ConstructDCCoefficientMatrix( Mat& );
template < class Mat >
void ConstructDCCorrectionMatrix( Mat& );
template < class Vec >
void ConstructDCConstantVector( Vec& );
template < class Vec >
typename Vec::value_type ConstructDCErrorVector( Vec& );
template < class Mat, class Perm >
void FactorizeCorrectionMatrix( Mat&, Perm& );
template < class Mat, class Perm, class Vec >
void SubstituteCorrectionVector( Mat const&, Perm const&, Vec& );
template < class Vec >
void CorrectDCBusValues( Vec const& );
void FinalizeDCBusValues();
public:
int NodeNum; //节点数目
Complex * pBranchLoss; //支路损耗
ACBus *pNodeData; //指向节点数据
ACBranch *pBranchData; //指向支路数据
double * Phase; //电压相位,优化后的编号顺序,包含平衡节点
double * U; //电压幅值,优化后的编号顺序,包含平衡节点
// QLimit * QLimit; //记录发电机和调相机的无功限值,为处理节点类型转化作准备
Complex * Iij, * Iji; //支路电流
double * Pij, * Pji; //支路中流过的有功功率
double * Qij, * Qji; //支路中流过的有功功率
bool ReadData( char* in, char* out ); // 读入潮流计算原始数据并完成初始化
private:
bool ReadACData(); // 读入交流系统数据,并完成其初始化
bool ReadDCData(); // 读入直流系统数据,并完成其初始化
bool ACInitialize(); // 初始化交流系统潮流计算所需数据
bool DCInitialize(); // 初始化直流系统潮流计算所需数据
public:
Flow();
Flow(int NodeNum,int BranchNum,int MaxIterNum,double Eps); //构造函数
~Flow(); //拆构函数
inline Complex GetY(int Row, int Col); //获取导纳矩阵元素
inline void SetY(int Row, int Col,Complex Value); //设置导纳矩阵元素
inline void SetX(int Row,int Col,double Value); //设置X矩阵中的元素
inline double GetX(int Row,int Col); //获得X矩阵中的元素
private:
int * OptimisedNodeTable; //节点编号表,从未优化至优化的映射
int * OriginalNodeTable; //节点编号表,从优化至未优化的映射
protected:
int OptimisedNode(int i) { return OptimisedNodeTable[i]; } //通过实际节点号获得优化后的节点号
int OriginalNode(int i) { return OriginalNodeTable[i]; } //通过优化后的节点号反查实际节点号
public:
void NodeSerialOptimize(); //半动态节点编号优化
void NodeSerialOptimize1(); //改进的半动态节点编号优化
void NodeSerialOptimize2(); // 2008.4.3 Dynamic optimum odering.
public:
enum Method { NR_METHOD = 0, PQ_BX_METHOD = 1, PQ_XB_METHOD = 2 };
void PrepareACLoadFlow( Method method, bool refresh = true );
void BuildMatrixY(); //建立Y阵
void BuildMatrixX(); //建立X阵
void BuildMatrixB(); //建立B阵
//牛拉法
bool NR1();
bool NR2();
//解耦法
bool PQ_BX1();
bool PQ_BX2();
bool PQ_XB1();
bool PQ_XB2();
public:
bool CalculateACLoadFlow( Method method );
bool CalcBranchPQ(); //计算出节点电压后计算支路中流过的功率
double CalcPLoss(); //计算有功损耗
double GetVQViolation(); //计算PQ节点电压越限和PV节点无功出力越限的情况
void OutputResult(char *grid); //输出结果
bool BackupJacobian(); //保存雅克比矩阵
private:
void OutputACResult();
void OutputDCResult();
ifstream infile; //输入文件流
ofstream outfile,fmidresults; //输出文件流
protected:
double GetQError(int i); //求解功率误差方程式
double GetPError(int i); //求解功率误差方程式
void CalcNodalPowerP(); //求V节点的静有功出力
void CalcNodalPowerQ(); //求所有节点的净无功出力
double GetQOutput1(int i); //求发电机的无功出力
bool PreHandData(); //在读入数据后对标准数据做处理
private:
double BaseS; //基准功率
int BranchNum; //支路数目
int SlackNodeOrder; //平衡节点序号(非优化编号)
int MaxIterNum; //最大迭代次数
double eps; //精度要求
int SumOfPQ; //PQ节点数目
int SumOfPV; //PV节点数目
double SumOfLoadP; //负荷的有功总量
double SumOfGenP; //发电机的有功总量,除去平衡机
bool bPFconverge; //潮流计算收敛与否
bool bInitialized; //是否初始化了
bool bBackupedJacobian; //是否备份了雅克比矩阵
double* NodalPowerP; //节点注入有功功率
double* NodalPowerQ; //节点注入无功功率
SparseMatrix<double>* Jacobian; //雅可比矩阵
SparseMatrix<Complex> Y; //Y矩阵
SparseMatrix<double> X; //X矩阵
SparseMatrix<double> B; //B矩阵
// SparMatrix<int> Adjacency; //声明关联矩阵
bool ** Adjacency; //声明关联矩阵
// 2008.10.27,处理小阻抗和R/X比值较大的支路而增加的类
public:
void StatisAbnormalBranches();
void SwitchPallelCompenTech(bool);
private:
ParallelCompensBranch * ParalCompensBranches;
bool bParallelCompenTechSwitched; //是否已经设置了,若是,则不能再设置了
bool bUseParallelCompenTech; //是否使用并列补偿的策略
int nAbnormalBranchNum; //统计这些非“正常”支路的个数
void CalcParalCompensBranchesPQ();
/*
//-------------------[4/27/2009 ZQfalcon更改]-------------------------------------
private:
CShuntLoad *ShuntLoad;
//-------------------[4/27/2009 ZQfalcon更改]-------------------------------------
*/
};
#endif // FLOW_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -