Skip to content

Commit

Permalink
Extended cpp template for solving linear systems
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10833 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Dec 23, 2011
1 parent 73d3b28 commit 9564748
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 91 deletions.
318 changes: 254 additions & 64 deletions Compiler/susan_codegen/SimCode/SimCodeCpp.tpl

Large diffs are not rendered by default.

45 changes: 31 additions & 14 deletions SimulationRuntime/cpp/Source/CMakeLists.txt
@@ -1,27 +1,38 @@
cmake_minimum_required (VERSION 2.6)

project(CppSolverInterface)

# 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_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_DIRY "$ENV{OMDEV}/lib/3rdParty/Lapack/Lib/" CACHE LOCATION "where was yarp built?")

#set mico paths
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 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)
if(MSVC)
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release/vc100)
elseif(MINGW)
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release/mingw)
endif()

ENDIF( WIN32 )



message(STATUS ${CVODES_LIB})

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)

SET(INSTALL_OMDEV_LIBS ON)


find_package(Boost 1.45.0 COMPONENTS serialization REQUIRED )
Expand All @@ -33,14 +44,14 @@ if(USE_SUNDIALS)

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

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

find_library(SUNDIALS_IDAS_LIB sundials_idas
find_library(SUNDIALS_IDAS_LIB "sundials_idas"
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} )

set(SUNDIALS_LIBS ${SUNDIALS_NVECSERIAL_LIB} ${SUNDIALS_CVODES_LIB} ${SUNDIALS_IDAS_LIB})
Expand Down Expand Up @@ -141,15 +152,21 @@ configure_file (
)

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)
if(INSTALL_OMDEV_LIBS)
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 "${LAPACK_lapack_LIBRARY}" DESTINATION bin)
install (FILES "${BLAS_blas_LIBRARY}" DESTINATION bin)
#install (FILES "${Boost_LIBRARIES}" 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)
Expand Down
5 changes: 3 additions & 2 deletions SimulationRuntime/cpp/Source/ModelicaExternalC/CMakeLists.txt
@@ -1,6 +1,7 @@
cmake_minimum_required (VERSION 2.6)
project(ModelicaExternalC)
add_library(ModelicaExternalC ModelicaTablesImpl.c tables.cpp )
add_library(ModelicaExternalC ModelicaTablesImpl.c tables.cpp )

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

#lib/omc/cpp
Expand Up @@ -20,8 +20,7 @@ int ModelicaTables_CombiTimeTable_init(const char* tableName, const char* fileNa
double const *table, int nRow, int nColumn,
double startTime, int smoothness,
int extrapolation)
{
return omcTableTimeIni(startTime, startTime, smoothness, extrapolation,
{ return omcTableTimeIni(startTime, startTime, smoothness, extrapolation,
tableName, fileName, table, nRow, nColumn, 0);
}

Expand Down
Expand Up @@ -5,7 +5,7 @@

GlobalSettings::GlobalSettings()
: _startTime (0.0)
, _endTime (5.0)
, _endTime (10.0)
, _hOutput (0.02)
, _resultsOutput (true)
, _infoOutput (true)
Expand Down
13 changes: 10 additions & 3 deletions SimulationRuntime/cpp/Source/Solver/CVode/Implementation/stdafx.h
Expand Up @@ -4,6 +4,13 @@
//

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

#include <map>
#include <boost/ref.hpp>
Expand All @@ -13,9 +20,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
Expand Up @@ -4,6 +4,14 @@
//

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

#include <map>
#include <boost/ref.hpp>
#include <boost/bind.hpp>
Expand Down
Expand Up @@ -45,6 +45,6 @@ AlgLoopSolverFactory::~AlgLoopSolverFactory()
else
{
// TODO: Throw an error message here.
throw std::invalid_argument("No Newton solver found");
throw std::invalid_argument("Algloop system is not of tpye real");
}
}
3 changes: 2 additions & 1 deletion SimulationRuntime/cpp/Source/System/Interfaces/IAlgLoop.h
Expand Up @@ -62,5 +62,6 @@ class IAlgLoop

/// Provide the right hand side (according to the index)
virtual void giveRHS(double* doubleFuncs, int* intFuncs, bool* boolFuncs) = 0;

virtual void giveAMatrix(double* A_matrix) = 0;
virtual bool isLinear() = 0;
};
Expand Up @@ -117,8 +117,15 @@ void Newton::solve(const IContinous::UPDATE command)
if(totStps < _newtonSettings->getNewtMax())
{
// Determination of Jacobian (Fortran-format)
calcJacobian();

if(_algLoop->isLinear())
{
calcFunction(_yHelp,_fHelp);
_algLoop->giveAMatrix(_jac);
}
else
{
calcJacobian();
}
// Solve linear System
dgesv_(&_dimSys,&dimRHS,_jac,&_dimSys,_fHelp,_f,&_dimSys,&irtrn);

Expand All @@ -133,9 +140,15 @@ void Newton::solve(const IContinous::UPDATE command)
++ totStps;

// New solution
if(_algLoop->isLinear())
{
memcpy(_y,_f,_dimSys*sizeof(double));
}
else
{
for(int i=0; i<_dimSys; ++i)
_y[i] -= _newtonSettings->getDelta() * _f[i];

}
// New right hand side
calcFunction(_y,_f);
}
Expand Down Expand Up @@ -176,6 +189,7 @@ void Newton::calcJacobian()
for(int i=0; i<_dimSys; ++i)
_jac[i+j*_dimSys] = (_fHelp[i] - _f[i]) / 1e-6;
}

}

using boost::extensions::factory;
Expand Down

0 comments on commit 9564748

Please sign in to comment.