Skip to content

Commit b97fedb

Browse files
author
Marcus Walther
committed
- fixed the ordering of the array elements in RefArray class
- added a counter for the number of ODE-evaluations to CVode - included version check for Sundials, colored jacobians are now enabled if the version is new enough - some typo fixes
1 parent e2a2224 commit b97fedb

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

SimulationRuntime/cpp/CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,29 @@ MESSAGE(STATUS ${LAPACK_LIBRARIES})
297297
# Find Sundials solvers
298298
IF(USE_SUNDIALS)
299299
FIND_PATH(SUNDIALS_INCLUDE_DIR cvode/cvode.h PATHS ${SUNDIALS_INLCUDE_HOME} $ENV{SUNDIALS_ROOT}/include)
300-
if (NOT SUNDIALS_INCLUDE_DIR)
301-
MESSAGE(FATAL_ERROR "Could not find Sundials, specify environment variable SUNDIALS_ROOT")
300+
IF (NOT SUNDIALS_INCLUDE_DIR)
301+
MESSAGE(FATAL_ERROR "Could not find Sundials, specify environment variable SUNDIALS_ROOT")
302+
ELSE(NOT SUNDIALS_INCLUDE_DIR)
303+
FIND_PATH(SUNDIALS_CONFIG_FILE "sundials_config.h" ${SUNDIALS_INCLUDE_DIR} "${SUNDIALS_INCLUDE_DIR}/sundials")
304+
SET(SUNDIALS_CONFIG_FILE "${SUNDIALS_CONFIG_FILE}/sundials_config.h")
305+
FILE(READ "${SUNDIALS_CONFIG_FILE}" SUNDIALS_CONFIG_FILE_CONTENT)
306+
STRING(REGEX MATCH "#define SUNDIALS_PACKAGE_VERSION .([0-9]+)\\.([0-9]+)\\.([0-9]+)." SUNDIALS_CONFIG_FILE_CONTENT ${SUNDIALS_CONFIG_FILE_CONTENT})
307+
STRING(REGEX REPLACE "#define SUNDIALS_PACKAGE_VERSION .([0-9]+)\\.([0-9]+)\\.([0-9]+)." "\\1;\\2;\\3" SUNDIALS_CONFIG_FILE_VERSION ${SUNDIALS_CONFIG_FILE_CONTENT})
308+
LIST(GET SUNDIALS_CONFIG_FILE_VERSION 0 SUNDIALS_MAJOR_VERSION)
309+
IF(SUNDIALS_MAJOR_VERSION)
310+
ADD_DEFINITIONS("-DSUNDIALS_MAJOR_VERSION=${SUNDIALS_MAJOR_VERSION}")
311+
ELSE()
312+
MESSAGE(FATAL_ERROR "Could not determine sundials version")
313+
ENDIF()
314+
LIST(GET SUNDIALS_CONFIG_FILE_VERSION 1 SUNDIALS_MINOR_VERSION)
315+
IF(SUNDIALS_MINOR_VERSION)
316+
ADD_DEFINITIONS("-DSUNDIALS_MINOR_VERSION=${SUNDIALS_MINOR_VERSION}")
317+
ELSE()
318+
MESSAGE(FATAL_ERROR "Could not determine sundials version")
319+
ENDIF()
320+
LIST(GET SUNDIALS_CONFIG_FILE_VERSION 2 SUNDIALS_PATCH_VERSION)
321+
MESSAGE(STATUS "Using sundials ${SUNDIALS_MAJOR_VERSION}.${SUNDIALS_MINOR_VERSION}.${SUNDIALS_PATCH_VERSION}")
302322
ENDIF()
303-
MESSAGE(STATUS ${SUNDIALS_INCLUDE_DIR})
304323

305324
FIND_LIBRARY(SUNDIALS_NVECSERIAL_LIB "sundials_nvecserial" PATHS ${SUNDIALS_LIBRARY_RELEASE_HOME} $ENV{SUNDIALS_ROOT}/lib)
306325
IF(NOT SUNDIALS_NVECSERIAL_LIB)

