Skip to content

Commit

Permalink
[OMSI] Add OMSIBase library with solvers
Browse files Browse the repository at this point in the history
Going to be used by OMSIC and OMSICPP libraries.

- Created build structure with Makefiles and CMake
  - Added OMSI to omc target in top Makefile
  - Added OMSI/omsi-clean target to Makefiles
  - Added Makefile.omsi.common with build rules for all OMSI stuff
  - Use CMake build for SimulationRuntime/OMSI
- Added OMSI in Simulation Runtime
  - OMSIBase library contains base functions for
    - data handling
    - event handling
    - solving loops
    - handling xml and json files
    - initialiazing/ freeing stuff
    - utility functions
  - OMSISolver library contains solver and interface
    - general solver API
    - KINSOL solver
    - LAPCAK solver
  - Data types
    - omsi.h contains most important definitions
    - omsi_solver.h
- Documentation with Doxygen
  - Doxyfile not included

Belonging to [master]:
  - OpenModelica/OMCompiler#2986

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

Belonging to [master]:
  - OpenModelica/OMCompiler#2986
  • Loading branch information
AnHeuermann authored and OpenModelica-Hudson committed Mar 26, 2019
1 parent f881685 commit e3fab53
Show file tree
Hide file tree
Showing 48 changed files with 11,895 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile.common
Expand Up @@ -374,9 +374,9 @@ openblas-clean:
test ! -d 3rdParty/OpenBLAS-0.2.8 || $(MAKE) -C 3rdParty/OpenBLAS-0.2.8 clean > /dev/null 2>&1

ifeq ($(OMENCRYPTION),yes)
clean: semla-clean fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean metis-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean umfpack-clean
clean: semla-clean fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean metis-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean umfpack-clean OMSI-clean
else
clean: fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean metis-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean umfpack-clean
clean: fmil-clean opencl_rt_clean gc-clean lis-clean runtimeCPPclean CMinpack-clean metis-clean Cdaskr-clean bootstrap-clean msgpack-clean graphstream-clean openblas-clean umfpack-clean OMSI-clean
endif
(cd SimulationRuntime/c && $(MAKE) -f $(defaultMakefileTarget) clean OMBUILDDIR=$(OMBUILDDIR))
(cd Compiler && $(MAKE) -f $(defaultMakefileTarget) clean OMBUILDDIR=$(OMBUILDDIR))
Expand Down
5 changes: 3 additions & 2 deletions Makefile.in
Expand Up @@ -74,15 +74,16 @@ MINGW_EXTRA_LIBS=@MINGW_EXTRA_LIBS@
SUITESPARSE_LIBS = -DKLU_LIBRARY="libklu$(SHREXT)" -DAMD_LIBRARY="libamd$(SHREXT)" -DCOLAMD_LIBRARY="libcolamd$(SHREXT)" -DBTF_LIBRARY="libbtf$(SHREXT)"

include Makefile.common
include Makefile.omsi.common

# We don't need OMDEV hacks, but using the same Makefile sure is nice!
.testvariables:
settings:

ifeq ($(OMENCRYPTION),yes)
omc: semla omc-bootstrapped
omc: semla omc-bootstrapped OMSI
else
omc: omc-bootstrapped
omc: omc-bootstrapped OMSI
endif

boehm-gc-lib: @LIBGC@
Expand Down
11 changes: 6 additions & 5 deletions Makefile.omdev.mingw
Expand Up @@ -13,7 +13,7 @@ ifeq (clang,$(findstring clang,$(CC)))
endif

# makefile for Windows MinGW OMDev
all : .testvariables settings omc
all : .testvariables settings omc

autoconfGeneratedFiles =

Expand Down Expand Up @@ -93,6 +93,9 @@ BOOTSTRAP_FMIL_DEP=fmil
defaultMakefileTarget = Makefile.omdev.mingw
MAKEFILE_BOOT = LinkMain.makefile.mingw

include Makefile.common
include Makefile.omsi.common

# For Windows build static FMI lib!
FMILIB_SHARED = OFF
# For Windows build static CMinpack lib!
Expand All @@ -105,8 +108,6 @@ else # mingw64
PLATFORM_ARCH = (64-bit)
endif

include Makefile.common

