Skip to content

Commit

Permalink
Modified cpp runtime
Browse files Browse the repository at this point in the history
 - outsourced object creation in own classes
 - changed some interface method names
 - removed unused interface methods
 - add get/set method to IContinuous for simulation variables
 - adapted cpp template 
 - adapted cpp fmu template
 - added SimManager for time events and removed time event handling from solver
 - added SimController class to start stop simulation, create Modelica system
 

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16796 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Aug 14, 2013
1 parent 0d7c818 commit 38d3208
Show file tree
Hide file tree
Showing 107 changed files with 4,348 additions and 2,001 deletions.
620 changes: 352 additions & 268 deletions Compiler/Template/CodegenCpp.tpl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -488,15 +488,15 @@ let modelName = '<%lastIdentOfPath(modelInfo.name)%>'
DLLEXT=<%makefileParams.dllext%>
CFLAGS_BASED_ON_INIT_FILE=<%extraCflags%>

CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -I"<%makefileParams.omhome%>/include/omc/cpp" -I"<%makefileParams.omhome%>/include/omc/cpp/Core" -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %>
CFLAGS=$(CFLAGS_BASED_ON_INIT_FILE) -I"<%makefileParams.omhome%>/include/omc/cpp" -I"<%makefileParams.omhome%>/include/omc/cpp/Core" -I"<%makefileParams.omhome%>/include/omc/cpp/SimCoreFactory" -I"$(BOOST_INCLUDE)" <%makefileParams.includes ; separator=" "%> <%makefileParams.cflags%> <%match sopt case SOME(s as SIMULATION_SETTINGS(__)) then s.cflags %>
LDFLAGS=-L"<%makefileParams.omhome%>/lib/omc/cpp" -L$(BOOST_LIBS)

SRC=<%modelName%>.cpp
SRC+= <%modelName%>FMU.cpp
SRC+= Functions.cpp
SRC+= <%algloopcppfilenames(listAppend(allEquations,initialEquations),simCode)%>

LIBS= -lOMCppSystem_static
LIBS= -lOMCppSystem_static -lOMCppDataExchange_static -lOMCppOMCFactory
LIBS+= $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_SERIALIZATION_LIB)
LIBS+= $(LINUX_LIB_DL)

Expand Down
33 changes: 28 additions & 5 deletions SimulationRuntime/cpp/CMakeLists.txt
Expand Up @@ -27,6 +27,7 @@ SET(MODELICA_MODEL "ModelicaSystem")
SET(LIBPREFIX "OMCpp")
SET(SolverName ${LIBPREFIX}Solver)
SET(SystemName ${LIBPREFIX}System)
SET(OMCFactoryName ${LIBPREFIX}OMCFactory)
set(MathName ${LIBPREFIX}Math)
set(ModelicaExternalName ${LIBPREFIX}ModelicaExternalC)
set(SimulationSettings ${LIBPREFIX}SimulationSettings)
Expand All @@ -39,11 +40,13 @@ set(KinsolName ${LIBPREFIX}Kinsol)
set(ModelicaName ${LIBPREFIX}Modelica)
set(NewtonName ${LIBPREFIX}Newton)
set(HybrjName ${LIBPREFIX}Hybrj)
set(DataExchangeName ${LIBPREFIX}DataExchange)

SET(USE_MICO OFF)
SET(REDUCE_DAE OFF)
SET(USE_SUNDIALS ON)

SET(USE_SUNDIALS OFF)
SET(OMC_BUILD ON)
SET(SIMSTER_BUILD OFF)
# Boost
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
Expand All @@ -64,6 +67,14 @@ elseif(MINGW)
SET(LAPACK_LIBRARIES ${LAPACK_MINGW} ${BLAS_MINGW} )

endif()

if(OMC_BUILD)
add_definitions(-DOMC_BUILD)
elseif(SIMSTER_BUILD)
add_definitions(-DSIMSTER_BUILD)
endif()


message(STATUS "Lapack Libraries")
message(STATUS ${LAPACK_LIBRARIES})
# Sundials solvers
Expand Down Expand Up @@ -105,6 +116,7 @@ endif()

link_directories ( ${Boost_LIBRARY_DIRS} )


include_directories (${Boost_INCLUDE_DIR})
include_directories ("${PROJECT_SOURCE_DIR}")
include_directories ("${PROJECT_BINARY_DIR}")
Expand All @@ -113,8 +125,10 @@ message(STATUS "Boost dirs "${Boost_LIBRARY_DIRS} " , " ${Boost_INCLUDE_DIR})

#build of simulation.core
include_directories ("Include/Core")

