⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readdata.cpp

📁 用于电力系统潮流计算 c++程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
          else ELptrp->Next=ELptr->Next;
#ifndef WINDOWS
          free(ELptr);
#else
          delete ELptr;
#endif
        }
      }
      NacEl--;
      if (Eptr->Prev==NULL) {
        Eptrp=Eptr->Next;
        dataPtr->Element=Eptrp;
        Eptrp->Prev=NULL;
      } else {
        Eptrp=Eptr->Prev;
        Eptrp->Next=Eptr->Next;
        if (Eptr->Next!=NULL) Eptr->Next->Prev=Eptrp;
      }
#ifndef WINDOWS
      free(Eptr);
#else
      delete Eptr;
#endif
      /* Remove DC bus from AC data base */
      Aptr=ACptr->Area;
      if (Aptr!=NULL) {
        for (ptrp=Aptr->AC;ptrp!=NULL;ptrp=ptrp->Next) if (ACptrp==ptrp->AC) break;
        if (ptrp!=NULL) {
          if (ptrp->Prev==NULL) {
            ptrs=ptrp->Next;
            Aptr->AC=ptrs;
            ptrs->Prev=NULL;
          } else {
            ptrs=ptrp->Prev;
            ptrs->Next=ptrp->Next;
            if (ptrp->Next!=NULL) ptrp->Next->Prev=ptrs;
          }
#ifndef WINDOWS
          free(ptrp);
#else
          delete ptrp;
#endif
        }
      }
      Nac--;
      for(ACptrs=ACptrp->Next;ACptrs!=NULL;ACptrs->N--,ACptrs=ACptrs->Next);
      if (ACptrp->Prev==NULL) {
        ACptrs=ACptrp->Next;
        dataPtr->ACbus=ACptrs;
        ACptrs->Prev=NULL;
      } else {
        ACptrs=ACptrp->Prev;
        ACptrs->Next=ACptrp->Next;
        if (ACptrp->Next!=NULL) ACptrp->Next->Prev=ACptrs;
      }
#ifndef WINDOWS
      free(ACptrp);
#else
      delete ACptrp;