getMSVCversion:
echo "Check for given VSVERSION (2010|2012|2013|2015) version: [VSVERSION=$(VSVERSION)]"
ifeq ("$(VSVERSION)","")
Expand Down Expand Up @@ -281,9 +282,9 @@ copycppmsvcheader: getMSVCversion
(cp -pufr $(BOOST_PATH_MSVC)/boost/* $(OMBUILDDIR)/include/omc/cpp/3rdParty/boost/msvc/boost)

ifeq ($(OMENCRYPTION),yes)
omc: interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream semla
omc: interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream semla OMSI
else
omc: interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream
omc: interactive fmil omdev_extra_dlls breakprocess opencl_rt CMinpack metis Cdaskr $(IPOPT_TARGET) graphstream OMSI
endif
(time $(MAKE) -f $(defaultMakefileTarget) CFLAGS="$(CFLAGS)" omc-bootstrapped OMBUILDDIR=$(OMBUILDDIR))

Expand Down
86 changes: 86 additions & 0 deletions Makefile.omsi.common
@@ -0,0 +1,86 @@
# Makefile for build omsi base libraries

# Specify a list of target platforms, including dynamic, static
PLATFORMS=static dynamic


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


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

OMSI: OMSIBaseInstall



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


#############################
# Rules for OMSIBase library
#############################

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

OMSIBaseMSVC: getMSVCversion
test -f """${VSCOMNTOOLS}/../../VC/vcvarsall.bat"""
echo 'Build the cppRuntime with MSVC' buildtype: $(BUILDTYPE)
#rm -rf Build_MSVC
mkdir -p Build_MSVC
echo call '"${VSCOMNTOOLS}\\..\\..\\VC\\vcvarsall.bat" ${VCVARS_PARAMS}' > Build_MSVC/build.bat

echo echo Running CMake from '%OMDEV%\\bin\\cmake\\bin\\cmake' >> Build_MSVC/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DPLATFORM="dynamic" $(CMAKE_FLAGS) -DIS_MINGW32=OFF -DIS_MINGW64=OFF -DCMAKE_INSTALL_PREFIX:PATH=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC/build.bat

# for some reason, the environment variable 'MAKEFLAGS' was set to 'w' on my and Niklas' machine?!
echo set MAKEFLAGS="" >> Build_MSVC/build.bat
echo echo Running NMake JOM >> Build_MSVC/build.bat
echo %OMDEV%\\tools\\jom\\jom.exe /f Makefile install >> Build_MSVC/build.bat
cd ./Build_MSVC; echo "change to Build_MSVC";\
cmd /c build.bat

echo 'Build cppRuntime (static) with MSVC'
#rm -rf Build_MSVC_static
mkdir -p Build_MSVC_static
echo call '"${VSCOMNTOOLS}\\..\\..\\VC\\vcvarsall.bat" ${VCVARS_PARAMS}' > Build_MSVC_static/build.bat

echo echo Running CMake from '%OMDEV%\\bin\\cmake\\bin\\cmake' >> Build_MSVC_static/build.bat
echo '%OMDEV%\\bin\\cmake\\bin\\cmake -DCMAKE_VERBOSE_MAKEFILE:Bool=ON -DPLATFORM="static" $(CMAKE_FLAGS) -DIS_MINGW32=OFF -DIS_MINGW64=OFF -DCMAKE_INSTALL_PREFIX:PATH=./tmp ../ -G "NMake Makefiles JOM" -D"CMAKE_MAKE_PROGRAM:PATH=%OMDEV%\\tools\\jom\\jom.exe"' >> Build_MSVC_static/build.bat

# for some reason, the environment variable 'MAKEFLAGS' was set to 'w' on my and Niklas' machine?!
echo set MAKEFLAGS="" >> Build_MSVC_static/build.bat
echo echo Running NMake JOM >> Build_MSVC_static/build.bat
echo %OMDEV%\\tools\\jom\\jom.exe /f Makefile install >> Build_MSVC_static/build.bat
cd ./Build_MSVC_static; echo "change to Build_MSVC_static";\
cmd /c build.bat

# move folder to build dir
cp -R --verbose Build_MSVC/tmp/* $(builddir_build)
cp -R --verbose Build_MSVC_static/tmp/lib/* $(builddir_build)/lib

OMSIBaseInstall: OMSIBase
cd SimulationRuntime/OMSI; \
$(foreach PLATFORM, $(PLATFORMS), \
(cd Build_$(PLATFORM); $(MAKE) install);)

OMSIBaseClean:
cd SimulationRuntime/OMSI; \
$(foreach PLATFORM, $(PLATFORMS), \
test -d Build_$(PLATFORM) && cd Build_$(PLATFORM) && $(MAKE) uninstall && $(MAKE) DESTDIR=$(OMBUILDDIR) clean && cd ..; \
rm -R -f Build_$(PLATFORM); \
)
85 changes: 85 additions & 0 deletions SimulationRuntime/OMSI/CMakeLists.txt
@@ -0,0 +1,85 @@
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(OMSIBaseSimulationRuntime)

# 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(OSUBaseName ${LIBPREFIX}OMSIBase${LIBSUFFIX})
SET(OMSISolverName ${LIBPREFIX}OMSISolver${LIBSUFFIX})

include_directories ("${CMAKE_SOURCE_DIR}/include")
# omsi base simulation runtime
ADD_SUBDIRECTORY(base)
ADD_SUBDIRECTORY(solver)

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

install(FILES
${CMAKE_SOURCE_DIR}/include/fmi2/omsi_fmi2_cs.h
${CMAKE_SOURCE_DIR}/include/fmi2/omsi_fmi2_me.h
${CMAKE_SOURCE_DIR}/include/fmi2/omsi_fmi2_wrapper.h
DESTINATION include/omc/omsi/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()




57 changes: 57 additions & 0 deletions SimulationRuntime/OMSI/base/CMakeLists.txt
@@ -0,0 +1,57 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
#OMSI base simulation runtime
PROJECT(OMSIBASE)
SET(CMAKE_VERBOSE_MAKEFILE ON)

#set exapat lib for visual studio compiler
IF(MSVC)
INCLUDE_DIRECTORIES($ENV{OMDEV}/lib/expat-win32-msvc)
link_directories($ENV{OMDEV}/lib/expat-win32-msvc)
link_directories($ENV{OMDEV}/lib/lapack-win32-msvc)
set(expat_lib "libexpat")
ELSE(MSVC)
set(expat_lib "expat")
ENDIF(MSVC)

include_directories ("${CMAKE_SOURCE_DIR}/base/include" "${CMAKE_SOURCE_DIR}/solver/include")
add_library(${OSUBaseName}
src/omsi_event_helper.c
src/omsi_getters_and_setters.c
src/omsi_initialization.c
src/omsi_input_json.c
src/omsi_input_model_variables.c
src/omsi_input_sim_data.c
src/omsi_input_xml.c
src/omsi_mmap.c
src/omsi_posix_func.c
src/omsi_solve_alg_system.c
src/omsi_utils.c)

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

IF(WIN32)
target_link_libraries(${OSUBaseName} ${OMSISolverName} ${CMAKE_DL_LIBS} wsock32 ws2_32 ${expat_lib})
ELSE(WIN32)
target_link_libraries(${OSUBaseName} ${OMSISolverName} ${CMAKE_DL_LIBS} )
ENDIF(WIN32)

install(TARGETS ${OSUBaseName} DESTINATION ${LIBINSTALLEXT})

install(FILES
${CMAKE_SOURCE_DIR}/base/include/omsi_event_helper.h
${CMAKE_SOURCE_DIR}/base/include/omsi_getters_and_setters.h
${CMAKE_SOURCE_DIR}/base/include/omsi_global.h
${CMAKE_SOURCE_DIR}/base/include/omsi_initialization.h
${CMAKE_SOURCE_DIR}/base/include/omsi_input_json.h
${CMAKE_SOURCE_DIR}/base/include/omsi_input_model_variables.h
${CMAKE_SOURCE_DIR}/base/include/omsi_input_sim_data.h
${CMAKE_SOURCE_DIR}/base/include/omsi_input_xml.h
${CMAKE_SOURCE_DIR}/base/include/omsi_mmap.h
${CMAKE_SOURCE_DIR}/base/include/omsi_posix_func.h
${CMAKE_SOURCE_DIR}/base/include/omsi_solve_alg_system.h
${CMAKE_SOURCE_DIR}/base/include/omsi_utils.h
${CMAKE_SOURCE_DIR}/base/include/uthash.h
DESTINATION include/omc/omsi/base)



71 changes: 71 additions & 0 deletions SimulationRuntime/OMSI/base/include/omsi_event_helper.h
@@ -0,0 +1,71 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
* GPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the OSMC (Open Source Modelica Consortium)
* Public License (OSMC-PL) are obtained from OSMC, either from the above
* address, from the URLs: http://www.openmodelica.org or
* http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
* distribution. GNU version 3 is obtained from:
* http://www.gnu.org/copyleft/gpl.html. The New BSD License is obtained from:
* http://www.opensource.org/licenses/BSD-3-Clause.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
* EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
* CONDITIONS OF OSMC-PL.
*
*/


#ifndef OMSI_EVENT_HELPER__H_
#define OMSI_EVENT_HELPER__H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <assert.h>
#include <math.h> /* fmin, fmod */

/* Public OMSI headers */
#include <omsi.h>
#include <omsi_utils.h>


/* Function prototypes */
omsi_bool omsi_function_zero_crossings (omsi_function_t* this_function,
omsi_bool new_zero_crossing,
omsi_unsigned_int index,
ModelState model_state);

omsi_bool omsi_on_sample_event (omsi_function_t* this_function,
omsi_unsigned_int sample_id,
ModelState model_state);

omsi_real omsi_next_sample(omsi_real time,
omsi_sample* sample_event);

omsi_real omsi_compute_next_event_time (omsi_real time,
omsi_sample* sample_events,
omsi_unsigned_int n_sample_events);

omsi_bool omsi_check_discrete_changes (omsi_t* omsi_data);

#ifdef __cplusplus
}
#endif
#endif

0 comments on commit e3fab53

Please sign in to comment.