Actual source code: power.h

  1: #ifndef PF_H
  2: #define PF_H

  4: #include <petscsnes.h>
  5: #include <petscdmnetwork.h>

  7: #define MAXLINE          1000
  8: #define REF_BUS          3
  9: #define PV_BUS           2
 10: #define PQ_BUS           1
 11: #define ISOLATED_BUS     4
 12: #define NGEN_AT_BUS_MAX  15
 13: #define NLOAD_AT_BUS_MAX 1

 15: struct _p_UserCtx_Power {
 16:   PetscScalar Sbase;
 17:   PetscBool   jac_error; /* introduce error in the jacobian */
 18:   PetscInt    compkey_branch;
 19:   PetscInt    compkey_bus;
 20:   PetscInt    compkey_gen;
 21:   PetscInt    compkey_load;
 22: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

 24: typedef struct _p_UserCtx_Power UserCtx_Power;

 26: /* 2. Bus data */
 27: /* 11 columns */
 28: struct _p_VERTEX_Power {
 29:   PetscInt    bus_i;                 /* Integer bus number .. used by some formats like Matpower */
 30:   char        i[20];                 /* Bus Number */
 31:   char        name[20];              /* Bus Name */
 32:   PetscScalar basekV;                /* Bus Base kV */
 33:   PetscInt    ide;                   /* Bus type code */
 34:   PetscScalar gl;                    /* Active component of shunt admittance to ground */
 35:   PetscScalar bl;                    /* Reactive component of shunt admittance to ground */
 36:   PetscInt    area;                  /* Area number */
 37:   PetscInt    zone;                  /* Zone number */
 38:   PetscScalar vm;                    /* Bus voltage magnitude; in pu */
 39:   PetscScalar va;                    /* Bus voltage phase angle */
 40:   PetscInt    owner;                 /* Owner number */
 41:   PetscInt    internal_i;            /* Internal Bus Number */
 42:   PetscInt    ngen;                  /* Number of generators incident at this bus */
 43:   PetscInt    gidx[NGEN_AT_BUS_MAX]; /* list of inndices for accessing the generator data in GEN structure */
 44:   PetscInt    nload;
 45:   PetscInt    lidx[NLOAD_AT_BUS_MAX];
 46: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

 48: typedef struct _p_VERTEX_Power *VERTEX_Power;

 50: /* 3. Load data */
 51: /* 12 columns */
 52: struct _p_LOAD {
 53:   PetscInt    bus_i;  /* Bus number */
 54:   char        i[20];  /* Bus Number or extended bus name*/
 55:   char        id[20]; /* Load identifier, in case of multiple loads. 1 by default */
 56:   PetscInt    status; /* Load status */
 57:   PetscInt    area;   /* Area to which load is assigned */
 58:   PetscInt    zone;   /* Zone to which load is assigned */
 59:   PetscScalar pl;     /* Active power component of constant MVA load */
 60:   PetscScalar ql;     /* Reactive power component of constant MVA load */
 61:   PetscScalar ip;     /* Active power component of constant current load: MW pu V */
 62:   PetscScalar iq;     /* Reactive power component of constant current load: Mvar pu V */
 63:   PetscScalar yp;     /* Active power component of constant admittance load: MW pu V */
 64:   PetscScalar yq;     /* Reactive power component of constant admittance load: Mvar pu V */
 65:   PetscScalar scale_load;
 66:   PetscInt    owner;      /* Owner number */
 67:   PetscInt    internal_i; /* Internal Bus Number */
 68: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

 70: typedef struct _p_LOAD *LOAD;

 72: /* 4. Generator data */
 73: /* 20+ columns */
 74: /******* 20, USING ONLY 1 OWNER's WORTH OF DATA. COME BACK TO THIS LATER, if necessary ******/
 75: struct _p_GEN {
 76:   PetscInt    bus_i;
 77:   char        i[20];  /* Bus Number or extended bus name*/
 78:   char        id[20]; /* Generator identifier, in case of multiple generators at same bus. 1 by default */
 79:   PetscScalar pg;     /* Generator active power output */
 80:   PetscScalar qg;     /* Generator reactive power output */
 81:   PetscScalar qt;     /* Maximum reactive power output: Mvar */
 82:   PetscScalar qb;     /* Minimum reactive power output: Mvar */
 83:   PetscScalar vs;     /* Regulated voltage setpoint: pu */
 84:   PetscInt    ireg;   /* Remote bus number/identifier */
 85:   PetscScalar mbase;  /* MVA base of the machine */
 86:   PetscScalar zr;     /* Complex machine impedance ZSOURCE in pu on mbase */
 87:   PetscScalar zx;     /* ----------------------"------------------------- */
 88:   PetscScalar rt;     /* Step-up transformer impedance XTRAN in pu on mbase */
 89:   PetscScalar xt;     /* -----------------------"-------------------------- */
 90:   PetscScalar gtap;   /* Step-up transformer turns ratio */
 91:   PetscInt    status; /* Machine status */
 92:   PetscScalar rmpct;  /* Mvar % required to hold voltage at remote bus */
 93:   PetscScalar pt;     /* Gen max active power output: MW */
 94:   PetscScalar pb;     /* Gen min active power output: MW */
 95:   PetscInt    o1;     /* Owner number */
 96:   PetscScalar f1;     /* Fraction of ownership */
 97:   PetscScalar scale_gen;
 98:   PetscInt    internal_i; /* Internal Bus Number */
 99: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

101: typedef struct _p_GEN *GEN;

103: /* 17+ columns */
104: struct _p_EDGE_Power {
105:   PetscInt    fbus;
106:   PetscInt    tbus;
107:   char        i[20];   /* Bus Number or extended bus name*/
108:   char        j[20];   /* Bus Number or extended bus name*/
109:   char        ckt[20]; /* Circuit identifier. 1 by default */
110:   PetscScalar r;       /* Branch resistance: pu */
111:   PetscScalar x;       /* Branch reactance: pu */
112:   PetscScalar b;       /* Branch charging susceptance: pu */
113:   PetscScalar rateA;   /* rate A in MVA */
114:   PetscScalar rateB;   /* rate B in MVA */
115:   PetscScalar rateC;   /* rate C in MVA */
116:   PetscScalar tapratio;
117:   PetscScalar phaseshift;
118:   PetscScalar gi;                             /* Complex admittance at 'i' end: pu */
119:   PetscScalar bi;                             /* Complex admittance at 'i' end: pu */
120:   PetscScalar gj;                             /* Complex admittance at 'j' end: pu */
121:   PetscScalar bj;                             /* Complex admittance at 'j' end: pu */
122:   PetscInt    status;                         /* Service status */
123:   PetscScalar length;                         /* Line length */
124:   PetscInt    o1;                             /* Owner number */
125:   PetscScalar f1;                             /* Fraction of ownership */
126:   PetscScalar yff[2], yft[2], ytf[2], ytt[2]; /* [G,B] */
127:   PetscInt    internal_i;                     /* Internal From Bus Number */
128:   PetscInt    internal_j;                     /* Internal To Bus Number */
129: } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

131: typedef struct _p_EDGE_Power *EDGE_Power;

133: /* PTI format data structure */
134: typedef struct {
135:   PetscScalar  sbase;                      /* System base MVA */
136:   PetscInt     nbus, ngen, nbranch, nload; /* # of buses,gens,branches, and loads (includes elements which are
137:                                           out of service */
138:   VERTEX_Power bus;
139:   LOAD         load;
140:   GEN          gen;
141:   EDGE_Power   branch;
142: } PFDATA PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));

144: extern PetscErrorCode PFReadMatPowerData(PFDATA *, char *);
145: extern PetscErrorCode GetListofEdges_Power(PFDATA *, PetscInt *);
146: extern PetscErrorCode FormJacobian_Power(SNES, Vec, Mat, Mat, void *);
147: extern PetscErrorCode FormJacobian_Power_private(DM, Vec, Mat, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
148: extern PetscErrorCode FormFunction_Power(DM, Vec, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
149: extern PetscErrorCode SetInitialGuess_Power(DM, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
150: #endif