Skip to content

Commit 9564748

Browse files
committed
Extended cpp template for solving linear systems
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10833 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 73d3b28 commit 9564748

File tree

10 files changed

+328
-91
lines changed

10 files changed

+328
-91
lines changed

Compiler/susan_codegen/SimCode/SimCodeCpp.tpl

Lines changed: 254 additions & 64 deletions
Large diffs are not rendered by default.

SimulationRuntime/cpp/Source/CMakeLists.txt

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
cmake_minimum_required (VERSION 2.6)
22

33
project(CppSolverInterface)
4-
54
# on windows boost,blas,lapack and sundial solvers from omdev is used else the installed versions are used
65
IF( WIN32 )
76
SET(ENV{BOOST_ROOT} $ENV{OMDEV}"/lib/3rdParty/boost_1_45_0/")
87
SET(BLAS_blas_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/blas_win32.dll CACHE FILEPATH "Blas library")
98
SET(LAPACK_lapack_LIBRARY $ENV{OMDEV}/lib/3rdParty/Lapack/Lib/lapack_win32.dll CACHE FILEPATH "Lapack library")
9+
SET(BLAS_DIRY "$ENV{OMDEV}/lib/3rdParty/Lapack/Lib/" CACHE LOCATION "where was yarp built?")
10+
11+
#set mico paths
1012
SET(MICO_LIB_HOME $ENV{OMDEV}/lib/mico-msys-mingw/)
1113
SET(MICO_INCLUDE_HOME $ENV{OMDEV}/include/mico-msys-mingw/)
12-
#Sundials solvers include and library directories
14+
#set sundials solvers include and library directories
1315
SET(SUNDIALS_INLCUDE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/include)
14-
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release)
16+
if(MSVC)
17+
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release/vc100)
18+
elseif(MINGW)
19+
SET(SUNDIALS_LIBRARY_RELEASE_HOME $ENV{OMDEV}/lib/3rdParty/Sundials/lib/release/mingw)
20+
endif()
21+
1522
ENDIF( WIN32 )
1623

24+
25+
26+
message(STATUS ${CVODES_LIB})
27+
1728
SET(Boost_USE_STATIC_LIBS OFF)
1829
SET(Boost_USE_MULTITHREADED ON)
1930
SET(Boost_USE_STATIC_RUNTIME OFF)
2031
SET(MODELICA_MODEL "ModelicaSystem")
2132
SET(USE_MICO OFF)
2233
SET(REDUCE_DAE OFF)
2334
SET(USE_SUNDIALS ON)
24-
35+
SET(INSTALL_OMDEV_LIBS ON)
2536

2637

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

3445
find_path(SUNDIALS_INCLUDE_DIR cvode/cvode.h
3546
PATHS ${SUNDIALS_INLCUDE_HOME})
36-
message(STATUS ${SUNDIALS_INCLUDE_DIR})
47+
message(STATUS ${SUNDIALS_INCLUDE_DIR})
3748

38-
find_library(SUNDIALS_NVECSERIAL_LIB sundials_nvecserial
49+
find_library(SUNDIALS_NVECSERIAL_LIB "sundials_nvecserial"
3950
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME})
40-
find_library(SUNDIALS_CVODES_LIB sundials_cvodes
51+
find_library(SUNDIALS_CVODES_LIB "sundials_cvodes"
4152
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} )
4253

43-
find_library(SUNDIALS_IDAS_LIB sundials_idas
54+
find_library(SUNDIALS_IDAS_LIB "sundials_idas"
4455
PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} )
4556

4657
set(SUNDIALS_LIBS ${SUNDIALS_NVECSERIAL_LIB} ${SUNDIALS_CVODES_LIB} ${SUNDIALS_IDAS_LIB})
@@ -141,15 +152,21 @@ configure_file (
141152
)
142153

143154
message(STATUS ${SUNDIALS_CVODES_LIB})
144-
if(USE_SUNDIALS)
145-
install (FILES "${SUNDIALS_NVECSERIAL_LIB}" "${SUNDIALS_IDAS_LIB}" "${SUNDIALS_CVODES_LIB}" DESTINATION bin)
146-
endif()
147155

148-
if(USE_MICO)
149-
install (FILES "${MICO_LIBRARY}" DESTINATION bin)
156+
if(INSTALL_OMDEV_LIBS)
157+
if(USE_SUNDIALS)
158+
install (FILES "${SUNDIALS_NVECSERIAL_LIB}" "${SUNDIALS_IDAS_LIB}" "${SUNDIALS_CVODES_LIB}" DESTINATION bin)
159+
endif()
160+
161+
if(USE_MICO)
162+
install (FILES "${MICO_LIBRARY}" DESTINATION bin)
163+
endif()
164+
165+
install (FILES "${LAPACK_lapack_LIBRARY}" DESTINATION bin)
166+
install (FILES "${BLAS_blas_LIBRARY}" DESTINATION bin)
167+
#install (FILES "${Boost_LIBRARIES}" DESTINATION bin)
150168
endif()
151169

152-
install (FILES "${Boost_LIBRARIES}" DESTINATION bin)
153170
install (FILES "${PROJECT_BINARY_DIR}/LibrariesConfig.h" DESTINATION bin)
154171
install (FILES "DataExchange/Interfaces/IHistory.h"
155172
DESTINATION include/omc/cpp/DataExchange/Interfaces)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required (VERSION 2.6)
22
project(ModelicaExternalC)
3-
add_library(ModelicaExternalC ModelicaTablesImpl.c tables.cpp )
3+
add_library(ModelicaExternalC ModelicaTablesImpl.c tables.cpp )
44

