xref: /petsc/src/snes/tutorials/network/power/power.h (revision 9dd11ecf0918283bb567d8b33a92f53ac4ea7840)
1 #pragma once
2 
3 #include <petscsnes.h>
4 #include <petscdmnetwork.h>
5 
6 #define MAXLINE          1000
7 #define REF_BUS          3
8 #define PV_BUS           2
9 #define PQ_BUS           1
10 #define ISOLATED_BUS     4
11 #define NGEN_AT_BUS_MAX  15
12 #define NLOAD_AT_BUS_MAX 1
13 
14 struct _p_UserCtx_Power {
15   PetscScalar Sbase;
16   PetscBool   jac_error; /* introduce error in the jacobian */
17   PetscInt    compkey_branch;
18   PetscInt    compkey_bus;
19   PetscInt    compkey_gen;
20   PetscInt    compkey_load;
21 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
22 
23 typedef struct _p_UserCtx_Power UserCtx_Power;
24 
25 /* 2. Bus data */
26 /* 11 columns */
27 struct _p_VERTEX_Power {
28   PetscInt    bus_i;                 /* Integer bus number .. used by some formats like Matpower */
29   char        i[20];                 /* Bus Number */
30   char        name[20];              /* Bus Name */
31   PetscScalar basekV;                /* Bus Base kV */
32   PetscInt    ide;                   /* Bus type code */
33   PetscScalar gl;                    /* Active component of shunt admittance to ground */
34   PetscScalar bl;                    /* Reactive component of shunt admittance to ground */
35   PetscInt    area;                  /* Area number */
36   PetscInt    zone;                  /* Zone number */
37   PetscScalar vm;                    /* Bus voltage magnitude; in pu */
38   PetscScalar va;                    /* Bus voltage phase angle */
39   PetscInt    owner;                 /* Owner number */
40   PetscInt    internal_i;            /* Internal Bus Number */
41   PetscInt    ngen;                  /* Number of generators incident at this bus */
42   PetscInt    gidx[NGEN_AT_BUS_MAX]; /* list of inndices for accessing the generator data in GEN structure */
43   PetscInt    nload;
44   PetscInt    lidx[NLOAD_AT_BUS_MAX];
45 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
46 
47 typedef struct _p_VERTEX_Power *VERTEX_Power;
48 
49 /* 3. Load data */
50 /* 12 columns */
51 struct _p_LOAD {
52   PetscInt    bus_i;  /* Bus number */
53   char        i[20];  /* Bus Number or extended bus name*/
54   char        id[20]; /* Load identifier, in case of multiple loads. 1 by default */
55   PetscInt    status; /* Load status */
56   PetscInt    area;   /* Area to which load is assigned */
57   PetscInt    zone;   /* Zone to which load is assigned */
58   PetscScalar pl;     /* Active power component of constant MVA load */
59   PetscScalar ql;     /* Reactive power component of constant MVA load */
60   PetscScalar ip;     /* Active power component of constant current load: MW pu V */
61   PetscScalar iq;     /* Reactive power component of constant current load: Mvar pu V */
62   PetscScalar yp;     /* Active power component of constant admittance load: MW pu V */
63   PetscScalar yq;     /* Reactive power component of constant admittance load: Mvar pu V */
64   PetscScalar scale_load;
65   PetscInt    owner;      /* Owner number */
66   PetscInt    internal_i; /* Internal Bus Number */
67 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
68 
69 typedef struct _p_LOAD *LOAD;
70 
71 /* 4. Generator data */
72 /* 20+ columns */
73 /******* 20, USING ONLY 1 OWNER's WORTH OF DATA. COME BACK TO THIS LATER, if necessary ******/
74 struct _p_GEN {
75   PetscInt    bus_i;
76   char        i[20];  /* Bus Number or extended bus name*/
77   char        id[20]; /* Generator identifier, in case of multiple generators at same bus. 1 by default */
78   PetscScalar pg;     /* Generator active power output */
79   PetscScalar qg;     /* Generator reactive power output */
80   PetscScalar qt;     /* Maximum reactive power output: Mvar */
81   PetscScalar qb;     /* Minimum reactive power output: Mvar */
82   PetscScalar vs;     /* Regulated voltage setpoint: pu */
83   PetscInt    ireg;   /* Remote bus number/identifier */
84   PetscScalar mbase;  /* MVA base of the machine */
85   PetscScalar zr;     /* Complex machine impedance ZSOURCE in pu on mbase */
86   PetscScalar zx;     /* ----------------------"------------------------- */
87   PetscScalar rt;     /* Step-up transformer impedance XTRAN in pu on mbase */
88   PetscScalar xt;     /* -----------------------"-------------------------- */
89   PetscScalar gtap;   /* Step-up transformer turns ratio */
90   PetscInt    status; /* Machine status */
91   PetscScalar rmpct;  /* Mvar % required to hold voltage at remote bus */
92   PetscScalar pt;     /* Gen max active power output: MW */
93   PetscScalar pb;     /* Gen min active power output: MW */
94   PetscInt    o1;     /* Owner number */
95   PetscScalar f1;     /* Fraction of ownership */
96   PetscScalar scale_gen;
97   PetscInt    internal_i; /* Internal Bus Number */
98 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
99 
100 typedef struct _p_GEN *GEN;
101 
102 /* 17+ columns */
103 struct _p_EDGE_Power {
104   PetscInt    fbus;
105   PetscInt    tbus;
106   char        i[20];   /* Bus Number or extended bus name*/
107   char        j[20];   /* Bus Number or extended bus name*/
108   char        ckt[20]; /* Circuit identifier. 1 by default */
109   PetscScalar r;       /* Branch resistance: pu */
110   PetscScalar x;       /* Branch reactance: pu */
111   PetscScalar b;       /* Branch charging susceptance: pu */
112   PetscScalar rateA;   /* rate A in MVA */
113   PetscScalar rateB;   /* rate B in MVA */
114   PetscScalar rateC;   /* rate C in MVA */
115   PetscScalar tapratio;
116   PetscScalar phaseshift;
117   PetscScalar gi;                             /* Complex admittance at 'i' end: pu */
118   PetscScalar bi;                             /* Complex admittance at 'i' end: pu */
119   PetscScalar gj;                             /* Complex admittance at 'j' end: pu */
120   PetscScalar bj;                             /* Complex admittance at 'j' end: pu */
121   PetscInt    status;                         /* Service status */
122   PetscScalar length;                         /* Line length */
123   PetscInt    o1;                             /* Owner number */
124   PetscScalar f1;                             /* Fraction of ownership */
125   PetscScalar yff[2], yft[2], ytf[2], ytt[2]; /* [G,B] */
126   PetscInt    internal_i;                     /* Internal From Bus Number */
127   PetscInt    internal_j;                     /* Internal To Bus Number */
128 } PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
129 
130 typedef struct _p_EDGE_Power *EDGE_Power;
131 
132 /* PTI format data structure */
133 typedef struct {
134   PetscScalar  sbase;                      /* System base MVA */
135   PetscInt     nbus, ngen, nbranch, nload; /* # of buses,gens,branches, and loads (includes elements which are
136                                           out of service */
137   VERTEX_Power bus;
138   LOAD         load;
139   GEN          gen;
140   EDGE_Power   branch;
141 } PFDATA PETSC_ATTRIBUTEALIGNED(PetscMax(sizeof(double), sizeof(PetscScalar)));
142 
143 extern PetscErrorCode PFReadMatPowerData(PFDATA *, char *);
144 extern PetscErrorCode GetListofEdges_Power(PFDATA *, PetscInt *);
145 extern PetscErrorCode FormJacobian_Power(SNES, Vec, Mat, Mat, void *);
146 extern PetscErrorCode FormJacobian_Power_private(DM, Vec, Mat, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
147 extern PetscErrorCode FormFunction_Power(DM, Vec, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
148 extern PetscErrorCode SetInitialGuess_Power(DM, Vec, PetscInt, PetscInt, const PetscInt *, const PetscInt *, void *);
149