Skip to content

Commit

Permalink
Merge pull request #1107 from NREL/ssc_1105
Browse files Browse the repository at this point in the history
Add ssc_module_exec_with_error per @dguittet with filtering to fix #1105
  • Loading branch information
sjanzou authored Dec 8, 2023
2 parents 0a87348 + b5d57bc commit f737221
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions ssc/cmod_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ class cm_hybrid : public compute_module
{
add_var_info(_cm_vtab_hybrid);
}

void ssc_module_exec_with_error(ssc_module_t module, var_table& input, std::string compute_module) {
if (!ssc_module_exec(module, static_cast<ssc_data_t>(&input))) {
std::string str = std::string(compute_module) + " execution error.\n";
int idx = 0;
int type = -1;
while (const char* msg = ssc_module_log(module, idx++, &type, nullptr))
{
if (/*/(type == SSC_NOTICE) || */(type == SSC_WARNING) || (type == SSC_ERROR)) {
str += "\t";
str += std::string(msg);
str += "\n\n";
}
}
ssc_module_free(module);
throw std::runtime_error(str);
}
}

void exec()
{
float percent = 0;
Expand Down Expand Up @@ -120,8 +139,7 @@ class cm_hybrid : public compute_module
var_table& input = compute_module_inputs->table;
ssc_data_set_number(static_cast<ssc_data_t>(&input), "en_batt", 0);


ssc_module_exec(module, static_cast<ssc_data_t>(&input));
ssc_module_exec_with_error(module, input, compute_module);

ssc_data_t compute_module_outputs = ssc_data_create();

Expand Down Expand Up @@ -297,7 +315,7 @@ class cm_hybrid : public compute_module
throw exec_error("hybrid", "No input input_table found for ." + hybridVarTable);
var_table& hybridinput = hybrid_inputs->table;
input.merge(hybridinput, false);
ssc_module_exec(module, static_cast<ssc_data_t>(&input));
ssc_module_exec_with_error(module, input, compute_module);

ssc_data_t compute_module_outputs = ssc_data_create();

Expand Down Expand Up @@ -415,7 +433,7 @@ class cm_hybrid : public compute_module
ssc_data_set_number(static_cast<ssc_data_t>(&input), "system_use_lifetime_output", 1);
ssc_data_set_number(static_cast<ssc_data_t>(&input), "en_batt", 1); // should be done at UI level

ssc_module_exec(module, static_cast<ssc_data_t>(&input));
ssc_module_exec_with_error(module, input, compute_module);

ssc_data_t compute_module_outputs = ssc_data_create();

Expand Down Expand Up @@ -612,7 +630,7 @@ class cm_hybrid : public compute_module
std::string compute_module = financials[i];

ssc_module_t module = ssc_module_create(compute_module.c_str());
ssc_module_exec(module, static_cast<ssc_data_t>(&input));
ssc_module_exec_with_error(module, input, compute_module);


int pidx = 0;
Expand Down

0 comments on commit f737221

Please sign in to comment.