📄 writejac.cpp
字号:
/* 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);
fprintf(OutFile,"%d %d\n",Nvar,Nvar);
for(i=1;i<=Nvar;i++) {
for(Jptr=Jac->RowHead[i];Jptr!=NULL;Jptr=Jptr->RowNext)
fprintf(OutFile,"%4d %4d %-11.5g\n",Jptr->Row,Jptr->Col,Jptr->Value);
}
fprintf(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);
fprintf(OutFile,"%d 1\n",Nvar);
fprintf(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); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
}
else {
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
}
sprintf(str,"dP%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"V%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->V);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(QRcont && strpbrk(ACptr->Type,"C")){
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
sprintf(str,"dP%-d",ACptr->Num); fprintf(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); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qr);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(Rcont && strpbrk(ACptr->Type,"T")){
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
sprintf(str,"dP%-d",ACptr->Num); fprintf(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);
fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Tap);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(strpbrk(ACptr->Type,"L")) {
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
sprintf(str,"dP%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
fprintf(OutFile,"%4d %8s %-11.5g\n",++i,"l",lambda);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(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); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
}
else {
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
}
sprintf(str,"dP%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Qg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(strpbrk(ACptr->Type,"Z")) {
sprintf(str,"d%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Ang);
sprintf(str,"dP%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Qz%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(strpbrk(ACptr->Type,"S")){
sprintf(str,"kg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
sprintf(str,"dP%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Qg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
sprintf(str,"dQ%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
if(Acont && strpbrk(ACptr->Type,"A")){
sprintf(str,"kg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Kg);
sprintf(str,"dPA%-d",ACptr->Area->N); fprintf(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); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Ang);
sprintf(str,"dP%-d_%-d",I,J); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(strpbrk(Eptr->Type,"PM")){
sprintf(str,"P%-d_%-d",I,J); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Cvar);
sprintf(str,"dP%-d_%-d",I,J); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else if(!strcmp(Eptr->Type,"RQ")){
sprintf(str,"1/t%-d_%-d",I,J); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Tap);
sprintf(str,"dQ%-d_%-d",I,J); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
else {
sprintf(str,"Q%-d_%-d",I,J); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,Eptr->Cvar);
sprintf(str,"dQ%-d_%-d",I,J); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
}
}
if (ACptr->Gen!=NULL) {
i=ACptr->Gen->Nvar;
sprintf(str,"dPg%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dQg%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dEq%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dEd%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dVd%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dVq%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dId%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dIq%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dVr%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dVi%-d",ACptr->Num); fprintf(OutFilep,"%4d %8s %-11.5g\n",++i,str,dF[i]);
sprintf(str,"dIa%-d",ACptr->Num); fprintf(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); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
} else {
sprintf(str,"Eq%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Eq);
}
sprintf(str,"dg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->dg);
sprintf(str,"Vr%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Vr);
sprintf(str,"Vi%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Vi);
sprintf(str,"Ir%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Ir);
sprintf(str,"Ii%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Ii);
sprintf(str,"Vq%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Vq);
sprintf(str,"Vd%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Vd);
sprintf(str,"Iq%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Iq);
sprintf(str,"Id%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Id);
if (strpbrk(ACptr->cont,"I")) {
sprintf(str,"Qg%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Qg);
} else {
sprintf(str,"Ia%-d",ACptr->Num); fprintf(OutFile,"%4d %8s %-11.5g\n",++i,str,ACptr->Gen->Ia);
}
}
}
for(k=0,DCptrR=dataPtr->DCbus;DCptrR!=NULL;DCptrR=DCptrR->Next){
DCptrI=DCptrR->To;
if(!strcmp(DCptrR->Type,"R")){
for (k++,l=1;l<=11;l++){
sprintf(str,"Fdc%-d_%-d",k,l); i++;
fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
for(l=i-11,j=1;j<=2;j++){
if(j==1) { DCptr=DCptrR; strcpy(type,"r"); }
else { DCptr=DCptrI; strcpy(type,"i"); }
if(strcmp(DCptr->Cont1,"VD")&&strcmp(DCptr->Cont2,"VD")) {
sprintf(str,"Vd%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->Vd);
}
if(strcmp(DCptr->Cont1,"AT")&&strcmp(DCptr->Cont2,"AT")) {
sprintf(str,"t%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->Tap);
}
if(strcmp(DCptr->Cont1,"AL")&&strcmp(DCptr->Cont2,"AL")) {
sprintf(str,"al%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->Alfa);
}
if(strcmp(DCptr->Cont1,"GA")&&strcmp(DCptr->Cont2,"GA")) {
sprintf(str,"ga%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->Gamma);
}
sprintf(str,"s%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->MVA);
if(strcmp(DCptr->Cont1,"PA")&&strcmp(DCptr->Cont2,"PA")) {
sprintf(str,"P%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->P);
}
if(strcmp(DCptr->Cont1,"QA")&&strcmp(DCptr->Cont2,"QA")) {
sprintf(str,"Q%1s%-d",type,k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptr->Q);
}
}
if(strcmp(DCptrR->Cont1,"ID")&&strcmp(DCptrR->Cont2,"ID")&&
strcmp(DCptrI->Cont1,"ID")&&strcmp(DCptrI->Cont2,"ID")) {
sprintf(str,"Id%-d",k);
fprintf(OutFile,"%4d %8s %-11.5g\n",++l,str,DCptrR->Id);
}
}
}
/* FACTS */
for(k=0,SVCptr=dataPtr->SVCbus;SVCptr!=NULL;SVCptr=SVCptr->Next){
k++; l=0;
sprintf(str,"Qsvc%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,SVCptr->Qsvc);
sprintf(str,"Fsvc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Bv%-d",k);i++; fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,SVCptr->Bv);
sprintf(str,"Fsvc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
if(!strcmp(SVCptr->Cont,"AL")){
sprintf(str,"alpha%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,SVCptr->alpha_svc);
} else {
sprintf(str,"Vrefc%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,SVCptr->Vvar);
}
sprintf(str,"Fsvc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
}
for(k=0,TCSCptr=dataPtr->TCSCbus;TCSCptr!=NULL;TCSCptr=TCSCptr->Next){
k++; l=0;
sprintf(str,"Ptcsc%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->Ptcsc);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Qtcsck%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->Qtcsck);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Qtcscm%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->Qtcscm);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Be%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->Be);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"alpha%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->alpha_tcsc);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"Itcsc%-d",k);i++;
fprintf(OutFile,"%4d %8s %-11.5g\n",i,str,TCSCptr->Itcsc);
sprintf(str,"Ftcsc%-d_%-d",k,++l); fprintf(OutFilep,"%4d %8s %-11.5g\n",i,str,dF[i]);
sprintf(str,"delta%-d",k);i++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -