Skip to content

Commit

Permalink
In c_runtime/tables.cpp, fixed modulo divison in extrapolation and
Browse files Browse the repository at this point in the history
add zero-division guarding in interpolation (since time samples do not 
need to be strictly monotonous anymore).

Also fixed incorrectly swapped min-time and max-time function in 
libModelicaExternalC.



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6038 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Anton Sodja committed Sep 7, 2010
1 parent 9216698 commit c2d026c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions c_runtime/ModelicaExternalC/Makefile
Expand Up @@ -10,3 +10,6 @@ libModelicaExternalC.a : $(OBJS)

ModelicaExternalC.o : ModelicaExternalC.cpp
g++ -O3 -c ModelicaExternalC.cpp -o ModelicaExternalC.o

clean:
rm -f libModelicaExternalC.a $(OBJS)
4 changes: 2 additions & 2 deletions c_runtime/ModelicaExternalC/ModelicaExternalC.cpp
Expand Up @@ -374,11 +374,11 @@ double ModelicaTables_CombiTimeTable_interpolate(int tableID, int icol, double t
}
double ModelicaTables_CombiTimeTable_minimumTime(int tableID)
{
return omcTableTimeTmax(tableID);
return omcTableTimeTmin(tableID);
}
double ModelicaTables_CombiTimeTable_maximumTime(int tableID)
{
return omcTableTimeTmin(tableID);
return omcTableTimeTmax(tableID);
}

int ModelicaTables_CombiTable1D_init(const char* tableName, const char* fileName, double* table, size_t table_size1, size_t table_size2, int smoothness)
Expand Down
7 changes: 5 additions & 2 deletions c_runtime/tables.cpp
Expand Up @@ -671,7 +671,7 @@ double InterpolationTable::extrapolate(double time, size_t col,
return interpolateLin(time,(beforeData?0:lastIdx),col);
case 2:
// periodically repeat signal
time = startTime + (time - floor(time/maxTime()));
time = startTime + (time - maxTime()*floor(time/maxTime()));
return interpolate(time,col);
default:
return 0.0;
Expand All @@ -683,7 +683,10 @@ double InterpolationTable::interpolateLin(double time, size_t i, size_t j) const
double t_2 = getElt(i+1,0);
double y_1 = getElt(i,j);
double y_2 = getElt(i+1,j);
return (y_1 + ((time-t_1)/(t_2-t_1)) * (y_2-y_1));
if (std::abs(t_2-t_1) < 100.0*std::numeric_limits<double>::epsilon())
return y_1;
else
return (y_1 + ((time-t_1)/(t_2-t_1)) * (y_2-y_1));
}

const double& InterpolationTable::getElt(size_t row, size_t col) const
Expand Down

0 comments on commit c2d026c

Please sign in to comment.