5-
install (TARGETS ModelicaExternalC DESTINATION lib/omc/cpp)
5+
install (TARGETS ModelicaExternalC DESTINATION bin)
66

7+
#lib/omc/cpp

SimulationRuntime/cpp/Source/ModelicaExternalC/ModelicaTablesImpl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ int ModelicaTables_CombiTimeTable_init(const char* tableName, const char* fileNa
2020
double const *table, int nRow, int nColumn,
2121
double startTime, int smoothness,
2222
int extrapolation)
23-
{
24-
return omcTableTimeIni(startTime, startTime, smoothness, extrapolation,
23+
{ return omcTableTimeIni(startTime, startTime, smoothness, extrapolation,
2524
tableName, fileName, table, nRow, nColumn, 0);
2625
}
2726

SimulationRuntime/cpp/Source/SettingsFactory/Implementation/GlobalSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
GlobalSettings::GlobalSettings()
77
: _startTime (0.0)
8-
, _endTime (5.0)
8+
, _endTime (10.0)
99
, _hOutput (0.02)
1010
, _resultsOutput (true)
1111
, _infoOutput (true)

SimulationRuntime/cpp/Source/Solver/CVode/Implementation/stdafx.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
//
55

66
#pragma once
7+
#pragma once
8+
#ifndef BOOST_THREAD_USE_DLL
9+
#define BOOST_THREAD_USE_DLL
10+
#endif
11+
#ifndef BOOST_ALL_DYN_LINK
12+
#define BOOST_ALL_DYN_LINK
13+
#endif
714

815
#include <map>
916
#include <boost/ref.hpp>
@@ -13,9 +20,9 @@
1320
#include <boost/numeric/ublas/io.hpp>
1421
#include <boost/numeric/ublas/matrix.hpp>
1522
#include <boost/numeric/ublas/matrix_proxy.hpp>
16-
//#include <boost/archive/xml_oarchive.hpp>
17-
//#include <boost/archive/xml_iarchive.hpp>
18-
//#include <boost/serialization/nvp.hpp>
23+
#include <boost/archive/xml_oarchive.hpp>
24+
#include <boost/archive/xml_iarchive.hpp>
25+
#include <boost/serialization/nvp.hpp>
1926
#include <string>
2027
#include <fstream>
2128
#include <boost/extension/extension.hpp>

SimulationRuntime/cpp/Source/Solver/Idas/Implementation/stdafx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
//
55

66
#pragma once
7+
#pragma once
8+
#ifndef BOOST_THREAD_USE_DLL
9+
#define BOOST_THREAD_USE_DLL
10+
#endif
11+
#ifndef BOOST_ALL_DYN_LINK
12+
#define BOOST_ALL_DYN_LINK
13+
#endif
14+
715
#include <map>
816
#include <boost/ref.hpp>
917
#include <boost/bind.hpp>

SimulationRuntime/cpp/Source/System/Implementation/AlgLoopSolverFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ AlgLoopSolverFactory::~AlgLoopSolverFactory()
4545
else
4646
{
4747
// TODO: Throw an error message here.
48-
throw std::invalid_argument("No Newton solver found");
48+
throw std::invalid_argument("Algloop system is not of tpye real");
4949
}
5050
}

SimulationRuntime/cpp/Source/System/Interfaces/IAlgLoop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ class IAlgLoop
6262

6363
/// Provide the right hand side (according to the index)
6464
virtual void giveRHS(double* doubleFuncs, int* intFuncs, bool* boolFuncs) = 0;
65-
65+
virtual void giveAMatrix(double* A_matrix) = 0;
66+
virtual bool isLinear() = 0;
6667
};

SimulationRuntime/cpp/Source/System/Newton/Implementation/Newton.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,15 @@ void Newton::solve(const IContinous::UPDATE command)
117117
if(totStps < _newtonSettings->getNewtMax())
118118
{
119119
// Determination of Jacobian (Fortran-format)
120-
calcJacobian();
121-
120+
if(_algLoop->isLinear())
121+
{
122+
calcFunction(_yHelp,_fHelp);
123+
_algLoop->giveAMatrix(_jac);
124+
}
125+
else
126+
{
127+
calcJacobian();
128+
}
122129
// Solve linear System
123130
dgesv_(&_dimSys,&dimRHS,_jac,&_dimSys,_fHelp,_f,&_dimSys,&irtrn);
124131

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

135142
// New solution
143+
if(_algLoop->isLinear())
144+
{
145+
memcpy(_y,_f,_dimSys*sizeof(double));
146+
}
147+
else
148+
{
136149
for(int i=0; i<_dimSys; ++i)
137150
_y[i] -= _newtonSettings->getDelta() * _f[i];
138-
151+
}
139152
// New right hand side
140153
calcFunction(_y,_f);
141154
}
@@ -176,6 +189,7 @@ void Newton::calcJacobian()
176189
for(int i=0; i<_dimSys; ++i)
177190
_jac[i+j*_dimSys] = (_fHelp[i] - _f[i]) / 1e-6;
178191
}
192+
179193
}
180194

181195
using boost::extensions::factory;

0 commit comments

Comments
 (0)