Skip to content

Commit

Permalink
Added CMakefiles for Idas an Cvode to cpp runtime
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10614 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Nov 30, 2011
1 parent 93011df commit eeac5b7
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 30 deletions.
4 changes: 4 additions & 0 deletions SimulationRuntime/cpp/Readme.txt
Expand Up @@ -34,8 +34,12 @@ files to you boost header files folder.
To generate the build files for out-of-source build call cmake from the build folder: trunk/SimulationRuntime/cpp/build :
cmake -G "your generator" -D CMAKE_INSTALL_PREFIX:PATH="Insall directory" MAKE_CXX_COMPILER=g++ folder to project source dir


e.g for MinGW and Windwos (you need the mingw/bin dir in you path environment variable)
cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX:PATH="C:/OpenModelica/build" MAKE_CXX_COMPILER=g++ C:/OpenModelica/SimulationRuntime/cpp/Source
or
cmake -G "Visual Studio 10" -D CMAKE_INSTALL_PREFIX:PATH="C:/OpenModelica/build" C:/OpenModelica/SimulationRuntime/cpp/Source

after that you can call
make install
e.g.
Expand Down
101 changes: 88 additions & 13 deletions SimulationRuntime/cpp/Source/CMakeLists.txt
Expand Up @@ -2,56 +2,121 @@ cmake_minimum_required (VERSION 2.6)

project(CppSolverInterface)

# on windows boost,blas,lapack from omdev is used else the installed versions are used
# on windows boost,blas,lapack and sundial solvers from omdev is used else the installed versions are used
IF( WIN32 )
SET(ENV{BOOST_ROOT} $ENV{OMDEV}"/lib/3rdParty/boost_1_45_0/")
#set(BLAS_blas_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/blas.dll CACHE FILEPATH "Blas library")
#set(LAPACK_lapack_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/lapack.dll CACHE FILEPATH "Lapack library")
#Lapack and Blas for Visual Studio
set(BLAS_blas_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/blas_win32.dll CACHE FILEPATH "Blas library")
set(LAPACK_lapack_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/lapack_win32.dll CACHE FILEPATH "Lapack library")
SET(BLAS_blas_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/blas_win32.dll CACHE FILEPATH "Blas library")
SET(LAPACK_lapack_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/lapack_win32.dll CACHE FILEPATH "Lapack library")
SET(MICO_LIB_HOME $ENV{OMDEV}/lib/mico-msys-mingw/)
SET(MICO_INCLUDE_HOME $ENV{OMDEV}/include/mico-msys-mingw/)
#Sundials solvers include and library directories
SET(SUNDIALS_INLCUDE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/include)
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release)
ENDIF( WIN32 )

SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
SET(MODELICA_MODEL "ModelicaSystem")
SET(USE_MICO OFF)
SET(REDUCE_DAE OFF)
SET(USE_SUNDIALS ON)



find_package(Boost 1.45.0 COMPONENTS serialization REQUIRED )
find_package( BLAS )
find_package( LAPACK )
#PATHS $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/
link_directories ( ${Boost_LIBRARY_DIRS} )
include_directories ( ${Boost_INCLUDE_DIRS} )

# Sundials solvers
if(USE_SUNDIALS)

find_path(SUNDIALS_INCLUDE_DIR cvode/cvode.h
PATHS ${SUNDIALS_INLCUDE_HOME})
message(STATUS ${SUNDIALS_INCLUDE_DIR})

find_library(SUNDIALS_NVECSERIAL_LIB sundials_nvecserial
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME})
find_library(SUNDIALS_CVODES_LIB sundials_cvodes
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} )

find_library(SUNDIALS_IDAS_LIB sundials_idas
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} )

set(SUNDIALS_LIBS ${SUNDIALS_NVECSERIAL_LIB} ${SUNDIALS_CVODES_LIB} ${SUNDIALS_IDAS_LIB})
message(STATUS ${SUNDIALS_LIBS})
add_definitions(-DPMC_USE_SUNDIALS)
endif()

#Mico corba
if(USE_MICO)
find_library(MICO_LIBRARY mico2313
PATHS ${MICO_LIB_HOME}) #you can add additional search paths for mico library
find_path(MICO_INCLUDE_DIR CORBA.h
${MICO_INCLUDE_HOME}) #you can add additional search paths for mico include
message(STATUS ${MICO_LIBRARY})
message(STATUS ${MICO_INCLUDE_DIR})
endif()



