?? homotpro.cpp
字號:
/* Homotopy Continuation Method: Group 2. */
#include "homot.h"
#ifdef WINDOWS
#include "Win UWPflow.h"
#include "GraphDLG.h"
#endif
/* ------- Global Variables ------ */
extern VALUETYPE *Dx,Dparam,param0,*x0,*x0p,Kh,Htol,SD0,AngTr,
DxiMax,VSFone,VSFinf,SF,TVI,lambda_o,
TotalPl,TotalQl,TotalPg,TotalQg;
extern INDEX TVIbus;
extern AClist *Vlist,*Vlistp;
extern int field;
extern BOOLEAN flagPrintTotalPl,flagPrintTotalQl,flagPrintTotalPg,flagPrintTotalQg;
#ifdef WINDOWS
extern CString dir;
extern GraphDLG* GraphDlg;
#endif
/* --------------------------- InList --------------------------------- */
#ifdef ANSIPROTO
BOOLEAN InList(ACbusData *ACptr,AClist *Vptr)
#else
BOOLEAN InList(ACptr,Vptr)
ACbusData *ACptr;
AClist *Vptr;
#endif
/* Check whether bus in list for V profiles */
{
AClist *Lptr;
for(Lptr=Vptr;Lptr!=NULL;Lptr=Lptr->Next) {if(ACptr==Lptr->AC) return(TRUE);}
return(FALSE);
}
/* --------------------------- MakeVlist --------------------------------- */
#ifdef ANSIPROTO
void MakeVlist(FILE *Out)
#else
void MakeVlist(Out)
FILE *Out;
#endif
/* Prepare list of buses/areas for voltage profiles. */
{
ACbusData *ACptr,*ACptrM;
AreaData *Aptr;
AClist *Lptr,*Lptrp;
DCbusData *DCptr;
char Line[BUFLEN],BusName[BUFLEN],Type[BUFLEN],*ptr,*Name;
FILE *Input;
INDEX N,i,count,countp;
VALUETYPE MaxV=0;
Vlist=Vlistp=NULL;
ACptrM=NULL;
Name=NameParameter('i');
flagPrintTotalPl=flagPrintTotalQl=flagPrintTotalPg=flagPrintTotalQg=FALSE;
if (!NullName(Name) && (Input=OpenInput(Name))!=NULL) {
for (;;) {
strcpy(Type,"");
if (fgets(Line,BUFLEN,Input)==NULL) break;
if ((count=sscanf(Line,"%d %s %s",&N,BusName,Type))>3 && strncmp(Line,"C",1)) {
fCustomPrint(stderr,"***Warning: Line-> %s",Line);
fCustomPrint(stderr," will be ignored in file %s.\n",Name);
}
else if (count>=2) {
if (BusName[0]=='\"'||BusName[0]=='\'') {
count=2;
for(ptr=Line;*ptr!='\"'&&*ptr!='\'';ptr++); ptr++;
for(i=0;*ptr!='\"'&&*ptr!='\''&&*ptr!='\n';BusName[i]= *ptr,i++,ptr++);
BusName[i]='\0';
ptr++;
count+=sscanf(ptr,"%s",Type);
}
if (N==0 && !strcmp(BusName,"0") && !strcmp(Type,"PL")) flagPrintTotalPl=TRUE;
else if (N==0 && !strcmp(BusName,"0") && !strcmp(Type,"QL")) flagPrintTotalQl=TRUE;
else if (N==0 && !strcmp(BusName,"0") && !strcmp(Type,"PG")) flagPrintTotalPg=TRUE;
else if (N==0 && !strcmp(BusName,"0") && !strcmp(Type,"QG")) flagPrintTotalQg=TRUE;
else {
if (!strcmp(Type,"PA")){
ACptr=NULL;
for (Aptr=dataPtr->Area;Aptr!=NULL;Aptr=Aptr->Next)
if(N==Aptr->N ||!strncmp(Aptr->Name,BusName,strlen(BusName))) break;
}
else {
Aptr=NULL;
for (ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next)
if(N==ACptr->Num||!strncmp(ACptr->Name,BusName,strlen(BusName))) break;
}
if(ACptr!=NULL || Aptr!=NULL){
Lptr=Vlist;
#ifdef WINDOWS
Vlist= new AClist;
#else
Vlist=(AClist *) malloc(sizeof(AClist));
if (Vlist==NULL) {
fclose(Out);
fclose(Input);
ErrorHalt("Insufficient memory to allocate profile List.");
stopExecute(ERROREXIT);
}
#endif
Vlist->AC=ACptr;
Vlist->Area=Aptr;
if (ACptr!=NULL) Vlist->N=ACptr->Num;
else Vlist->N=Aptr->N;
if (!strcmp(Type,"V") || !strcmp(Type,"D") || !strcmp(Type,"PL") || !strcmp(Type,"QL") ||
!strcmp(Type,"PG") ||!strcmp(Type,"QG") ||!strcmp(Type,"PA")) strcpy(Vlist->Type,Type);
else strcpy(Vlist->Type,"V");
Vlist->Next=Lptr;
Vlist->Prev=NULL;
if(Lptr!=NULL) Lptr->Prev=Vlist;
}
else if (strncmp(Line,"C",1)) {
fCustomPrint(stderr,"***Warning: Line-> %s",Line);
fCustomPrint(stderr," will be ignored in file %s.\n",Name);
}
}
}
}
Lptr=Vlist;
while(Lptr!=NULL){
Lptrp=Lptr->Next;
Lptr->Next=Lptr->Prev;
Lptr->Prev=Lptrp;
if(Lptrp==NULL) Vlist=Lptr;
Lptr=Lptrp;
}
fclose(Input);
}
if (Vlistp==NULL) {
countp=1;
while (countp<=8 && countp<=Nac) {
MaxV=0;
for (ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next) {
if(Nac<=8 && !InList(ACptr,Vlistp)) {
ACptrM=ACptr;
break;
}
else if((ACptr->Cont!=NULL &&(QRcont || !strpbrk(ACptr->Type,"G"))) ||
(!Rcont && strpbrk(ACptr->Type,"T"))||
(!QRcont && strpbrk(ACptr->Type,"C"))) {
i=ACvar[ACptr->N]+1;
if (fabs(Dx[i])>MaxV && !InList(ACptr,Vlistp)) {MaxV=fabs(Dx[i]); ACptrM=ACptr;}
}
}
if(ACptrM!=NULL){
Lptr=Vlistp;
#ifdef WINDOWS
Vlistp= new AClist;
#else
Vlistp=(AClist *) malloc(sizeof(AClist));
if (Vlistp==NULL) {
fclose(Out);
ErrorHalt("Insufficient memory to allocate Voltage Profile Bus List.");
stopExecute(ERROREXIT);
}
#endif
Vlistp->AC=ACptrM;
strcpy(Vlistp->Type,"V");
Vlistp->N=ACptrM->Num;
Vlistp->Area=NULL;
Vlistp->Next=Lptr;
Vlistp->Prev=NULL;
if(Lptr!=NULL) Lptr->Prev=Vlistp;
ACptrM=NULL;
countp++;
} else break;
}
}
if (Vlist==NULL) Vlist=Vlistp;
if (ExistParameter('m')){
if (ExistParameter('O')) {
for (DCptr=dataPtr->DCbus;DCptr!=NULL;DCptr=DCptr->Next) {
for(Lptr=Vlist;Lptr!=NULL;Lptr=Lptr->Next) if(Lptr->AC==DCptr->AC && !strcmp(Lptr->Type,"V")) break;
if (Lptr==NULL) {
Lptr=Vlist;
#ifdef WINDOWS
Vlist= new AClist;
#else
Vlist=(AClist *) malloc(sizeof(AClist));
if (Vlist==NULL) {
fclose(Out);
ErrorHalt("Insufficient memory to allocate Voltage Profile Bus List.");
stopExecute(ERROREXIT);
}
#endif
Vlist->AC=DCptr->AC;
Vlist->Area=NULL;
Vlist->N=DCptr->AC->Num;
strcpy(Vlist->Type,"V");
Vlist->Next=Lptr;
Vlist->Prev=NULL;
if(Lptr!=NULL) Lptr->Prev=Vlist;
}
for(Lptr=Vlist;Lptr!=NULL;Lptr=Lptr->Next) if(Lptr->AC==DCptr->AC && !strcmp(Lptr->Type,"D")) break;
if (Lptr==NULL) {
Lptr=Vlist;
#ifdef WINDOWS
Vlist= new AClist;
#else
Vlist=(AClist *) malloc(sizeof(AClist));
if (Vlist==NULL) {
fclose(Out);
ErrorHalt("Insufficient memory to allocate Voltage Profile Bus List.");
stopExecute(ERROREXIT);
}
#endif
Vlist->AC=DCptr->AC;
Vlist->Area=NULL;
Vlist->N=DCptr->AC->Num;
strcpy(Vlist->Type,"D");
Vlist->Next=Lptr;
Vlist->Prev=NULL;
if(Lptr!=NULL) Lptr->Prev=Vlist;
}
}
}
//extra % because when it's read by fprintf, one % will be ignored
fCustomPrint(Out,"%s ", "%%");
}
fCustomPrint(Out,"L.F. ");
#ifdef WINDOWS
GraphDlg->totalElements = 0;
GraphDlg->show = true;
char tmpCaption[20];
char tmpN[20];
//clear last graph
GraphDlg->Reset();
#endif
for(Lptr=Vlist;Lptr!=NULL;Lptr=Lptr->Next)
{
fCustomPrint(Out,"%s%-5d ",Lptr->Type,Lptr->N);
#ifdef WINDOWS
//initialize elements of the graph here where headings are printed
//so this is the first point where the program can know how many elements there are
//create element
if (GraphDlg->totalElements!=0)
GraphDlg->m_GraphCtrl.AddElement();
long color = RGB(rand(), rand(), rand());
GraphDlg->m_GraphCtrl.SetElementLineColor(color);
//set annotation
strcpy(tmpCaption,Lptr->Type);
sprintf(tmpN, "%-5d", Lptr->N);
strcat(tmpCaption, tmpN);
GraphDlg->m_GraphCtrl.AddAnnotation();
GraphDlg->m_GraphCtrl.SetAnnoLabelCaption(tmpCaption);
GraphDlg->m_GraphCtrl.SetAnnoLabelColor(color);
//increase element count
GraphDlg->totalElements++;
#endif
}
if (ExistParameter('e')) {
for(Lptr=Vlist;Lptr!=NULL;Lptr=Lptr->Next) if (Lptr->AC!=NULL) {
if (Lptr->AC->Gen!=NULL) {
fCustomPrint(Out,"Ia%-5d ",Lptr->N);
fCustomPrint(Out,"Eq%-5d ",Lptr->N);
fCustomPrint(Out,"dg%-5d ",Lptr->N);
}
}
}
if (ExistParameter('O')) {
fCustomPrint(Out,"Vac ");
if (field>7) fCustomPrint(Out," ");
}
if (ExistParameter('O') || ExistParameter('e')) {
for (i=0,DCptr=dataPtr->DCbus;DCptr!=NULL;DCptr=DCptr->Next) if(!strcmp(DCptr->Type,"R")) {
i+=2;
if (ExistParameter('O')) {
fCustomPrint(Out,"a%1d ",i-1); if (field>7) fCustomPrint(Out," ");
fCustomPrint(Out,"b%1d ",i-1); if (field>7) fCustomPrint(Out," ");
fCustomPrint(Out,"d%1d ",i-1); if (field>7) fCustomPrint(Out," ");
fCustomPrint(Out,"a%1d ",i); if (field>7) fCustomPrint(Out," ");
fCustomPrint(Out,"b%1d ",i); if (field>7) fCustomPrint(Out," ");
fCustomPrint(Out,"d%1d ",i); if (field>7) fCustomPrint(Out," ");
} else if (ExistParameter('e')) {
fCustomPrint(Out,"alR_%1d ",i);
fCustomPrint(Out,"gaI_%1d ",i);
fCustomPrint(Out,"Id_%1d ",i);
}
}
}
if (flagPrintTotalPl) fCustomPrint(Out,"PL ");
if (flagPrintTotalQl) fCustomPrint(Out,"QL ");
if (flagPrintTotalPg) fCustomPrint(Out,"PG ");
if (flagPrintTotalQg) fCustomPrint(Out,"QG ");
if (ExistParameter('f')) {
fCustomPrint(Out,"VSFone ");
fCustomPrint(Out,"VSFbus ");
fCustomPrint(Out,"VSFinf ");
fCustomPrint(Out,"SF ");
if (TVI!=0) fCustomPrint(Out,"TVI_%d %d_Rank",TVIbus,TVIbus);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -