Skip to content

Commit 9a25e2d

Browse files
committed
Added zone and area info to JSON output
1 parent e0e187c commit 9a25e2d

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

include/private/psimpl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ struct _p_PSLINE {
298298
PetscScalar kvlevel; /* Kv level for lines, for transformers uses the HV side
299299
voltage */
300300

301+
PetscInt areaf,areat; /**< Areas for from and to buses */
302+
PetscInt zonef,zonet; /**< Zones for from and to buses */
303+
301304
PSBUS connbuses[2]; /**< From and to buses */
302305

303306
/****** For DC lines **********/
@@ -371,6 +374,7 @@ typedef struct {
371374
PSConngroupi *ci;
372375
} PSConngroup;
373376

377+
/* Substation data */
374378
struct _p_PSSUBST {
375379
PetscInt num; /* Substation number */
376380
PetscInt intnum; /* Internal number */
@@ -380,6 +384,8 @@ struct _p_PSSUBST {
380384
PSBUS bus[20]; /* Pointers for buses */
381385
PetscInt nkvlevels; /* Number of KV levels at this substation */
382386
PetscScalar kvlevels[10]; /* Substation KV levels */
387+
PetscInt zone; /* zone number */
388+
PetscInt area; /* area number */
383389
};
384390

385391
/* Struct to save system summary stats */
@@ -484,6 +490,11 @@ struct _p_PS {
484490

485491
PetscBool read_load_cost; /* are individual load costs assigned? */
486492

493+
PetscInt nzones; /* Number of zones */
494+
PetscInt nareas; /* Number of areas */
495+
PetscInt *areas; /* Areas */
496+
PetscInt *zones; /* Zones */
497+
487498
PetscBool setupcalled; /* Is setup called on PS? */
488499

489500
PetscLogDouble solve_real_time;

src/ps/ps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,12 @@ PetscErrorCode PSDestroy(PS *ps) {
858858
CHKERRQ(ierr);
859859
}
860860

861+
ierr = PetscFree((*ps)->zones);
862+
CHKERRQ(ierr);
863+
864+
ierr = PetscFree((*ps)->areas);
865+
CHKERRQ(ierr);
866+
861867
ierr = PetscFree((*ps)->busext2intmap);
862868
CHKERRQ(ierr);
863869
ierr = DMDestroy(&(*ps)->networkdm);

src/ps/psoutput.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,23 @@ static void PrintJSONArray(FILE *fd, const char *name, int nvals,
443443
PrintJSONArrayEnd(fd, trail_comma);
444444
}
445445

446+
static void PrintJSONArrayInt(FILE *fd, int value, bool trail_comma) {
447+
std::string str = trail_comma ? "," : "";
448+
fprintf(fd, "%s%d%s\n", tabstring, value, str.c_str());
449+
}
450+
451+
static void PrintJSONIntArray(FILE *fd, const char *name, int nvals,
452+
int *values, bool trail_comma) {
453+
PrintJSONArrayBegin(fd, name);
454+
455+
for (int i = 0; i < nvals - 1; i++) {
456+
PrintJSONArrayInt(fd, values[i], true);
457+
}
458+
PrintJSONArrayInt(fd, values[nvals - 1], false);
459+
460+
PrintJSONArrayEnd(fd, trail_comma);
461+
}
462+
446463
static void PrintGenData(FILE *fd, PSBUS bus, bool trail_comma,
447464
PetscScalar MVAbase) {
448465
PSGEN gen;
@@ -522,6 +539,19 @@ static void PrintLineData(FILE *fd, PSLINE line, bool trail_comma,
522539
PrintJSONDouble(fd, "RATE_A", (line->rateA > 1e5) ? 10000 : line->rateA,
523540
true);
524541

542+
// Zones for from and to bus
543+
// Zone from bus
544+
PrintJSONInt(fd, "ZONE_FBUS", line->zonef, true);
545+
546+
// Zone to bus
547+
PrintJSONInt(fd, "ZONE_TBUS", line->zonet, true);
548+
549+
// Area from bus
550+
PrintJSONInt(fd, "AREA_FBUS", line->areaf, true);
551+
552+
// Zone to bus
553+
PrintJSONInt(fd, "AREA_TBUS", line->areat, true);
554+
525555
// PF,QF, PT, QT
526556
PrintJSONDouble(fd, "PF", line->pf * MVAbase, true);
527557
PrintJSONDouble(fd, "QF", line->qf * MVAbase, true);
@@ -573,6 +603,12 @@ static void PrintBusData(FILE *fd, PSSUBST subst, bool trail_comma,
573603
// Base KV
574604
PrintJSONDouble(fd, "BASE_KV", bus->basekV, true);
575605

606+
// Zone
607+
PrintJSONInt(fd, "ZONE", bus->zone, true);
608+
609+
// Area
610+
PrintJSONInt(fd,"AREA",bus->area, true);
611+
576612
// PD
577613
if (bus->nload) {
578614
PSBUSGetLoad(bus, 0, &load);
@@ -665,6 +701,8 @@ PetscErrorCode PSSaveSolution_JSON(PS ps, const char outfile[]) {
665701
snprintf(subst->name, 64, "%d", ps->bus[i].bus_i);
666702
subst->nbus = 1;
667703
subst->nkvlevels = 1;
704+
subst->zone = ps->bus[i].zone;
705+
subst->area = ps->bus[i].area;
668706
/* Circular distribution of lats and long from some location with .5
669707
* degrees deviation. This is completely random baseless lat/long creation
670708
*/
@@ -714,6 +752,12 @@ PetscErrorCode PSSaveSolution_JSON(PS ps, const char outfile[]) {
714752
PrintJSONString(fd, "gicfile", "not given", true);
715753
}
716754

755+
/* Print number of zones */
756+
PrintJSONInt(fd, "nzones", ps->nzones, true);
757+
758+
/* Print number of zones */
759+
PrintJSONInt(fd, "nareas", ps->nareas, true);
760+
717761
/* Print number of lines */
718762
PrintJSONInt(fd, "nbranch", ps->Nline, true);
719763

@@ -723,6 +767,12 @@ PetscErrorCode PSSaveSolution_JSON(PS ps, const char outfile[]) {
723767
/* Print Number of bus */
724768
PrintJSONInt(fd, "nbus", ps->Nbus, true);
725769

770+
/* Print zones */
771+
PrintJSONIntArray(fd, "zones", ps->nzones, ps->zones, true);
772+
773+
/* Print areas */
774+
PrintJSONIntArray(fd, "areas", ps->nareas, ps->areas, true);
775+
726776
/* Print KV levels */
727777
PrintJSONArray(fd, "KVlevels", ps->nkvlevels, ps->kvlevels, true);
728778

@@ -757,6 +807,12 @@ PetscErrorCode PSSaveSolution_JSON(PS ps, const char outfile[]) {
757807
// Name
758808
PrintJSONString(fd, "NAME", ps->substations[i].name, true);
759809

810+
// Zone number
811+
PrintJSONInt(fd, "zone", ps->substations[i].zone, true);
812+
813+
// Area number
814+
PrintJSONInt(fd, "area", ps->substations[i].area, true);
815+
760816
// Number of buses
761817
PrintJSONInt(fd, "nbus", ps->substations[i].nbus, true);
762818

@@ -883,6 +939,8 @@ PetscErrorCode PSSaveSolution_MINIMAL(PS ps, const char outfile[]) {
883939
fprintf(fd, "\tTotal Load Shed P, Q: %9g, %9g\n",
884940
ps->sys_info.total_loadshed[0], ps->sys_info.total_loadshed[1]);
885941
fprintf(fd, "\tSolve Time: %5g\n", ps->solve_real_time);
942+
fprintf(fd, "\tNzones: %d\n",ps->nzones);
943+
fprintf(fd, "\tNareas: %d\n",ps->nareas);
886944

887945
fclose(fd);
888946

src/ps/psreaddata.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ PetscErrorCode PSReadMatPowerData(PS ps, const char netfile[]) {
572572
ps->Nload = 0;
573573
ps->maxbusnum = -1;
574574
ps->read_load_cost = PETSC_FALSE;
575+
576+
ps->nzones = ps->nareas = 0;
577+
ierr = PetscCalloc1(100,&ps->zones);CHKERRQ(ierr);
578+
ierr = PetscCalloc1(100,&ps->areas);CHKERRQ(ierr);
575579
while ((out = fgets(line, MAXLINE, fp)) != NULL) {
576580
if (strstr(line, "mpc.baseMVA")) {
577581
/* Read base MVA */
@@ -764,6 +768,26 @@ PetscErrorCode PSReadMatPowerData(PS ps, const char netfile[]) {
764768
ps->nbus++;
765769
ps->Nbus++;
766770

771+
/* Save zone and area information to PS struct */
772+
int area_found = 0;
773+
for(int num=0; num < ps->nareas; num++) {
774+
if(Bus[busi].area == ps->areas[num]) {
775+
area_found = 1;
776+
break;
777+
}
778+
}
779+
if(!area_found) ps->areas[ps->nareas++] = Bus[busi].area;
780+
781+
int zone_found = 0;
782+
for(int num=0; num < ps->nzones; num++) {
783+
if(Bus[busi].zone == ps->zones[num]) {
784+
zone_found = 1;
785+
break;
786+
}
787+
}
788+
if(!zone_found) ps->zones[ps->nzones++] = Bus[busi].zone;
789+
790+
767791
Bus[busi].Vmax = Bus[busi].Vmax == 0 ? 1.1 : Bus[busi].Vmax;
768792
Bus[busi].Vmin = Bus[busi].Vmin == 0 ? 0.9 : Bus[busi].Vmin;
769793
/* Sanity check for voltage limits */
@@ -1249,6 +1273,12 @@ PetscErrorCode PSReadMatPowerData(PS ps, const char netfile[]) {
12491273
Bus[Branch[bri].internal_i].nconnlines++;
12501274
Bus[Branch[bri].internal_j].nconnlines++;
12511275

1276+
/* Set from and to bus areas and zones for the line */
1277+
Branch[bri].areaf = Bus[Branch[bri].internal_i].area;
1278+
Branch[bri].areat = Bus[Branch[bri].internal_j].area;
1279+
Branch[bri].zonef = Bus[Branch[bri].internal_i].zone;
1280+
Branch[bri].zonet = Bus[Branch[bri].internal_j].zone;
1281+
12521282
PetscInt lineididx = 0;
12531283
for (linenum = 0; linenum < bri - 1; linenum++) {
12541284
if (Branch[bri].internal_i == Branch[linenum].internal_i &&
@@ -1380,6 +1410,9 @@ PetscErrorCode PSReadGICData(PS ps) {
13801410
bus = &ps->bus[ps->busext2intmap[bus_num]];
13811411
subst->bus[subst->nbus++] = bus;
13821412

1413+
subst->zone = bus->zone;
1414+
subst->area = bus->area;
1415+
13831416
for (int j = 0; j < subst->nkvlevels; j++) {
13841417
if (PetscAbsScalar(bus->basekV - subst->kvlevels[j]) < 1e-6) {
13851418
found = true;

0 commit comments

Comments
 (0)