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

📄 writejac.cpp

📁 用于潮流计算的程序请让我下载我需要的吧感谢了啊
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* Write Jacobian. */

#include "write.h"


/* ---------- Global Variables --------- */
INDEX TFnum,TFbus;
char TFname[13];
extern VALUETYPE K;
extern INDEX *ACvar;

/* --------------- WriteJac ---------------------- */
#ifdef ANSIPROTO
void WriteJac(void)
#else
void WriteJac()
#endif
{
  SparseMatrixElement *Jptr;
  ACbusData *ACptr,*ACptrp;
  AClist *Lptr;
  DCbusData *DCptrR,*DCptrI,*DCptr;
  ElementData *Eptr;
  ElementList *ELptr;
  char Namebase[80],Name[80],str[80],type[2];
  FILE *OutFile,*OutFilep;
  int i,j,k,l;
  INDEX I,J,N,Nvar;
  BOOLEAN flag=FALSE;
  SVCbusData *SVCptr;                  /* FACTS */
  TCSCbusData *TCSCptr;                /* FACTS */
  STATCOMbusData *STATCOMptr;          /* FACTS */

  if (ExistParameter('J')) strcpy(Namebase,NameParameter('J'));
  else strcpy(Namebase,NameParameter('j'));
  if(NullName(Namebase)) return;
  if (ExistParameter('J') && Bl)
    for (ACptr=dataPtr->ACbus;ACptr!=NULL;ACptr=ACptr->Next) {
      if(ACptr->Num==Bl) {
	strcpy(ACptr->Type,"B");
	if(ACptr->Area!=NULL && ACptr->Area->Slack==ACptr) strcat(ACptr->Type,"A");
	Bl=0;
	ACptr->Cont=ACptr;
	break;
      }
    }
  flag=(!ExistParameter('J')) && flagPoC;
  DeleteJac(Jac,NewRow,NewCol,OldRow,OldCol);
  RowPer=NewRow; ColPer=NewCol;
  Nvar=NacVar+11*Ndc/2+3*Nsvc+NtcscVar+7*Nstatcom;  /*  FACTS  */ 
  ACFunJac(Jac,NULL,TRUE,TRUE,FALSE);
  DCFunJac(Jac,TRUE,TRUE);
  SVCFunJac(Jac,TRUE,TRUE);                  /*  FACTS  */
  TCSCFunJac(Jac,TRUE,TRUE);                 /*  FACTS  */
  STATCOMFunJac(Jac,TRUE,TRUE);              /*  FACTS  */
  if(flagH) { Nvar++; HFunJac(TRUE,TRUE,NULL,Dx);}
  else if (flag) {
    Nvar=2*Nvar+1;
    ACFunHes(TRUE,TRUE);
    DCFunHes(TRUE,TRUE);
    SVCFunHes(TRUE,TRUE);                   /* FACTS  */
    TCSCFunHes(TRUE,TRUE);                  /* FACTS  */
    STATCOMFunHes(TRUE,TRUE);               /* FACTS  */
  }
  SortRowsColumns(Jac);
  strcpy(Name,Namebase);
  strcat(Name,".jac");
  OutFile=OpenOutput(Name);
  fCustomPrint(OutFile,"%d %d\n",Nvar,Nvar);
  for(i=1;i<=Nvar;i++) {
    for(Jptr=Jac->RowHead[i];Jptr!=NULL;Jptr=Jptr->RowNext)
      fCustomPrint(OutFile,"%4d %4d %-11.5g\n",Jptr->Row,Jptr->Col,Jptr->Value);
  }
  fCustomPrint(OutFile,"%4d %4d %-11.5g\n",0,0,0.);
  fclose(OutFile);
  strcpy(Name,Namebase);
  strcat(Name,".var");
  OutFile=OpenOutput(Name);
  strcpy(Name,Namebase);
  strcat(Name,".mis");
  OutFilep=OpenOutput(Name);
  fCustomPrint(OutFile,"%d 1\n",Nvar);
  fCustomPrint(OutFilep,"%d 1\n",Nvar);
  for (i=0,ACptr=dataPtr->ACbus; ACptr!=NULL; ACptr=ACptr->Next){
    if (ACptr->Cont!=NULL) {
      if (strpbrk(ACptr->Type,"S")) {
        sprintf(str,"kg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
      }
      else {
        sprintf(str,"d%-d",ACptr->Num);  fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      }
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      sprintf(str,"V%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->V);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(QRcont && strpbrk(ACptr->Type,"C")){
      sprintf(str,"d%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      for(Lptr=ACptr->ContBus;Lptr!=NULL;Lptr=Lptr->Next){
        ACptrp=Lptr->AC;
        if (strpbrk(ACptrp->cont,"V")) break;
      }
      sprintf(str,"Qr%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qr);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(Rcont && strpbrk(ACptr->Type,"T")){
      sprintf(str,"d%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      for(ELptr=ACptr->Reg;ELptr!=NULL;ELptr=ELptr->Next){
	     Eptr=ELptr->Eptr;
	     I=Eptr->From->Num;
	     J=Eptr->To->Num;
	     if(!strcmp(Eptr->Type,"R")) break;
      }
      sprintf(str,"1/t%-d_%-d",I,J);
      fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Tap);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(strpbrk(ACptr->Type,"L")) {
      sprintf(str,"d%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,"l",lambda);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(strpbrk(ACptr->Type,"Q") || strpbrk(ACptr->Type,"V") || (!QRcont && strpbrk(ACptr->Type,"G"))) {
      if (strpbrk(ACptr->Type,"S")) {
        sprintf(str,"kg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
      }
      else {
        sprintf(str,"d%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      }
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      sprintf(str,"Qg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(strpbrk(ACptr->Type,"Z")) {
      sprintf(str,"d%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      sprintf(str,"Qz%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    else if(strpbrk(ACptr->Type,"S")){
      sprintf(str,"kg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
      sprintf(str,"dP%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      sprintf(str,"Qg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
      sprintf(str,"dQ%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    if(Acont && strpbrk(ACptr->Type,"A")){
      sprintf(str,"kg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
      sprintf(str,"dPA%-d",ACptr->Area->N); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
    }
    if (PQcont) for(ELptr=ACptr->Reg;ELptr!=NULL;ELptr=ELptr->Next) {
      Eptr=ELptr->Eptr;
      if(strpbrk(Eptr->Type,"PQNM")) {
      	 if (Eptr->From==ACptr) {
	         I=Eptr->From->Num;
	         J=Eptr->To->Num;
      	 } else {
	         J=Eptr->From->Num;
	         I=Eptr->To->Num;
	       }
	       if(!strcmp(Eptr->Type,"RP")){
	         sprintf(str,"a%-d_%-d",I,J); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Ang);
	         sprintf(str,"dP%-d_%-d",I,J); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
	       }
	       else if(strpbrk(Eptr->Type,"PM")){
	         sprintf(str,"P%-d_%-d",I,J); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Cvar);
	         sprintf(str,"dP%-d_%-d",I,J); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
      	 }
	       else if(!strcmp(Eptr->Type,"RQ")){
	         sprintf(str,"1/t%-d_%-d",I,J); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Tap);
	         sprintf(str,"dQ%-d_%-d",I,J); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
	       }
	       else {
	         sprintf(str,"Q%-d_%-d",I,J); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Cvar);
	         sprintf(str,"dQ%-d_%-d",I,J); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
	       }
      }
    }
    if (ACptr->Gen!=NULL) {
      i=ACptr->Gen->Nvar;
      sprintf(str,"dPg%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dQg%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dEq%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dEd%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dVd%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dVq%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dId%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dIq%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dVr%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dVi%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      sprintf(str,"dIa%-d",ACptr->Num); fCustomPrint(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
      i=ACptr->Gen->Nvar;
      if (strpbrk(ACptr->cont,"E")) {
        sprintf(str,"Qg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
      } else {
        sprintf(str,"Eq%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Eq);
      }
      sprintf(str,"dg%-d",ACptr->Num); fCustomPrint(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->dg);

⌨️ 快捷键说明

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