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

Commit

Permalink
[cRuntime] fix nonlinear value extrapolation
Browse files Browse the repository at this point in the history
 - use minimal step size as threshold for comparision of equal time stamps
 - fixes ticket:5049

Belonging to [master]:
  - #2587
  - OpenModelica/OpenModelica-testsuite#1006
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Aug 2, 2018
1 parent 4892660 commit fc9be10
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions SimulationRuntime/c/simulation/solver/nonlinearValuesList.c
Expand Up @@ -38,6 +38,7 @@
*
*/

#include "epsilon.h"
#include "nonlinearValuesList.h"

#include "util/list.h"
Expand Down Expand Up @@ -186,7 +187,7 @@ void addListElement(VALUES_LIST* valuesList, VALUE* newElem)
* push the element just in front and if the end element
* is later than current push it just back.*/
node = listFirstNode(valuesList->valueList);
if (((VALUE*)listNodeData(node))->time < newElem->time)
if ( fabs( ((VALUE*)listNodeData(node))->time - newElem->time ) > MINIMAL_STEP_SIZE )
{
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 0, "First Value list element is:");
printValueElement(((VALUE*)listNodeData(node)));
Expand Down Expand Up @@ -215,13 +216,14 @@ void addListElement(VALUES_LIST* valuesList, VALUE* newElem)
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 0, "Next node of list is element:");
printValueElement(elem);

if (elem->time < newElem->time)

if (fabs(elem->time - newElem->time)<=MINIMAL_STEP_SIZE)
{
replace = 1;
break;
}
else if (elem->time == newElem->time)
else if (elem->time < newElem->time)
{
replace = 1;
break;
}
node = next;
Expand Down Expand Up @@ -270,7 +272,7 @@ void getValues(VALUES_LIST* valuesList, double time, double* extrapolatedValues,
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 0, "Searching current element:");
printValueElement(elem);

if (elem->time == time)
if (fabs(elem->time - time)<=MINIMAL_STEP_SIZE)
{
old = begin;
old2 = NULL;
Expand Down

0 comments on commit fc9be10

Please sign in to comment.