#endif
    }


    if (DCptr->MVA>0) {
      KVs=ACptr->KV*DCptr->Ntrf/DCptr->Nbr;
      DCptr->Xc=DCptr->Xc/DCptr->Nbr;
      DCptr->Xc=(DCptr->Xc*KVs*KVs/DCptr->MVA)*DCptr->Nbr;
    }
    if (DCptr->Xc<=0.1){
      fprintf(stderr,"ERROR: DC bus %8s has a negative or zero commutation reactance ->\n",DCptr->Name);
      fprintf(stderr,"       Xc=%6.3lf (Ohms)\n",DCptr->Xc);
      fprintf(stderr,"       Check the BD and/or BZ cards.\n");
      InputError=TRUE;
    }
    if (DCptr->To==NULL){
      fprintf(stderr,"ERROR: DC bus %8s is isolated.\n",DCptr->Name);
      fprintf(stderr,"       Check the DC line input cards.\n");
      InputError=TRUE;
    }
    DCptr->Area=ACptr->Area;
    if(!strcmp(DCptr->Cont1,"AL")||!strcmp(DCptr->Cont2,"AL")) {
      if (DCptr->Alfa>DCptr->AlfaMax || DCptr->Alfa<DCptr->AlfaMin) {
         fprintf(stderr,"ERROR: DC bus %8s has ALPHA outside its limits.\n",DCptr->Name);
         fprintf(stderr,"       Check the BD (limits) and/or BZ card.\n");
         InputError=TRUE;
      }
      DCptr->Gamma=180-DCptr->Alfa;
    }
    else if(!strcmp(DCptr->Cont1,"GA")||!strcmp(DCptr->Cont2,"GA")) {
      if (DCptr->Gamma<DCptr->GammaMin) {
         fprintf(stderr,"ERROR: DC bus %8s has GAMMA outside its limits.\n",DCptr->Name);
         fprintf(stderr,"       Check the BD (limits) and/or BZ card.\n");
         InputError=TRUE;
      }
      DCptr->Alfa=180-DCptr->Gamma;
    }
    else if(!strcmp(DCptr->Type,"R")) {
      DCptr->Alfa=DCptr->AlfaMin;
      DCptr->Gamma=180-DCptr->Alfa;
    }
    else {
      DCptr->Gamma=DCptr->GammaMin;
      DCptr->Alfa=180-DCptr->Gamma;
    }
    if (DCptr->Alfa>DCptr->AlfaMax || DCptr->Alfa<DCptr->AlfaMin || DCptr->Gamma<DCptr->GammaMin)
         fprintf(stderr,"***Warning: DC bus %8s could have wrong ALPHA or GAMMA limits.\n",DCptr->Name);
    if (DCptr->Tap<=0) DCptr->Tap=1;
    if (DCptr->Tap<DCptr->TapMin) DCptr->Tap=DCptr->TapMin;
    if (DCptr->Tap>DCptr->TapMax) DCptr->Tap=DCptr->TapMax;
  }

 /* ------------------- DC elements ------------------------ */
  if (Ndc!=(2*NdcEl)) {
    fprintf(stderr,"ERROR: There are inconsistencies between the DC bus and DC line input data.\n");
    fprintf(stderr,"       Check DC input data and remember that the program just allows for \n");
    fprintf(stderr,"       two-terminal HVDC links.\n");
    InputError=TRUE;
  }
  for(DCptr=dataPtr->DCbus;DCptr!=NULL;DCptr=DCptr->Next){
    DCptrp=DCptr->To;
    if (DCptr->N!=0 && DCptrp->N!=0){
      if ((strcmp(DCptr->Type,"R") || strcmp(DCptrp->Type,"I")) &&
         (strcmp(DCptr->Type,"I") || strcmp(DCptrp->Type,"R"))){
         fprintf(stderr,"ERROR: Both converters for the DC link between %8s and %8s\n",
                  DCptr->Name,DCptrp->Name);
         fprintf(stderr,"       are either rectifiers or inverters.\n");
         InputError=TRUE;
      }
      if ((!strcmp(DCptr->Cont1,"ID") || !strcmp(DCptr->Cont2,"ID")) &&
           (!strcmp(DCptrp->Cont1,"ID") || !strcmp(DCptrp->Cont2,"ID"))){
         fprintf(stderr,"ERROR: Both converters for the DC link between %8s and %8s\n",
                  DCptr->Name,DCptrp->Name);
         fprintf(stderr,"       are controlling the current.\n");
         InputError=TRUE;
      }
      if (DCptr->Area==DCptrp->Area||!strcmp(DCptr->Zone,DCptrp->Zone))   DCptr->Meter=DCptrp->Meter=NULL;
      if (DCptr->Area!=DCptrp->Area) for(i=1;i<=2;i++) {
         if (i==1) Aptr=DCptr->Area;
         else Aptr=DCptrp->Area;
         if (Aptr!=NULL) {
           ptr=Aptr->DC;
#ifdef WINDOWS
           Aptr->DC= new DClist;
#else
           Aptr->DC=(DClist *) malloc(sizeof(DClist));
           if (Aptr->DC==NULL) {ErrorHalt("Insufficient memory to allocate area data."); exit(ERROREXIT);}
#endif
           if (i==1) Aptr->DC->DC=DCptr;
           else Aptr->DC->DC=DCptrp;
           Aptr->DC->Next=ptr;
         }
      }
      if (DCptr->Id>0) DCptrp->Id=DCptr->Id;
      else if (DCptrp->Id>0) DCptr->Id=DCptrp->Id;
      DCptr->N=0;
      DCptrp->N=0;
    }
  }

 /* -------------------------- Areas --------------------------- */
  for (Aptr=dataPtr->Area; Aptr!=NULL; Aptr=Aptr->Next) {
    flag=TRUE;
    i=0; j=0;
    for(ELptr=Aptr->Elem;ELptr!=NULL;ELptr=ELptr->Next){
      Eptr=ELptr->Eptr; flag=FALSE; i++;
      if(!strcmp(Eptr->Type,"RP")) j++;
      if (Eptr->From->Area!=Aptr) Aptrp=Eptr->From->Area;
      else Aptrp=Eptr->To->Area;
      if (!Acont && strpbrk(Aptr->Slack->Type,"S") && !strpbrk(Aptrp->Slack->Type,"S")) ExpandSlack(Aptr->Slack,Aptrp);
    }
    if (!flag && i==j) {
      fprintf(stderr,"ERROR: All tie lines for area %d %s are P reg. transf.\n",Aptr->N,Aptr->Name);
      fprintf(stderr,"       Change at least one reg. transf. to a standard one.\n");
      InputError=TRUE;
    }
    if (flag && !strpbrk(Aptr->Slack->Type,"S")) {
      strcat(Aptr->Slack->Type,"S");
      Nslack++;
    }
    ptrp=Aptr->AC;
    while(ptrp!=NULL){
      ptrs=ptrp->Next;
      ptrp->Next=ptrp->Prev;
      ptrp->Prev=ptrs;
      if (ptrs==NULL) Aptr->AC=ptrp;
      ptrp=ptrs;
    }
  }

 /* -------------------------- FACTS --------------------------- */
  for(SVCptr=dataPtr->SVCbus;SVCptr!=NULL;SVCptr=SVCptr->Next){
    ACptr=SVCptr->Ctrl;
    if (ACptr->Cont==NULL) {
      fprintf(stderr,"ERROR: The SVC controlled bus %d %s is already controlled.\n",ACptr->N,ACptr->Name);
      fprintf(stderr,"       Check the AC bus cards.\n");
      InputError=TRUE;
    }
    ACptr=SVCptr->From;
    if (ACptr->Cont==NULL) {
      fprintf(stderr,"ERROR: The SVC bus %d %s is a voltage controlled bus.\n",ACptr->N,ACptr->Name);
      fprintf(stderr,"       Check the AC bus cards.\n");
      InputError=TRUE;
    }
    for (ELptr=ACptr->Elem,i=0;ELptr!=NULL;ELptr=ELptr->Next,i++);
    if (i>1) {
      fprintf(stderr,"ERROR: The SVC bus %d %s has more than one AC element connected to it.\n",ACptr->N,ACptr->Name);
      fprintf(stderr,"       Check the AC element cards.\n");
      InputError=TRUE;
    }
  }
  for(STATCOMptr=dataPtr->STATCOMbus;STATCOMptr!=NULL;STATCOMptr=STATCOMptr->Next){
    ACptr=STATCOMptr->Ctrl;
    if (ACptr->Cont==NULL) {
      fprintf(stderr,"ERROR: The STATCOM controlled bus %d %s is already controlled.\n",ACptr->N,ACptr->Name);
      fprintf(stderr,"       Check the AC bus cards.\n");
      InputError=TRUE;
    }
    ACptr=STATCOMptr->From;
    if (ACptr->Cont==NULL) {
      fprintf(stderr,"ERROR: The STATCOM bus %d %s is a voltage controlled bus.\n",ACptr->N,ACptr->Name);
      fprintf(stderr,"       Check the AC bus cards.\n");
      InputError=TRUE;
    }
  }
}