include_directories ("Include/SimCoreFactory")
add_subdirectory (Core/Math)
add_subdirectory (Core/DataExchange)
add_subdirectory (SimCoreFactory/OMCFactory)
#add system default implemention project
add_subdirectory (Core/System)
#add solver default implemention project
Expand Down Expand Up @@ -186,6 +200,13 @@ GET_FILENAME_COMPONENT(libSolverName ${libSolver} NAME)
GET_TARGET_PROPERTY(libMath ${MathName} LOCATION)
GET_FILENAME_COMPONENT(libMathName ${libMath} NAME)

GET_TARGET_PROPERTY(libDataExchange ${DataExchangeName} LOCATION)
GET_FILENAME_COMPONENT(libDataExchangeName ${libDataExchange} NAME)


GET_TARGET_PROPERTY(libSimObjFactory ${OMCFactoryName} LOCATION)
GET_FILENAME_COMPONENT(libSimObjFactoryName ${libSimObjFactory} NAME)

set (EULER_LIB ${libEulerName})
set (SETTINGSFACTORY_LIB ${libSetFactoryName})
set (MODELICASYSTEM_LIB ${libModelicaName})
Expand All @@ -194,6 +215,9 @@ set (SYSTEM_LIB ${libSystemName})
set (SOLVER_LIB ${libSolverName})
set (MATH_LIB ${libMathName})
set (HYBRJ_LIB ${libHybrjName})
set (SIMOBJFACTORY_LIB ${libSimObjFactoryName})
set (DATAEXCHANGE_LIB ${libDataExchangeName})

# configure a header file to pass some library names
# to the source code which are used to dynamic load and instantiate

Expand Down Expand Up @@ -234,8 +258,7 @@ ENDMACRO(INSTALL_HEADERS_WITH_DIRECTORY)


install (FILES "${PROJECT_BINARY_DIR}/LibrariesConfig.h" DESTINATION include/omc/cpp)
install (FILES "Include/Core/DataExchange/IHistory.h"
DESTINATION include/omc/cpp/Core/DataExchange)



#copy Utils/extension
Expand Down
23 changes: 23 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/CMakeLists.txt
@@ -0,0 +1,23 @@
cmake_minimum_required (VERSION 2.6)

project(${DataExchangeName})

add_library(${DataExchangeName} SHARED SimData.cpp FactoryExport.cpp )
target_link_libraries (${DataExchangeName} ${Boost_LIBRARIES} )

add_library(${DataExchangeName}_static STATIC SimData.cpp )
target_link_libraries (${DataExchangeName}_static ${Boost_LIBRARIES} )

install (TARGETS ${DataExchangeName} DESTINATION lib/omc/${LIBINSTALLEXT})
install (TARGETS ${DataExchangeName}_static DESTINATION lib/omc/${LIBINSTALLEXT})

