Skip to content

Commit 85b54b0

Browse files
author
Maksudul Alam
committed
Adds CTest
1 parent 97dfc85 commit 85b54b0

3 files changed

Lines changed: 29 additions & 150 deletions

File tree

src/sopflow/interface/sopflowscen.cpp

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ PetscErrorCode
5151
SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
5252
const char windgenprofile[]) {
5353

54-
// printf("I am being called\n");
5554
PetscErrorCode ierr;
5655
FILE *fp;
5756
char line[MAXLINE];
@@ -96,15 +95,6 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
9695
scen_num -= 1; /* Scenario numbers start with 1 in the file, convert to
9796
zero-based start */
9897

99-
// printf("Parsing scenario number %d\n", scen_num);
100-
101-
// tok2 = strsep(&tok, sep2_dash); // Bus Number
102-
103-
// sscanf(tok2, "%d", &bus[nw]);
104-
// tok3 = strsep(&tok, sep2_dash); // Wind
105-
// tok4 = strsep(&tok, sep2_dash); // Gen ID
106-
// tok5 = strsep(&tok, sep2_dash); // Value
107-
10898
if (scen_num < scenlist->Nscen || scen_num == sopflow->Ns) {
10999
fclose(fp);
110100
PetscFunctionReturn(0);
@@ -122,43 +112,28 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
122112
tok = strtok(NULL, sep_comma);
123113
sscanf(tok, "%lf", &weight);
124114

125-
// printf("Scenario weight = %lf\n", weight);
126-
127115
tok = strtok(NULL, sep_comma);
128116
while (tok != NULL) {
129117

130-
// printf("## tok = %s\n", tok);
131-
132118
GenData gd;
133119

134120
/* Parse generator info */
135121
tok2 = strsep(&tok, sep2_dash); // Bus Number
136122
sscanf(tok2, "%d", &gd.busnum);
137-
// printf("Bus number = %d\n", gd.busnum);
138123
tok3 = strsep(&tok, sep2_dash); // Type (Load or Gen)
139124
tok4 = strsep(&tok, sep2_dash); // CKT
140125
sscanf(tok4, "%d", &genid);
141126
snprintf(gd.id, 3, "%-2d", genid);
142-
// printf("Gen ID = %s\n", gd.id);
143127
tok5 = strsep(&tok, sep2_dash); // Value1
144128
sscanf(tok5, "%lf", &gd.value1);
145-
// printf("Value1 = %lf\n", gd.value1);
146129
tok6 = strsep(&tok, sep2_dash); // Value2
147130
sscanf(tok6, "%lf", &gd.value2);
148-
// printf("Value2 = %lf\n", gd.value2);
149131

150132
gendata.push_back(gd);
151133

152-
// printf("## gd = %d, %s, %lf, %lf\n", gd.busnum, gd.id, gd.value1,
153-
// gd.value2);
154-
155-
// printf("!Token = %s\n", gendata.back());
156134
tok = strtok(NULL, sep_comma);
157-
158-
// printf("## tok = %s\n", tok);
159135
}
160136

161-
// printf("Done Parsing 1 line of Tokens\n");
162137
scenario = &scenlist->scen[scen_num];
163138
forecast = &scenario->forecastlist[scenario->nforecast];
164139
forecast->num = scen_num;
@@ -177,135 +152,15 @@ SOPFLOWReadScenarioData_LoadPQ_SinglePeriod(SOPFLOW sopflow,
177152
ierr = PetscCalloc1(forecast->nele, &forecast->val2);
178153
CHKERRQ(ierr);
179154

180-
181-
// tok = strtok(NULL, sep_comma);
182-
183155
for (i = 0; i < gendata.size(); i++) {
184156
forecast->buses[i] = gendata[i].busnum;
185157
ierr = PetscStrcpy(forecast->id[i], gendata[i].id);
186158
CHKERRQ(ierr);
187-
// sscanf(tok, "%lf", &pg);
188159
forecast->val1[i] = gendata[i].value1;
189160
forecast->val2[i] = gendata[i].value2;
190-
// tok = strtok(NULL, sep_comma);
191161
}
192162

193163
// /* Read scenario weight */
194-
// sscanf(tok, "%lf", &weight);
195-
scenario->prob = weight;
196-
197-
scenario->nforecast++;
198-
scenlist->Nscen++;
199-
}
200-
PetscFunctionReturn(0);
201-
}
202-
203-
/*
204-
SOPFLOWReadScenarioData_Wind_SinglePeriod - Reads the wind data and populates
205-
the scenario list Input Parameters
206-
+ sopflow - SOPFLOW object
207-
. windgenprofile - wind generator profile file
208-
209-
Note: This function reads the wind scenario data for "single period" format
210-
files.
211-
*/
212-
PetscErrorCode
213-
SOPFLOWReadScenarioData_Wind_SinglePeriod_2(SOPFLOW sopflow,
214-
const char windgenprofile[]) {
215-
PetscErrorCode ierr;
216-
FILE *fp;
217-
char line[MAXLINE];
218-
char *out;
219-
PetscInt ngenwind, nw = 0;
220-
char *tok, *tok2;
221-
char sep[] = ",", sep2[] = "_";
222-
PetscReal pg, weight;
223-
int scen_num = 0;
224-
int genid;
225-
int windgenbus[1000];
226-
char windgenid[1000][3];
227-
int i;
228-
ScenarioList *scenlist = &sopflow->scenlist;
229-
Scenario *scenario;
230-
Forecast *forecast;
231-
232-
PetscFunctionBegin;
233-
234-
ngenwind = 1000; // This should be increased for larger cases (?)
235-
fp = fopen(windgenprofile, "r");
236-
if (fp == NULL) {
237-
SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
238-
"Cannot open wind generation profile file %s", windgenprofile);
239-
}
240-
241-
/* First line -- has the bus numbers */
242-
out = fgets(line, MAXLINE, fp);
243-
/* Parse wind generator numbers */
244-
tok = strtok(line, sep);
245-
tok = strtok(NULL, sep); /* Skip first token */
246-
while (tok != NULL) {
247-
if (strcmp(tok, "weight") == 0 || strcmp(tok, "weight\n") == 0 ||
248-
strcmp(tok, "weight\r\n") == 0) {
249-
tok = strtok(NULL, sep);
250-
continue;
251-
}
252-
/* Parse generator info */
253-
tok2 = strsep(&tok, sep2);
254-
sscanf(tok2, "%d", &windgenbus[nw]);
255-
tok2 = strsep(&tok, sep2);
256-
tok2 = strsep(&tok, sep2); /* Skip string "Wind" */
257-
sscanf(tok2, "%d", &genid);
258-
if (nw == ngenwind)
259-
SETERRQ(PETSC_COMM_SELF, PETSC_ERR_SUP,
260-
"Exceeded max. number of wind generators=%d\n", ngenwind);
261-
snprintf(windgenid[nw], 3, "%-2d", genid);
262-
263-
nw++;
264-
tok = strtok(NULL, sep);
265-
}
266-
267-
while ((out = fgets(line, MAXLINE, fp)) != NULL) {
268-
if (strcmp(line, "\r\n") == 0 || strcmp(line, "\n") == 0) {
269-
continue; /* Skip blank lines */
270-
}
271-
272-
tok = strtok(line, sep);
273-
sscanf(tok, "%d", &scen_num); /* Scenario number */
274-
scen_num -= 1; /* Scenario numbers start with 1 in the file, convert to
275-
zero-based start */
276-
277-
if (scen_num < scenlist->Nscen || scen_num == sopflow->Ns) {
278-
fclose(fp);
279-
PetscFunctionReturn(0);
280-
}
281-
282-
scenario = &scenlist->scen[scen_num];
283-
forecast = &scenario->forecastlist[scenario->nforecast];
284-
forecast->num = scen_num;
285-
forecast->type = FORECAST_WIND;
286-
forecast->nele = nw;
287-
ierr = PetscCalloc1(forecast->nele, &forecast->buses);
288-
CHKERRQ(ierr);
289-
ierr = PetscCalloc1(forecast->nele, &forecast->id);
290-
CHKERRQ(ierr);
291-
for (i = 0; i < forecast->nele; i++) {
292-
ierr = PetscCalloc1(3, &forecast->id[i]);
293-
}
294-
ierr = PetscCalloc1(forecast->nele, &forecast->val1);
295-
CHKERRQ(ierr);
296-
297-
tok = strtok(NULL, sep);
298-
for (i = 0; i < nw; i++) {
299-
forecast->buses[i] = windgenbus[i];
300-
ierr = PetscStrcpy(forecast->id[i], windgenid[i]);
301-
CHKERRQ(ierr);
302-
sscanf(tok, "%lf", &pg);
303-
forecast->val1[i] = pg;
304-
tok = strtok(NULL, sep);
305-
}
306-
307-
/* Read scenario weight */
308-
sscanf(tok, "%lf", &weight);
309164
scenario->prob = weight;
310165

311166
scenario->nforecast++;

tests/functionality/sopflow/selfcheck.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct SopflowFunctionalityTestParameters {
99
std::string solver = "";
1010
std::string network = "";
1111
std::string scenfile = "";
12+
std::string loadfile = "";
1213
std::string contingencies = "";
1314
std::string pload = "";
1415
std::string qload = "";
@@ -54,6 +55,7 @@ struct SopflowFunctionalityTestParameters {
5455
set_if_found(solver, values, "solver");
5556
set_if_found(network, values, "network");
5657
set_if_found(scenfile, values, "scenfile");
58+
set_if_found(loadfile, values, "loadfile");
5759
set_if_found(num_scenarios, values, "num_scenarios");
5860
set_if_found(tolerance, values, "tolerance");
5961
set_if_found(warning_tolerance, values, "warning_tolerance");
@@ -139,7 +141,7 @@ struct SopflowFunctionalityTests
139141
};
140142

141143
for (const auto &opt :
142-
{"solver", "network", "scenfile", "num_scenarios", "tolerance"})
144+
{"solver", "network", "num_scenarios", "tolerance"})
143145
ensure_option_available(opt);
144146

145147
bool is_multicontingency = false;
@@ -171,7 +173,10 @@ struct SopflowFunctionalityTests
171173
testcase["description"] = params.description;
172174
testcase["solver"] = params.solver;
173175
testcase["network"] = params.network;
174-
testcase["scenfile"] = params.scenfile;
176+
if (params.loadfile != "")
177+
testcase["loadfile"] = params.loadfile;
178+
else if (params.scenfile != "")
179+
testcase["scenfile"] = params.scenfile;
175180
testcase["num_scenarios"] = params.num_scenarios;
176181
testcase["initialization_type"] = params.initialization_type;
177182

@@ -231,10 +236,19 @@ struct SopflowFunctionalityTests
231236
ExaGOCheckError(ierr);
232237

233238
// Prepend installation directory to scenario data
234-
resolve_datafiles_path(params.scenfile);
235-
ierr = SOPFLOWSetScenarioData(sopflow, SOPFLOW_NATIVE_SINGLEPERIOD, WIND,
239+
if (params.loadfile != ""){
240+
std::cout << "Network: " << params.network << " Using Load File: " << params.loadfile << std::endl;
241+
resolve_datafiles_path(params.loadfile);
242+
ierr = SOPFLOWSetScenarioData(sopflow, SOPFLOW_NATIVE_SINGLEPERIOD, LOAD,
243+
params.loadfile.c_str());
244+
ExaGOCheckError(ierr);
245+
} else if (params.scenfile != ""){
246+
std::cout << "Network: " << params.network << " Using Scenario File: " << params.scenfile << std::endl;
247+
resolve_datafiles_path(params.scenfile);
248+
ierr = SOPFLOWSetScenarioData(sopflow, SOPFLOW_NATIVE_SINGLEPERIOD, WIND,
236249
params.scenfile.c_str());
237-
ExaGOCheckError(ierr);
250+
ExaGOCheckError(ierr);
251+
}
238252

239253
ierr = SOPFLOWSetInitializationType(sopflow, params.initialization_type);
240254
ExaGOCheckError(ierr);

tests/functionality/sopflow/sopflow_multiscenario.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ solver = 'EMPAR'
5353
num_scenarios = 3
5454
num_iters = 0
5555
obj_value = 14316.630954933302
56+
57+
[[testcase]]
58+
description = 'LoadTest'
59+
tolerance = 1e-3
60+
network = 'datafiles/case9/case9mod.m'
61+
loadfile = 'datafiles/case9/10_scenarios_9bus_load.txt'
62+
solver = 'EMPAR'
63+
num_scenarios = 3
64+
num_iters = 0
65+
obj_value = 722.106958693

0 commit comments

Comments
 (0)