Skip to content

Commit

Permalink
Add new flag to set maximum number of bisection iterations
Browse files Browse the repository at this point in the history
to determine state event time value
  • Loading branch information
lochel authored and OpenModelica-Hudson committed Apr 11, 2016
1 parent 3a64133 commit 0c3a76e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -76,6 +76,7 @@
#include "simulation/solver/solver_main.h"
#include "simulation_info_json.h"
#include "modelinfo.h"
#include "simulation/solver/events.h"
#include "simulation/solver/model_help.h"
#include "simulation/solver/mixedSystem.h"
#include "simulation/solver/linearSystem.h"
Expand Down Expand Up @@ -525,6 +526,10 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data, threadData_t
init_lambda_steps_string = omc_flagValue[FLAG_ILS];
init_lambda_steps = atoi(init_lambda_steps_string.c_str());
}
if(omc_flag[FLAG_MAX_BISECTION_ITERATIONS]) {
maxBisectionIterations = atoi(omc_flagValue[FLAG_MAX_BISECTION_ITERATIONS]);
infoStreamPrint(LOG_STDOUT, 0, "Maximum number of bisection iterations changed to %d", maxBisectionIterations);
}
if(omc_flag[FLAG_MAX_EVENT_ITERATIONS]) {
maxEventIterations = atoi(omc_flagValue[FLAG_MAX_EVENT_ITERATIONS]);
infoStreamPrint(LOG_STDOUT, 0, "Maximum number of event iterations changed to %d", maxEventIterations);
Expand Down
3 changes: 2 additions & 1 deletion SimulationRuntime/c/simulation/solver/events.c
Expand Up @@ -50,6 +50,7 @@
extern "C" {
#endif

int maxBisectionIterations = 0;
double bisection(DATA* data, threadData_t *threadData, double*, double*, double*, double*, LIST*, LIST*);
int checkZeroCrossings(DATA *data, LIST *list, LIST*);
void saveZeroCrossingsAfterEvent(DATA *data, threadData_t *threadData);
Expand Down Expand Up @@ -416,7 +417,7 @@ double bisection(DATA* data, threadData_t *threadData, double* a, double* b, dou
double c;
long i=0;
/* n >= log(2)/log(2) + log(|b-a|/TOL)/log(2)*/
unsigned int n = 1 + ceil(log(fabs(*b - *a)/TTOL)/log(2));
unsigned int n = maxBisectionIterations > 0 ? maxBisectionIterations : 1 + ceil(log(fabs(*b - *a)/TTOL)/log(2));

memcpy(data->simulationInfo->zeroCrossingsBackup, data->simulationInfo->zeroCrossings, data->modelData->nZeroCrossings * sizeof(modelica_real));

Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/events.h
Expand Up @@ -42,6 +42,7 @@
extern "C" {
#endif

extern int maxBisectionIterations;
void checkForSampleEvent(DATA *data, SOLVER_INFO* solverInfo);
int checkEvents(DATA* data, threadData_t *threadData, LIST* eventLst, modelica_boolean useRootFinding, double *eventTime);

Expand Down
6 changes: 6 additions & 0 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -68,6 +68,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_LSS_MAX_DENSITY */ "lssMaxDensity",
/* FLAG_LSS_MIN_SIZE */ "lssMinSize",
/* FLAG_LV */ "lv",
/* FLAG_MAX_BISECTION_ITERATIONS */ "mbi",
/* FLAG_MAX_EVENT_ITERATIONS */ "mei",
/* FLAG_MAX_ORDER */ "maxIntegrationOrder",
/* FLAG_MAX_STEP_SIZE */ "maxStepSize",
Expand Down Expand Up @@ -134,6 +135,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_LSS_MAX_DENSITY */ "[double (default 0.2)] value specifies the maximum density for using a linear sparse solver",
/* FLAG_LSS_MIN_SIZE */ "[int (default 4001)] value specifies the minimum system size for using a linear sparse solver",
/* FLAG_LV */ "[string list] value specifies the logging level",
/* FLAG_MAX_BISECTION_ITERATIONS */ "[int (default 0)] value specifies the maximum number of bisection iterations for state event detection or zero for default behavior",
/* FLAG_MAX_EVENT_ITERATIONS */ "[int (default 20)] value specifies the maximum number of event iterations",
/* FLAG_MAX_ORDER */ "value specifies maximum integration order, used by dassl solver",
/* FLAG_MAX_STEP_SIZE */ "value specifies maximum absolute step size, used by dassl solver",
Expand Down Expand Up @@ -254,6 +256,9 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
/* FLAG_LV */
" Value (a comma-separated String list) specifies which logging levels to\n"
" enable. Multiple options can be enabled at the same time.",
/* FLAG_MAX_BISECTION_ITERATIONS */
" value specifies the maximum number of bisection iterations for state event\n"
" detection or zero for default behavior",
/* FLAG_MAX_EVENT_ITERATIONS */
" Value specifies the maximum number of event iterations.\n"
" The value is an Integer with default value 20.",
Expand Down Expand Up @@ -368,6 +373,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_LSS_MAX_DENSITY */ FLAG_TYPE_OPTION,
/* FLAG_LSS_MIN_SIZE */ FLAG_TYPE_OPTION,
/* FLAG_LV */ FLAG_TYPE_OPTION,
/* FLAG_MAX_BISECTION_ITERATIONS */ FLAG_TYPE_OPTION,
/* FLAG_MAX_EVENT_ITERATIONS */ FLAG_TYPE_OPTION,
/* FLAG_MAX_ORDER */ FLAG_TYPE_OPTION,
/* FLAG_MAX_STEP_SIZE */ FLAG_TYPE_OPTION,
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -76,6 +76,7 @@ enum _FLAG
FLAG_LSS_MAX_DENSITY,
FLAG_LSS_MIN_SIZE,
FLAG_LV,
FLAG_MAX_BISECTION_ITERATIONS,
FLAG_MAX_EVENT_ITERATIONS,
FLAG_MAX_ORDER,
FLAG_MAX_STEP_SIZE,
Expand Down

0 comments on commit 0c3a76e

Please sign in to comment.