/* --------- ExpandSlack --------- */
#ifdef ANSIPROTO
void ExpandSlack(ACbusData *BSptr,AreaData *Aptr)
#else
void ExpandSlack(BSptr,Aptr)
ACbusData *BSptr;
AreaData *Aptr;
#endif
{
  AreaData *Aptrp;
  ElementList *ELptr;
  ElementData *Eptr;

  Aptr->Slack=BSptr;
  for(ELptr=Aptr->Elem;ELptr!=NULL;ELptr=ELptr->Next) {
    Eptr=ELptr->Eptr;
    if (Eptr->From->Area!=Aptr) Aptrp=Eptr->From->Area;
    else Aptrp=Eptr->To->Area;
    if (!strpbrk(Aptrp->Slack->Type,"S")) ExpandSlack(Aptr->Slack,Aptrp);
  }
}

/* --------- WriteSummary --------- */
#ifdef ANSIPROTO
void WriteSummary(void)
#else
void WriteSummary()
#endif
{
  ACbusData *ACptr;
  int i;

  fprintf(stderr,"Summary of input data for case:\n");
  i=0;
  while(i<=2 && dataPtr->Title[0][0]!='\0'){
    fprintf(stderr,"%s",dataPtr->Title[i]);
    i++;
  }
  fprintf(stderr,"            AC buses -> %d\n",Nac);
  fprintf(stderr,"            PV buses -> %d\n",Nvolt);
  fprintf(stderr,"            X buses  -> %d\n",NXvolt);
  fprintf(stderr,"            Z buses  -> %d\n",NZvolt);
  fprintf(stderr,"            AC elem. -> %d\n",NacEl);
  fprintf(stderr,"         V Reg. Trf. -> %d\n",NregV);
  fprintf(stderr,"        PQ Reg. Trf. -> %d\n",NregPQ);
  fprintf(stderr,"            DC buses -> %d\n",Ndc);
  fprintf(stderr,"            DC lines -> %d\n",NdcEl);
  fprintf(stderr,"                SVCs -> %d\n",Nsvc);     /* FACTS */
  fprintf(stderr,"               TCSCs -> %d\n",Ntcsc);    /* FACTS */
  fprintf(stderr,"            STATCOMs -> %d\n",Nstatcom); /* FACTS */
  fprintf(stderr,"           No. Areas -> %d\n",Narea);
  fprintf(stderr,"   Reference Bus(es) -> ");
  i=0;
  for (ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next)
    if(strpbrk(ACptr->Type,"S")){
      if (i>0)   fprintf(stderr,"                        ");
      fprintf(stderr,"%d %s (Angle=%6.2lf deg.)\n",ACptr->Num,ACptr->Name,ACptr->Ang*180/PI);
      i++;
    }
  if (i==0) fprintf(stderr,"\n");
  return;
}



