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

📄 limits.c

📁 电力系统分析计算 学习调试程序 UNIX / LINUX / CYGWIN 系统使用
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Check AC/DC limits. */#include <stdlib.h>//#ifndef WINDOWS//#include <stdio.h>//#else#include "pfwstdio.h"//#endif#include <math.h>#include <string.h>#include "constant.h"#include "param.h"#include "sparse.h"#include "pflow.h"#ifdef ANSIPROTOBOOLEAN CheckRlimits(void);BOOLEAN CheckVlimits(void);BOOLEAN CheckQlimits(void);BOOLEAN CheckDClimits(void);void WriteSolution(INDEX Iter,char *File1,char *str);#elseBOOLEAN CheckRlimits();BOOLEAN CheckVlimits();BOOLEAN CheckQlimits();BOOLEAN CheckDClimits();void WriteSolution();#endif/* ------- Global Variables ------ */extern Data *dataPtr;extern SparseMatrix *Jac;extern INDEX MaxIter,Nac,NacEl,NregPQ,NregV,Ndc,Nslack,Nvolt,Narea,NacVar,Bl,NZvolt,NXvolt;extern INDEX *ACvar;extern VALUETYPE *dx,*dF,tol,Tol,Sn,lambda,*x0;extern VALUETYPE K1,K2,MaxdFi,alpha;extern IntegerVector *NewRow,*OldRow,*NewCol,*OldCol,*RowPartition,*ColPartition;extern IntegerVector *RowPer,*ColPer;extern BOOLEAN Acont,PQcont,QRcont,Rcont,               PQlim,Tlim,Qlim,Ilim,Elim,Vlim,Zlim,Xlim,               flagH,flagPoC,flagL,flagR,flagBS,flagPgMax,flagSmax;/* -------------------- CheckRlimits ----------------------- */#ifdef ANSIPROTOBOOLEAN CheckRlimits(void)#elseBOOLEAN CheckRlimits()#endif{  BOOLEAN flag=FALSE;  char str[4];  ACbusData *ACptr;  ElementList *ELptr,*Rptr;  ElementData *Eptr;  INDEX i,j;  for(ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next){    for (ELptr=ACptr->Reg;ELptr!=NULL;ELptr=ELptr->Next){      Eptr=ELptr->Eptr;      if(Tlim&&!strcmp(Eptr->Type,"R")&&(Eptr->Tap<=1/Eptr->Tmax+0.00001||                                         Eptr->Tap>=1/Eptr->Tmin-0.00001)){        flag=TRUE; i=j=0; NregV--;        if(Eptr->Tap<=1/Eptr->Tmax+0.00001) {Eptr->Tap=1/Eptr->Tmax; strcpy(str,"max");}        else {Eptr->Tap=1/Eptr->Tmin; strcpy(str,"min");}        for(Rptr=ACptr->Reg;Rptr!=NULL;Rptr=Rptr->Next){          if(!strcmp(Rptr->Eptr->Type,"R")) i++;          else if(!strcmp(Rptr->Eptr->Type,"RV")) j++;        }        if (i==1 && j==0) {          strcpy(ACptr->Type,"B");          if(ACptr->Area!=NULL && ACptr->Area->Slack==ACptr) strcat(ACptr->Type,"A");          ACptr->Cont=ACptr;          if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->V;        }        else if(i==1 && j!=0) {          strcpy(ACptr->Type,"BR");          if(ACptr->Area!=NULL && ACptr->Area->Slack==ACptr) strcat(ACptr->Type,"A");          ACptr->Cont=ACptr;          if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->V;        }        strcpy(Eptr->Type,"TR");        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",                Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to a fixed tap transf. at t%3s.\n",str);      }      else if(Rcont&&!strcmp(Eptr->Type,"RV")&&(ACptr->V>=Eptr->Max||ACptr->V<=Eptr->Min)){        flag=TRUE;        strcpy(Eptr->Type,"R");        if(ACptr->V>=Eptr->Max) {ACptr->V=Eptr->Max; strcpy(str,"max");}        else {ACptr->V=Eptr->Min;  strcpy(str,"min");}        if(!strpbrk(ACptr->Type,"T")){          strcpy(ACptr->Type,"BT");          if(ACptr->Area!=NULL && ACptr->Area->Slack==ACptr) strcat(ACptr->Type,"A");          ACptr->Cont=NULL;          if (flagH) x0[ACvar[ACptr->N]+1]=Eptr->Tap;        }        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",				Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to an LTC at V%3s for bus %d %s.\n",                str,ACptr->Num,ACptr->Name);      }      else if(Tlim&&!strcmp(Eptr->Type,"RP")&&(Eptr->Ang>=Eptr->Tmax || Eptr->Ang<=Eptr->Tmin)){        flag=TRUE; NregPQ--;        strcpy(Eptr->Type,"TP");        if(Eptr->Ang>=Eptr->Tmax) {Eptr->Ang=Eptr->Tmax; strcpy(str,"max");}        else {Eptr->Ang=Eptr->Tmin; strcpy(str,"min");}        i=ACvar[ACptr->N]+1+ACptr->Ncont-Eptr->Ncont;        if (Acont && strpbrk(ACptr->Type,"A")) i++;        if (flagH) x0[i]=Eptr->Cvar;        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",                Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to a fixed angle transf. at a%3s.\n",str);      }      else if(Tlim&&!strcmp(Eptr->Type,"RQ")&&(Eptr->Tap<=1/Eptr->Tmax+0.00001||                                                 Eptr->Tap>=1/Eptr->Tmin-0.00001)){        flag=TRUE; NregPQ--;        strcpy(Eptr->Type,"TQ");        if(Eptr->Tap<=1/Eptr->Tmax+0.00001) {Eptr->Tap=1/Eptr->Tmax; strcpy(str,"max");}        else {Eptr->Tap=1/Eptr->Tmin; strcpy(str,"min");}        i=ACvar[ACptr->N]+1+ACptr->Ncont-Eptr->Ncont;        if (Acont && strpbrk(ACptr->Type,"A")) i++;        if (flagH) x0[i]=Eptr->Cvar;        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",                Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to a fixed tap at t%3s.\n",str);      }      else if(PQcont&&PQlim&&strpbrk(Eptr->Type,"M")&&(Eptr->Cvar>=Eptr->Max||Eptr->Cvar<=Eptr->Min)){        flag=TRUE;        strcpy(Eptr->Type,"RP");        if(Eptr->Cvar>=Eptr->Max) {Eptr->Cvar=Eptr->Max; strcpy(str,"max");}        else {Eptr->Cvar=Eptr->Min; strcpy(str,"min");}        i=ACvar[ACptr->N]+1+ACptr->Ncont-Eptr->Ncont;        if (Acont && strpbrk(ACptr->Type,"A")) i++;        if (flagH) x0[i]=Eptr->Ang;        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",                Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to control %1s at P%3s.\n",Eptr->Ctype,str);      }      else if(PQcont&&PQlim&&strpbrk(Eptr->Type,"N")&&(Eptr->Cvar>=Eptr->Max||Eptr->Cvar<=Eptr->Min)){        flag=TRUE;        strcpy(Eptr->Type,"RQ");        if(Eptr->Cvar>=Eptr->Max) {Eptr->Cvar=Eptr->Max; strcpy(str,"max");}        else {Eptr->Cvar=Eptr->Min; strcpy(str,"min");}        i=ACvar[ACptr->N]+1+ACptr->Ncont-Eptr->Ncont;        if (Acont && strpbrk(ACptr->Type,"A")) i++;        if (flagH) x0[i]=Eptr->Tap;        fCustomPrint(stderr,"***Warning: %1s Reg. transf. from %d %s to %d %s\n",                Eptr->Ctype,Eptr->From->Num,Eptr->From->Name,Eptr->To->Num,Eptr->To->Name);        fCustomPrint(stderr,"            has been changed to control %1s at Q%3s.\n",Eptr->Ctype,str);      }    }  }  return(flag);}/* -------------------- CheckVlimits ----------------------- */#ifdef ANSIPROTOBOOLEAN CheckVlimits(void)#elseBOOLEAN CheckVlimits()#endif{  ACbusData *ACptr,*BEptr;  char str[4];  BOOLEAN flag=FALSE,Recover=TRUE;  INDEX i;  if (Narea<2){    for(BEptr=dataPtr->ACbus;BEptr!=NULL;BEptr=BEptr->Next)      if(strpbrk(BEptr->Type,"S")) break;  }  if(ExistParameter('G')) Recover=FALSE;  if (Vlim || Elim || Ilim || Xlim) for(ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next){    if (strpbrk(ACptr->Type,"V")) {      if (Vlim && strpbrk(ACptr->cont,"Q") && (ACptr->V>=ACptr->Vmax || ACptr->V<=ACptr->Vmin)) {        flag=TRUE; Nvolt++;        if(ACptr->V>=ACptr->Vmax) {ACptr->V=ACptr->Vmax; strcpy(str,"max");}        else                      {ACptr->V=ACptr->Vmin; strcpy(str,"min");}        strcpy(ACptr->cont,"V");        ACptr->VCont=ACptr->Qg;        ACptr->Cont=NULL;        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->Qg;        fCustomPrint(stderr,"***Warning: Generator %d %s will start controlling the voltage\n",ACptr->Num,ACptr->Name);        fCustomPrint(stderr,"            due to V_%3s problems.\n",str);      }      else if (Vlim && Recover && strpbrk(ACptr->cont,"V") &&               ((ACptr->V==ACptr->Vmax && ACptr->Qg>=ACptr->VCont)||                (ACptr->V==ACptr->Vmin && ACptr->Qg<=ACptr->VCont)) ){        flag=TRUE; Nvolt--;        strcpy(ACptr->cont,"Q");        ACptr->Qg=ACptr->VCont;        ACptr->Cont=ACptr;        if (flagH) x0[ACvar[ACptr->N]+1]=ACptr->V;        fCustomPrint(stderr,"***Warning: Generator %d %s voltage is back\n",ACptr->Num,ACptr->Name);        fCustomPrint(stderr,"            within limits.\n",str);      }      else if (ACptr->Gen!=NULL) {        if (Ilim && strpbrk(ACptr->cont,"Q") && ACptr->Gen->Ia>=ACptr->Gen->IaMax) {          flag=TRUE;  Nvolt++;          ACptr->Gen->Ia=ACptr->Gen->IaMax;          strcpy(ACptr->cont,"I");          ACptr->VCont=ACptr->Qg;          ACptr->Cont=ACptr;          if (flagH) x0[ACptr->Gen->Nvar+11]=ACptr->Qg;          fCustomPrint(stderr,"***Warning: Generator %d %s has lost Q control\n",ACptr->Num,ACptr->Name);          fCustomPrint(stderr,"            due to Ia_max limit problems.\n");        }        else if (Ilim && Recover && strpbrk(ACptr->cont,"I") &&                 ACptr->Gen->Ia==ACptr->Gen->IaMax && ACptr->Qg>=ACptr->VCont) {          flag=TRUE; Nvolt--;          strcpy(ACptr->cont,"Q");          ACptr->Cont=ACptr;          if (flagH) x0[ACptr->Gen->Nvar+11]=ACptr->Gen->Ia;          fCustomPrint(stderr,"***Warning: Generator %d %s has recovered\n",ACptr->Num,ACptr->Name);          fCustomPrint(stderr,"            Q control as Ia is again within limits.\n");        }        else if (Elim && strpbrk(ACptr->cont,"Q") &&                 (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");

⌨️ 快捷键说明

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