link_directories ( ${Boost_LIBRARY_DIRS} )

include_directories ( ${Boost_INCLUDE_DIRS} )
include_directories ("${PROJECT_SOURCE_DIR}")
include_directories ("${PROJECT_BINARY_DIR}")






#add solver default implemention project
add_subdirectory (Solver/Implementation)


#add Euler solver project
add_subdirectory (Solver/Euler/Implementation)



#add math project
add_subdirectory (Math/Implementation)
add_subdirectory (SettingsFactory/Implementation)
#add simmanager project
add_subdirectory (SimManager)
#add system default implementation project

if(REDUCE_DAE)
add_subdirectory(ReduceDAE/Implementation)
endif()

add_subdirectory (System/Implementation)
add_subdirectory (System/Modelica)
add_subdirectory (System/Newton/Implementation)
add_subdirectory (ModelicaExternalC)

#include_directories ("${PROJECT_SOURCE_DIR}/System/Modelica/Implementation")
if(USE_SUNDIALS)
#add Cvode solver project
add_subdirectory (Solver/CVode/Implementation)
#add Idas solver project
add_subdirectory (Solver/Idas/Implementation)
GET_TARGET_PROPERTY(libCVode CVode LOCATION)
GET_FILENAME_COMPONENT(libCVodeName ${libCVode} NAME)
GET_TARGET_PROPERTY(libIdas Idas LOCATION)
GET_FILENAME_COMPONENT(libIdasName ${libIdas} NAME)
set (IDAS_LIB ${libIdasName})
set (CVODE_LIB ${libCVodeName})

endIf()

GET_TARGET_PROPERTY(libNewton Newton LOCATION)
GET_FILENAME_COMPONENT(libNewtonName ${libNewton} NAME)

GET_TARGET_PROPERTY(libEuler Euler LOCATION)
GET_FILENAME_COMPONENT(libEulerName ${libEuler} NAME)



GET_TARGET_PROPERTY(libSetFactory SettingsFactory LOCATION)
GET_FILENAME_COMPONENT(libSetFactoryName ${libSetFactory} NAME)

Expand All @@ -75,8 +140,18 @@ configure_file (
"${PROJECT_BINARY_DIR}/LibrariesConfig.h"
)


message(STATUS ${SUNDIALS_CVODES_LIB})
if(USE_SUNDIALS)
install (FILES "${SUNDIALS_NVECSERIAL_LIB}" "${SUNDIALS_IDAS_LIB}" "${SUNDIALS_CVODES_LIB}" DESTINATION bin)
endif()

if(USE_MICO)
install (FILES "${MICO_LIBRARY}" DESTINATION bin)
endif()

install (FILES "${Boost_LIBRARIES}" DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/LibrariesConfig.h" DESTINATION bin)
install (FILES "DataExchange/Interfaces/IHistory.h"
DESTINATION include/omc/cpp/DataExchange/Interfaces)
DESTINATION include/omc/cpp/DataExchange/Interfaces)


2 changes: 2 additions & 0 deletions SimulationRuntime/cpp/Source/LibrariesConfig.h.in
@@ -1,5 +1,7 @@

#define EULER_LIB "@EULER_LIB@"
#define CVODE_LIB "@CVODE_LIB@"
#define IDAS_LIB "@IDAS_LIB@"
#define SETTINGSFACTORY_LIB "@SETTINGSFACTORY_LIB@"
#define MODELICASYSTEM_LIB "@MODELICASYSTEM_LIB@"
#define NEWTON_LIB "@NEWTON_LIB@"
Expand Down
Expand Up @@ -2,5 +2,5 @@ cmake_minimum_required (VERSION 2.6)
project(ModelicaExternalC)
add_library(ModelicaExternalC ModelicaTablesImpl.c tables.cpp )

install (TARGETS ModelicaExternalC DESTINATION bin)
install (TARGETS ModelicaExternalC DESTINATION lib/omc/cpp)

Expand Up @@ -26,14 +26,15 @@ tuple<boost::shared_ptr<IGlobalSettings>,boost::shared_ptr<ISolverSettings> > Se
_global_settings->load("config//GlobalSettings.xml");
std::string solver_dll;
//Load solver dll

