Skip to content

Commit b501e12

Browse files
authored
Do not ouptut individual load parameters if not in original network (#112)
* Only output individual load costs if they are read (#109) * If needed, initialize individual load cost parameters (#109) * Apply pre-commmit fixes
1 parent 97f5d3c commit b501e12

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

include/private/psimpl.h

+2
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ struct _p_PS {
451451

452452
PSSystemSummary sys_info;
453453

454+
PetscBool read_load_cost; /* are individual load costs assigned? */
455+
454456
PetscBool setupcalled; /* Is setup called on PS? */
455457

456458
PetscLogDouble solve_real_time;

src/opflow/interface/opflow.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -1644,20 +1644,22 @@ PetscErrorCode OPFLOWSetUp(OPFLOW opflow) {
16441644
ierr = OPFLOWGetLinesMonitored(opflow);
16451645
CHKERRQ(ierr);
16461646
}
1647+
1648+
/* Set individual load cost parameters to the blanket values if they
1649+
were not read from the input network */
16471650
if (opflow->include_loadloss_variables) {
16481651
PS ps;
1649-
PSBUS bus;
1650-
PSLOAD load;
1651-
16521652
ierr = OPFLOWGetPS(opflow, &ps);
16531653
CHKERRQ(ierr);
16541654

1655-
for (int i = 0; i < ps->nbus; i++) {
1656-
bus = &(ps->bus[i]);
1657-
for (int l = 0; l < bus->nload; l++) {
1658-
ierr = PSBUSGetLoad(bus, l, &load);
1659-
CHKERRQ(ierr);
1660-
if (load->loss_cost == BOGUSLOSSCOST) {
1655+
if (!ps->read_load_cost) {
1656+
for (int i = 0; i < ps->nbus; i++) {
1657+
PSBUS bus = &(ps->bus[i]);
1658+
for (int l = 0; l < bus->nload; l++) {
1659+
PSLOAD load;
1660+
ierr = PSBUSGetLoad(bus, l, &load);
1661+
CHKERRQ(ierr);
1662+
load->loss_frac = 1.0;
16611663
load->loss_cost = opflow->loadloss_penalty;
16621664
}
16631665
}

src/ps/psoutput.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,24 @@ PetscErrorCode PSSaveSolution_MATPOWER(PS ps, const char outfile[]) {
232232
fprintf(fd, "\n};\n");
233233
}
234234

235-
/* Load cost data */
236-
fprintf(fd, "\n%%%% load cost data\n");
237-
fprintf(fd, "%% %%maxallowedloadshed loadshedcost\n");
238-
fprintf(fd, "mpc.loadcost = [\n");
239-
for (i = 0; i < ps->nbus; i++) {
240-
bus = &ps->bus[i];
241-
for (k = 0; k < bus->nload; k++) {
242-
PSLOAD load;
243-
ierr = PSBUSGetLoad(bus, k, &load);
244-
CHKERRQ(ierr);
245-
fprintf(fd, "%10.5g %10.5g; \n", load->loss_frac * 100.0,
246-
load->loss_cost);
235+
if (ps->read_load_cost) {
236+
237+
/* Load cost data */
238+
fprintf(fd, "\n%%%% load cost data\n");
239+
fprintf(fd, "%% %%maxallowedloadshed loadshedcost\n");
240+
fprintf(fd, "mpc.loadcost = [\n");
241+
for (i = 0; i < ps->nbus; i++) {
242+
bus = &ps->bus[i];
243+
for (k = 0; k < bus->nload; k++) {
244+
PSLOAD load;
245+
ierr = PSBUSGetLoad(bus, k, &load);
246+
CHKERRQ(ierr);
247+
fprintf(fd, "%10.5g %10.5g; \n", load->loss_frac * 100.0,
248+
load->loss_cost);
249+
}
247250
}
251+
fprintf(fd, "];\n");
248252
}
249-
fprintf(fd, "];\n");
250253

251254
/* Solution summary info */
252255
fprintf(fd, "\n%%%% summary data\n");

src/ps/psreaddata.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ PetscErrorCode PSReadMatPowerData(PS ps, const char netfile[]) {
539539

540540
ps->Nload = 0;
541541
ps->maxbusnum = -1;
542+
ps->read_load_cost = PETSC_FALSE;
542543
while ((out = fgets(line, MAXLINE, fp)) != NULL) {
543544
if (strstr(line, "mpc.baseMVA")) {
544545
/* Read base MVA */
@@ -557,6 +558,7 @@ PetscErrorCode PSReadMatPowerData(PS ps, const char netfile[]) {
557558
gencost_start_line =
558559
line_counter + 1; /* Gen cost data starts from next line */
559560
if (strstr(line, "mpc.loadcost") != NULL) {
561+
ps->read_load_cost = PETSC_TRUE;
560562
loadcost_start_line =
561563
line_counter + 1; /* Load cost data starts from next line */
562564
}

0 commit comments

Comments
 (0)