Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 65d1390

Browse files
niklworsOpenModelica-Hudson
authored andcommitted
Added flag to use only one instance of algebraic loop solver in cpp
runtime Added flag to use only one instance of algebraich loop solver in cpp runtime [cppRuntime] Simplified handling algebraic loops in cpp runtime Use only one solver for linear and one for nonlinear system. If needed a own solver can used for a system removed accidentally added files added new AlglooperSolver class for linear and nonlinear systems adapted linear and nonlinear solvers on new interfaces ILinearAlgloopSolver and INonLinearAlgloopSolver added restart attribute to solve methode of algloopsolver, to restart without initialisation of algloop system Adapted cpp template for new algloop solver interface fix for intialize algloops at first solve call fix for init algloop solvers used by analytic jacobians fix for start algebraic loop solver without initializing Combined initialize and evaluate function from algebraic loops for parallel simulation use multiple instances of algloopsolver fix typo added flag to use only one instance of algloop solver in cpp runtime removed initiequation call for some kind of linear equations added missing code for jacobian algloopsolvers fix call for create kinsol solver in cpp runtime Belonging to [master]: - #2574
1 parent 23656fa commit 65d1390

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+792
-418
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ $RECYCLE.BIN/
5656
.Spotlight-V100
5757
.Trashes
5858

59+
60+
5961
# Directories potentially created on remote AFP share
6062
.AppleDB
6163
.AppleDesktop
@@ -153,5 +155,7 @@ Parser/ParModelica_Lexer_BaseModelica_Lexer.h
153155

154156
SimulationRuntime/**/test_files/*.jar
155157
SimulationRuntime/cpp/build_msvc/
156-
158+
# Visual Studio 2015/2017 cache/options directory
159+
SimulationRuntime/cpp/.vs/
160+
SimulationRuntime/cpp/CMakeSettings.json
157161
tags

Compiler/Template/CodegenCpp.tpl

Lines changed: 328 additions & 105 deletions
Large diffs are not rendered by default.

Compiler/Template/SimCodeTV.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3551,7 +3551,7 @@ package Flags
35513551
constant ConfigFlag LABELED_REDUCTION;
35523552
constant ConfigFlag LOAD_MSL_MODEL;
35533553
constant ConfigFlag Load_PACKAGE_FILE;
3554-
3554+
constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER;
35553555
function set
35563556
input DebugFlag inFlag;
35573557
input Boolean inValue;

Compiler/Util/Flags.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,9 @@ constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
14591459
"evalRecursionLimit", NONE(), EXTERNAL(), INT_FLAG(256), NONE(),
14601460
Util.gettext("The recursion limit used when evaluating constant function calls."));
14611461

1462+
constant ConfigFlag SINGLE_INSTANCE_AGLSOLVER = CONFIG_FLAG(127, "singleInstanceAglSolver",
1463+
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
1464+
Util.gettext("Sets to instantiate only one algebraic loop solver all algebraic loops"));
14621465

14631466
protected
14641467
// This is a list of all configuration flags. A flag can not be used unless it's
@@ -1590,7 +1593,8 @@ constant list<ConfigFlag> allConfigFlags = {
15901593
BUILDING_MODEL,
15911594
POST_OPT_MODULES_DAE,
15921595
EVAL_LOOP_LIMIT,
1593-
EVAL_RECURSION_LIMIT
1596+
EVAL_RECURSION_LIMIT,
1597+
SINGLE_INSTANCE_AGLSOLVER
15941598
};
15951599

15961600
public function new

SimulationRuntime/cpp/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ else()
6969
message(STATUS "Libs will be installed in ${LIBINSTALLEXT}")
7070
endif()
7171

72-
PROJECT(CppSolverInterface)
72+
PROJECT(CppSimulationRuntime)
7373
SET(CMAKE_VERBOSE_MAKEFILE ON)
7474
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
7575
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -93,11 +93,14 @@ OPTION(USE_CPP_03 "USE_CPP_03" OFF)
9393
#Set Variables
9494
IF(NOT FMU_TARGET)
9595
IF(MSVC)
96-
SET(LIBINSTALLEXT "lib/omc/cpp/msvc" CACHE STRING "library directory")
96+
SET(LIBINSTALLEXT "lib/omc/cpp/msvc" CACHE STRINGz "library directory")
9797
ELSE(MSVC)
9898
SET(LIBINSTALLEXT "lib/omc/cpp" CACHE STRING "library directory")
9999
ENDIF()
100100
ENDIF(NOT FMU_TARGET)
101+
102+
MESSAGE(STATUS "Using library folder extension" ${LIBINSTALLEXT})
103+
101104
SET(MODELICA_MODEL "ModelicaSystem")
102105
SET(LIBPREFIX "OMCpp")
103106
IF(BUILD_SHARED_LIBS)
@@ -350,7 +353,7 @@ IF(WIN32)
350353
SET(MICO_LIB_HOME $ENV{OMDEV}/lib/mico-msys-mingw/)
351354
SET(MICO_INCLUDE_HOME $ENV{OMDEV}/include/mico-msys-mingw/)
352355

353-
SET(INSTALL_OMDEV_LIBS ON)
356+
SET(INSTALL_OMDEV_LIBS OFF)
354357
ENDIF(WIN32)
355358

356359
# Find OpenMP

SimulationRuntime/cpp/Core/Modelica/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ install (FILES
268268
DESTINATION include/omc/cpp)
269269
ENDIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
270270

271-
install(FILES $<TARGET_PDB_FILE:${ModelicaName}> DESTINATION ${LIBINSTALLEXT} OPTIONAL)
271+
272272

273273
install(TARGETS ${ModelicaName} DESTINATION ${LIBINSTALLEXT})
274274
install (FILES ${CMAKE_SOURCE_DIR}/Include/Core/Modelica.h ${CMAKE_SOURCE_DIR}/Include/Core/ModelicaDefine.h DESTINATION include/omc/cpp/Core)

SimulationRuntime/cpp/Core/SimController/Initialization.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void Initialization::initializeSystem()
5353
if( _solver->stateSelection())
5454
{
5555
_system->initEquations();
56+
continous_system->stepCompleted(0.0);
57+
5658

5759
/* report a warning about strange start values */
5860
if(_solver->stateSelection())

