| 972 | } |
| 973 | |
| 974 | bool Simulation::InvokeSSCWithHandler(ISimulationHandler* ih, ssc_data_t p_data) |
| 975 | { |
| 976 | assert(0 != ih); |
| 977 | |
| 978 | m_totalElapsedMsec = 0; |
| 979 | m_sscElapsedMsec = 0; |
| 980 | wxStopWatch sw; |
| 981 | |
| 982 | |
| 983 | if (m_simlist.size() == 0) |
| 984 | ih->Error("No simulation compute modules defined for this configuration."); |
| 985 | |
| 986 | // // Warning - be careful here if threading! |
| 987 | // std::ifstream test(fn.ToStdString().c_str()); |
| 988 | // std::string json_str((std::istreambuf_iterator<char>(test)), std::istreambuf_iterator<char>()); |
| 989 | // auto p_data = json_to_ssc_data(json_str.c_str()); |
| 990 | |
| 991 | // if (!JSONInputsToSSCData(fn, p_data)) { |
| 992 | // ih->Error(ssc_data_get_string(p_data, "error")); |
| 993 | // } |
| 994 | |
| 995 | for (size_t kk = 0; kk < m_simlist.size(); kk++) |
| 996 | { |
| 997 | ssc_module_t p_mod = ssc_module_create(m_simlist[kk].c_str()); |
| 998 | if (!p_mod) { |
| 999 | wxString err = "could not create ssc module: " + m_simlist[kk]; |
| 1000 | ssc_data_set_string(p_data, "error", err.c_str()); |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
| 1004 | // if (m_bSscTestsGeneration) |
| 1005 | // WriteSSCTestInputs(m_simlist[kk], p_mod, p_data); |
| 1006 | |
| 1007 | // optionally write a debug input file if the ISimulationHandler defines it |
| 1008 | // wxString fn = folder + "/ssc-" + m_simlist[kk] + ".lk"; |
| 1009 | // ih->WriteDebugFile(fn, p_mod, p_data); |
| 1010 | //ih->WriteDebugFile( m_simlist[kk], p_mod, p_data ); |
| 1011 | |
| 1012 | wxStopWatch ssctime; |
| 1013 | ssc_bool_t ok = ssc_module_exec_with_handler(p_mod, p_data, ssc_invoke_handler, ih); |
| 1014 | m_sscElapsedMsec += (int)ssctime.Time(); |
| 1015 | |
| 1016 | if (!ok) |
| 1017 | { |
| 1018 | ih->Error("Simulation " + m_simlist[kk] + " failed :" + ssc_module_log(p_mod, 0, nullptr, nullptr)); |
| 1019 | } |
| 1020 | else |
| 1021 | { |
| 1022 | int pidx = 0; |
| 1023 | while (const ssc_info_t p_inf = ssc_module_var_info(p_mod, pidx++)) |
| 1024 | { |
| 1025 | int var_type = ssc_info_var_type(p_inf); // SSC_INPUT, SSC_OUTPUT, SSC_INOUT |
| 1026 | int data_type = ssc_info_data_type(p_inf); // SSC_STRING, SSC_NUMBER, SSC_ARRAY, SSC_MATRIX |
| 1027 | const char* name = ssc_info_name(p_inf); // assumed to be non-null |
| 1028 | wxString label(ssc_info_label(p_inf)); |
| 1029 | wxString units(ssc_info_units(p_inf)); |
| 1030 | wxString ui_hint(ssc_info_uihint(p_inf)); |
| 1031 |
no test coverage detected