📄 readdata.cpp
字号:
/* Read input data.
Transform the input data into the data structures needed by
the power flow, i.e., AC, DC and FACTS bus data and interconnecting
elements (lines, transformers with fixed taps, and PI equivalents).
Main. */
#include "readdata.h"
/* ------- Global Variables ------ */
VALUETYPE AngSlack;
INDEX NdcEl,LineNum;
FILE *InputDataFile;
/* ------------------- ErrorDetect -------------------------- */
#ifdef ANSIPROTO
void ErrorDetect(void)
#else
void ErrorDetect()
#endif
/* Detect inconsistencies in input data. */
{
ACbusData *ACptr,*ACptrp,*ACptrs;
AClist *ptrp,*ptrs;
DClist *ptr;
DCbusData *DCptr,*DCptrp;
ElementData *Eptr,*Eptrp;
ElementList *ELptr,*ELptrp;
AreaData *Aptr,*Aptrp;
SVCbusData *SVCptr; /* FACTS */
STATCOMbusData *STATCOMptr; /* FACTS */
VALUETYPE KVs;
BOOLEAN flag,ieee;
int i,j;
if (Nac==0||(NacEl+NdcEl)==0) ErrorHalt("No AC buses and/or elements in input data.");
if (Ndc==0) dataPtr->DCbus=NULL;
if (NacEl==0) dataPtr->Element=NULL;
if (Nsvc==0) dataPtr->SVCbus=NULL; /* FACTS */
if (Ntcsc==0) dataPtr->TCSCbus=NULL; /* FACTS */
if (Nstatcom==0) dataPtr->STATCOMbus=NULL; /* FACTS */
if (Narea<2) {dataPtr->Area=NULL; Narea=0;}
if (Nslack==0) ErrorHalt("No angle reference Bus for AC system.");
/* ------------------- AC buses ------------------------ */
ACptr=dataPtr->ACbus;
ieee=ExistParameter('I');
while(ACptr!=NULL){
if (ACptr->V==0){
fprintf(stderr,"ERROR: AC/DC bus %d %s has not been defined.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check the bus input cards.\n");
InputError=TRUE;
}
/* FACTS */
if (ACptr->Elem==NULL && ACptr->DC==NULL && ACptr->TCSC==NULL){
fprintf(stderr,"ERROR: AC bus %d %s is isolated.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check the AC/DC/FACTS input cards.\n");
InputError=TRUE;
}
/* END OF FACTS */
if (strpbrk(ACptr->Type,"G")){
#ifdef WINDOWS
ptrp= new AClist;
#else
ptrp= (AClist *) malloc(sizeof(AClist));
if (ptrp==NULL) {ErrorHalt("Insufficient memory to allocate list of AC controlled buses."); exit(ERROREXIT);}
#endif
ACptr->ContBus=ptrp;
ACptr->ContBus->AC=ACptr->Cont;
ACptr->ContBus->Next=ACptr->ContBus->Prev=NULL;
if (ACptr->Cont!=NULL) {
if (!strpbrk(ACptr->Cont->Type,"C")){
fprintf(stderr,"ERROR: The voltage controlled bus %d %s of PV bus\n",ACptr->Cont->Num,ACptr->Cont->Name);
fprintf(stderr," %d %s, is not a PQ bus. Check the AC bus input data.\n",ACptr->Num,ACptr->Name);
InputError=TRUE;
} else {
#ifdef WINDOWS
ptrp= new AClist;
#else
ptrp= (AClist *) malloc(sizeof(AClist));
if (ptrp==NULL) {ErrorHalt("Insufficient memory to allocate list of AC controlling buses."); exit(ERROREXIT);}
#endif
ptrp->AC=ACptr;
ptrp->Prev=NULL;
if(ACptr->Cont->ContBus==NULL) {
ACptr->Cont->ContBus=ptrp;
ACptr->Cont->ContBus->Next=ACptr->Cont->ContBus->Prev=NULL;
} else {
ptrs=ACptr->Cont->ContBus;
ACptr->Cont->ContBus=ptrp;
ptrs->Prev=ptrp;
ptrp->Next=ptrs;
}
}
if (!QRcont) { ACptr->Cont->Cont=ACptr->Cont; ACptr->Cont=NULL; }
else {
if (flag2Vcontrol) {
if (ACptr->Cont->Kbg1>0) ACptr->Kbg1=ACptr->Qmax/ACptr->Cont->Kbg1;
else ACptr->Kbg1=1;
if (ACptr->Cont->Kbg2<0) ACptr->Kbg2=ACptr->Qmin/ACptr->Cont->Kbg2;
else ACptr->Kbg2=1;
ACptr->Kbg=ACptr->Kbg1;
}
ACptr->Cont->Qr=ACptr->Cont->Qr+ACptr->Qg;
}
} else {
fprintf(stderr,"ERROR: The remote controlled bus of PV bus %d %s\n",ACptr->Num,ACptr->Name);
fprintf(stderr," has not been defined. Check the AC bus input data.\n");
InputError=TRUE;
}
}
if (strpbrk(ACptr->Type,"C") && ACptr->Kbg<1){
fprintf(stderr,"ERROR: The voltage controlled bus %d %s does not have\n",ACptr->Num,ACptr->Name);
fprintf(stderr," any generator controlling the voltage. Check the AC bus input data.\n");
InputError=TRUE;
}
if (Rcont && strpbrk(ACptr->Type,"T")) ACptr->Cont=NULL;
if (Narea>1){
if(ACptr->Area==NULL) for (Aptr=dataPtr->Area; Aptr!=NULL; Aptr=Aptr->Next){
for (i=1;i<=10;i++){
if(!strcmp(ACptr->Zone,Aptr->Zone[i])) {
ACptr->Area=Aptr;
if (strpbrk(ACptr->Type,"S")) Aptr->i++;
if (Aptr->i>1) {
fprintf(stderr,"ERROR: Area %d %s has 2 slack buses.\n",Aptr->N,Aptr->Name);
fprintf(stderr," Check AC area and bus input data.\n");
InputError=TRUE;
}
break;
}
}
if (ACptr->Area!=NULL) break;
}
if (ACptr->Area==NULL) {
fprintf(stderr,"ERROR: AC/DC bus %d %s is not in any area.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check area and bus input data.\n");
InputError=TRUE;
}
else {
if (!strcmp(ACptr->Area->Name,"")) {
fprintf(stderr,"ERROR: Area %d has not been defined.\n",ACptr->Area->N);
fprintf(stderr," Check area and bus input data.\n");
InputError=TRUE;
}
if(ACptr==ACptr->Area->Slack && !strpbrk(ACptr->Type,"S")) {
strcat(ACptr->Type,"A");
ACptr->Area->i++;
if (ACptr->Area->i>1) {
fprintf(stderr,"ERROR: Area %d %s has 2 slack buses.\n",ACptr->Area->N,ACptr->Area->Name);
fprintf(stderr," Check AC area and bus input data.\n");
InputError=TRUE;
}
}
Aptr=ACptr->Area;
ptrp=Aptr->AC;
#ifdef WINDOWS
Aptr->AC= new AClist;
#else
Aptr->AC=(AClist *) malloc(sizeof(AClist));
if (Aptr->AC==NULL) {ErrorHalt("Insufficient memory to allocate area data."); exit(ERROREXIT);}
#endif
Aptr->AC->AC=ACptr;
Aptr->AC->Next=ptrp;
Aptr->AC->Prev=NULL;
if (ptrp!=NULL) ptrp->Prev=Aptr->AC;
if (ExistParameter('6') && Aptr->BSptr==NULL) Aptr->Slack=Aptr->BSptr=ACptr;
}
} else ACptr->Area=NULL;
if(ACptr->Ang>=1000) ACptr->Ang=AngSlack;
if(ACptr->DPg==0 && strpbrk(ACptr->Type,"AS")) {
if (ExistParameter('6')) {if (strpbrk(ACptr->Type,"S")) ACptr->DPg=1;}
else ACptr->DPg=1;
}
if (ACptr->PgMax<=0) ACptr->PgMax=99999999.;
if (ACptr->Smax<=0) ACptr->Smax=99999999.;
ACptr->DPG=ACptr->DPg;
if (strpbrk(ACptr->Type,"X")) {
if (ACptr->Cont==NULL) {
fprintf(stderr,"ERROR: The reactance controlled bus %d %s does not have\n",ACptr->Num,ACptr->Name);
fprintf(stderr," a controlling bus. Check the AC input data.\n");
InputError=TRUE;
}
else {
ACptrp=ACptr->Cont;
ACptr->Vmax=ACptrp->Vmax;
ACptr->Vmin=ACptrp->Vmin;
if (ACptr->Vmin>=ACptr->Vmax) {
fprintf(stderr,"ERROR: The reactance controlling bus %d %s has inconsistent\n",ACptrp->Num,ACptrp->Name);
fprintf(stderr," voltage limits. Check the AC input data.\n");
InputError=TRUE;
}
else if (ACptrp->steps==0) {
fprintf(stderr,"ERROR: The reactance controlling bus %d %s has zero MVAr steps.\n",ACptrp->Num,ACptrp->Name);
fprintf(stderr," Check the AC input data.\n");
InputError=TRUE;
}
}
}
/* -------------------------- AC elements --------------------------- */
i=0;
for (ELptr=ACptr->Reg;ELptr!=NULL;ELptr=ELptr->Next){
Eptr=ELptr->Eptr;
if((!strcmp(Eptr->Type,"R") && !strpbrk(ACptr->Type,"T")) ||
(!strcmp(Eptr->Type,"RV") && !strpbrk(ACptr->Type,"R"))){
fprintf(stderr,"ERROR: LTC volt. controlled bus %d %s is not PQ.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check the AC/DC bus input cards.\n");
InputError=TRUE;
}
if(!strcmp(Eptr->Type,"R") || !strcmp(Eptr->Type,"RV")) i++;
}
if((ACptr->Reg==NULL || (ACptr->Reg!=NULL && i==0)) && strpbrk(ACptr->Type,"T")) {
fprintf(stderr,"ERROR: LTC volt. controlled bus %d %s does not have LTCs.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check the AC/DC bus and element input cards.\n");
InputError=TRUE;
}
if (strpbrk(ACptr->Type,"S,A")) {
ptrp=dataPtr->KGbus;
#ifdef WINDOWS
ptrs= new AClist;
#else
ptrs=(AClist *) malloc(sizeof(AClist));
if (ptrs==NULL) {ErrorHalt("Insufficient memory to allocate area data."); exit(ERROREXIT);}
#endif
ptrs->AC=ACptr;
ptrs->Next=ptrp;
ptrs->Prev=NULL;
dataPtr->KGbus=ptrs;
if (ptrp!=NULL) ptrp->Prev=ptrs;
}
ACptr->PG=ACptr->Pg;
ACptr->PL=ACptr->Pl;
ACptr->QL=ACptr->Ql;
ACptrp=ACptr->Next;
if(ieee) {
ACptr->Next=ACptr->Prev;
ACptr->Prev=ACptrp;
dataPtr->ACbus=ACptr;
}
ACptr=ACptrp;
}
Eptr=dataPtr->Element;
while(Eptr!=NULL){
if(strpbrk(Eptr->Type,"R") && !strcmp(Eptr->Zone,"")) {
fprintf(stderr,"ERROR: Reg. transf. from %d %s to %d %s\n",
Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);
fprintf(stderr," has not been completely defined. Check T cards on WSCC format.\n");
InputError=TRUE;
}
if (!strcmp(Eptr->Type,"R") || !strcmp(Eptr->Type,"RV")) strcpy(Eptr->Ctype,"V");
else if (strpbrk(Eptr->Type,"PM")) strcpy(Eptr->Ctype,"P");
else if (strpbrk(Eptr->Type,"QN")) strcpy(Eptr->Ctype,"Q");
if (strcmp(Eptr->Owner,"")){
if (!strcmp(Eptr->Owner,Eptr->From->Owner)) strcpy(Eptr->Zone,Eptr->From->Zone);
else strcpy(Eptr->Zone,Eptr->To->Zone);
}
if (Narea>1) {
Aptr=Eptr->From->Area;
Aptrp=Eptr->To->Area;
if(Aptr!=Aptrp && Aptr!=NULL && Aptrp!=NULL){
Aptr->Elem=(ElementList *) AddElemToList(Aptr->Elem,Eptr);
Aptrp->Elem=(ElementList *) AddElemToList(Aptrp->Elem,Eptr);
}
if (Eptr->Meter==NULL) {
if (strcmp(Eptr->Owner,"")){
if (strcmp(Eptr->Owner,Eptr->From->Owner)) Eptr->Meter=Eptr->From;
else Eptr->Meter=Eptr->To;
}
else if (Eptr->Area==Aptr) Eptr->Meter=Eptr->To;
else Eptr->Meter=Eptr->From;
}
}
Eptrp=Eptr->Next;
Eptr->Next=Eptr->Prev;
Eptr->Prev=Eptrp;
dataPtr->Element=Eptr;
Eptr=Eptrp;
}
/* ------------------- DC buses ------------------------ */
for(DCptr=dataPtr->DCbus;DCptr!=NULL;DCptr=DCptr->Next){
ACptr=DCptr->AC;
if (ACptr==NULL || !strcmp(DCptr->Type,"")){
fprintf(stderr,"ERROR: DC bus %8s has not been fully defined in the input data.\n",DCptr->Name);
fprintf(stderr," Check the BD, LD, and/or BZ cards.\n");
InputError=TRUE;
}
/* --------- Fix data read in WSCC/BPA Format --------- */
if (DCptr->Xc==0) {
for (ELptrp=ELptr=ACptr->Elem;ELptr!=NULL;ELptrp=ELptr,ELptr=ELptr->Next) {
Eptr=ELptr->Eptr;
if (!strcmp(Eptr->From->Name,DCptr->Name)) { ACptrp=Eptr->From; break;}
if (!strcmp(Eptr->To->Name,DCptr->Name)) { ACptrp=Eptr->To; break;}
}
DCptr->Name[8]='\0';
if (ELptr==NULL) {
fprintf(stderr,"ERROR: The tranformer for DC bus %8s has not been defined in the\n",DCptr->Name);
fprintf(stderr," input data. Check the T data cards.\n");
InputError=TRUE;
} else {
DCptr->Xc=-Eptr->B/(Eptr->G*Eptr->G+Eptr->B*Eptr->B);
DCptr->Xc=(DCptr->Xc*ACptr->KV*ACptr->KV/Sn)*DCptr->Nbr;
DCptr->Tap=Eptr->Tap;
if (strpbrk(Eptr->Type,"P,Q,M,N")) {
fprintf(stderr,"ERROR: DC bus %8s regulating transfomer may only control voltage.\n",DCptr->Name);
fprintf(stderr," Check the related R transfomer input cards.\n");
InputError=TRUE;
}
if (!strcmp(Eptr->Type,"R")) {
if (Eptr->Cont!=ACptrp) {
fprintf(stderr,"ERROR: DC bus %8s regulating transfomer must control voltage\n",DCptr->Name);
fprintf(stderr," of DC bus. Check the related R transfomer input cards.\n");
InputError=TRUE;
}
NregV--;
DCptr->TapMax=Eptr->Tmax;
DCptr->TapMin=Eptr->Tmin;
} else {
DCptr->TapMax=1.1;
DCptr->TapMin=0.9;
}
}
/* Remove extra element from AC data base */
if (ELptrp==ELptr) {
ACptr->Elem=ELptr->Next;
if (ACptr->Elem==NULL) {
fprintf(stderr,"ERROR: AC bus %d %s is isolated from the rest of the system.\n",ACptr->Num,ACptr->Name);
fprintf(stderr," Check the related AC element input cards.\n");
InputError=TRUE;
}
}
else ELptrp->Next=ELptr->Next;
#ifndef WINDOWS
free(ELptr);
#else
delete ELptr;
#endif
Aptr=ACptr->Area;
if (Aptr!=NULL) {
for (ELptrp=ELptr=Aptr->Elem;ELptr!=NULL;ELptrp=ELptr,ELptr=ELptr->Next) if (Eptr==ELptr->Eptr) break;
if (ELptr!=NULL) {
if (ELptrp==ELptr) Aptr->Elem=ELptr->Next;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -