📄 readital.cpp
字号:
if (!strcmp(Code,"T")) {
if (!strcmp(ACptr->Type,"BQ")) {
ACptr->Qmax=99999999.;
ACptr->Qmin=-99999999.;
} else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This bus was not defined as a PV bus in the main input data file; \n");
fCustomPrint(stderr," hence, its Q-limits cannot be released (check field 50).\n");
fCustomPrint(stderr," This line in the ADD file will be ignored.\n");
}
}
GetStr(Line,58,1,1,Code);
if (strcmp(Code,"T")) ACptr->DPG=ACptr->DPg=ACptr->Pg;
if (strpbrk(ACptr->Type,"Q,S")) {
GetStr(Line,66,2,2,Zone);
strcpy(ACptr->Zone,Zone);
strcpy(ACptr->Owner,Zone);
} else {
strcpy(ACptr->Zone," 0");
strcpy(ACptr->Owner," 0");
}
ACptr->Nc=GetInt(Line,68,2);
GetStr(Line,70,1,1,Code);
if (strpbrk(Code,"P") && !strcmp(ACptr->Type,"B")) {
strcpy(ACptr->Type,"BC");
ACptr->VCont=ACptr->V;
flag2Vcontrol=TRUE;
}
else if (strpbrk(Code,"V,S") && strpbrk(ACptr->Type,"Q,S")) {
if (!strcmp(ACptr->Type,"BQ")) strcpy(ACptr->Type,"BG");
else strcpy(ACptr->Type,"BGS");
flag2Vcontrol=TRUE;
}
ACptr->Qn=ACptr->Ql;
ACptr->b=GetValue(Line,71,7,0);
ACptr->Pn=ACptr->Pl;
ACptr->a=GetValue(Line,81,7,0);
if (ACptr->a!=0 || ACptr->b!=0) flagVloads=TRUE;
}
}
/* --------------- Generators --------------------------- */
else if (Line[79]=='G' || Line[79]=='H') {
if (flagPrint) {
fCustomPrint(stderr,"***Warning: The program ignores the G and H cards, as capability curves\n");
fCustomPrint(stderr," are implemented here through direct limits on Sg, Pg, Qg,\n");
fCustomPrint(stderr," Ef and Ia (see -3 option).\n");
flagPrint=FALSE;
}
}
/* --------------- Transformers ------------------------ */
else if (Line[79]=='R') {
N=GetInt(Line,1,3);
GetStr(Line,4,1,1,Zone);
KVl=GetInt(Line,5,1);
sprintf(Code,"%3d%1s%1d",N,Zone,KVl);
ACptr=ACbusInList2(0,Code,Nac,1,FALSE);
N=GetInt(Line,7,3);
GetStr(Line,10,1,1,Zone);
KVl=GetInt(Line,11,1);
sprintf(Code,"%3d%1s%1d",N,Zone,KVl);
ACptrp=ACbusInList2(0,Code,Nac,1,FALSE);
GetStr(Line,13,1,1,Ckt);
if(!strcmp(Ckt," ")) strcpy(Ckt,"0");
Eptr=ElemInList2(ACptr,ACptrp,NacEl,"R,T",Ckt,FALSE);
if (Eptr!=NULL) {
KV=ACptr->KV;
KVp=ACptrp->KV;
if (KV>KVp) Taps=KVp/KV;
else Taps=KV/KVp;
Eptr->Taps=Taps;
Tap=GetValue(Line,14,8,0)*Taps;
if (Tap>0) Eptr->Tap=Tap;
else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This transformer data has a negative tap setting.\n");
fCustomPrint(stderr," The tap will be assumed to be equal to the nominal\n");
fCustomPrint(stderr," voltage ratio.\n");
Eptr->Tap=Tap=1;
}
Tmin=GetValue(Line,24,8,0)*Taps;
Tmax=GetValue(Line,34,8,0)*Taps;
if (Tmax>Tmin && Tmax>Tap && Tap>Tmin) {
Eptr->Tmax=Tmax;
Eptr->Tmin=Tmin;
} else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: The max. and min. tap settings of this transformer are incorrect.\n");
fCustomPrint(stderr," These limits will be assumed to be equal to 1.1 and 0.9 p.u.,\n");
fCustomPrint(stderr," respectively.\n");
Eptr->Tmax=1.1;
Eptr->Tmin=0.9;
}
N=GetInt(Line,42,2);
KVs=GetValue(Line,45,8,0);
if (!strcmp(Eptr->Type,"R")) {
ACptrs=Eptr->Cont;
if (N==0) {
NregV--;
strcpy(Eptr->Type,"T");
ACptrs->Reg=TakeElemFromList(ACptrs->Reg,Eptr);
Eptr->Cont=NULL;
}
else {
if (N>0) {
if (KV>KVp) { ACptrs=ACptr; ACptrs->V=KVs/KV; }
else { ACptrs=ACptrp; ACptrs->V=KVs/KVp; }
} else {
if (KV<KVp) { ACptrs=ACptr; ACptrs->V=KVs/KV; }
else { ACptrs=ACptrp; ACptrs->V=KVs/KVp; }
}
if (ACptrs!=Eptr->Cont) {
Eptr->Cont->Reg=TakeElemFromList(Eptr->Cont->Reg,Eptr);
ACptrs->Reg=AddElemToList(ACptrs->Reg,Eptr);
Eptr->Cont=ACptrs;
}
}
}
else if (N!=0) {
NregV++;
strcpy(Eptr->Type,"R");
if (N>0) {
if (KV>KVp) ACptrs=ACptr;
else ACptrs=ACptrp;
} else {
if (KV<KVp) ACptrs=ACptr;
else ACptrs=ACptrp;
}
if (!strcmp(ACptrs->Type,"B")) strcpy(ACptrs->Type,"BT");
ACptrs->Reg=AddElemToList(ACptrs->Reg,Eptr);
Eptr->Cont=ACptrs;
}
}
else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This transformer has not been defined in the main data file.\n");
fCustomPrint(stderr," This line in the ADD file will be ignored.\n");
}
}
/* --------------- Shunt Compensation ------------------ */
else if (Line[79]=='B') {
N=GetInt(Line,1,3);
GetStr(Line,4,1,1,Zone);
KVl=GetInt(Line,5,1);
sprintf(Code,"%3d%1s%1d",N,Zone,KVl);
ACptr=ACbusInList2(0,Code,Nac,1,FALSE);
if (ACptr==NULL) {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This bus has not been defined on the main input data file.\n");
fCustomPrint(stderr," This line in the ADD file will be ignored.\n");
}
else {
Q=GetValue(Line,15,8,0)/Sn;
GetStr(Line,31,1,1,Code);
if (!strcmp(Code,"T")) {
if(!strcmp(ACptr->Type,"B")) {
ACptr->Qg=ACptr->Qg+Q;
Qmin=GetValue(Line,7,8,0)/Sn;
Qmax=GetValue(Line,23,8,0)/Sn;
if (Qmax<=Qmin || Qmax<Q || Q<Qmin){
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: The Q limits are inconsistent on this bus and hence will\n");
fCustomPrint(stderr," be given arbitrarily large values (~+/-10^8 p.u.).\n");
Qmax=99999999.;
Qmin=-99999999.;
}
ACptr->Qmax=Qmax;
ACptr->Qmin=Qmin;
GetStr(Line,33,1,1,Code);
if (!strcmp(Code,"T")) {
strcpy(ACptr->Type,"BZ");
NZvolt++;
} else {
strcpy(ACptr->Type,"BQ");
Nvolt++;
}
ACptr->Cont=NULL;
strcpy(ACptr->cont,"V");
} else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This bus cannot be defined as a voltage controlled bus, as it\n");
fCustomPrint(stderr," has already been defined as a controlled bus in the main file.\n");
}
} else {
GetStr(Line,33,1,1,Code);
if (!strcmp(Code,"T")) ACptr->B=Q/(ACptr->V*ACptr->V);
else ACptr->Qg=ACptr->Qg+Q;
}
GetStr(Line,35,2,2,Zone);
strcpy(ACptr->Zone,Zone);
strcpy(ACptr->Owner,Zone);
}
}
/* --------------- Areas ------------------------------- */
else if (Line[79]=='J') {
NJcard++;
sprintf(Zone,"%2d",NJcard);
GetStr(Line,1,16,16,Code);
val=GetValue(Line,34,4,0)/100.0;
for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next) if (ACptr->Area==NULL) {
if (!strcmp(ACptr->Zone,Zone)) {
Aptr=(AreaData *) AreaInList(0,Code,Narea);
if (Aptr->N==0) {
Narea++;
Aptr->N=Narea;
strcpy(Aptr->Zone[1],Zone);
flagAreas=TRUE;
}
ACptr->Area=Aptr;
if (strpbrk(ACptr->Type,"S")) Aptr->Slack=Aptr->BSptr=ACptr;
else if (strpbrk(ACptr->Type,"Q") && Aptr->Slack==NULL) Aptr->Slack=Aptr->BSptr=ACptr;
Pn=val*ACptr->Pl;
Qn=val*ACptr->Ql;
ACptr->Pnl=Pn;
ACptr->Qnl=Qn;
Sum+=Pn+Qn;
}
}
}
/* --------------- Secondary Voltage Control ----------- */
else if (Line[79]=='S') {
flagScards=TRUE;
N2SVCarea++;
ACptrp=NULL;
GetStr(Line,1,16,16,Code);
for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next) {
if (ACptr->Nc==N2SVCarea && strpbrk(ACptr->Type,"C")) {
if (ACptrp==NULL) {
ACptrp=ACptr;
ACptrp->Cont=NULL;
ACptrp->VCont=ACptr->V;
}
else {
fCustomPrint(stderr,"***Warning: Secondary voltage control area %s has more than 1 pilot node.\n",Code);
fCustomPrint(stderr," The pilot node %d %s will be ignored.\n",ACptr->N,ACptr->Name);
strcpy(ACptr->Type,"B");
}
}
}
if (ACptrp!=NULL) {
for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next) {
if (ACptr->Nc==N2SVCarea && strpbrk(ACptr->Type,"G")) {
ACptr->Cont=ACptrp;
ACptrp->Kbg++;
ACptrp->Kbg1=ACptrp->Kbg1+ACptr->Qmax;
ACptrp->Kbg2=ACptrp->Kbg2+ACptr->Qmin;
}
}
} else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: The secondary voltage control area does not have a pilot node.\n",Code);
fCustomPrint(stderr," This area in the ADD file will be ignored.\n");
}
}
/* --------------- Ignore data ------------------------- */
else {
fCustomPrint(stderr,"Input Line-> %d\n%s",LineNum,Line);
fCustomPrint(stderr,"***Warning: This line in the ADD file will be ignored.\n");
}
}
fclose(InputFile);
}
if (flag2Vcontrol && !flagScards ) {
for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next) {
if (!strcmp(ACptr->Type,"BC")) strcpy(ACptr->Type,"B");
else if (!strcmp(ACptr->Type,"BG")) strcpy(ACptr->Type,"BQ");
else if (!strcmp(ACptr->Type,"BGS")) strcpy(ACptr->Type,"BS");
}
flag2Vcontrol=FALSE;
}
if (Sum!=0) flagKdirection=TRUE;
else {
if (ExistParameter('v')) {
fCustomPrint(stderr,"ERROR: The -v option will yield a singular Jacobian in voltage collapse\n");
fCustomPrint(stderr," studies since Pnl, Qnl, Pzl, and Qzl are zero in all load buses.\n");
InputError=TRUE;
} else if (ExistParameter('L')) {
fCustomPrint(stderr,"***Warning: The loading factor lambda will not yield different results\n");
fCustomPrint(stderr," from the base case since Pnl, Qnl, Pzl, and Qzl are zero\n");
fCustomPrint(stderr," in all load buses.\n");
} else if ((ExistParameter('H') || ExistParameter('c'))) {
fCustomPrint(stderr,"ERROR: The Homotopy Continuation Method will not yield different results\n");
fCustomPrint(stderr," from the base case since Pnl, Qnl, Pzl, and Qzl are zero in all\n");
fCustomPrint(stderr," load buses.\n");
InputError=TRUE;
} else if (ExistParameter('C')) {
fCustomPrint(stderr,"ERROR: The Point of Collapse Method will not yield different results\n");
fCustomPrint(stderr," from the base case since Pnl, Qnl, Pzl, and Qzl are zero in\n");
fCustomPrint(stderr," all load buses.\n");
InputError=TRUE;
}
}
if (flagAreas) {
for (ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next) {
if (ACptr->Area==NULL && !strcmp(ACptr->Zone," 0")) {
Aptr=(AreaData *) AreaInList(0,"REST",Narea);
if (Aptr->N==0) {
Narea++;
Aptr->N=Narea;
strcpy(Aptr->Zone[1]," 0");
}
ACptr->Area=Aptr;
if (strpbrk(ACptr->Type,"S")) Aptr->Slack=Aptr->BSptr=ACptr;
else if (strpbrk(ACptr->Type,"Q") && Aptr->Slack==NULL) Aptr->Slack=Aptr->BSptr=ACptr;
}
else if (ACptr->Area==NULL && ACptr->SVC!=NULL) {
Eptr=ACptr->Elem->Eptr;
if (Eptr->From==ACptr) ACptrp=Eptr->To;
else ACptrp=Eptr->From;
ACptr->Area=ACptrp->Area;
}
}
}
return(flagAreas);
}
/* --------------- TakeElemFromList ------------------- */
#ifdef ANSIPROTO
ElementList *TakeElemFromList(ElementList *ELptr,ElementData *Eptr)
#else
ElementList *TakeElemFromList(ELptr,Eptr)
ElementList *ELptr;
ElementData *Eptr;
#endif
{
ElementList *ptr,*prevptr,*firstptr,*nextptr;
BOOLEAN flag;
firstptr=prevptr=ptr=ELptr;
while (ptr!=NULL) {
nextptr=ptr->Next;
if (ptr->Eptr==Eptr) {
if (ptr==firstptr) flag=TRUE;
else flag=FALSE;
#ifdef WINDOWS
delete ptr;
#else
free(ptr);
#endif
if (flag) return(nextptr);
else { prevptr->Next=nextptr; return(firstptr); }
}
prevptr=ptr;
ptr=nextptr;
}
return(firstptr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -