Changeset c2c9092 in OpenModelica
- Timestamp:
- 2020-10-21T18:53:49+02:00 (4 years ago)
- Branches:
- maintenance/v1.16
- Children:
- ef0683e
- Parents:
- dae55cf1
- git-author:
- Niklas Worschech <niklas.worschech@…> (09/17/20 14:30:27)
- git-committer:
- Adrian Pop <adrian.pop@…> (10/21/20 18:53:49)
- Location:
- OMCompiler/SimulationRuntime/OMSICpp
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/SimulationRuntime/OMSICpp/omsi/src/omsi.cpp
rce9a30f rc2c9092 48 48 49 49 //OpenModelica Simulation Interface 50 51 52 #include <csignal> 53 54 extern "C" void handle_aborts(int signal_number) 55 { 56 57 std::string error = std::string("Abort was called with error code: ") + to_string(signal_number); 58 throw ModelicaSimulationError(MODEL_EQ_SYSTEM, error); 59 60 } 61 62 63 64 65 50 66 #include <omsi.h> 51 67 … … 56 72 57 73 74 75 76 77 58 78 #if defined(_MSC_VER) || defined(__MINGW32__) 59 79 #include <tchar.h> 80 60 81 61 82 int _tmain(int argc, const _TCHAR* argv[]) … … 64 85 #endif 65 86 { 87 88 //use handle_aborts for abort() calls 89 signal(SIGABRT, &handle_aborts); 66 90 // default program options 67 91 std::map<std::string, std::string> opts; -
OMCompiler/SimulationRuntime/OMSICpp/runtime/include/Core/SimController/threading/Communicator.h
r573788c rc2c9092 32 32 void notifyResults(double time); 33 33 34 void setSimStoped( );34 void setSimStoped(bool success, string erro_message = string("no error has occurred")); 35 35 void setSimStarted(); 36 36 void setSimStopedByException(std::exception& except); -
OMCompiler/SimulationRuntime/OMSICpp/runtime/include/Core/SimController/threading/INotify.h
r573788c rc2c9092 43 43 Simulation has finished 44 44 */ 45 virtual void NotifyFinish( ) = 0;45 virtual void NotifyFinish(bool success, string erro_message = string("no error has occurred")) = 0; 46 46 47 47 /** -
OMCompiler/SimulationRuntime/OMSICpp/runtime/include/Core/SimController/threading/ToZeroMQEvent.h
r573788c rc2c9092 15 15 virtual void NotifyStarted(); 16 16 virtual void NotifyResults(double progress); 17 virtual void NotifyFinish( );17 virtual void NotifyFinish(bool success, string erro_message = string("no error has occurred")); 18 18 virtual void NotifyException(std::string message); 19 19 virtual void NotifyWaitForStarting(); -
OMCompiler/SimulationRuntime/OMSICpp/runtime/include/Core/System/OMSUSystem.h
rce9a30f rc2c9092 13 13 * 14 14 *****************************************************************************/ 15 16 17 15 18 typedef vector<tuple<fmi2_value_reference_t, unsigned int>> out_vars_vr_t; 19 20 21 16 22 17 23 class omsi_me; -
OMCompiler/SimulationRuntime/OMSICpp/runtime/src/Core/SimController/SimController.cpp
r3d14a91e rc2c9092 102 102 shared_ptr<IMixedSystem> system = createSystem(modelLib, modelKey, _config->getGlobalSettings()); 103 103 104 if (system) 105 std::cout << "1 system is here " << modelKey << std::endl; 106 else 107 std::cout << "1 no system is here " << modelKey << std::endl; 104 108 105 109 106 _systems[modelKey] = system; … … 225 222 #endif 226 223 224 225 if (!_startZeroMQ) 226 { 227 //initialize for zeromq simulation is done in simulation thread 227 228 _simMgr->initialize(); 228 229 230 }229 } 230 231 } 231 232 catch (ModelicaSimulationError& ex) 232 233 { -
OMCompiler/SimulationRuntime/OMSICpp/runtime/src/Core/SimController/threading/Communicator.cpp
r3d14a91e rc2c9092 184 184 Indicates simulation thread is finished 185 185 */ 186 void Communicator::setSimStoped( )186 void Communicator::setSimStoped(bool success, string erro_message) 187 187 { 188 188 std::lock_guard<std::mutex> lockGuard(_mutex); … … 191 191 _simstopped = true; 192 192 _stop = true; 193 _notify->NotifyFinish( );193 _notify->NotifyFinish(success,erro_message); 194 194 _simulation_finish.notify_all(); 195 195 } … … 236 236 { 237 237 238 setSimStoped(); 238 239 std::lock_guard<std::mutex> lockGuard(_mutex); 240 //cout << "sim stoped" << std::endl; 241 _paused = false; 242 _simstopped = true; 243 _stop = true; 244 239 245 if (_notify) 240 246 _notify->NotifyException(except.what()); 247 248 _simulation_finish.notify_all(); 241 249 242 250 } … … 257 265 { 258 266 std::lock_guard<std::mutex> lockGuard(_mutex); 259 cout << "gui stoped" << std::endl;267 //cout << "gui stoped" << std::endl; 260 268 _guistopped = true; 261 269 -
OMCompiler/SimulationRuntime/OMSICpp/runtime/src/Core/SimController/threading/SimulationThread.cpp
r3d14a91e rc2c9092 31 31 { 32 32 33 33 34 34 35 35 try … … 47 47 48 48 _simManager = simManager; 49 49 50 bool starting = _communicator->waitForSimulationStarting(1); 51 50 52 if (starting) 51 53 { 52 54 _communicator->setSimStarted(); 53 55 simManager->initialize(); 54 56 55 57 #ifdef RUNTIME_PROFILING … … 61 63 #endif 62 64 high_resolution_clock::time_point t_s = high_resolution_clock::now(); 65 63 66 simManager->runSimulation(); 64 67 high_resolution_clock::time_point t1 = high_resolution_clock::now(); 65 68 seconds elapsed = duration_cast<std::chrono::seconds>(t1 - t_s); 66 cout << "time for simulation: " << elapsed.count();69 67 70 68 71 … … 104 107 simData->addTimeEntries(time_values); 105 108 } 106 _communicator->setSimStoped(); 109 110 _communicator->setSimStoped(true); 107 111 } 108 112 else 109 113 { 110 114 string error = string("Simulation failed for ") + modelKey; 115 _communicator->setSimStoped(false,error); 111 116 throw ModelicaSimulationError(SIMMANAGER, error); 112 117 } … … 116 121 { 117 122 string error = add_error_info(string("Simulation failed for ") + modelKey, ex.what(), ex.getErrorID()); 123 //_communicator->setSimStopedByException(ex); 124 125 _communicator->setSimStoped(false,error); 118 126 throw ModelicaSimulationError(SIMMANAGER, error, "", ex.isSuppressed()); 119 127 } -
OMCompiler/SimulationRuntime/OMSICpp/runtime/src/Core/SimController/threading/ToZeroMQEvent.cpp
r573788c rc2c9092 25 25 std::this_thread::sleep_for(std::chrono::milliseconds(500)); 26 26 27 //std::cout << "pub port: " << to_string(pubPort)<< " sub port: " << to_string(subPort) << " job id " << zeroMQJobiID << " server thread id " << zeromq_simultaion_thread_id << std::endl;27 28 28 } 29 29 ToZeroMQEvent::~ToZeroMQEvent() … … 59 59 void ToZeroMQEvent::NotifyWaitForStarting() 60 60 { 61 //std::cout << "Wating for ID" << std::endl;61 62 62 s_sendmore(publisher_, _zeromq_server_id); 63 63 s_sendmore(publisher_, "SimulationThreadWatingForID"); … … 86 86 if (!message.empty()) 87 87 { 88 // std::cout << "received topic" << message << std::endl;88 89 89 // Read message contents 90 90 std::string type = s_recv(subscriber_,false); 91 std::cout << "received type " << type << std::endl;91 92 92 if (type == "StopSimulationThread") 93 93 { … … 101 101 102 102 103 void ToZeroMQEvent::NotifyFinish( )103 void ToZeroMQEvent::NotifyFinish(bool success, string erro_message) 104 104 { 105 105 if (!_zeromq_job_id.empty()) … … 107 107 s_sendmore(publisher_, _zeromq_client_id); 108 108 s_sendmore(publisher_, "SimulationFinished"); 109 s_send(publisher_, "{\"Succeeded\":true,\"JobId\":\"" + _zeromq_job_id + "\",\"ResultFile\":\"\",\"Error\":\"\"}"); 109 string sim_success; 110 if(success) 111 sim_success = "true"; 112 else 113 sim_success = "false"; 114 string finished = string("{\"Succeeded\":") + sim_success + string(",\"JobId\":\"") + _zeromq_job_id + string("\",\"ResultFile\":\"\",\"Error\":\"") + erro_message +string("\"}"); 115 s_send(publisher_,finished.c_str()); 110 116 } 111 117 else … … 115 121 void ToZeroMQEvent::NotifyException(std::string message) 116 122 { 117 123 if (!_zeromq_job_id.empty()) 124 { 125 s_sendmore(publisher_, _zeromq_client_id); 126 s_sendmore(publisher_, "SimulationFinished"); 127 string finished = string("{\"Succeeded\":false,\"JobId\":\"") + _zeromq_job_id + string("\",\"ResultFile\":\"\",\"Error\":\"") + message + string("\"}"); 128 129 s_send(publisher_,finished.c_str()); 130 } 131 else 132 throw ModelicaSimulationError(SIMMANAGER, "No simulation id received"); 118 133 119 134 } … … 127 142 s_send(publisher_, "{\"JobId\":\"" + _zeromq_job_id + "\"}"); 128 143 } 144 else 145 throw ModelicaSimulationError(SIMMANAGER, "No simulation id received"); 129 146 } 130 147
Note: See TracChangeset
for help on using the changeset viewer.