Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DC line implementation #143

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
321ec37
Read DC line data from file
abhyshr Jul 26, 2023
3f68f15
Data file for DC line
abhyshr Jul 26, 2023
f83398e
More work on DC line
abhyshr Aug 5, 2023
9ede518
Added DC line model equations to power flow
abhyshr Aug 29, 2023
7342992
Power flow works now for dc line. Reactive power calculation for DC l…
abhyshr Aug 29, 2023
ac2bda9
Exclude isolated buses.
abhyshr Sep 1, 2023
d5e6ab3
MAX_KVLEVELS set to 200, removed -Werror flag, rebased develop
abhyshr Nov 7, 2023
6c72545
Set up number of variables and constraints in OPFLOW.
abhyshr Nov 15, 2023
a8cf206
Added variable and constraint bounds
abhyshr Nov 15, 2023
0e7d2e4
First functioning version of OPF with DC line
abhyshr Nov 15, 2023
ea7d546
Added sanity check for input data, fixed set but unsed warnings.
abhyshr Dec 1, 2023
4e516ba
Added sanity check for data reading, fixed handling of isolated buses…
abhyshr Dec 2, 2023
86b87fb
Update code.
abhyshr Feb 20, 2024
cdd65e0
Fix bug in parsing data.
abhyshr Feb 21, 2024
71eb3b9
Added smoke test and TOML test
abhyshr May 8, 2024
5875434
Apply pre-commmit fixes
abhyshr May 8, 2024
3e48fa8
Removed some unused variables and constants
abhyshr May 9, 2024
6ca1d68
Apply pre-commmit fixes
abhyshr May 9, 2024
baa707e
Added some flop count for operations.
abhyshr May 9, 2024
c3ad0c1
Apply pre-commmit fixes
abhyshr May 9, 2024
79839e5
Added DC line implementation for DCOPF
abhyshr May 9, 2024
a388f32
Apply pre-commmit fixes
abhyshr May 9, 2024
b3fadc8
Revert angle limits back to negative and positive infinity.
abhyshr May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions datafiles/case9/case9_dcline.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
function mpc = case9_dcline
%T_CASE9_DCLINE Same as T_CASE9_OPFV2 with addition of DC line data.
% Please see CASEFORMAT for details on the case file format.
%
% See also: TOGGLE_DCLINE, IDX_DCLINE.

% MATPOWER

%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%----- Power Flow Data -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [
1 3 0 0 0 0 1 1 0 345 1 1.1 0.9;
2 2 0 0 0 0 1 1 0 345 1 1.1 0.9;
30 2 0 0 0 0 1 1 0 345 1 1.1 0.9;
4 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
5 1 90 30 0 0 1 1 0 345 1 1.1 0.9;
6 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
7 1 100 35 0 0 1 1 0 345 1 1.1 0.9;
8 1 0 0 0 0 1 1 0 345 1 1.1 0.9;
9 1 125 50 0 0 1 1 0 345 1 1.1 0.9;
];

%% generator data
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
mpc.gen = [
1 0 0 300 -300 1 100 1 250 90 0 0 0 0 0 0 0 0 0 0 0;
2 163 0 300 -300 1 100 1 300 10 0 200 -20 20 -10 10 0 0 0 0 0;
30 85 0 300 -300 1 100 1 270 10 0 200 -30 30 -15 15 0 0 0 0 0;
];

%% branch data
% fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
mpc.branch = [
1 4 0 0.0576 0 0 250 250 0 0 1 -360 2.48;
4 5 0.017 0.092 0.158 0 250 250 0 0 1 -360 360;
5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360;
30 6 0 0.0586 0 0 300 300 0 0 1 -360 360;
6 7 0.0119 0.1008 0.209 40 150 150 0 0 1 -360 360;
7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360;
8 2 0 0.0625 0 250 250 250 0 0 1 -360 360;
8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360;
9 4 0.01 0.085 0.176 250 250 250 0 0 1 -2 360;
];

%%----- OPF Data -----%%
%% generator cost data
% 1 startup shutdown n x1 y1 ... xn yn
% 2 startup shutdown n c(n-1) ... c0
mpc.gencost = [
2 1500.00 0.00 3 0.11 5 150;
2 2000.00 0.00 3 0.085 1.2 600;
2 3000 0 3 0.1225 1 335;
];

%%----- DC Line Data -----
%% Change 30-4 Vf to 1.0 from 1.01 to match with gen set-point voltage
% fbus tbus status Pf Pt Qf Qt Vf Vt Pmin Pmax QminF QmaxF QminT QmaxT loss0 loss1
mpc.dcline = [
30 4 1 10 8.9 0 0 1 1 1 10 -10 10 -10 10 1 0.01;
7 9 1 2 1.96 0 0 1 0.98 2 10 0 0 0 0 0 0;
5 8 1 0 0 0 0 1 1 1 10 -10 10 -10 10 0 0;
5 9 1 10 9.5 0 0 1 0.98 0 10 -10 10 -10 10 0 0.05;
];

%% DC line cost data
% 1 startup shutdown n x1 y1 ... xn yn
% 2 startup shutdown n c(n-1) ... c0
mpc.dclinecost = [
2 0 0 2 0 0 0 0 0 0 0 0 0 0;
2 0 0 2 0 0 0 0 0 0 0 0 0 0;
2 0 0 2 0 0 0 0 0 0 0 0 0 0;
2 0 0 2 7.3 0 0 0 0 0 0 0 0 0;
];
3 changes: 2 additions & 1 deletion include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
#define NLOAD_AT_BUS_MAX 32 /**< Maximum number of loads allowed at a bus */
#define NPHASE 1 /**< Per-phase analysis */
#define MAX_KV_LEVELS 20 /**< Maximum KV levels */
#define MAX_KV_LEVELS \
200 /**< Maximum KV (voltage) levels allowed in input file */

