Skip to content

Commit d36ca88

Browse files
committed
- handle CombiTable1D tables of 1 row only in tables.c
Modelica.Blocks.Tables.CombiTable1D z(table = [0, 0.7]); git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14221 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 73afbf6 commit d36ca88

File tree

1 file changed

+19
-3
lines changed
  • SimulationRuntime/c/ModelicaExternalC

1 file changed

+19
-3
lines changed

SimulationRuntime/c/ModelicaExternalC/tables.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,12 @@ double InterpolationTable_interpolate(InterpolationTable *tpl, double time, size
10521052

10531053
if (!tpl->data) return 0.0;
10541054

1055+
/* adrpo: if we have only one row [0, 0.7] return the value column */
1056+
if (lastIdx == 1)
1057+
{
1058+
return InterpolationTable_getElt(tpl,0,col);
1059+
}
1060+
10551061
/* substract time offset */
10561062
if (time < InterpolationTable_minTime(tpl))
10571063
return InterpolationTable_extrapolate(tpl,time,col,time <= InterpolationTable_minTime(tpl));
@@ -1096,11 +1102,11 @@ double InterpolationTable_extrapolate(InterpolationTable *tpl, double time, size
10961102
switch(tpl->expoType) {
10971103
case 1:
10981104
/* hold last/first value */
1099-
return InterpolationTable_getElt(tpl,(beforeData ? 0 :tpl->rows-1),col);
1105+
return InterpolationTable_getElt(tpl,(beforeData ? 0 : tpl->rows-1),col);
11001106
case 2:
11011107
/* extrapolate through first/last two values */
11021108
lastIdx = (tpl->colWise ? tpl->cols : tpl->rows) - 2;
1103-
return InterpolationTable_interpolateLin(tpl,time,(beforeData?0:lastIdx),col);
1109+
return InterpolationTable_interpolateLin(tpl,time,(beforeData ? 0 : lastIdx),col);
11041110
case 3:
11051111
/* periodically repeat signal */
11061112
time = tpl->startTime + (time - InterpolationTable_maxTime(tpl)*floor(time/InterpolationTable_maxTime(tpl)));
@@ -1124,13 +1130,23 @@ double InterpolationTable_interpolateLin(InterpolationTable *tpl, double time, s
11241130

11251131
const double InterpolationTable_getElt(InterpolationTable *tpl, size_t row, size_t col)
11261132
{
1127-
ASSERT6(row < tpl->rows && col < tpl->cols, "In Table: %s from File: %s with Size[%lu,%lu] try to get Element[%lu,%lu] aut of range!", tpl->tablename, tpl->filename, (unsigned long)tpl->rows, (unsigned long)tpl->cols, (unsigned long)row, (unsigned long)col);
1133+
/* is this really correct? doesn't it depends on tpl>colWise? */
1134+
ASSERT6(
1135+
row < tpl->rows && col < tpl->cols,
1136+
"In Table: %s from File: %s with Size[%lu,%lu] try to get Element[%lu,%lu] aut of range!",
1137+
tpl->tablename, tpl->filename,
1138+
(unsigned long)tpl->rows, (unsigned long)tpl->cols,
1139+
(unsigned long)row, (unsigned long)col);
1140+
11281141
return tpl->data[tpl->colWise ? col*tpl->rows+row : row*tpl->cols+col];
11291142
}
11301143
void InterpolationTable_checkValidityOfData(InterpolationTable *tpl)
11311144
{
11321145
size_t i = 0;
11331146
size_t maxSize = tpl->colWise ? tpl->cols : tpl->rows;
1147+
/* if we have only one row or column, return */
1148+
if (maxSize == 1) return;
1149+
/* else check the validity */
11341150
for(i = 1; i < maxSize; ++i)
11351151
if (InterpolationTable_getElt(tpl,i-1,0) > InterpolationTable_getElt(tpl,i,0))
11361152
THROW2("TimeTable: Column with time variable not monotonous: %g >= %g.", InterpolationTable_getElt(tpl,i-1,0),InterpolationTable_getElt(tpl,i,0));

0 commit comments

Comments
 (0)