diff --git a/OMCompiler/Compiler/Template/CodegenCpp.tpl b/OMCompiler/Compiler/Template/CodegenCpp.tpl index dee71afac69..349a0c5be71 100644 --- a/OMCompiler/Compiler/Template/CodegenCpp.tpl +++ b/OMCompiler/Compiler/Template/CodegenCpp.tpl @@ -1529,14 +1529,14 @@ template simulationMainRunScript(SimCode simCode ,Text& extraFuncs,Text& extraFu let libFolder =simulationLibDir(simulationCodeTarget(),simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace) let libPaths = makefileParams.libPaths |> path => path; separator=";" - + let zermMQParams = if getConfigBool(USE_ZEROMQ_IN_SIM) then '-u true -p <%getConfigInt(ZEROMQ_PUB_PORT)%> -s <%getConfigInt(ZEROMQ_SUB_PORT)%> -i <%getConfigInt(ZEROMQ_SIM_ID)%>' else '' match makefileParams.platform case "linux32" case "linux64" then << #!/bin/sh <%preRunCommandLinux%> - <%execCommandLinux%> ./<%fileNamePrefixx%> <%execParameters%> <%outputParameter%> $* + <%execCommandLinux%> ./<%fileNamePrefixx%> <%execParameters%> <%zermMQParams%> <%outputParameter%> $* >> case "win32" case "win64" then @@ -1545,7 +1545,7 @@ template simulationMainRunScript(SimCode simCode ,Text& extraFuncs,Text& extraFu <%preRunCommandWindows%> REM ::export PATH=<%libFolder%>:$PATH REPLACE C: with /C/ SET PATH=<%home%>/bin;<%libFolder%>;<%libPaths%>;%PATH% - <%moLib%>/<%fileNamePrefixx%>.exe <%execParameters%> <%outputParameter%> + <%moLib%>/<%fileNamePrefixx%>.exe <%execParameters%> <%zermMQParams%> <%outputParameter%> >> end match end match diff --git a/OMCompiler/Compiler/Template/SimCodeTV.mo b/OMCompiler/Compiler/Template/SimCodeTV.mo index f009af8eb7a..b75a31cf8c3 100644 --- a/OMCompiler/Compiler/Template/SimCodeTV.mo +++ b/OMCompiler/Compiler/Template/SimCodeTV.mo @@ -3758,6 +3758,10 @@ package Flags constant ConfigFlag Load_PACKAGE_FILE; constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER; constant ConfigFlag LINEARIZATION_DUMP_LANGUAGE; + constant ConfigFlag USE_ZEROMQ_IN_SIM; + constant ConfigFlag ZEROMQ_PUB_PORT; + constant ConfigFlag ZEROMQ_SUB_PORT; + constant ConfigFlag ZEROMQ_SIM_ID; function set input DebugFlag inFlag; input Boolean inValue; diff --git a/OMCompiler/Compiler/Util/Flags.mo b/OMCompiler/Compiler/Util/Flags.mo index 1bc7eee286b..e639d44d4bf 100644 --- a/OMCompiler/Compiler/Util/Flags.mo +++ b/OMCompiler/Compiler/Util/Flags.mo @@ -1518,6 +1518,22 @@ constant ConfigFlag FULL_ASSC = CONFIG_FLAG(133, "fullASSC", NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(), Util.gettext("Enables full equation replacement for BLT transformation from the ASSC algorithm.")); +constant ConfigFlag USE_ZEROMQ_IN_SIM = CONFIG_FLAG(134, "useZeroMQInSim", + NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(), + Util.gettext("Configures to use zeroMQ in simulation runtime to exchange information via ZeroMQ with other applications")); + +constant ConfigFlag ZEROMQ_PUB_PORT = CONFIG_FLAG(135, "zeroMQPubPort", + NONE(), EXTERNAL(), INT_FLAG(3203), NONE(), + Util.gettext("Configures port number for simulation runtime to send information via ZeroMQ")); + +constant ConfigFlag ZEROMQ_SUB_PORT = CONFIG_FLAG(136, "zeroMQSubPort", + NONE(), EXTERNAL(), INT_FLAG(3204), NONE(), + Util.gettext("Configures port number for simulation runtime to receive information via ZeroMQ")); + +constant ConfigFlag ZEROMQ_SIM_ID = CONFIG_FLAG(137, "zeroMQSimID", + NONE(), EXTERNAL(), INT_FLAG(-1), NONE(), + Util.gettext("Configures the ID with which the simulation is labelled for zeroMQ communication.")); + protected // This is a list of all configuration flags. A flag can not be used unless it's // in this list, and the list is checked at initialization so that all flags are @@ -1655,7 +1671,11 @@ constant list allConfigFlags = { STRICT, LINEARIZATION_DUMP_LANGUAGE, NO_ASSC, - FULL_ASSC + FULL_ASSC, + USE_ZEROMQ_IN_SIM, + ZEROMQ_PUB_PORT, + ZEROMQ_SUB_PORT, + ZEROMQ_SIM_ID }; public function new diff --git a/OMCompiler/SimulationRuntime/cpp/Core/ReduceDAE/com/ModelicaCompiler.cpp b/OMCompiler/SimulationRuntime/cpp/Core/ReduceDAE/com/ModelicaCompiler.cpp index 91ce633f0cd..a404f4d07fe 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/ReduceDAE/com/ModelicaCompiler.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/ReduceDAE/com/ModelicaCompiler.cpp @@ -33,7 +33,7 @@ _model(model) std::cout << "Intialize OMC, use gcc" << std::endl; - status = InitOMC(&_omcPtr,"gcc",omhome); + status = InitOMC(&_omcPtr,"gcc",omhome,""); if(status > 0) { std::cout << "..ok" << std::endl; diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimController/FactoryExport.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimController/FactoryExport.cpp index 5c0676f8d28..1eb74efcde6 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimController/FactoryExport.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimController/FactoryExport.cpp @@ -4,38 +4,8 @@ */ #include #include -#if defined(__vxworks) || defined(__TRICORE__) - - -#include -#include -#include - -extern "C" ISimController* createSimController(PATH library_path, PATH modelicasystem_path) -{ - return new SimController(library_path, modelicasystem_path); -} - -shared_ptr createSimObjects(PATH library_path, PATH modelicasystem_path,IGlobalSettings* settings) -{ - return shared_ptr(new SimObjects(library_path, modelicasystem_path,settings)); -} - -#elif defined(SIMSTER_BUILD) - - - -#include -#include -/*Simster factory*/ -extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export_simcontroller(boost::extensions::factory_map & fm) -{ - fm.get()[1].set(); - // fm.get()[1].set(); -} - -#elif defined(OMC_BUILD) && !defined(RUNTIME_STATIC_LINKING) +#if defined(OMC_BUILD) && !defined(RUNTIME_STATIC_LINKING) #include #include @@ -45,6 +15,8 @@ using boost::extensions::factory; BOOST_EXTENSION_TYPE_MAP_FUNCTION { types.get > >() ["SimController"].set(); +types.get > >() +["SimController"].set(); types.get > >() ["SimObjects"].set(); } diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimController/SimController.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimController/SimController.cpp index 145c0ec8246..3c4b4639df3 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimController/SimController.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimController/SimController.cpp @@ -179,6 +179,9 @@ try global_settings->setSolverThreads(simsettings.solverThreads); global_settings->setInputPath(simsettings.inputPath); global_settings->setOutputPath(simsettings.outputPath); + global_settings->setZeroMQPubPort(simsettings.zeroMQPubPort); + global_settings->setZeroMQSubPort(simsettings.zeroMQSubPort); + _simMgr = shared_ptr(new SimManager(mixedsystem, _config.get())); @@ -210,6 +213,7 @@ catch (ModelicaSimulationError& ex) if(_startZeroMQ) { #if defined(USE_ZEROMQ) + _communicator->initialize(global_settings->getZeroMQPubPort(), global_settings->getZeroMQSubPort(), global_settings->getSimulationID()); _communicator->startThreads(_simMgr, global_settings, mixedsystem, _sim_objects, modelKey); _communicator->waitForAllThreads(120); #elif defined(USE_ZEROMQ) diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/Communicator.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/Communicator.cpp index 7824c312731..a923866e5ba 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/Communicator.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/Communicator.cpp @@ -13,21 +13,9 @@ Communicator::Communicator() , _simstopped(true) ,_guistopped(true) , _stop(false) + ,_isInitialized(false) { - try - { - - - _notify = shared_ptr(new ToZeroMQEvent()); - - - } - catch (std::exception& ex) - { - - std::string error(ex.what()); - - } + } @@ -40,6 +28,25 @@ Communicator::~Communicator() +} + + void Communicator::initialize(int pubPort, int subPort, int simulationID) +{ + try + { + + + _notify = shared_ptr(new ToZeroMQEvent( pubPort, subPort, simulationID)); + + + } + catch (std::exception & ex) + { + + std::string error(ex.what()); + + } + _isInitialized = true; } /** Waits for all threads to end. diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/SimulationThread.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/SimulationThread.cpp index b60ec1a565d..a81db38db4e 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/SimulationThread.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/SimulationThread.cpp @@ -49,7 +49,7 @@ void SimulationThread::Run(shared_ptr simManager, shared_ptrsetSimStarted(); - simManager->initialize(); + #ifdef RUNTIME_PROFILING if (MeasureTime::getInstance() != NULL) diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/ToZeroMQEvent.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/ToZeroMQEvent.cpp index 56062bfa5ee..e1b08443835 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/ToZeroMQEvent.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimController/threading/ToZeroMQEvent.cpp @@ -8,14 +8,14 @@ // Short alias for this namespace namespace pt = boost::property_tree; -ToZeroMQEvent::ToZeroMQEvent() +ToZeroMQEvent::ToZeroMQEvent(int pubPort, int subPort, int simulationID) :ctx_(1), publisher_(ctx_, ZMQ_PUB), subscriber_(ctx_, ZMQ_SUB), - _simulation_id("") + _simulation_id(std::to_string(simulationID)) { - publisher_.connect("tcp://127.0.0.1:3203"); - subscriber_.connect("tcp://127.0.0.1:3204"); + publisher_.connect("tcp://127.0.0.1:" + to_string(pubPort)); + subscriber_.connect("tcp://127.0.0.1:" + to_string(subPort)); subscriber_.setsockopt(ZMQ_SUBSCRIBE, "OMCSimultionThread", 18); //Needed to establish connection std::this_thread::sleep_for(std::chrono::milliseconds(500)); diff --git a/OMCompiler/SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp b/OMCompiler/SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp index 143916fba16..0db8cc703db 100644 --- a/OMCompiler/SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp +++ b/OMCompiler/SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp @@ -23,6 +23,9 @@ GlobalSettings::GlobalSettings() , _outputPointType(OPT_ALL) , _alarm_time(0) , _outputFormat(MAT) + ,_zeroMQ_pub_port(3203) + ,_zeroMQ_sub_port(3204) + ,_simulation_id(-1) { } @@ -229,4 +232,32 @@ int GlobalSettings::getSolverThreads() { _outputFormat = outputFormat; } + + + void GlobalSettings::setZeroMQPubPort(int pubPort) + { + _zeroMQ_pub_port = pubPort; + } + int GlobalSettings::getZeroMQPubPort() + { + return _zeroMQ_pub_port; + } + + void GlobalSettings::setZeroMQSubPort(int subPort) + { + _zeroMQ_sub_port = subPort; + } + int GlobalSettings::getZeroMQSubPort() + { + return _zeroMQ_sub_port; + } + + void GlobalSettings::setSimulationID(int id) + { + _simulation_id = id; + } + int GlobalSettings::getSimulationID() + { + return _simulation_id; + } /** @} */ // end of coreSimulationSettings diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/ISimController.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/ISimController.h index 462146aba66..5579a91ddd3 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/ISimController.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/ISimController.h @@ -25,6 +25,10 @@ struct SimSettings EmitResults emitResults; string inputPath; string outputPath; + bool useZeroMQ; + int zeroMQPubPort; + int zeroMQSubPort; + int simulationID; }; /** diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/Communicator.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/Communicator.h index dc1955d6fba..7783338ced0 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/Communicator.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/Communicator.h @@ -27,7 +27,7 @@ class Communicator virtual void startPause(); virtual void stopPause(); virtual bool shouldStop(); - + virtual void initialize(int pubPort, int subPort, int simulationID); void notifyResults(double time); @@ -61,7 +61,7 @@ class Communicator bool _paused; double _end_time; shared_ptr _sim_thread; - + bool _isInitialized; }; diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/ToZeroMQEvent.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/ToZeroMQEvent.h index a54dc7aa05a..ff2690434e1 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/ToZeroMQEvent.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimController/threading/ToZeroMQEvent.h @@ -9,7 +9,7 @@ class ToZeroMQEvent: public INotify { public: - ToZeroMQEvent( ); + ToZeroMQEvent(int pubPort, int subPort, int simulationID); ~ToZeroMQEvent(); virtual void NotifyStarted(); diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/GlobalSettings.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/GlobalSettings.h index 4442452da24..f26518b9851 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/GlobalSettings.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/GlobalSettings.h @@ -64,6 +64,14 @@ class GlobalSettings : public IGlobalSettings virtual void setSolverThreads(int); virtual int getSolverThreads(); + virtual void setZeroMQPubPort(int); + virtual int getZeroMQPubPort(); + + virtual void setZeroMQSubPort(int); + virtual int getZeroMQSubPort() ; + + virtual void setSimulationID(int); + virtual int getSimulationID(); private: double _startTime, ///< Start time of integration (default: 0.0) @@ -89,5 +97,8 @@ class GlobalSettings : public IGlobalSettings int _solverThreads; OutputFormat _outputFormat; + int _zeroMQ_pub_port; + int _zeroMQ_sub_port; + int _simulation_id; }; /** @} */ // end of coreSimulationSettings diff --git a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/IGlobalSettings.h b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/IGlobalSettings.h index cc4b3e3e4a0..abc21c72e2e 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/IGlobalSettings.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/Core/SimulationSettings/IGlobalSettings.h @@ -103,5 +103,15 @@ class IGlobalSettings virtual void setSolverThreads(int) = 0; virtual int getSolverThreads() = 0; + + virtual void setZeroMQPubPort(int) = 0; + virtual int getZeroMQPubPort() = 0; + + virtual void setZeroMQSubPort(int) = 0; + virtual int getZeroMQSubPort() = 0; + + + virtual void setSimulationID(int) = 0; + virtual int getSimulationID() = 0; }; /** @} */ // end of coreSimulationSettings diff --git a/OMCompiler/SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h b/OMCompiler/SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h index acdc8d3e222..05b53839708 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h @@ -59,5 +59,11 @@ class FMUGlobalSettings : public IGlobalSettings virtual int getSolverThreads() { return 1; }; virtual OutputFormat getOutputFormat() {return EMPTY;}; virtual void setOutputFormat(OutputFormat) {}; + virtual void setZeroMQPubPort(int) {}; + virtual int getZeroMQPubPort() { return -1; }; + virtual void setZeroMQSubPort(int) {}; + virtual int getZeroMQSubPort() { return -1; }; + virtual void setSimulationID(int) {}; + virtual int getSimulationID() { return -1; }; private: }; diff --git a/OMCompiler/SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h b/OMCompiler/SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h index 4559fd9272b..4e36f741a57 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h @@ -91,5 +91,11 @@ class FMU2GlobalSettings : public IGlobalSettings virtual int getSolverThreads() { return 1; }; virtual OutputFormat getOutputFormat() {return EMPTY;}; virtual void setOutputFormat(OutputFormat) {}; + virtual void setZeroMQPubPort(int) {}; + virtual int getZeroMQPubPort() { return -1; }; + virtual void setZeroMQSubPort(int) {}; + virtual int getZeroMQSubPort() { return -1; }; + virtual void setSimulationID(int) {}; + virtual int getSimulationID() { return -1; }; }; /** @} */ // end of fmu2 diff --git a/OMCompiler/SimulationRuntime/cpp/Include/SimCoreFactory/OMCFactory/OMCFactory.h b/OMCompiler/SimulationRuntime/cpp/Include/SimCoreFactory/OMCFactory/OMCFactory.h index a8bfc84811a..fc6a9bfd93d 100644 --- a/OMCompiler/SimulationRuntime/cpp/Include/SimCoreFactory/OMCFactory/OMCFactory.h +++ b/OMCompiler/SimulationRuntime/cpp/Include/SimCoreFactory/OMCFactory/OMCFactory.h @@ -97,5 +97,6 @@ class OMCFactory unordered_set _argumentsToIgnore; //a set of arguments that should be ignored std::map _argumentsToReplace; //a mapping to replace arguments (e.g. -r=... -> -F=...) std::string _overrideOMEdit; // unrecognized options if called from OMEdit + bool _use_zeroMQ; }; /** @} */ // end of simcorefactoryOMCFactory diff --git a/OMCompiler/SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp b/OMCompiler/SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp index 32222dbe746..4f8056c4290 100644 --- a/OMCompiler/SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp +++ b/OMCompiler/SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp @@ -107,6 +107,7 @@ OMCFactory::OMCFactory(PATH library_path, PATH modelicasystem_path) , _defaultLinSolver("linearSolver") #endif , _defaultNonLinSolver("kinsol") + , _use_zeroMQ(false) { fillArgumentsToIgnore(); fillArgumentsToReplace(); @@ -121,6 +122,7 @@ OMCFactory::OMCFactory() , _defaultLinSolver("linearSolver") #endif , _defaultNonLinSolver("kinsol") + , _use_zeroMQ(false) { fillArgumentsToIgnore(); fillArgumentsToReplace(); @@ -332,7 +334,11 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[]) ("output-type,O", po::value< string >()->default_value("all"), "the points in time written to result file: all (output steps + events), step (just output points), none") ("output-format,P", po::value< string >()->default_value("mat"), "simulation results output format: csv, mat, buffer, empty") ("emit-results,U", po::value< string >()->default_value("public"), "emit results: all, public, none") - ; + ("use-zeromq,u", po::value()->default_value(false), "use zeromq for communication during simulation with other applications") + ("port-publish,p", po::value()->default_value(3203), "zeromq publishing port") + ("port-subscribe,s", po::value()->default_value(3204), "zeromq subscribing port") + ("simlation-ID,i", po::value()->default_value(-1), "ID that identifies the translation and simulation for one model") + ; // a group for all options that should not be visible if '--help' is set po::options_description descHidden("Hidden options"); @@ -471,13 +477,35 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[]) "Unknown emit-results " + emitResults_str); } + int port_pub =3203; + int port_sub = 3204; + int simulation_id = -1; + + if (vm.count("port-publish")) + { + port_pub = vm["port-publish"].as(); + } + + if (vm.count("port-subscribe")) + { + port_sub = vm["port-subscribe"].as(); + } + + if (vm.count("simlation-ID")) + { + simulation_id = vm["simlation-ID"].as(); + } + if (vm.count("use-zeromq")) + { + _use_zeroMQ = vm["use-zeromq"].as(); + } fs::path libraries_path = fs::path( runtime_lib_path) ; fs::path modelica_path = fs::path( modelica_lib_path) ; libraries_path.make_preferred(); modelica_path.make_preferred(); - SimSettings settings = {solver, linSolver, nonLinSolver, starttime, stoptime, stepsize, 1e-24, 0.01, tolerance, resultsfilename, timeOut, outputPointType, logSettings, nlsContinueOnError, solverThreads, outputFormat, emitResults, inputPath, outputPath}; + SimSettings settings = {solver, linSolver, nonLinSolver, starttime, stoptime, stepsize, 1e-24, 0.01, tolerance, resultsfilename, timeOut, outputPointType, logSettings, nlsContinueOnError, solverThreads, outputFormat, emitResults, inputPath, outputPath,_use_zeroMQ ,port_pub ,port_sub,simulation_id }; _library_path = libraries_path.string(); _modelicasystem_path = modelica_path.string(); @@ -677,13 +705,13 @@ shared_ptr OMCFactory::loadSimControllerLib(PATH simcontroller_p if (result != LOADER_SUCCESS) throw ModelicaSimulationError(MODEL_FACTORY,string("Failed loading SimConroller library!") + simcontroller_path); - map >::iterator iter; - map >& factories(simcontroller_type_map.get()); + map >::iterator iter; + map >& factories(simcontroller_type_map.get()); iter = factories.find("SimController"); if (iter ==factories.end()) throw ModelicaSimulationError(MODEL_FACTORY,"No such SimController library"); - return shared_ptr(iter->second.create(_library_path, _modelicasystem_path)); + return shared_ptr(iter->second.create(_library_path, _modelicasystem_path, _use_zeroMQ)); } /** @} */ // end of simcorefactoryOMCFactory diff --git a/OMCompiler/SimulationRuntime/cpp/omcWrapper/CMakeLists.txt b/OMCompiler/SimulationRuntime/cpp/omcWrapper/CMakeLists.txt index 2d3a7b82e03..15d9b6a4081 100644 --- a/OMCompiler/SimulationRuntime/cpp/omcWrapper/CMakeLists.txt +++ b/OMCompiler/SimulationRuntime/cpp/omcWrapper/CMakeLists.txt @@ -58,7 +58,7 @@ ENDIF(ZeroMQ_FOUND AND cppzmq_FOUND) #in Visual Studio command prompt: #dumpbin /exports libOMCDLL.dll > libOMCDLL.def #remove all symbols except the function names -#->Exports +#->EXPORTS #->fun1 #->fun2 #lib /def:libOMCDLL.def /out:libOMCDLL.lib /machine:[x86,x64] diff --git a/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/include/OMC.h b/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/include/OMC.h index f4c429f956c..7e4f7828cae 100644 --- a/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/include/OMC.h +++ b/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/include/OMC.h @@ -14,10 +14,12 @@ extern "C" /** * \brief Allocates and initializes OpenModelica compiler(omc) instance * \param [in] compiler name of c++ compiler (gcc for mingw compiler, msvc10 for Visual Studio 2010 compiler,msvc12 for Visual Studio 2012 compiler ...) + * \param [in] zeromqOptions configure us of zeromq in simulationruntime with: --useZeroMQInSim [true,false] --zeroMQSimID=[ID for simulation run] --zeroMQPubPort=[portnumber] --zeroMQSubPort=[portnumber] + * \param [out] omcPtr pointer to allocated omc instance * \return returns a status flag */ - int OMC_DLL InitOMC(data** omcDataPtr, const char* compiler, const char* openModelicaHome); + int OMC_DLL InitOMC(data** omcDataPtr, const char* compiler, const char* openModelicaHome, const char* zeromqOptions); /** * \brief returns the version of the OpenModelica compiler (omc) instance * \param [in] omcPtr Pointer to omc instance diff --git a/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/src/OMC.cpp b/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/src/OMC.cpp index bc9b7a1f3b8..c95bd939279 100644 --- a/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/src/OMC.cpp +++ b/OMCompiler/SimulationRuntime/cpp/omcWrapper/omcCAPI/src/OMC.cpp @@ -39,7 +39,7 @@ extern "C" { mmc_GC_init(); } - int InitOMC(OMCData** omcDataPtr, const char* compiler, const char* openModelicaHome) + int InitOMC(OMCData** omcDataPtr, const char* compiler, const char* openModelicaHome, const char* zeromqOptions) { // alloc omcData OMCData* omcData = new OMCData((threadData_t*)GC_malloc_uncollectable(sizeof(threadData_t))); @@ -59,12 +59,23 @@ extern "C" { MMC_CATCH_TOP(return -1) - - std::string options = "+d=execstat --simCodeTarget=Cpp --target=" + std::string(compiler); + char* result = 0; + /* std::string set_openmodelica_home = std::string("setInstallationDirectoryPath(\"") + openModelicaHome + std::string("\")"); + int status = SendCommand(omcData, set_openmodelica_home.c_str(), &result); + if (status < 0) + { + std::cout << " Could not set OpenModelica home path"<< std::endl; + return -1; + }*/ + //std::cout << "set OpenModelica home path " << set_openmodelica_home << result << std::endl; + + std::string options = "+d=execstat --simCodeTarget=Cpp --target=" + std::string(compiler) + " "+ std::string(zeromqOptions); std::cout << "options " << options << "\n"; if (SetCommandLineOptions(omcData, options.c_str()) == -1) { - std::cout << "could not set OpenModelica options: " << options << std::endl; + char* errorMsg = 0; + GetError(omcData, &errorMsg); + std::cout << "could not set OpenModelica options: " << options <<" "<< *errorMsg < #include #include "zhelpers.hpp" - - +#include +#include "stdlib.h" OMCData* omc; // Short alias for this namespace @@ -33,22 +33,24 @@ using std::string; -void initOMC(OMCData** omc, string compiler) +void initOMC(OMCData** omc, string compiler, string openmodelicaHome , string zeroMQOptions) { + + int status = 0; + + //std::cout << "Initialize OMC" << std::endl; InitMetaOMC(); - int status = 0; + char* change_dir_results = 0, *mkDirResults = 0, *version = 0, *errorMsg2 = 0, *simulateResult = 0, *clear = 0; // if you send in 1 here it will crash on Windows, i need do debug more why this happens - status = InitOMC(omc, compiler.c_str(), ""); - /* - if (status > 0) - std::cout << "init omc using compiler " << compiler << ": ok" << std::endl; - else - std::cout << "init omc: failed" << std::endl; - */ + status = InitOMC(omc, compiler.c_str(), openmodelicaHome.c_str(), zeroMQOptions.c_str()); + + if (status < 0) + throw std::invalid_argument("Coudl not iniitialize omc"); + } string getVersion(OMCData* omc) @@ -125,10 +127,13 @@ int main(int argc, const char* argv[]) else throw std::invalid_argument("Path for OpenModelica home was not passed"); - - initOMC(&omc, "msvc15"); + string zeromqOptions = "--useZeroMQInSim=true --zeroMQSimID=" + std::to_string(simulation_id) + " --zeroMQPubPort=" + std::to_string(port_pub) + " --zeroMQSubPort=" + std::to_string(port_sub); + initOMC(&omc, "msvc15", openmodelica_home_path,zeromqOptions); string version = getVersion(omc); std::cout << "used omc version: " << version << std::endl; + char* result = 0; + int status = SendCommand(omc, "getInstallationDirectoryPath()", &result); + std::cout << result << std::endl; }