install (FILES ${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/IHistory.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/ISimVar.h
${CMAKE_SOURCE_DIR}/Include/Core/DataExchange/SimData.h
DESTINATION include/omc/cpp/Core/DataExchange)






31 changes: 31 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/FactoryExport.cpp
@@ -0,0 +1,31 @@
#pragma once

#if defined(__vxworks)



#elif defined(OMC_BUILD)
#include "stdafx.h"
#include <DataExchange/SimData.h>

/* OMC factory*/
using boost::extensions::factory;

BOOST_EXTENSION_TYPE_MAP_FUNCTION {
types.get<std::map<std::string, factory<ISimData > > >()
["SimData"].set<SimData>();
}
#elif defined(SIMSTER_BUILD)
#include "stdafx.h"
#include <DataExchange/SimData.h>

/*Simster factory*/
extern "C" void BOOST_EXTENSION_EXPORT_DECL extension_export_dataExchange(boost::extensions::factory_map & fm)
{
fm.get<ISimData,int>()[1].set<SimData>();
}
#else
error "operating system not supported"
#endif


85 changes: 85 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/SimData.cpp
@@ -0,0 +1,85 @@
#include "StdAfx.h"
#include <DataExchange/SimData.h>



/*Vxworks
* extern "C" ISimData* createSimData()
{
return new SimData();
}
*/

SimData::SimData(void)
{
}


SimData::~SimData(void)
{
}
void SimData::Add(string key,boost::shared_ptr<ISimVar> var)
{
std::pair<string,boost::shared_ptr<ISimVar> > elem(key,var);
std::pair<Objects_type::iterator,bool> p = _sim_vars.insert(elem);
}
ISimVar* SimData::Get(string key)
{
Objects_type::const_iterator iter =_sim_vars.find(key);

//Prüfen ob das Simobjekt in Liste ist.
if(iter!=_sim_vars.end())
{
boost::shared_ptr<ISimVar> obj= iter->second;
return obj.get();
}
else
throw std::invalid_argument("There is no such sim variable " + key);
}

void SimData::addOutputResults(string name,ublas::vector<double> v)
{
std::pair<string,ublas::vector<double> > elem(name,v);
std::pair<OutputResults_type::iterator,bool> p = _result_vars.insert(elem);

}
void SimData::getTimeEntries(vector<double>& time_entries)
{
time_entries = boost::ref(_time_entries);
}


void SimData::addTimeEntries(vector<double> time_entries)
{
_time_entries = time_entries;
}

void SimData::destroy()
{
delete this;
}
void SimData::clearResults()
{
_result_vars.clear();
_time_entries.clear();
}


void SimData::clearVars()
{
_sim_vars.clear();
}
void SimData::getOutputResults(string name,ublas::vector<double>& v)
{
OutputResults_type::const_iterator iter =_result_vars.find(name);

//Prüfen ob die Ergebnisse in Liste ist.
if(iter!=_result_vars.end())
{

v = boost::ref(iter->second);
}
else
throw std::invalid_argument("There is no such output variable " + name);
}

99 changes: 99 additions & 0 deletions SimulationRuntime/cpp/Core/DataExchange/stdafx.h
@@ -0,0 +1,99 @@
// stdafx.h : Includedatei für Standardsystem-Includedateien,
// oder projektspezifische Includedateien, die häufig benutzt, aber
// in unregelmäßigen Abständen geändert werden.
//

#pragma once
#ifndef BOOST_THREAD_USE_DLL
#define BOOST_THREAD_USE_DLL
#endif
#ifndef BOOST_ALL_DYN_LINK
#define BOOST_ALL_DYN_LINK
#endif

#define WIN32_LEAN_AND_MEAN


#include <vector>
#include <map>
#include <string>
#include <ostream> // Use stream for output

#include <boost/ref.hpp>
#include <boost/bind.hpp>
//vxworks #include <boost/function.hpp>
#define BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR
#include <boost/numeric/ublas/storage.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
//vxworks #include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/unordered_map.hpp>
#include <boost/any.hpp>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/math/tools/real_cast.hpp>
using std::vector;
using std::map;
using std::string;
using std::string;
using std::ostream;
using boost::tuple;
using boost::tie;
using namespace boost::numeric;
using namespace std;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::get;
using boost::unordered_map;
typedef ublas::shallow_array_adaptor<double> adaptor_t;
typedef ublas::vector<double, adaptor_t> shared_vector_t;
typedef ublas::matrix<double, adaptor_t> shared_matrix_t;
#include <Policies/FactoryConfig.h>
#include <Math/Constants.h>
#include <Object/IObject.h>
#include <Object/Object.h>
#include <Solver/ISolverSettings.h>
#include <Solver/ISolver.h>
#include <System/IMixedSystem.h>
#include <SimulationSettings/ISettingsFactory.h>
#include <SimulationSettings/ISimControllerSettings.h>
#include <SimulationSettings/IGlobalSettings.h>
#include <System/IAlgloopSolverFactory.h>
#include <System/IMixedSystem.h>
#include <System/ISystemProperties.h>
#include <System/ISystemInitialization.h>
#include <System/IContinuous.h>
#include <System/ITime.h>
#include <System/IEvent.h>
#include <System/IAlgLoop.h>
#include <System/ICoupledSystem.h>
#include <Solver/INonLinSolverSettings.h>
#include <Solver/IAlgLoopSolver.h>
#include <System/IAlgLoopSolverFactory.h>
#include <SimController/ISimController.h>
#include <SimController/ISimData.h>
#include <Extensions/IModelicaCompiler.h>
#include <DataExchange/IHistory.h>
#include <SimController/ISimdata.h>
#include "DataExchange/IHistory.h"











21 changes: 21 additions & 0 deletions SimulationRuntime/cpp/Core/Modelica/FactoryExport.h
@@ -0,0 +1,21 @@
#pragma once

#if defined(__vxworks)

#define BOOST_EXTENSION_SYSTEM_DECL
#define BOOST_EXTENSION_EVENTHANDLING_DECL
#define BOOST_EXTENSION_ALGLOOPDEFAULTIMPL_DECL


#elif defined(OMC_BUILD) || defined(SIMSTER_BUILD)

#define BOOST_EXTENSION_SYSTEM_DECL BOOST_EXTENSION_EXPORT_DECL
#define BOOST_EXTENSION_EVENTHANDLING_DECL BOOST_EXTENSION_EXPORT_DECL
#define BOOST_EXTENSION_ALGLOOPDEFAULTIMPL_DECL BOOST_EXTENSION_EXPORT_DECL

#else
error "operating system not supported"
#endif



0 comments on commit 38d3208

Please sign in to comment.