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

📄 limits.cpp

📁 用于电力系统潮流计算 c++程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        else if (Elim && Recover && strpbrk(ACptr->cont,"E") &&   ACptr->Cont->Kbg<1  &&
                 ((ACptr->Gen->Eq==ACptr->Gen->EqMax && ACptr->Cont->V>=ACptr->Cont->VCont) ||
                  (ACptr->Gen->Eq==ACptr->Gen->EqMin && ACptr->Cont->V<=ACptr->Cont->VCont)) ){
          flag=TRUE;  Nvolt++;
          strcpy(ACptr->cont,"V");
          if (flagH) x0[ACptr->Gen->Nvar+1]=ACptr->Gen->Eq;
          fprintf(stderr,"***Warning: Generator %d %s has recovered\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"            remote V control as Eq is again within limits.\n");
          ACptr->Cont->Kbg++;
          if (ACptr->Cont->Kbg==1) {
            ACptr->Cont->Cont=NULL;
            ACptr->Cont->V=ACptr->Cont->VCont;
            if (flagH) x0[ACvar[ACptr->Cont->N]+1]=ACptr->Qg/ACptr->Kbg;
            fprintf(stderr,"***Warning: Remote voltage controlled bus %d %s\n",ACptr->Cont->Num,ACptr->Cont->Name);
            fprintf(stderr,"            has recovered generator support.\n");
          }
        }
        else if (strpbrk(ACptr->cont,"Q") &&
                 ((Ilim && ACptr->Gen->Ia>=ACptr->Gen->IaMax) ||
                  (Elim && (ACptr->Gen->Eq>=ACptr->Gen->EqMax || ACptr->Gen->Eq<=ACptr->Gen->EqMin)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at a Q limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Ia and/or Eq limits.\n");
          WriteSolution(0,TrueParamStr(2),"Ia/Eq Limit Problems:");
          exit(1);
        }
        else if (strpbrk(ACptr->cont,"I") &&
                 ((Qlim && (ACptr->Qg>=ACptr->Max || ACptr->Qg<=ACptr->Min)) ||
                  (Elim && (ACptr->Gen->Eq>=ACptr->Gen->EqMax || ACptr->Gen->Eq<=ACptr->Gen->EqMin)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at an Ia limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Q and/or Eq limits.\n");
          WriteSolution(0,TrueParamStr(2),"Q/Eq Limit Problems:");
          exit(1);
        }
        else if (strpbrk(ACptr->cont,"E") &&
                 ((Ilim && ACptr->Gen->Ia>=ACptr->Gen->IaMax) ||
                  (Qlim && (ACptr->Qg>=ACptr->Max || ACptr->Qg<=ACptr->Min)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at an Eq limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Q and/or Ia limits.\n");
          WriteSolution(0,TrueParamStr(2),"Q/Ia Limit Problems:");
          exit(1);
        }
      }
    }
    else if (strpbrk(ACptr->Type,"Q,S") || (!QRcont && strpbrk(ACptr->Type,"G")) ) {
      if (Qlim && strpbrk(ACptr->cont,"V") && (ACptr->Qg>=ACptr->Max || ACptr->Qg<=ACptr->Min)) {
        flag=TRUE; Nvolt--;
        if(ACptr->Qg>=ACptr->Max) {
          ACptr->Qg=ACptr->Max;
          strcpy(str,Qmax);
        }
        else {
          ACptr->Qg=ACptr->Min;
          strcpy(str,Qmin);
        }
        strcpy(ACptr->cont,"Q");
        ACptr->VCont=ACptr->V;
        if (strpbrk(ACptr->Type,"G")) ACptr->Cont=ACptr->ContBus->AC;
        else                          ACptr->Cont=ACptr;
        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->V;
        fprintf(stderr,"***Warning: Generator %d %s has lost voltage control\n",ACptr->Num,ACptr->Name);
        fprintf(stderr,"            due to %4s problems.\n",str);
      }
      else if (Qlim && Recover && strpbrk(ACptr->cont,"Q") &&
               ((ACptr->Qg>=ACptr->Max && ACptr->V>=ACptr->VCont) ||
                (ACptr->Qg<=ACptr->Min && ACptr->V<=ACptr->VCont)) ){
        flag=TRUE; Nvolt++;
        ACptr->V=ACptr->VCont;
        strcpy(ACptr->cont,"V");
        ACptr->Cont=NULL;
        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->Qg;
        fprintf(stderr,"***Warning: Generator %d %s has recovered\n",ACptr->Num,ACptr->Name);
        fprintf(stderr,"            voltage control as Qg/Sg is again within limits.\n");
      }
      else if (ACptr->Gen!=NULL) {
        if (Ilim && strpbrk(ACptr->cont,"V") && ACptr->Gen->Ia>=ACptr->Gen->IaMax) {
          flag=TRUE;  Nvolt--;
          ACptr->Gen->Ia=ACptr->Gen->IaMax;
          strcpy(ACptr->cont,"I");
          ACptr->VCont=ACptr->V;
          if (strpbrk(ACptr->Type,"G")) ACptr->Cont=ACptr->ContBus->AC;
          else                          ACptr->Cont=ACptr;
          if (flagH) {
            x0[ACvar[ACptr->N]+1]=ACptr->V;
            x0[ACptr->Gen->Nvar+11]=ACptr->Qg;
          }
          fprintf(stderr,"***Warning: Generator %d %s has lost V control\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"            due to Ia_max limit problems.\n");
        }
        else if (Ilim && Recover && strpbrk(ACptr->cont,"I") &&
                 ACptr->Gen->Ia==ACptr->Gen->IaMax && ACptr->V>=ACptr->VCont) {
          flag=TRUE;  Nvolt++;
          strcpy(ACptr->cont,"V");
          ACptr->V=ACptr->VCont;
          ACptr->Cont=NULL;
          if (flagH) {
            x0[ACvar[ACptr->N]+1]=ACptr->Qg;
            x0[ACptr->Gen->Nvar+11]=ACptr->Gen->Ia;
          }
          fprintf(stderr,"***Warning: Generator %d %s has recovered\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"            V control as Ia is again within limits.\n");
        }
        else if (Elim && strpbrk(ACptr->cont,"V") &&
                 (ACptr->Gen->Eq>=ACptr->Gen->EqMax || ACptr->Gen->Eq<=ACptr->Gen->EqMin)) {
          flag=TRUE; Nvolt--;
          if (ACptr->Gen->Eq>=ACptr->Gen->EqMax) {
            ACptr->Gen->Eq=ACptr->Gen->EqMax;
            strcpy(str,"max");
          } else {
            ACptr->Gen->Eq=ACptr->Gen->EqMin;
            strcpy(str,"min");
          }
          strcpy(ACptr->cont,"E");
          ACptr->VCont=ACptr->V;
          if (strpbrk(ACptr->Type,"G")) ACptr->Cont=ACptr->ContBus->AC;
          else                          ACptr->Cont=ACptr;
          if (flagH) {
            x0[ACvar[ACptr->N]+1]=ACptr->V;
            x0[ACptr->Gen->Nvar+1]=ACptr->Qg;
          }
          fprintf(stderr,"***Warning: Generator %d %s has lost V control\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"            due to Eq_%3s limit problems.\n",str);
        }
        else if (Elim && Recover && strpbrk(ACptr->cont,"E") &&
                 ((ACptr->Gen->Eq==ACptr->Gen->EqMax && ACptr->V>=ACptr->VCont) ||
                  (ACptr->Gen->Eq==ACptr->Gen->EqMin && ACptr->V<=ACptr->VCont)) ){
          flag=TRUE;  Nvolt++;
          strcpy(ACptr->cont,"V");
          ACptr->V=ACptr->VCont;
          ACptr->Cont=NULL;
          if (flagH) {
            x0[ACvar[ACptr->N]+1]=ACptr->Qg;
            x0[ACptr->Gen->Nvar+1]=ACptr->Gen->Eq;
          }
          fprintf(stderr,"***Warning: Generator %d %s has recovered\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"            V control as Eq is again within limits.\n");
        }
        else if (strpbrk(ACptr->cont,"Q") &&
                 ((Ilim && ACptr->Gen->Ia>=ACptr->Gen->IaMax) ||
                  (Elim && (ACptr->Gen->Eq>=ACptr->Gen->EqMax || ACptr->Gen->Eq<=ACptr->Gen->EqMin)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at a Q limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Ia and/or Eq limits.\n");
          WriteSolution(0,TrueParamStr(2),"Ia/Eq Limit Problems:");
          exit(1);
        }
        else if (strpbrk(ACptr->cont,"I") &&
                 ((Qlim && (ACptr->Qg>=ACptr->Max || ACptr->Qg<=ACptr->Min)) ||
                  (Elim && (ACptr->Gen->Eq>=ACptr->Gen->EqMax || ACptr->Gen->Eq<=ACptr->Gen->EqMin)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at an Ia limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Q and/or Eq limits.\n");
          WriteSolution(0,TrueParamStr(2),"Q/Eq Limit Problems:");
          exit(1);
        }
        else if (strpbrk(ACptr->cont,"E") &&
                 ((Ilim && ACptr->Gen->Ia>=ACptr->Gen->IaMax) ||
                  (Qlim && (ACptr->Qg>=ACptr->Max || ACptr->Qg<=ACptr->Min)))) {
          fprintf(stderr,"***Error: Generator %d %s it's already at an Eq limit.\n",ACptr->Num,ACptr->Name);
          fprintf(stderr,"          Try changing Q and/or Ia limits.\n");
          WriteSolution(0,TrueParamStr(2),"Q/Ia Limit Problems:");
          exit(1);
        }
      }
    }
    else if (strpbrk(ACptr->Type,"Z")) {
      if (Zlim && strpbrk(ACptr->cont,"V") && (ACptr->Qg>=ACptr->Qmax || ACptr->Qg<=ACptr->Qmin)) {
        flag=TRUE; NZvolt--;
        if(ACptr->Qg>=ACptr->Qmax) {
          ACptr->Qg=ACptr->Qmax;
          strcpy(str,Qmax);
        }
        else {
          ACptr->Qg=ACptr->Qmin;
          strcpy(str,Qmin);
        }
        ACptr->Bz=ACptr->Qg/(ACptr->V*ACptr->V);
        strcpy(ACptr->cont,"Q");
        ACptr->VCont=ACptr->V;
        ACptr->Cont=ACptr;
        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->V;
        fprintf(stderr,"***Warning: Reactance-controlled bus %d %s has lost\n",ACptr->Num,ACptr->Name);
        fprintf(stderr,"            voltage control due to %4s problems.\n",str);
      }
      else if (Zlim && strpbrk(ACptr->cont,"Q") &&
               ((ACptr->Qg>=ACptr->Qmax && ACptr->V>=ACptr->VCont) ||
                (ACptr->Qg<=ACptr->Qmin && ACptr->V<=ACptr->VCont)) ){
        flag=TRUE; NZvolt++;
        ACptr->V=ACptr->VCont;
        strcpy(ACptr->cont,"V");
        ACptr->Cont=NULL;
        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->Qg;
        fprintf(stderr,"***Warning: Reactance-controlled bus %d %s has recovered\n",ACptr->Num,ACptr->Name);
        fprintf(stderr,"            voltage control as Q is again within limits.\n");
      }
    }
  }
  
  if ((Qlim || Elim || Ilim || Zlim) && RemoteVlost && QRcont)
    for(ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next) {
      if (strpbrk(ACptr->Type,"C") && ACptr->Kg<0) ACptr->Kbg=0;
    }

  return(flag);
}

/* -------------------- CheckDClimits ----------------------- */
#ifdef ANSIPROTO
BOOLEAN CheckDClimits(void)
#else
BOOLEAN CheckDClimits()
#endif
{
  DCbusData *DCptrR,*DCptrI;
  BOOLEAN flag=FALSE;

  for (DCptrR=dataPtr->DCbus;DCptrR!=NULL;DCptrR=DCptrR->Next) if(!strcmp(DCptrR->Type,"R")) {
    DCptrI=DCptrR->To;
    if ((strcmp(DCptrR->Cont1,"AT") && strcmp(DCptrR->Cont2,"AT") &&
         (DCptrR->Tap>=DCptrR->TapMax || DCptrR->Tap<=DCptrR->TapMin)) ||
        (strcmp(DCptrI->Cont1,"AT") && strcmp(DCptrI->Cont2,"AT") &&
         (DCptrI->Tap>=DCptrI->TapMax || DCptrI->Tap<=DCptrI->TapMin))){
      flag=TRUE;
      fprintf(stderr,"***Warning: The program will release tap limits in the HVDC links.\n");
      break;
    }
  }
  return(flag);
}

⌨️ 快捷键说明

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