if(_global_settings->getSelectedSolver().compare("Euler")==0)
solver_dll.assign(EULER_LIB);
else if(_global_settings->getSelectedSolver().compare("Idas")==0)
solver_dll.assign(IDAS_LIB);
else if(_global_settings->getSelectedSolver().compare("CVode")==0)
solver_dll.assign(CVODE_LIB);
else
throw std::invalid_argument("Selected Solver is not available");

//solver_dll.assign("Idas.dll");
//solver_dll.assign("CVODE.dll");

string settings = _global_settings->getSelectedSolver().append("Settings");
string settings_file ="config//";
settings_file.append(
Expand Down
5 changes: 0 additions & 5 deletions SimulationRuntime/cpp/Source/SimManager/CMakeLists.txt
Expand Up @@ -7,8 +7,3 @@ target_link_libraries( Simulation ${Boost_LIBRARIES})

install (TARGETS Simulation DESTINATION bin)






8 changes: 5 additions & 3 deletions SimulationRuntime/cpp/Source/SimManager/Configuration.cpp
Expand Up @@ -43,11 +43,13 @@ IDAESolver* Configuration::createSolver(IDAESystem* system)
string solver = _global_settings->getSelectedSolver().append("Solver");
if(_global_settings->getSelectedSolver().compare("Euler")==0)
solver_dll.assign(EULER_LIB);
else if(_global_settings->getSelectedSolver().compare("Idas")==0)
solver_dll.assign(IDAS_LIB);
else if(_global_settings->getSelectedSolver().compare("CVode")==0)
solver_dll.assign(CVODE_LIB);
else
throw std::invalid_argument("Selected Solver is not available");

//solver_dll.assign("Idas.dll");
//solver_dll.assign("CVODE.dll");

if(!load_single_library(types, solver_dll))
throw std::invalid_argument(solver_dll + "library could not be loaded");
std::map<std::string, factory<IDAESolver,IDAESystem*, ISolverSettings*> >::iterator iter;
Expand Down
@@ -0,0 +1,23 @@
cmake_minimum_required (VERSION 2.6)

project(CVode)
include_directories(${SUNDIALS_INCLUDE_DIR}/Cvodes ${SUNDIALS_INCLUDE_DIR}/nvector ${SUNDIALS_INCLUDE_DIR}/sundials ${SUNDIALS_INCLUDE_DIR})

# add the solver default implementation library
add_library(CVode SHARED CVode.cpp CVodeSettings.cpp )
target_link_libraries (CVode Solver ${Boost_LIBRARIES} ${SUNDIALS_LIBS})
#target_link_libraries( Euler ${Boost_serialization_LIBRARY})






install (TARGETS CVode DESTINATION bin)
#install (FILES "../Interfaces/EulerSettings.xml"
# DESTINATION bin/config)





Expand Up @@ -13,9 +13,9 @@
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/serialization/nvp.hpp>
//#include <boost/archive/xml_oarchive.hpp>
//#include <boost/archive/xml_iarchive.hpp>
//#include <boost/serialization/nvp.hpp>
#include <string>
#include <fstream>
#include <boost/extension/extension.hpp>
Expand Down
@@ -0,0 +1,14 @@
cmake_minimum_required (VERSION 2.6)

project(Idas)
include_directories(${SUNDIALS_INCLUDE_DIR}/Idas ${SUNDIALS_INCLUDE_DIR}/nvector ${SUNDIALS_INCLUDE_DIR}/sundials ${SUNDIALS_INCLUDE_DIR})
# add the solver default implementation library
add_library(Idas SHARED Idas.cpp IdasSettings.cpp )
target_link_libraries (Idas Solver ${Boost_LIBRARIES} ${SUNDIALS_LIBS} )

install (TARGETS Idas DESTINATION bin)





Expand Up @@ -4,7 +4,7 @@ project(Modelica)

add_library(Modelica SHARED ModelicaSystem.cpp )

target_link_libraries (Modelica System)
target_link_libraries (Modelica System ModelicaExternalC)


GET_TARGET_PROPERTY(libModelicaSystem Modelica LOCATION)
Expand Down

0 comments on commit eeac5b7

Please sign in to comment.