/* ------------------------- ReadData ------------------------------- */
#ifdef ANSIPROTO
void ReadData(char *Name)
#else
void ReadData(Name)
char *Name;
#endif
 /* Main routine. */
{
  InputDataFile=(FILE *) OpenInput(Name);
#ifdef WINDOWS
  dataPtr= new Data;
#else
  dataPtr=(Data *) malloc(sizeof(Data));
  if (dataPtr==NULL) {
    fclose(InputDataFile);
    ErrorHalt("Insufficient memory to read input data.");
    exit(ERROREXIT);
  }
#endif
  dataPtr->Title[0][0]='\0';
  dataPtr->ACbus=NULL;
  dataPtr->DCbus=NULL;
  dataPtr->Element=NULL;
  dataPtr->Area=NULL;
  dataPtr->KGbus=NULL;
  dataPtr->SVCbus=NULL;     /* FACTS */
  dataPtr->TCSCbus=NULL;    /* FACTS */
  dataPtr->STATCOMbus=NULL; /* FACTS */
  Nac=0; Ndc=0; NacEl=0; NdcEl=0;
  Nsvc=Nstatcom=0; Ntcsc=NtcscVar=0;  /* FACTS */
  LineNum=0;  Nvolt=0; Nslack=0;
  Narea=0; NregPQ=NregV=0;
  NZvolt=NXvolt=0;
  InputError=FALSE;
  flag2Vcontrol=ExistParameter('#');
  if(ExistParameter('I')) ReadIEEE();
  else if(ExistParameter('6')) ReadITALY();
  else ReadWSCC();
  ErrorDetect();
  WriteSummary();
  if (InputError==TRUE) {
      fprintf(stderr,"*** The data has errors! Please review the input file. ***\n");
      exit(ERROREXIT);
  }
  else fprintf(stderr,"*** The data has been read successfully ***\n");
#ifdef WINDOWS
  delete[] Name;
#else
  free(Name);
#endif

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -