📄 dnet.cpp
字号:
if(m_nBranchMap[nIndex]->m_bState==FALSE)
return FALSE;
for(INT i=1;i<=m_nDNetInfo.nFeederRoot;++i)
{
INT system=m_nNodeSubSystem[m_nNewFeederRoot[i]];
if(m_nBranchSubSystem[nIndex]==system)
{
int node=m_nBranchMap[nIndex]->m_nHeadNode;
head=m_nBranchMap[nIndex]->m_nHeadElement;
tail=m_nBranchMap[nIndex]->m_nTailElement;
double wPHead=m_nBranchMap[nIndex]->m_wPHead;
double wQHead=m_nBranchMap[nIndex]->m_wQHead;
PFeWaste=fabs((1e-3)*m_nBranchMap[nIndex]->m_dP0TRANS*m_nNodeArray[m_nBranchMap[nIndex]->m_nHeadNode].wVoltage*
m_nNodeArray[m_nBranchMap[nIndex]->m_nHeadNode].wVoltage/(m_nBranchMap[nIndex]->m_VnTRANS*
m_nBranchMap[nIndex]->m_VnTRANS));
QFeWaste=fabs((1e-3)*0.01*m_nBranchMap[nIndex]->m_CurrentTRANS*m_nBranchMap[nIndex]->m_SnTRANS*
m_nNodeArray[m_nBranchMap[nIndex]->m_nHeadNode].wVoltage*
m_nNodeArray[m_nBranchMap[nIndex]->m_nHeadNode].wVoltage/(m_nBranchMap[nIndex]->m_VnTRANS*
m_nBranchMap[nIndex]->m_VnTRANS));
PCuWaste=fabs(m_nBranchMap[nIndex]->m_wPHead-m_nBranchMap[nIndex]->m_wPTail-PFeWaste);
QCuWaste=fabs(m_nBranchMap[nIndex]->m_wQHead-m_nBranchMap[nIndex]->m_wQTail-QFeWaste);
wCurrent=sqrt(wPHead*wPHead+wQHead*wQHead)/(m_nNodeArray[node].wVoltage*sqrt(3.0));
if(!m_nDNetInfo.m_bMark)
{
PFeWaste*=m_nDNetInfo.wSB;
QFeWaste*=m_nDNetInfo.wSB;
PCuWaste*=m_nDNetInfo.wSB;
QCuWaste*=m_nDNetInfo.wSB;
wCurrent=sqrt(wPHead*wPHead+wQHead*wQHead)/m_nNodeArray[node].wVoltage;
}
return TRUE;
}
}
return FALSE;
}
int CDNet::GetMaxElement()
{
return m_nDNetInfo.nMaxElement;
}
int CDNet::GetBranchNumber()
{
return m_nDNetInfo.nTBranch;
}
BOOL CDNet::GetSwitchInfo(INT nIndex,INT& head,INT& tail,double& current)
{
if(nIndex<=0||nIndex>m_nDNetInfo.nSwitch) return FALSE;
if(!m_nSwitchMap[nIndex]->bState) return FALSE;
int node=m_nSwitchMap[nIndex]->nHeadElement;
if(!IsOnSystem(m_nMaxElementArray[node])) return FALSE;
int node1=m_nSwitchMap[nIndex]->nTailElement;
head=node;
tail=node1;
BOOL bHead=IsLinkSwitch(nIndex,node);
double CurrentRe=0,CurrentIm=0;
if(!bHead)
{
current=AccountCurrent(node,CurrentRe,CurrentIm);
return TRUE;
}
BOOL bTail=IsLinkSwitch(nIndex,node1);
if(!bTail)
{
head=node1;
tail=node;
current=AccountCurrent(node1,CurrentRe,CurrentIm);
return TRUE;
}
int node2=node;
if(bHead==3&&bTail==3) return FALSE;
if(bHead==3)
{
node2=node1;
head=node1;
tail=node;
}
current=AccountCurrent0(nIndex,node2,CurrentRe,CurrentIm);
if(bHead==2)
{
double CurrentRe0=CurrentRe,CurrentIm0=CurrentIm;
AccountLoad(node2,CurrentRe,CurrentIm);
CurrentRe0+=CurrentRe;
CurrentIm0+=CurrentIm;
current=sqrt(CurrentRe0*CurrentRe0+CurrentIm0*CurrentIm0);
}
return TRUE;
}
BOOL CDNet::IsOnSystem(INT node)
{
for(INT i=1;i<=m_nDNetInfo.nFeederRoot;++i)
{
INT system=m_nNodeSubSystem[m_nNewFeederRoot[i]];
if(m_nNodeSubSystem[node]==system) return TRUE;
}
return FALSE;
}
BOOL CDNet::IsLinkSwitch(INT nIndex,INT node)
{
for(POSITION pos=m_nBeginInfoMap.GetStartPosition();pos!=NULL;)
{
UINT key=0;
CBeginInfo* pBeginInfo;
m_nBeginInfoMap.GetNextAssoc(pos,key,pBeginInfo);
if(pBeginInfo->m_nLoadIndex==UINT(node)) return 2;
}
for(INT i=1;i<=m_nDNetInfo.nFeederRoot;++i)
if(m_nFeederRoot[i]==UINT(node)) return 3;
for(pos=m_nSwitchMap.GetStartPosition();pos!=NULL;)
{
UINT key=0;
CSwitch* pSwitch;
m_nSwitchMap.GetNextAssoc(pos,key,pSwitch);
if(key==UINT(nIndex)) continue;
if(node==INT(pSwitch->nHeadElement)||node==INT(pSwitch->nTailElement))
return TRUE;
}
return FALSE;
}
double CDNet::AccountLoad(INT nIndex,double& currentRe,double& currentIm)
{
currentRe=currentIm=0;
for(POSITION pos=m_nBeginInfoMap.GetStartPosition();pos!=NULL;)
{
UINT key=0;
CBeginInfo* pBeginInfo;
m_nBeginInfoMap.GetNextAssoc(pos,key,pBeginInfo);
if(pBeginInfo->m_nLoadIndex==UINT(nIndex))
{
int node2=pBeginInfo->m_nLoadNode;
currentRe-=pBeginInfo->m_wPLoad/(m_nNodeArray[node2].wVoltage*sqrt(3.0));
currentIm-=-pBeginInfo->m_wQLoad/(m_nNodeArray[node2].wVoltage*sqrt(3.0));
}
}
if(!m_nDNetInfo.m_bMark)
{
currentRe*=sqrt(3.0);
currentIm*=sqrt(3.0);
}
return sqrt(currentRe*currentRe+currentIm*currentIm);
}
double CDNet::AccountCurrent(INT nIndex,double& currentRe,double& currentIm)
{
currentRe=currentIm=0;
for(POSITION pos=m_nBranchMap.GetStartPosition();pos!=NULL;)
{
UINT key=0;
CBranch* pBranch;
m_nBranchMap.GetNextAssoc(pos,key,pBranch);
int node1=pBranch->m_nHeadNode;
int node2=pBranch->m_nTailNode;
if(pBranch->m_nHeadElement==UINT(nIndex))
{
double wP=pBranch->m_wPHead;
double wQ=pBranch->m_wQHead;
currentRe-=wP/(m_nNodeArray[node1].wVoltage*sqrt(3.0));
currentIm-=-wQ/(m_nNodeArray[node1].wVoltage*sqrt(3.0));
}
if(pBranch->m_nTailElement==UINT(nIndex))
{
double wP=pBranch->m_wPTail;
double wQ=pBranch->m_wQTail;
currentRe+=wP/(m_nNodeArray[node2].wVoltage*sqrt(3.0));
currentIm+=-wQ/(m_nNodeArray[node2].wVoltage*sqrt(3.0));
}
}
if(!m_nDNetInfo.m_bMark)
{
currentRe*=sqrt(3.0);
currentIm*=sqrt(3.0);
}
return sqrt(currentRe*currentRe+currentIm*currentIm);
}
double CDNet::AccountCurrent0(INT nIndex,INT node,double& currentRe,double& currentIm)
{
currentRe=currentIm=0;
double currentRe0=0,currentIm0=0;
for(POSITION pos=m_nSwitchMap.GetStartPosition();pos!=NULL;)
{
UINT key=0;
CSwitch* pSwitch;
m_nSwitchMap.GetNextAssoc(pos,key,pSwitch);
if(key==UINT(nIndex)) continue;
if(node==INT(pSwitch->nHeadElement))
{
int node1=pSwitch->nTailElement;
BOOL bTail=IsLinkSwitch(key,node1);
if(!bTail)
AccountCurrent(node1,currentRe0,currentIm0);
else
AccountCurrent0(nIndex,node1,currentRe0,currentIm0);
currentRe+=currentRe0;
currentIm+=currentIm0;
}
if(node==INT(pSwitch->nTailElement))
{
int node1=pSwitch->nHeadElement;
BOOL bHead=IsLinkSwitch(key,node1);
if(!bHead)
AccountCurrent(node1,currentRe0,currentIm0);
else
AccountCurrent0(nIndex,node1,currentRe0,currentIm0);
currentRe+=currentRe0;
currentIm+=currentIm0;
}
}
AccountCurrent(node,currentRe0,currentIm0);
currentRe+=currentRe0;
currentIm+=currentIm0;
return sqrt(currentRe*currentRe+currentIm*currentIm);
}
int CDNet::GetSwitch()
{
return m_nDNetInfo.nSwitch;
}
BOOL CDNet::Flow()
{
Initialization();
FILE* fp;
if((fp=fopen("Branch.ini","r"))==NULL)
{
CString str;
str="输入文件Branch.ini不存在或路径不正确";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 1001;
}
INT nFeeder,nMaxIter;
float SB,VB,VLimit;
fscanf(fp,"%d %d %f %f %f",&nFeeder,&nMaxIter,&SB,
&VB,&VLimit);
if(nFeeder<=0||nMaxIter>=1000)
{
CString str;
str="馈线数目必须大于0或最大迭代次数小于1000";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 2001;
}
SetFeederMumber(nFeeder);
SetIterstion(nMaxIter);
SetSB(SB,VB);
SetVoltageConergence(VLimit);
BOOL bMark=FALSE;
INT nIndex,node;
float voltage;
for(INT i=1;i<=nFeeder;++i)
{
fscanf(fp,"%d %d %f",&nIndex,&node,&voltage);
SetFeederInfo(nIndex, node, voltage);
}
fscanf(fp,"%d %d %f",&nIndex,&node,&voltage);
BOOL state;
INT head,tail;
float area,length;
while(!feof(fp))
{
fscanf(fp,"%d%d%d%d%f%f",&nIndex,&state,&head,&tail,&area,&length);
if(nIndex==-1) break;
SetBranch(nIndex, state, head, tail, area, length);
}
INT sort;
while(!feof(fp))
{
fscanf(fp,"%d%d%d%d%f%d%f%f",&nIndex,&state,&head,&tail,&area,&sort,&voltage,&length);
if(nIndex==-1) break;
SetCable(nIndex, state, head, tail, area, sort,
voltage, length);
}
float PF, VF, PK, KC, ST,position;
while(!feof(fp))
{
fscanf(fp,"%d%d%d%d%f%f%f%f%f%f%f",&nIndex,&state,&head,&tail,&PF,&VF,
&PK,&KC,&ST,&voltage,&position);
if(nIndex==-1) break;
SetTrans(nIndex, state, head, tail,
PF, VF, PK, KC, ST, voltage, position);
}
while(!feof(fp))
{
int k=fscanf(fp,"%d%d%d%d",&nIndex,&head,&tail,&state);
if(nIndex==-1) break;
SetSwitch(nIndex,head,tail);
SetSwitchState(nIndex,state);
}
float dP,Sn;
while(!feof(fp))
{
int k=fscanf(fp,"%d%d%f%f%f",&nIndex,&node,&dP,&Sn,&voltage);
if(k==5)
SetCapInfo(nIndex, node, dP, Sn, voltage);
}
fclose(fp);
float wP, wQ;
if((fp=fopen("Load.ini","r"))==NULL)
{
CString str;
str="输入文件Load.ini不存在或路径不正确";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 1001;
}
while(!feof(fp))
{
fscanf(fp,"%d%d%f%f",&nIndex,&node,&wP,&wQ);
SetBeginInfo(nIndex, node, wP, wQ);
}
fclose(fp);
////////////////////////////////////////////////
//dNet operate
///////////////////////////////////////////////
NetAnalyse();
BOOL LP=DNetInitialization();
if(!LP)
{
CString str;
str="系统存在环网,请检查系统结构";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 3001;
}
LP=DistributionFlow();
if(!LP)
{
CString str;
str="超过最大迭代次数,最大迭代次数过小或配网不收敛";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 4001;
}
///////////////////////////////////////////
//get result
////////////////////////////////////////////
if((fp=fopen("Result.ini","w"))==NULL)
{
CString str;
str="输出文件Result.ini不存在或路径不正确";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 1001;
}
INT nMaxEle=GetMaxElement();
UINT nNode;
for(i=1;i<=nMaxEle;++i)
{
bMark=GetNodeAtElement(i,nNode);
if(bMark)
fprintf(fp,"%10d%10d\n",i,nNode);
}
i=nIndex=-1;
fprintf(fp,"\n\n%10d%10d\n\n\n",i,nIndex);
double wVoltage,wP0,wQ0;
for(i=1;i<=nMaxEle;++i)
{
bMark=GetNodeData(i,wVoltage,wP0,wQ0);
if(bMark)
fprintf(fp," %10d%15.8f\n",i,wVoltage);
}
i=-1;
voltage=-1;
fprintf(fp,"\n\n%10d%15.8f\n\n\n",i,voltage);
INT nBranch=GetBranchNumber();
double wC;
UINT Head,Tail;
for(i=1;i<=nBranch;++i)
{
bMark=BranchWaste(i,Head,Tail,wP0,wQ0,wC);
float wP1,wQ1;
wP1=wQ1=0;
if(bMark)
fprintf(fp,"%10d 0 %10d%10d%15.8f%15.8f%15.8f%15.8f%15.8f\n",
i, Head, Tail, wP0, wQ0, wP1, wQ1, wC);
}
double PFe,QFe,PCu,QCu;
for(i=1;i<=nBranch;++i)
{
bMark=TransWaste(i,Head,Tail,PFe,QFe,PCu,QCu,wC);
if(bMark)
fprintf(fp,"%10d 1 %10d%10d%15.8f%15.8f%15.8f%15.8f%15.8f\n",
i, Head, Tail, PFe, QFe, PCu, QCu, wC);
}
i=head=tail=-1;
PFe=QFe=PCu=QCu=wC=-1;
fprintf(fp,"\n\n%10d -1 %10d%10d%15.8f%15.8f%15.8f%15.8f%15.8f\n\n\n",
i, head, tail, PFe, QFe, PCu, QCu, wC);
int nSwitch=GetSwitch();
for(int number=1;number<=nSwitch;++number)
{
BOOL bMark=GetSwitchInfo(number,head,tail,wC);
if(bMark)
fprintf(fp,"%10d%10d%10d%15.8f\n",number, head, tail, wC);
}
number=head=tail=-1;
wC=-1;
fprintf(fp,"\n\n%10d%10d%10d%15.8f\n",number, head, tail, wC);
fclose(fp);
return LP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -