Skip to content

Commit 5f7f528

Browse files
authored
Add dcopflow app (#199)
1 parent 6f04993 commit 5f7f528

File tree

3 files changed

+170
-1
lines changed

3 files changed

+170
-1
lines changed

applications/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(EXAGO_ENABLE_IPOPT OR EXAGO_ENABLE_HIOP)
1313

1414
set_source_files_properties(
1515
opflow_main.cpp scopflow_main.cpp sopflow_main.cpp tcopflow_main.cpp
16-
PROPERTIES LANGUAGE CXX
16+
dcopflow_main.cpp PROPERTIES LANGUAGE CXX
1717
)
1818

1919
# OPFLOW
@@ -23,6 +23,13 @@ if(EXAGO_ENABLE_IPOPT OR EXAGO_ENABLE_HIOP)
2323
set_target_properties(app_opflow PROPERTIES OUTPUT_NAME opflow)
2424
install(TARGETS app_opflow RUNTIME DESTINATION bin)
2525

26+
# DCOPFLOW
27+
set(DCOPFLOW_SRC dcopflow_main.cpp)
28+
add_executable(app_dcopflow ${DCOPFLOW_SRC})
29+
target_link_libraries(app_dcopflow ExaGO::OPFLOW)
30+
set_target_properties(app_dcopflow PROPERTIES OUTPUT_NAME dcopflow)
31+
install(TARGETS app_dcopflow RUNTIME DESTINATION bin)
32+
2633
if(EXAGO_ENABLE_IPOPT)
2734

2835
# SCOPFLOW
@@ -45,5 +52,6 @@ if(EXAGO_ENABLE_IPOPT OR EXAGO_ENABLE_HIOP)
4552
target_link_libraries(app_tcopflow ExaGO::TCOPFLOW)
4653
set_target_properties(app_tcopflow PROPERTIES OUTPUT_NAME tcopflow)
4754
install(TARGETS app_tcopflow RUNTIME DESTINATION bin)
55+
4856
endif()
4957
endif()

applications/dcopflow_main.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
static char help[] = "User example calling OPFLOW with the DCOPF model.\n\n";
2+
3+
#include <opflow.h>
4+
#include <exago_config.h>
5+
#include <utils.h>
6+
#include <string>
7+
#include <private/opflowimpl.h>
8+
9+
int main(int argc, char **argv) {
10+
PetscErrorCode ierr;
11+
OPFLOW dcopf;
12+
char file[PETSC_MAX_PATH_LEN], gicfile[PETSC_MAX_PATH_LEN],
13+
output_name[PETSC_MAX_PATH_LEN];
14+
PetscBool flg = PETSC_FALSE, print_output = PETSC_FALSE,
15+
save_output = PETSC_FALSE;
16+
PetscLogStage stages[3];
17+
char appname[] = "dcopflow";
18+
const char default_output_name[] = "dcopflowout";
19+
MPI_Comm comm = MPI_COMM_WORLD;
20+
21+
/** Use `ExaGOLogSetLoggingFileName("dcopflow-logfile");` to log the output.
22+
*/
23+
ierr = ExaGOInitialize(comm, &argc, &argv, appname, help);
24+
if (ierr) {
25+
fprintf(stderr, "Could not initialize ExaGO application %s.\n", appname);
26+
return ierr;
27+
}
28+
29+
ierr = PetscOptionsGetBool(NULL, NULL, "-print_output", &print_output, NULL);
30+
ExaGOCheckError(ierr);
31+
ierr = PetscOptionsGetString(NULL, NULL, "-save_output", &output_name[0],
32+
PETSC_MAX_PATH_LEN, &save_output);
33+
ExaGOCheckError(ierr);
34+
35+
/* Register stages for profiling application code sections */
36+
ierr = PetscLogStageRegister("Reading Data", &stages[0]);
37+
ExaGOCheckError(ierr);
38+
ierr = PetscLogStageRegister("Set up", &stages[1]);
39+
ExaGOCheckError(ierr);
40+
ierr = PetscLogStageRegister("Solve", &stages[2]);
41+
ExaGOCheckError(ierr);
42+
43+
/* Stage 1 - Application creation and reading data */
44+
ierr = PetscLogStagePush(stages[0]);
45+
ExaGOCheckError(ierr);
46+
47+
ExaGOLog(EXAGO_LOG_INFO, "{}", "Creating DCOPF\n");
48+
49+
/* Create OPFLOW object */
50+
ierr = OPFLOWCreate(comm, &dcopf);
51+
ExaGOCheckError(ierr);
52+
53+
/* Get network data file from command line */
54+
ierr = PetscOptionsGetString(NULL, NULL, "-netfile", file, PETSC_MAX_PATH_LEN,
55+
&flg);
56+
ExaGOCheckError(ierr);
57+
if (flg) {
58+
if (strcasestr(file, ".raw") != NULL) {
59+
ierr = OPFLOWReadPSSERawData(dcopf, file);
60+
ExaGOCheckError(ierr);
61+
} else {
62+
ierr = OPFLOWReadMatPowerData(dcopf, file);
63+
ExaGOCheckError(ierr);
64+
}
65+
} else {
66+
ierr = OPFLOWReadMatPowerData(dcopf, "datafiles/case9/case9mod.m");
67+
ExaGOCheckError(ierr);
68+
}
69+
70+
/* Get gic data file from command line */
71+
ierr = PetscOptionsGetString(NULL, NULL, "-gicfile", gicfile,
72+
PETSC_MAX_PATH_LEN, &flg);
73+
74+
ExaGOCheckError(ierr);
75+
if (flg) {
76+
ierr = OPFLOWSetGICData(dcopf, gicfile);
77+
ExaGOCheckError(ierr);
78+
}
79+
80+
ierr = PetscLogStagePop();
81+
ExaGOCheckError(ierr);
82+
83+
/* Stage 2 - Set up OPFLOW application */
84+
ierr = PetscLogStagePush(stages[1]);
85+
ExaGOCheckError(ierr);
86+
87+
/* Set options with options for DCOPF */
88+
ierr = PetscOptionsSetValue(NULL, "-opflow_model", "DCOPF");
89+
ExaGOCheckError(ierr);
90+
91+
ierr = PetscOptionsSetValue(NULL, "-opflow_initialization", "DCOPF");
92+
ExaGOCheckError(ierr);
93+
94+
/* Set up */
95+
ierr = OPFLOWSetUp(dcopf);
96+
ExaGOCheckError(ierr);
97+
98+
ierr = PetscLogStagePop();
99+
ExaGOCheckError(ierr);
100+
101+
/* Stage 3 - Solve */
102+
ierr = PetscLogStagePush(stages[2]);
103+
ExaGOCheckError(ierr);
104+
105+
/* Solve */
106+
ierr = OPFLOWSolve(dcopf);
107+
ExaGOCheckError(ierr);
108+
109+
ierr = PetscLogStagePop();
110+
ExaGOCheckError(ierr);
111+
112+
if (print_output) {
113+
ierr = OPFLOWPrintSolution(dcopf);
114+
ExaGOCheckError(ierr);
115+
}
116+
117+
if (save_output) {
118+
// deal with "-save_output 0/1" (the way it used to be)
119+
if (strlen(output_name) == 1 && output_name[0] == '1') {
120+
strncpy(output_name, default_output_name, PETSC_MAX_PATH_LEN);
121+
} else if (strlen(output_name) == 1 && output_name[0] == '0') {
122+
save_output = PETSC_FALSE;
123+
} else if (strlen(output_name) == 0) {
124+
strncpy(output_name, default_output_name, PETSC_MAX_PATH_LEN);
125+
}
126+
if (save_output) {
127+
ierr = OPFLOWSaveSolutionDefault(dcopf, output_name);
128+
ExaGOCheckError(ierr);
129+
}
130+
}
131+
132+
/* Destroy OPFLOW object */
133+
ierr = OPFLOWDestroy(&dcopf);
134+
ExaGOCheckError(ierr);
135+
136+
ExaGOFinalize();
137+
return 0;
138+
}

src/utils/utils.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,29 @@ template <typename T> static inline void print(T const &opt) {
408408
// fprintf(stderr, "\t -print_output <0|1>\n");
409409
// fprintf(stderr, "\t -save_output <0|1>\n");
410410
// fprintf(stderr, "\n");
411+
} else if (appname == "dcopflow") {
412+
print(OPFLOWOptions::solver);
413+
print(OPFLOWOptions::objective);
414+
print(OPFLOWOptions::genbusvoltage);
415+
print(OPFLOWOptions::has_gensetpoint);
416+
print(OPFLOWOptions::use_agc);
417+
print(OPFLOWOptions::tolerance);
418+
print(OPFLOWOptions::ignore_lineflow_constraints);
419+
print(OPFLOWOptions::include_loadloss_variables);
420+
print(OPFLOWOptions::loadloss_penalty);
421+
print(OPFLOWOptions::include_powerimbalance_variables);
422+
print(OPFLOWOptions::powerimbalance_penalty);
423+
424+
#ifdef EXAGO_ENABLE_HIOP
425+
print(OPFLOWOptions::hiop_compute_mode);
426+
print(OPFLOWOptions::hiop_verbosity_level);
427+
428+
#ifdef EXAGO_ENABLE_IPOPT
429+
print(OPFLOWOptions::hiop_ipopt_debug);
430+
#endif
431+
432+
#endif
433+
411434
} else if (appname == "pflow") {
412435
/* pflow application driver does not take any additional arguments */
413436
#if defined EXAGO_ENABLE_IPOPT

0 commit comments

Comments
 (0)