/* Fuel types for generators */
#define GENFUEL_COAL 0 /* Coal */
Expand Down
53 changes: 40 additions & 13 deletions include/private/psimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ struct _p_PSLINE {

PSBUS connbuses[2]; /**< From and to buses */

/****** For DC lines **********/
PetscBool isdcline; /**< Is line a DC line? */
PetscScalar pmin; /**< lower limit on PF (MW flow at "from" end) */
abhyshr marked this conversation as resolved.
Show resolved Hide resolved
PetscScalar pmax; /**< upper limit on PF (MW flow at "from" end) */
abhyshr marked this conversation as resolved.
Show resolved Hide resolved
PetscScalar Vf; /**<Voltage set-point at "from" bus (p.u.) */
PetscScalar Vt; /**<Voltage set-point at "to" bus (p.u.) */
PetscScalar qminf; /**< lower limit on QF (MVAr flow at "from" end) */
PetscScalar qmaxf; /**< upper limit on QF (MVAr flow at "from" end) */
PetscScalar qmint; /**< lower limit on QT (MVAr flow at "to" end) */
PetscScalar qmaxt; /**< upper limit on QT (MVAr flow at "to" end) */
PetscScalar loss0, loss1; /* constant and linear term for loss function (loss
= loss0 + loss1*PF) */
/* loss0 given in terms of MW, loss1 is dimensionless */
PetscScalar mult_pmin, mult_pmax;
PetscScalar mult_qminf, mult_qmaxf, mult_qmint, mult_qmaxt;
PetscScalar mult_pf;
/*******************/

PetscScalar
mult_sf; /* Lagrange multiplier for from bus injection (set by OPFLOW) */
PetscScalar
Expand All @@ -323,6 +341,8 @@ struct _p_PSLINE {
PetscInt nconeq; /* Number of equality constraints */
PetscInt nconineq; /* Number of inequality constraints */

PetscInt startxdcloc; /* Location of starting variable for dc line */

PetscInt starteqloc; /* Starting location for equality constraints */
PetscInt startineqloc; /* Starting location for inequality constraints */
};
Expand Down Expand Up @@ -364,11 +384,14 @@ struct _p_PSSUBST {

/* Struct to save system summary stats */
typedef struct {
PetscInt Nbus; /* Number of buses */
PetscInt Ngen; /* Number of generators */
PetscInt NgenON; /* Number of committed generators */
PetscInt Nline; /* Number of lines */
PetscInt NlineON; /* Number of lines ON */
PetscInt Nbus; /* Number of buses */
PetscInt Ngen; /* Number of generators */
PetscInt NgenON; /* Number of committed generators */
PetscInt Nline; /* Number of lines (includes DC lines) */
PetscInt NlineON; /* Number of lines ON (includes DC lines) */
PetscInt Ndcline; /* Number of dc lines */
PetscInt NdclineON; /* Number of dc lines ON */

PetscInt Nload; /* Number of loads */
PetscScalar total_pgencap; /* Total active generation capacity */

Expand All @@ -384,19 +407,23 @@ typedef struct {
*/
struct _p_PS {
PetscScalar MVAbase; /* System base MVA */
PetscInt Nbus, Ngen, Nline,
Nload; /* global # of buses,gens,branches, and loads (includes elements
which are out of service */
PetscInt nbus, ngen, nline,
nload; /* local # of buses,gens,branches,and loads */
PetscInt NlineON, nlineON; /* Number of active lines */
PetscInt NgenON, ngenON; /* Number of active generators */
PetscInt Nref, nref; /* Number of reference buses */
PetscInt Nbus, Ngen, Nline, Nload,
Ndcline; /* global # of buses,gens,branches,loads, and dclines (includes
elements which are out of service */
PetscInt nbus, ngen, nline, nload,
ndcline; /* local # of buses,gens,branches,and loads */
PetscInt NlineON, nlineON; /* Number of active lines (includes DC lines) */
PetscInt NdclineON, ndclineON; /* Number of active dc lines */
PetscInt NgenON, ngenON; /* Number of active generators */
PetscInt Nref, nref; /* Number of reference buses */
/* Number of generator types */
PetscInt ngencoal, ngenwind, ngensolar, ngenng, ngennuclear, ngenhydro,
ngenundefined;
/* Number of renewable generators (solar, wind) */
PetscInt ngenrenew;
/* Number of isolated buses */
PetscInt nisolated_buses, Nisolated_buses;
PetscInt *isolated_buses; /* Array to hold isolated buses */
Comment on lines +410 to +426
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not thrilled about a lot of these variable names. Is there a better way to differentiate / describe these variables? The difference of 1 letter in a different case is easy to typo / miss, and the intention isn't clear from reading.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N and n are typically used in the context of a parallel implementation where N is the global size and n is the local size. Perhaps, it is confusing here and this should be replaced. But, this is a big change that we need to do through another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create an issue for this then? Perhaps naming n_local_... and n_global_... would make more sense? A little more of a cumbersome name, but should be more readable.


PSBUS bus;
PSLOAD load;
Expand Down
1 change: 1 addition & 0 deletions src/opflow/interface/opflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,7 @@ PetscErrorCode OPFLOWSetUpPS(OPFLOW opflow) {
PetscFunctionBegin;
ierr = PSSetUp(opflow->ps);
CHKERRQ(ierr);

/* set individual load costs if necessary */

PetscFunctionReturn(0);
Expand Down
Loading
Loading