Skip to content

Commit

Permalink
do not use extrapolation for to big steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Jul 5, 2016
1 parent 9206950 commit f2eb970
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions SimulationRuntime/c/simulation/solver/nonlinearSystem.c
Expand Up @@ -372,6 +372,8 @@ int initializeNonlinearSystems(DATA *data, threadData_t *threadData)
/* allocate value list*/
nonlinsys[i].oldValueList = (void*) allocValueList(1);

nonlinsys[i].lastTimeSolved = 0.0;

nonlinsys[i].nominal = (double*) malloc(size*sizeof(double));
nonlinsys[i].min = (double*) malloc(size*sizeof(double));
nonlinsys[i].max = (double*) malloc(size*sizeof(double));
Expand Down Expand Up @@ -610,6 +612,7 @@ int updateInitialGuessDB(NONLINEAR_SYSTEM_DATA *nonlinsys, double time, int cont
}
}
messageClose(LOG_NLS_EXTRAPOLATE);
return 0;
}

/*! \fn updateInnerEquation
Expand Down Expand Up @@ -684,12 +687,21 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
data->simulationInfo->noThrowDivZero = 1;
((DATA*)data)->simulationInfo->solveContinuous = 1;

/* performace measuremeant */
/* performance measurement */
rt_ext_tp_tick(&nonlinsys->totalTimeClock);

/* grab the initial guess */
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 1, "############ Start new iteration for system %d at time at %g ############", nonlinsys->equationIndex, data->localData[0]->timeValue);
getInitialGuess(nonlinsys, data->localData[0]->timeValue);
/* if last solving is too long ago use just old values */
if (fabs(data->localData[0]->timeValue - nonlinsys->lastTimeSolved) < 5*data->simulationInfo->stepSize)
{
getInitialGuess(nonlinsys, data->localData[0]->timeValue);
}
else
{
nonlinsys->getIterationVars(data, nonlinsys->nlsx);
memcpy(nonlinsys->nlsx, nonlinsys->nlsxOld, nonlinsys->size*(sizeof(double)));
}

/* update non continuous */
if (data->simulationInfo->discreteCall)
Expand Down Expand Up @@ -770,16 +782,21 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)

/* update value list database */
updateInitialGuessDB(nonlinsys, data->localData[0]->timeValue, data->simulationInfo->currentContext);
if (nonlinsys->solved == 1)
{
nonlinsys->lastTimeSolved = data->localData[0]->timeValue;
}


/* enable to avoid division by zero */
data->simulationInfo->noThrowDivZero = 0;
((DATA*)data)->simulationInfo->solveContinuous = 0;

/* performace measuremeant and statistics */
/* performance measurement and statistics */
nonlinsys->totalTime += rt_ext_tp_tock(&(nonlinsys->totalTimeClock));
nonlinsys->numberOfCall++;

/* write csv file for debuging */
/* write csv file for debugging */
#if !defined(OMC_MINIMAL_RUNTIME)
if (data->simulationInfo->nlsCsvInfomation)
{
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation_data.h
Expand Up @@ -286,6 +286,7 @@ typedef struct NONLINEAR_SYSTEM_DATA

modelica_real residualError; /* not used */
modelica_boolean solved; /* 1: solved in current step - else not */
modelica_real lastTimeSolved; /* save last successful solved point in time */

/* statistics */
unsigned long numberOfCall; /* number of solving calls of this system */
Expand Down

0 comments on commit f2eb970

Please sign in to comment.