Skip to content

Commit

Permalink
Add flag to change the tolerances for newton solver
Browse files Browse the repository at this point in the history
<-newtonFTol=value> or <-newtonFTol value>
  [double (default 1e-24)] tolerance for accepting accuracy in Newton solver
<-newtonXTol=value> or <-newtonXTol value>
  [double (default 1e-24)] tolerance for updating solution vector in Newton solver
  • Loading branch information
ptaeuber committed May 20, 2016
1 parent c5b68a9 commit d665b64
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -801,6 +801,15 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data, threadData_t *thr
linearSparseSolverMinSize = atoi(omc_flagValue[FLAG_LSS_MIN_SIZE]);
infoStreamPrint(LOG_STDOUT, 0, "Maximum system size for using linear sparse solver changed to %d", linearSparseSolverMinSize);
}
if(omc_flag[FLAG_NEWTON_XTOL]) {
newtonXTol = atof(omc_flagValue[FLAG_NEWTON_XTOL]);
infoStreamPrint(LOG_STDOUT, 0, "Tolerance for updating solution vector in Newton solver changed to %g", newtonXTol);
}

if(omc_flag[FLAG_NEWTON_FTOL]) {
newtonFTol = atof(omc_flagValue[FLAG_NEWTON_FTOL]);
infoStreamPrint(LOG_STDOUT, 0, "Tolerance for accepting accuracy in Newton solver changed to %g", newtonFTol);
}

rt_tick(SIM_TIMER_INIT_XML);
read_input_xml(data->modelData, data->simulationInfo);
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -53,6 +53,8 @@
int maxEventIterations = 20;
double linearSparseSolverMaxDensity = 0.2;
int linearSparseSolverMinSize = 4001;
double newtonXTol = 1e-24;
double newtonFTol = 1e-24;
const size_t SIZERINGBUFFER = 3;
int compiledInDAEMode = 0;

Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/simulation/solver/model_help.h
Expand Up @@ -77,6 +77,8 @@ extern "C" {
extern int maxEventIterations;
extern double linearSparseSolverMaxDensity;
extern int linearSparseSolverMinSize;
extern double newtonXTol;
extern double newtonFTol;
extern const size_t SIZERINGBUFFER;
extern int compiledInDAEMode;

Expand Down
Expand Up @@ -61,7 +61,7 @@ typedef struct DATA_HOMOTOPY
int m; /* dimension: m == size+1 */

double xtol; /* tolerance for updating solution vector */
double ftol; /* tolerance fo accepting accuracy */
double ftol; /* tolerance for accepting accuracy */

double error_f;

Expand Down Expand Up @@ -150,8 +150,8 @@ int allocateHomotopyData(int size, void** voiddata)
data->initialized = 0;
data->n = size;
data->m = size + 1;
data->xtol = 1e-24;
data->ftol = 1e-24;
data->xtol = newtonXTol;
data->ftol = newtonFTol;

data->error_f = 0;

Expand Down
12 changes: 12 additions & 0 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -76,6 +76,8 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_MAX_ORDER */ "maxIntegrationOrder",
/* FLAG_MAX_STEP_SIZE */ "maxStepSize",
/* FLAG_MEASURETIMEPLOTFORMAT */ "measureTimePlotFormat",
/* FLAG_NEWTON_FTOL */ "newtonFTol",
/* FLAG_NEWTON_XTOL */ "newtonXTol",
/* FLAG_NEWTON_STRATEGY */ "newton",
/* FLAG_NLS */ "nls",
/* FLAG_NLS_INFO */ "nlsInfo",
Expand Down Expand Up @@ -146,6 +148,8 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* 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",
/* FLAG_MEASURETIMEPLOTFORMAT */ "value specifies the output format of the measure time functionality",
/* FLAG_NEWTON_FTOL */ "[double (default 1e-24)] tolerance for accepting accuracy in Newton solver",
/* FLAG_NEWTON_XTOL */ "[double (default 1e-24)] tolerance for updating solution vector in Newton solver",
/* FLAG_NEWTON_STRATEGY */ "value specifies the damping strategy for the newton solver",
/* FLAG_NLS */ "value specifies the nonlinear solver",
/* FLAG_NLS_INFO */ "outputs detailed information about solving process of non-linear systems into csv files.",
Expand Down Expand Up @@ -285,6 +289,12 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
" * ps\n"
" * gif\n"
" * ...",
/* FLAG_NEWTON_FTOL */
" Tolerance for accepting accuracy in Newton solver."
" The value is a Double with default value 1e-24.",
/* FLAG_NEWTON_XTOL */
" Tolerance for updating solution vector in Newton solver."
" The value is a Double with default value 1e-24.",
/* FLAG_NEWTON_STRATEGY */
" Value specifies the damping strategy for the newton solver.",
/* FLAG_NLS */
Expand Down Expand Up @@ -393,6 +403,8 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_MAX_ORDER */ FLAG_TYPE_OPTION,
/* FLAG_MAX_STEP_SIZE */ FLAG_TYPE_OPTION,
/* FLAG_MEASURETIMEPLOTFORMAT */ FLAG_TYPE_OPTION,
/* FLAG_NEWTON_FTOL */ FLAG_TYPE_OPTION,
/* FLAG_NEWTON_XTOL */ FLAG_TYPE_OPTION,
/* FLAG_NEWTON_STRATEGY */ FLAG_TYPE_OPTION,
/* FLAG_NLS */ FLAG_TYPE_OPTION,
/* FLAG_NLS_INFO */ FLAG_TYPE_FLAG,
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -84,6 +84,8 @@ enum _FLAG
FLAG_MAX_ORDER,
FLAG_MAX_STEP_SIZE,
FLAG_MEASURETIMEPLOTFORMAT,
FLAG_NEWTON_FTOL,
FLAG_NEWTON_XTOL,
FLAG_NEWTON_STRATEGY,
FLAG_NLS,
FLAG_NLS_INFO,
Expand Down

0 comments on commit d665b64

Please sign in to comment.