输出为iPso的格式

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-02-07 22:14:59 +08:00
parent 1f9734d727
commit d1ac696c1e
2 changed files with 170 additions and 23 deletions

View File

@ -58,6 +58,8 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,DG* dg)
void CIMExporter::exportTo(const QString& path,const QString &rootID) void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
char seperator='\t';
QString endLine="\r\n";
//输出到文件 //输出到文件
QFile fd(path); QFile fd(path);
if(fd.open(QFile::WriteOnly)) if(fd.open(QFile::WriteOnly))
@ -91,11 +93,27 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
this->idToNumber(this->sw); this->idToNumber(this->sw);
this->idToNumber(this->tf); this->idToNumber(this->tf);
this->idToNumber(this->dg); this->idToNumber(this->dg);
//开始按要求输出 //开始按iPso格式要求输出
//先输出线路
QTextStream writer(&fd); QTextStream writer(&fd);
writer<<QStringLiteral("线路")<<QStringLiteral("\r\n"); //iPso 第一行
writer<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("型号")<<QStringLiteral("\t")<<QStringLiteral("长度(m)")<<QStringLiteral("\r\n"); writer<<this->number.keys().length()<<seperator;//节点数
//TODO: 支路数要单独计算
writer<<0<<seperator;//支路数,由于有些支路被删掉了,所以要计算一下。这里暂时不计算。
writer<<1<<seperator;//计算目标
writer<<1e-5<<seperator;//收敛精度
writer<<-1<<endLine;//忘记是什么了
writer<<0<<endLine;//数据间隔
int balanceNum;//平衡节点号
balanceNum=this->line.first().fromNum;
writer<<1<<seperator<<balanceNum<<seperator;
writer<<"1.05"<<endLine;//平衡节点电压
writer<<0<<endLine;//数据间隔
int seqN=1;//序号
//先输出线路
// writer<<QStringLiteral("线路")<<QStringLiteral("\r\n");
// writer<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("节点号")<<QStringLiteral("\t")<<QStringLiteral("型号")<<QStringLiteral("\t")<<QStringLiteral("长度(m)")<<QStringLiteral("\r\n");
for(QList<LineStru>::iterator ite=this->line.begin(); for(QList<LineStru>::iterator ite=this->line.begin();
ite!=this->line.end(); ite!=this->line.end();
ite++) ite++)
@ -106,12 +124,19 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
continue; continue;
} }
// writer<<elements.first()->length<<"\t"<<elements.first()->id<<"\t"; // writer<<elements.first()->length<<"\t"<<elements.first()->id<<"\t";
writer<<l.fromNum<<"\t"; writer<<seqN++<<seperator;
writer<<l.toNum<<"\t"; writer<<l.fromNum<<seperator;
writer<<"type"<<"\t"; writer<<l.toNum<<seperator;
writer<<l.line->r<<seperator;
writer<<l.line->x<<seperator;
writer<<l.line->b1<<seperator;
writer<<l.line->b2<<seperator;
writer<<endLine;
// writer<<"type"<<seperator;
// writer<<l.id<<"\t"; // writer<<l.id<<"\t";
writer<<l.length<<"\r\n"; // writer<<l.length<<"\r\n";
} }
//输出刀闸 //输出刀闸
for(QList<SwitchStru>::iterator ite=this->sw.begin(); for(QList<SwitchStru>::iterator ite=this->sw.begin();
ite!=this->sw.end(); ite!=this->sw.end();
@ -121,18 +146,26 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
continue; continue;
} }
writer<<ite->fromNum<<"\t"; writer<<seqN++<<seperator;
writer<<ite->toNum<<"\t"; writer<<ite->fromNum<<seperator;
writer<<"type"<<"\t"; writer<<ite->toNum<<seperator;
writer<<ite->sw->r<<seperator;
writer<<ite->sw->x<<seperator;
writer<<ite->sw->b1<<seperator;
writer<<ite->sw->b2<<seperator;
writer<<endLine;
// writer<<"type"<<"\t";
// writer<<ite->id<<"\t"; // writer<<ite->id<<"\t";
writer<<0<<"\r\n"; // writer<<0<<"\r\n";
} }
//输出负荷 writer<<0<<endLine;//数据间隔
//输出变压器
RecurseDir recurseDir; RecurseDir recurseDir;
recurseDir.setDir(this->loadDir); recurseDir.setDir(this->loadDir);
QStringList files; QStringList files;
files=recurseDir.getFiles(); files=recurseDir.getFiles();
//只取文件名 //只取文件名
QStringList baseNames; QStringList baseNames;
foreach(QString file,files) foreach(QString file,files)
{ {
@ -144,9 +177,14 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
baseNames<<fileInfo.baseName(); baseNames<<fileInfo.baseName();
// std::cout<<"has "<<fileInfo.baseName().toLocal8Bit().data()<<std::endl; // std::cout<<"has "<<fileInfo.baseName().toLocal8Bit().data()<<std::endl;
} }
seqN=1;
// writer<<QStringLiteral("变压器")<<"\r\n";
// writer<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("型号")<<"\t"<<QStringLiteral("容量(MVA)")<<"\r\n";
//把接地支路准备一下
QList<CIMExporter::GroundBranch > groudBranch;//first is g, second is b.
QList<CIMExporter::NodePQ> nodePQ;//节点注入功率,也就是负荷或者发电机
writer<<QStringLiteral("变压器")<<"\r\n";
writer<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("节点号")<<"\t"<<QStringLiteral("型号")<<"\t"<<QStringLiteral("容量(MVA)")<<"\r\n";
QStringList usedLoad; QStringList usedLoad;
for(QList<TransformerStru>::iterator ite=this->tf.begin(); for(QList<TransformerStru>::iterator ite=this->tf.begin();
ite!=this->tf.end(); ite!=this->tf.end();
@ -177,11 +215,24 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
// std::cout<<targetBasename.baseName().toLocal8Bit().data()<<" used "<<std::endl; // std::cout<<targetBasename.baseName().toLocal8Bit().data()<<" used "<<std::endl;
usedLoad<<targetBasename.baseName(); usedLoad<<targetBasename.baseName();
writer<<ite->fromNum<<"\t"; writer<<seqN++<<seperator;
writer<<ite->toNum<<"\t"; writer<<0<<seperator;//变压器区域
writer<<"type"<<"\t"; writer<<ite->fromNum<<seperator;
writer<<ite->toNum<<seperator;
writer<<ite->tf->r<<seperator;
writer<<ite->tf->x<<seperator;
writer<<ite->tf->ratio<<seperator;
writer<<1<<seperator;
writer<<1<<seperator;
writer<<1<<seperator;
writer<<endLine;
//保存接地支路
groudBranch.push_back(CIMExporter::GroundBranch(ite->toNum, ite->tf->g1,ite->tf->b1));//都只用g1,b1的数据
//保存节点注入功率
nodePQ.push_back(CIMExporter::NodePQ(ite->toNum,p->get3PhP(),p->get3PhQ()));
// writer<<"type"<<"\t";
// writer<<ite->id<<"\t"; // writer<<ite->id<<"\t";
writer<<tf->getMVA()<<"\r\n"; // writer<<tf->getMVA()<<"\r\n";
//加到LoadExport中 //加到LoadExport中
LoadExporter loadExporter; LoadExporter loadExporter;
loadExporter.add(targetBasename.baseName(),p); loadExporter.add(targetBasename.baseName(),p);
@ -190,16 +241,88 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
} }
} }
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
seqN=1;
foreach(CIMExporter::GroundBranch gb,groudBranch)
{
writer<<seqN++<<seperator;
writer<<gb.nodeNum<<seperator;
writer<<gb.g<<seperator;
writer<<gb.b<<seperator;
}
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
//列出DG //列出DG
writer<<QStringLiteral("分布式电源")<<"\r\n"; // writer<<QStringLiteral("分布式电源")<<"\r\n";
for(QList<DGStru>::iterator ite=this->dg.begin(); for(QList<DGStru>::iterator ite=this->dg.begin();
ite!=this->dg.end(); ite!=this->dg.end();
ite++) ite++)
{ {
writer<<ite->fromNum<<"\t"; //保存到节点注入功率中
writer<<ite->toNum<<"\t"; nodePQ.push_back(CIMExporter::NodePQ(ite->toNum,-ite->dg->capacity,-ite->dg->capacity) );
writer<<ite->dg->capacity<<"\r\n"; // writer<<ite->fromNum<<"\t";
// writer<<ite->toNum<<"\t";
// writer<<ite->dg->capacity<<"\r\n";
} }
//iPso 开始输出注入功率
CIMExporter::NodePQ *nodePQPointer=new CIMExporter::NodePQ[this->number.keys().length()];
foreach(CIMExporter::NodePQ n,nodePQ)
{
int nodeNum=n.nodeNum;
if(nodeNum>this->number.keys().length())
{
std::cout<<"number of nodePQ is beyond node number."<<std::endl;
break;
}
nodePQPointer[nodeNum-1]=n;
}
seqN=1;
for(int i=0;i<this->number.keys().length();i++)
{
writer<<seqN<<seperator;
writer<<-1<<seperator;
writer<<seqN++<<seperator;
writer<<10<<seperator;
writer<<0<<seperator;
writer<<0<<seperator;
writer<<nodePQPointer[i].P<<seperator;
writer<<nodePQPointer[i].Q<<seperator;
writer<<1<<seperator;
writer<<0<<seperator;
writer<<endLine;
}
writer<<0<<endLine;//数据间隔
writer<<1<< seperator<<1<< seperator<<balanceNum<< seperator<<1<< seperator<< -100<< seperator<<100<< seperator<<0<< seperator<<0<< seperator<<0<< seperator<<0<< seperator;
writer<<endLine;
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<1<< seperator<<1<< seperator<<balanceNum<<1<< seperator<<1.05<< seperator<< -100<< seperator<<100<< seperator<<0<< seperator<<0<< seperator<<0<< seperator<<0<< seperator;
writer<<endLine;
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<1<< seperator<<balanceNum<< seperator<<0.999<< seperator<<1.001<<seperator;
writer<<endLine;
//接着13个0
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
writer<<0<<endLine;//数据间隔
//列出没有用的负荷文件 //列出没有用的负荷文件
foreach(QString name, baseNames) foreach(QString name, baseNames)
{ {
@ -218,6 +341,7 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
} }
this->topologyTest(); this->topologyTest();
fd.close(); fd.close();
} }

View File

@ -27,6 +27,29 @@
//class Substation; //class Substation;
class CIMExporter class CIMExporter
{ {
class NodePQ
{
public:
NodePQ():nodeNum(0),P(0),Q(0)
{}
explicit NodePQ(int nodeNum,double P,double Q):nodeNum(nodeNum),P(P),Q(Q)
{}
int nodeNum;
double P;
double Q;
};
class GroundBranch
{
public:
explicit GroundBranch(int nodeNum,double g,double b):nodeNum(nodeNum),g(g),b(b)
{}
int nodeNum;
double g;
double b;
};
public: public:
explicit CIMExporter(const QHash<QString,BasicElementInfo *>& eleHT,const QString& loadDir); explicit CIMExporter(const QHash<QString,BasicElementInfo *>& eleHT,const QString& loadDir);