SimulationRuntime/cpp/Core/SimController/Main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ int main(int argc, const char* argv[])
3232
("stop-time,e", po::value< double >()->default_value(1.0), "simulation stop time")
3333
("step-size,f", po::value< double >()->default_value(1e-2), "simulation step size")
3434
("solver,i", po::value< string >()->default_value("euler"), "solver method")
35-
("number-of-intervalls,v", po::value< int >()->default_value(500), "number of intervalls")
36-
("tollerance,y", po::value< double >()->default_value(1e-6), "solver tollerance")
35+
("number-of-intervals,v", po::value< int >()->default_value(500), "number of intervals")
36+
("tolerance,y", po::value< double >()->default_value(1e-6), "solver tolerance")
37+
("solverLog,l", "print additional solver information after simulation")
3738
;
3839
po::variables_map vm;
3940
po::store(po::parse_command_line(argc, argv, desc,
@@ -47,8 +48,8 @@ int main(int argc, const char* argv[])
4748
string runtime_lib_path;
4849
double starttime = vm["start-time"].as<double>();
4950
double stoptime = vm["stop-time"].as<double>();
50-
double stepsize = stoptime/vm["number-of-intervalls"].as<int>();
51-
double tollerance =vm["tollerance"].as<double>();
51+
double stepsize = stoptime/vm["number-of-intervals"].as<int>();
52+
double tollerance =vm["tolerance"].as<double>();
5253
string solver = vm["solver"].as<string>();
5354
if (vm.count("runtime-library"))
5455
{

SimulationRuntime/cpp/Include/Core/Math/Array.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class RefArrayDim2 : public RefArray<T, size1*size2>
428428
virtual const T& operator()(const vector<size_t>& idx) const
429429
{
430430
return *(RefArray<T, size1*size2>::
431-
_ref_array[idx[0]-1 + size1*(idx[1]-1)]);
431+
_ref_array[(idx[0]-1)*size2 + (idx[1]-1)]);
432432
}
433433

434434
/**
@@ -438,7 +438,7 @@ class RefArrayDim2 : public RefArray<T, size1*size2>
438438
virtual T& operator()(const vector<size_t>& idx)
439439
{
440440
return *(RefArray<T, size1*size2>::
441-
_ref_array[idx[0]-1 + size1*(idx[1]-1)]);
441+
_ref_array[(idx[0]-1)*size2 + (idx[1]-1)]);
442442
}
443443

444444
/**
@@ -449,7 +449,7 @@ class RefArrayDim2 : public RefArray<T, size1*size2>
449449
inline virtual T& operator()(size_t i, size_t j)
450450
{
451451
return *(RefArray<T, size1*size2>::
452-
_ref_array[i-1 + size1*(j-1)]);
452+
_ref_array[(i-1)*size2 + (j-1)]);
453453
}
454454

455455
/**
@@ -553,7 +553,7 @@ class RefArrayDim3 : public RefArray<T, size1*size2*size3>
553553
virtual const T& operator()(const vector<size_t>& idx) const
554554
{
555555
return *(RefArray<T, size1*size2*size3>::
556-
_ref_array[idx[0]-1 + size1*(idx[1]-1 + size2*(idx[2]-1))]);
556+
_ref_array[size3*(idx[0]-1 + size2*(idx[1]-1)) + idx[2]-1]);
557557
}
558558

559559
/**
@@ -563,7 +563,7 @@ class RefArrayDim3 : public RefArray<T, size1*size2*size3>
563563
virtual T& operator()(const vector<size_t>& idx)
564564
{
565565
return *(RefArray<T, size1*size2*size3>::
566-
_ref_array[idx[0]-1 + size1*(idx[1]-1 + size2*(idx[2]-1))]);
566+
_ref_array[size3*(idx[0]-1 + size2*(idx[1]-1)) + idx[2]-1]);
567567
}
568568

569569
/**
@@ -575,7 +575,7 @@ class RefArrayDim3 : public RefArray<T, size1*size2*size3>
575575
inline virtual T& operator()(size_t i, size_t j, size_t k)
576576
{
577577
return *(RefArray<T, size1*size2*size3>::
578-
_ref_array[i-1 + size1*(j-1 + size2*(k-1))]);
578+
_ref_array[size3*(i-1 + size2*(j-1)) + (k-1)]);
579579
}
580580

581581
/**

SimulationRuntime/cpp/Include/Solver/CVode/CVode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ double
234234
IMixedSystem* _mixed_system;
235235
ITime* _time_system;
236236

237+
int _numberOfOdeEvaluations;
238+
237239
#ifdef RUNTIME_PROFILING
238240
std::vector<MeasureTimeData> measureTimeFunctionsArray;
239241
MeasureTimeValues *measuredFunctionStartValues, *measuredFunctionEndValues, *solveFunctionStartValues, *solveFunctionEndValues;

SimulationRuntime/cpp/Solver/CVode/CVode.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Cvode::Cvode(IMixedSystem* system, ISolverSettings* settings)
3131
_event_system(NULL),
3232
_mixed_system(NULL),
3333
_time_system(NULL),
34+
_numberOfOdeEvaluations(0),
3435
_delta(NULL),
3536
_deltaInv(NULL),
3637
_ysave(NULL),
@@ -275,7 +276,7 @@ void Cvode::initialize()
275276

276277
// Use own jacobian matrix
277278
// Check if Colored Jacobians are worth to use
278-
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
279+
#if SUNDIALS_MAJOR_VERSION >= 2 || (SUNDIALS_MAJOR_VERSION == 2 && SUNDIALS_MINOR_VERSION >= 5)
279280
_maxColors = _system->getAMaxColors();
280281
if(_maxColors < _dimSys && _continuous_system->getDimContinuousStates() > 0)
281282
{
@@ -717,6 +718,7 @@ int Cvode::calcFunction(const double& time, const double* y, double* f)
717718
_continuous_system->setContinuousStates(y);
718719
_continuous_system->evaluateODE(IContinuous::CONTINUOUS);
719720
_continuous_system->getRHS(f);
721+
_numberOfOdeEvaluations++;
720722
} //workaround until exception can be catch from c- libraries
721723
catch (std::exception & ex )
722724
{
@@ -968,6 +970,7 @@ void Cvode::writeSimulationInfo()
968970
BOOST_LOG_SEV(slg, cvode_normal)<< " Linear solver setups " << "nsetups: " << nsetups;
969971
BOOST_LOG_SEV(slg, cvode_normal)<< " Nonlinear iterations " << "nni: " << nni;
970972
BOOST_LOG_SEV(slg, cvode_normal)<< " Convergence failures " << "ncfn: " << ncfn;
973+
BOOST_LOG_SEV(slg, cvode_normal)<< " Number of evaluateODE calls " << "eODE: " << _numberOfOdeEvaluations;
971974

972975
#endif
973976
//// Solver

0 commit comments

Comments
 (0)