📄 dnet.cpp
字号:
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()
{
CHAR inBuf[50];
Initialization();
FILE* fp;
if((fp=fopen("..\\data\\Branch.ini","r"))==NULL)
{
CString str;
str="输入文件Branch.ini不存在或路径不正确";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 1001;
}
fclose(fp);
INT nFeeder,nMaxIter;
double SB,VB,VLimit;
GetPrivateProfileString ("输入", "网络参数",
"", inBuf, 50,
"..\\data\\Branch.ini");
INT nIndex=0;
nFeeder=atoi(GetStr(nIndex,inBuf));
nMaxIter=atoi(GetStr(nIndex,inBuf));
SB=atof(GetStr(nIndex,inBuf));
VB=atof(GetStr(nIndex,inBuf));
VLimit=atof(GetStr(nIndex,inBuf));
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);
GetPrivateProfileString ("输入", "结构参数",
"", inBuf, 50,
"..\\data\\Branch.ini");
nIndex=0;
int nBranch=atoi(GetStr(nIndex,inBuf));
INT nCable=atoi(GetStr(nIndex,inBuf));
INT nTrans=atoi(GetStr(nIndex,inBuf));
INT nCap=atoi(GetStr(nIndex,inBuf));
INT nSwitch=atof(GetStr(nIndex,inBuf));
BOOL bMark=FALSE;
INT node;
float voltage;
char* pFeederInfo=new char[20*nFeeder];
GetPrivateProfileString ("输入", "馈线信息",
"", pFeederInfo, 20*nFeeder,
"..\\data\\Branch.ini");
INT nCount=0;
for(INT i=1;i<=nFeeder;++i)
{
nIndex=atoi(GetStr(nCount,pFeederInfo));
node=atoi(GetStr(nCount,pFeederInfo));
voltage=atof(GetStr(nCount,pFeederInfo));
SetFeederInfo(nIndex, node, voltage);
}
delete[] pFeederInfo;
BOOL state;
INT head,tail;
double area,length;
char* pBranchInfo=new char[40*nBranch];
GetPrivateProfileString ("输入", "架空支路",
"", pBranchInfo, 40*nBranch,
"..\\data\\Branch.ini");
nCount=0;
for(i=1;i<=nBranch;++i)
{
nIndex=atoi(GetStr(nCount,pBranchInfo));
state=atoi(GetStr(nCount,pBranchInfo));
head=atoi(GetStr(nCount,pBranchInfo));
tail=atoi(GetStr(nCount,pBranchInfo));
area=atof(GetStr(nCount,pBranchInfo));
length=atof(GetStr(nCount,pBranchInfo));
SetBranch(nIndex, state, head, tail, area, length);
}
delete[] pBranchInfo;
INT sort;
char* pCableInfo=new char[50*nCable];
GetPrivateProfileString ("输入", "电缆支路",
"", pCableInfo, 50*nCable,
"..\\data\\Branch.ini");
nCount=0;
for(i=1;i<=nCable;++i)
{
nIndex=atoi(GetStr(nCount,pCableInfo));
state=atoi(GetStr(nCount,pCableInfo));
head=atoi(GetStr(nCount,pCableInfo));
tail=atoi(GetStr(nCount,pCableInfo));
area=atof(GetStr(nCount,pCableInfo));
sort=atoi(GetStr(nCount,pCableInfo));
voltage=atof(GetStr(nCount,pCableInfo));
length=atof(GetStr(nCount,pCableInfo));
SetCable(nIndex, state, head, tail, area, sort,
voltage, length);
}
delete[] pCableInfo;
double PF, VF, PK, KC, ST,position;
char* pTranInfo=new char[100*nTrans];
GetPrivateProfileString ("输入", "变压器支路",
"", pTranInfo, 100*nTrans,
"..\\data\\Branch.ini");
nCount=0;
for(i=1;i<=nTrans;++i)
{
nIndex=atoi(GetStr(nCount,pTranInfo));
state=atoi(GetStr(nCount,pTranInfo));
head=atoi(GetStr(nCount,pTranInfo));
tail=atoi(GetStr(nCount,pTranInfo));
PF=atof(GetStr(nCount,pTranInfo));
VF=atof(GetStr(nCount,pTranInfo));
PK=atof(GetStr(nCount,pTranInfo));
KC=atof(GetStr(nCount,pTranInfo));
ST=atof(GetStr(nCount,pTranInfo));
voltage=atof(GetStr(nCount,pTranInfo));
position=atof(GetStr(nCount,pTranInfo));
SetTrans(nIndex, state, head, tail,
PF, VF, PK, KC, ST, voltage, position);
}
delete[] pTranInfo;
char* pSwitchInfo=new char[20*nSwitch];
GetPrivateProfileString ("输入", "开关支路",
"", pSwitchInfo, 20*nSwitch,
"..\\data\\Branch.ini");
nCount=0;
for(i=1;i<=nSwitch;++i)
{
nIndex=atoi(GetStr(nCount,pSwitchInfo));
head=atoi(GetStr(nCount,pSwitchInfo));
tail=atoi(GetStr(nCount,pSwitchInfo));
state=atoi(GetStr(nCount,pSwitchInfo));
SetSwitch(nIndex,head,tail);
SetSwitchState(nIndex,state);
}
delete[] pSwitchInfo;
double dP,Sn;
char* pCapInfo=new char[40*nCap];
GetPrivateProfileString ("输入", "电容信息",
"", pCapInfo, 40*nCap,
"..\\data\\Branch.ini");
nCount=0;
for(i=1;i<=nCap;++i)
{
nIndex=atoi(GetStr(nCount,pCapInfo));
node=atoi(GetStr(nCount,pCapInfo));
dP=atof(GetStr(nCount,pTranInfo));
Sn=atof(GetStr(nCount,pTranInfo));
voltage=atof(GetStr(nCount,pTranInfo));
SetCapInfo(nIndex, node, dP, Sn, voltage);
}
delete[] pCapInfo;
if((fp=fopen("..\\data\\Load.ini","r"))==NULL)
{
CString str;
str="输入文件Load.ini不存在或路径不正确";
MessageBox(NULL,str,"警告",MB_OK|MB_ICONEXCLAMATION);
return 1001;
}
fclose(fp);
INT nLoad=GetPrivateProfileInt ("输入", "负荷数",
0, "..\\data\\Load.ini");
float wP, wQ;
char* pLoadInfo=new char[30*nLoad];
GetPrivateProfileString ("输入", "负荷信息",
"", pLoadInfo, 30*nLoad,
"..\\data\\Load.ini");
nCount=0;
for(i=1;i<=nLoad;++i)
{
nIndex=atoi(GetStr(nCount,pLoadInfo));
node=atoi(GetStr(nCount,pLoadInfo));
wP=atof(GetStr(nCount,pLoadInfo));
wQ=atof(GetStr(nCount,pLoadInfo));
SetBeginInfo(nIndex, node, wP, wQ);
}
delete[] pLoadInfo;
////////////////////////////////////////////////
//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
////////////////////////////////////////////
INT nMaxEle=GetMaxElement();
double wVoltage,wP0,wQ0;
CString str,str1;
str1="";
for(i=1;i<=nMaxEle;++i)
{
bMark=GetNodeData(i,wVoltage,wP0,wQ0);
if(bMark)
{
str.Format("(%d,%f),",i,wVoltage);
str1+=str;
}
}
WritePrivateProfileString ("输出", "节点量",
str1, "..\\data\\Result.ini");
nBranch=GetBranchNumber();
str1="";
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)
{
str.Format("(%d,0,%d,%d,%f,%f,%f,%f,%f),",
i, Head, Tail, wP0, wQ0, wP1, wQ1, wC);
str1+=str;
}
}
double PFe,QFe,PCu,QCu;
for(i=1;i<=nBranch;++i)
{
bMark=TransWaste(i,Head,Tail,PFe,QFe,PCu,QCu,wC);
if(bMark)
{
str.Format("(%d,1,%d,%d,%f,%f,%f,%f,%f),",
i, Head, Tail, PFe, QFe, PCu, QCu, wC);
str1+=str;
}
}
WritePrivateProfileString ("输出", "损耗量",
str1, "..\\data\\Result.ini");
nSwitch=GetSwitch();
str1="";
for(int number=1;number<=nSwitch;++number)
{
BOOL bMark=GetSwitchInfo(number,head,tail,wC);
if(bMark)
{
str.Format("(%d,%d,%d,%f),",number, head, tail, wC);
str1+=str;
}
}
INT nLength=str1.GetLength();
WritePrivateProfileString ("输出", "开关量",
str1, "..\\data\\Result.ini");
return LP;
}
CString CDNet::GetStr(INT& nIndex,CString str)
{
CString strText;
while(str[nIndex]!='\0')
{
if(str[nIndex]=='('||str[nIndex]==')'||str[nIndex]==','
||str[nIndex]==' ')
{
++nIndex;
continue;
}
strText="";
while(str[nIndex]!=','&&str[nIndex]!=')'||str[nIndex]==' ')
{
strText+=str[nIndex];
++nIndex;
}
return strText;
}
return "";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -