Skip to content

Commit

Permalink
[OMSI] Add OMSI C library
Browse files Browse the repository at this point in the history
Simulation runtime for FMU/OMSU simulation in ANSI C.

 - Added OMSIC build
   - Added OMSIC to existing omsi-Makefiles
   - Use CMake to build SimultaionRuntime/OMSIC
 - Added OMSIC in Simulation Runtime
   - Using OMSIBase library for base functionalities shared with OMSICpp runtime
   - Wrapper for FMI 2.0 ModelExchange functions
     - Functions for continuous simulation of FMU/OMSU
     - Functions for event simulation of FMU/OMSU
     - Getter and Setter functions for FMU/OMSU
     - Logging and some debugging functionalities
     - Initialization and deallocation of FMU/OMSU
 - Documentation with Doxygen
   - Doxyfile not included

Belonging to [master]:
  - #3059

Co-authored-by: niklwors <niiklas.worschech@boschrexroth.de>
Co-authored-by: wibraun <wbraun@fh-bielefeld.de>

Belonging to [master]:
  - OpenModelica/OMCompiler#3059
  • Loading branch information
AnHeuermann authored and OpenModelica-Hudson committed Apr 23, 2019
1 parent 047112f commit c252b04
Show file tree
Hide file tree
Showing 22 changed files with 4,176 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -101,6 +101,8 @@ SimulationRuntime/opc/ua/open62541.c
SimulationRuntime/opc/ua/libomopcua.dll
SimulationRuntime/OMSI/Build_dynamic/
SimulationRuntime/OMSI/Build_static/
SimulationRuntime/OMSIC/Build_dynamic/
SimulationRuntime/OMSIC/Build_static/

# OpenModelicaSetup
Compiler/OpenModelicaSetup
Expand Down
35 changes: 30 additions & 5 deletions Makefile.omsi.common
Expand Up @@ -8,20 +8,20 @@ CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=$(BUILDTYPE)

CMAKE_CALL=cmake -G $(CMAKE_TARGET) --build . -DPLATFORM=$(PLATFORM) $(CMAKE_FLAGS) $(IS_MINGW32) $(IS_MINGW64) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" -DLIB_OMC=$(LIB_OMC) ..

.PHONY: OMSIBaseClean
.PHONY: OMSIBaseClean OMSICClean


#############################
# Rules for OMSI
#############################

OMSI: OMSIBaseInstall
OMSI: OMSIBaseInstall OMSICInstall



OMSI-clean: OMSIBaseClean
cd $(OMBUILDDIR); \
rm -rf include/omc/omsi; \
OMSI-clean: OMSIBaseClean OMSICClean
cd $(OMBUILDDIR); \
rm -rf include/omc/omsi include/omc/omsic; \
rm -rf $(LIB_OMC)/omsi;


Expand Down Expand Up @@ -87,3 +87,28 @@ OMSIBaseClean:
test -d Build_$(PLATFORM) && cd Build_$(PLATFORM) && $(MAKE) uninstall && $(MAKE) DESTDIR=$(OMBUILDDIR) clean && cd ..; \
rm -R -f Build_$(PLATFORM); \
)


#############################
# Rules for OMSIC libraries
#############################

OMSIC: OMSIBaseInstall
cd SimulationRuntime/OMSIC; \
$(foreach PLATFORM, $(PLATFORMS), \
mkdir -p Build_$(PLATFORM); \
(cd ./Build_$(PLATFORM); echo "change to Build_$(PLATFORM)"; \
$(CMAKE_CALL); \
$(MAKE) ); )

OMSICInstall: OMSIC
cd SimulationRuntime/OMSIC; \
$(foreach PLATFORM, $(PLATFORMS), \
(cd Build_$(PLATFORM); $(MAKE) install);)

OMSICClean:
cd SimulationRuntime/OMSIC; \
$(foreach PLATFORM, $(PLATFORMS), \
test -d Build_$(PLATFORM) && cd Build_$(PLATFORM) && $(MAKE) uninstall && $(MAKE) DESTDIR=$(OMBUILDDIR) clean && cd ..; \
rm -R -f Build_$(PLATFORM); \
)
40 changes: 23 additions & 17 deletions SimulationRuntime/OMSI/include/omsi.h
Expand Up @@ -33,11 +33,13 @@

/** \defgroup OMSI OpenModelica Simulation Interface
*
* Long description of OMSI group.
* \brief OpenModelica Simulation Interface
*
* OpenModelica Simulation Interface generalizing simulation runtimes for C and C++ runtimes.
* Containing base library and solver library used by both runtimes.
*/



/** \addtogroup OMSIBase OMSI Base Library
* \ingroup OMSI
*
Expand Down Expand Up @@ -146,25 +148,29 @@ static const omsi_string log_categories_names[NUMBER_OF_CATEGORIES] = {
};


/* Model FMU/ OSU states */
/**
* Model FMU/ OSU states
*/
typedef enum {
modelInstantiated = 1<<0, /* ME and CS */
modelInitializationMode = 1<<1, /* ME and CS */
modelContinuousTimeMode = 1<<2, /* ME only */
modelEventMode = 1<<3, /* ME only */
modelSlaveInitialized = 1<<4, /* CS only */
modelTerminated = 1<<5, /* ME and CS */
modelError = 1<<6 /* ME and CS */
modelInstantiated = 1<<0, /**< Model is instantiated (ME and CS). */
modelInitializationMode = 1<<1, /**< Model is initialized (ME and CS). */
modelContinuousTimeMode = 1<<2, /**< Model is in continuous time mode (ME only). */
modelEventMode = 1<<3, /**< Model is in event mode (ME only). */
modelSlaveInitialized = 1<<4, /**< Co-Simulation slave is initialized (CS only). */
modelTerminated = 1<<5, /**< Model is terminated (ME and CS). */
modelError = 1<<6 /**< Model errored (ME and CS). */
} ModelState;

/* Event informations */
/**
* Event informations
*/
typedef struct {
omsi_bool newDiscreteStatesNeeded;
omsi_bool terminateSimulation;
omsi_bool nominalsOfContinuousStatesChanged;
omsi_bool valuesOfContinuousStatesChanged;
omsi_bool nextEventTimeDefined;
omsi_real nextEventTime;
omsi_bool newDiscreteStatesNeeded; /**< New discrete states needed. */
omsi_bool terminateSimulation; /**< Terminate simulation. */
omsi_bool nominalsOfContinuousStatesChanged; /**< Nominals of continuous states changed and need to be updated. */
omsi_bool valuesOfContinuousStatesChanged; /**< Values of continuous states changed and need to be updated. */
omsi_bool nextEventTimeDefined; /**< `omsi_true` if next event time is defined. */
omsi_real nextEventTime; /**< Value of next defined event time. */
} omsi_event_info;


Expand Down
91 changes: 91 additions & 0 deletions SimulationRuntime/OMSIC/CMakeLists.txt
@@ -0,0 +1,91 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
SET(CMAKE_VERBOSE_MAKEFILE ON)
MESSAGE(STATUS "CMake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")

PROJECT(OMSICSimulationRuntime)

# enable warnings and use ANSI C compatible compiler
if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected, adding compile flags")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -ansi -pedantic -g")
IF(NOT WIN32)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF()
endif(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Compiling with C flags: ${CMAKE_C_FLAGS}")

if(NOT PLATFORM OR PLATFORM STREQUAL "dynamic")
set(BUILD_SHARED_LIBS ON)
elseif(PLATFORM STREQUAL "static")
set(BUILD_SHARED_LIBS OFF)
else()
endif()

IF(BUILD_SHARED_LIBS)
SET(LIBSUFFIX "")
ELSE(BUILD_SHARED_LIBS)
SET(LIBSUFFIX "_static")
ENDIF(BUILD_SHARED_LIBS)

IF(MSVC)
MESSAGE(STATUS "MSVC")
IF(LIB_OMC)
SET(LIBINSTALLEXT "${LIB_OMC}/omsi/msvc" CACHE STRING "library directory" FORCE)
ELSE(LIB_OMC)
SET(LIBINSTALLEXT "omsi/msvc" CACHE STRING "library directory" FORCE)
ENDIF(LIB_OMC)
ELSE(MSVC)
IF(LIB_OMC)
SET(LIBINSTALLEXT "${LIB_OMC}/omsi" CACHE STRING "library directory" FORCE)
ELSE(LIB_OMC)
SET(LIBINSTALLEXT "omsi" CACHE STRING "library directory" FORCE)
ENDIF(LIB_OMC)
ENDIF(MSVC)
message(STATUS "Libs will be installed in ${CMAKE_INSTALL_PREFIX}/${LIBINSTALLEXT}")


SET(OMSICName ${LIBPREFIX}OMSIC${LIBSUFFIX})

SET(OMSI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../OMSI)

include_directories ("${OMSI_SOURCE_DIR}/include")
include_directories ("${OMSI_SOURCE_DIR}/include/fmi2")
include_directories ("${OMSI_SOURCE_DIR}/base/include")
include_directories ("${OMSI_SOURCE_DIR}/solver/include")

# omsic simulation runtime
ADD_SUBDIRECTORY(src/omsu)


install(FILES
${OMSI_SOURCE_DIR}/include/omsi.h
${OMSI_SOURCE_DIR}/include/omsi_callbacks.h
${OMSI_SOURCE_DIR}/include/omsi_api_functions.h
DESTINATION include/omc/omsi)

install(FILES
${CMAKE_SOURCE_DIR}/include/omsic.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_common.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_helper.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_initialization.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_getters_and_setters.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_continuous_simulation.h
${CMAKE_SOURCE_DIR}/include/omsu/omsu_event_simulation.h
DESTINATION include/omc/omsic)

install(FILES
${CMAKE_SOURCE_DIR}/include/fmi2/fmi2Functions.h
${CMAKE_SOURCE_DIR}/include/fmi2/fmi2FunctionTypes.h
${CMAKE_SOURCE_DIR}/include/fmi2/fmi2TypesPlatform.h
DESTINATION include/omc/omsic/fmi2/)

# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
19 changes: 19 additions & 0 deletions SimulationRuntime/OMSIC/cmake_uninstall.cmake.in
@@ -0,0 +1,19 @@
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

0 comments on commit c252b04

Please sign in to comment.