SimulationRuntime/cpp/Core/Solver/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ install(FILES $<TARGET_PDB_FILE:${SolverName}> DESTINATION ${LIBINSTALLEXT} OPTI
1515

1616
install(TARGETS ${SolverName} DESTINATION ${LIBINSTALLEXT})
1717
install(FILES
18-
${CMAKE_SOURCE_DIR}/Include/Core/Solver/IAlgLoopSolver.h
18+
${CMAKE_SOURCE_DIR}/Include/Core/Solver/ILinearAlgLoopSolver.h
19+
${CMAKE_SOURCE_DIR}/Include/Core/Solver/INonLinearAlgLoopSolver.h
1920
${CMAKE_SOURCE_DIR}/Include/Core/Solver/ILinSolverSettings.h
2021
${CMAKE_SOURCE_DIR}/Include/Core/Solver/INonLinSolverSettings.h
2122
${CMAKE_SOURCE_DIR}/Include/Core/Solver/ISolver.h

SimulationRuntime/cpp/Core/System/AlgLoopSolverFactory.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ AlgLoopSolverFactory::~AlgLoopSolverFactory()
2020
{
2121
}
2222

23-
shared_ptr<IAlgLoopSolver> AlgLoopSolverFactory::createLinearAlgLoopSolver(ILinearAlgLoop* algLoop)
23+
shared_ptr<ILinearAlgLoopSolver> AlgLoopSolverFactory::createLinearAlgLoopSolver(shared_ptr<ILinearAlgLoop> algLoop)
2424
{
2525
try
2626
{
2727
string linsolver_name = _global_settings->getSelectedLinSolver();
2828
shared_ptr<ILinSolverSettings> algsolversetting= createLinSolverSettings(linsolver_name);
2929
_linalgsolversettings.push_back(algsolversetting);
30-
shared_ptr<IAlgLoopSolver> algsolver= createLinSolver(algLoop,linsolver_name,algsolversetting);
31-
_algsolvers.push_back(algsolver);
30+
shared_ptr<ILinearAlgLoopSolver> algsolver= createLinSolver(linsolver_name,algsolversetting,algLoop);
31+
_linear_algsolvers.push_back(algsolver);
3232
return algsolver;
3333
}
3434
catch(std::exception &arg)
@@ -39,24 +39,23 @@ shared_ptr<IAlgLoopSolver> AlgLoopSolverFactory::createLinearAlgLoopSolver(ILine
3939
}
4040

4141
/// Creates a nonlinear solver according to given system of equations of type algebraic loop
42-
shared_ptr<IAlgLoopSolver> AlgLoopSolverFactory::createNonLinearAlgLoopSolver(INonLinearAlgLoop* algLoop)
42+
shared_ptr<INonLinearAlgLoopSolver> AlgLoopSolverFactory::createNonLinearAlgLoopSolver(shared_ptr<INonLinearAlgLoop> algLoop)
4343
{
44-
if(algLoop->getDimReal() > 0)
45-
{
46-
47-
string nonlinsolver_name = _global_settings->getSelectedNonLinSolver();
48-
shared_ptr<INonLinSolverSettings> algsolversetting= createNonLinSolverSettings(nonlinsolver_name);
49-
algsolversetting->setContinueOnError(_global_settings->getNonLinearSolverContinueOnError());
50-
_algsolversettings.push_back(algsolversetting);
51-
52-
shared_ptr<IAlgLoopSolver> algsolver= createNonLinSolver(algLoop,nonlinsolver_name,algsolversetting);
53-
_algsolvers.push_back(algsolver);
54-
return algsolver;
55-
}
56-
else
57-
{
58-
// TODO: Throw an error message here.
59-
throw ModelicaSimulationError(MODEL_FACTORY,"AlgLoop solver is not available");
60-
}
44+
try
45+
{
46+
string nonlinsolver_name = _global_settings->getSelectedNonLinSolver();
47+
shared_ptr<INonLinSolverSettings> algsolversetting= createNonLinSolverSettings(nonlinsolver_name);
48+
algsolversetting->setContinueOnError(_global_settings->getNonLinearSolverContinueOnError());
49+
_algsolversettings.push_back(algsolversetting);
50+
51+
shared_ptr<INonLinearAlgLoopSolver> algsolver= createNonLinSolver(nonlinsolver_name,algsolversetting,algLoop);
52+
_non_linear_algsolvers.push_back(algsolver);
53+
return algsolver;
54+
}
55+
catch(std::exception &arg)
56+
{
57+
throw ModelicaSimulationError(MODEL_FACTORY,"Linear AlgLoop solver is not available");
58+
}
59+
6160
}
6261
/** @} */ // end of coreSystem

SimulationRuntime/cpp/Core/System/LinearAlgLoopDefaultImplementation.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ LinearAlgLoopDefaultImplementation::LinearAlgLoopDefaultImplementation()
1212
,_b(NULL)
1313
,_AData(NULL)
1414
,_Ax(NULL)
15+
,_x0(NULL)
16+
, _firstcall(true)
1517
{
18+
1619
}
1720

1821
LinearAlgLoopDefaultImplementation::~LinearAlgLoopDefaultImplementation()
1922
{
2023
if(_b)
2124
delete [] _b;
25+
if (_x0)
26+
delete [] _x0;
2227
}
2328

2429
/// Provide number (dimension) of variables according to data type
@@ -37,6 +42,9 @@ void LinearAlgLoopDefaultImplementation::initialize()
3742
delete [] _b;
3843
_b = new double[_dimAEq];
3944
memset(_b,0,_dimAEq*sizeof(double));
45+
if(_x0)
46+
delete [] _x0;
47+
_x0 = new double[_dimAEq];
4048
};
4149

4250
void LinearAlgLoopDefaultImplementation::getb(double* res) const
@@ -52,7 +60,10 @@ bool LinearAlgLoopDefaultImplementation::getUseSparseFormat(){
5260
void LinearAlgLoopDefaultImplementation::setUseSparseFormat(bool value){
5361
_useSparseFormat = value;
5462
}
55-
63+
void LinearAlgLoopDefaultImplementation::getRealStartValues(double* vars) const
64+
{
65+
memcpy(vars, _x0, sizeof(double) * _dimAEq);
66+
}
5667

5768

5869
//void LinearAlgLoopDefaultImplementation::getSparseAdata(double* data, int nonzeros)

0 commit comments

Comments
 (0)