This package contains components to interpolate linearly in tables. Table data may optionally be read in from files (ASCII or Matlab-4 binary format). This package contains the following components:
CombiTableTime Table look-up with time as abszissa CombiTableTime2 Table look-up with time as abszissa and linear/perodic extrapolation methods CombiTable1D Table look-up in one dimension CombiTable1Ds Table look-up in one dimension with same input for different coloumns CombiTable2D Table look-up in two dimensions
This package is not part of the Modelica standard library, because it is planned to realize a package with better and more general table support based on a different design.
Release Notes:
Copyright © 2000-2002, DLR.
The ModelicaAdditions.Tables package is free software; it can be redistributed and/or modified under the terms of the Modelica license, see the license conditions and the accompanying disclaimer in the documentation of package Modelica in file "Modelica/package.mo".
Linear interpolation in a table with respect to time. Via parameter icol it can be defined how many columns of the table are interpolated. If, e.g., icol={2,4}, it is assumed that 2 output signals are present and that the first output is computed by interpolation of column 2 and the second output is computed by interpolation of column 4 of the table matrix.
The time points and function values are stored in a matrix "table[i,j]", where the first column "table[:,1]" contains the time points and the other columns contain the data to be interpolated. Example:
table = [0, 0; 1, 0; 1, 1; 2, 4; 3, 9; 4, 16] If, e.g., time = 1.0, the output y = 0.0 (before event), 1.0 (after event) e.g., time = 1.5, the output y = 2.5, e.g., time = 2.0, the output y = 4.0, e.g., time = 5.0, the output y = 23.0 (i.e. extrapolation).
The table matrix can be defined in the following ways:
tableName is "NoName" or has only blanks, fileName is "NoName" or has only blanks.
save tables.mat tab1 tab2 tab3 -V4when the three tables tab1, tab2, tab3 should be used from the model.
Table definition methods (1) and (3) do not allocate dynamic memory, and do not access files, whereas method (2) does. Therefore (1) and (3) are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware). When the constant "NO_FILE" is defined, all parts of the source code of method (2) are removed by the C-preprocessor, such that no dynamic memory allocation and no access to files takes place.
If tables are read from an ASCII-file, the file need to have the following structure ("-----" is not part of the file content):
----------------------------------------------------- #1 double tab1(6,2) # comment line 0 0 1 0 1 1 2 4 3 9 4 16 double tab2(6,2) # another comment line 0 0 2 0 2 2 4 8 6 18 8 32 -----------------------------------------------------
Note, that the first two characters in the file need to be "#1". Afterwards, the corresponding matrix has to be declared with type, name and actual dimensions. Finally, in successive rows of the file, the elements of the matrix have to be given. Several matrices may be defined one after another.
Name | Default | Description |
---|---|---|
table[:, :] | [0, 0; 1, 1] | table matrix (time = first column) |
tableName | "NoName" | table name on file or in function usertab(optional) |
fileName | "NoName" | file where matrix is stored (optional) |
icol[:] | {2} | columns of table to be interpolated |
model CombiTableTime "Table look-up with time as abszissa (matrix/file) " parameter Real table[:, :]=[0, 0; 1, 1] "table matrix (time = first column)"; parameter String tableName="NoName" "table name on file or in function usertab(optional)"; parameter String fileName="NoName" "file where matrix is stored (optional)"; parameter Real icol[:]={2} "columns of table to be interpolated"; extends Modelica.Blocks.Interfaces.MO(final nout=size(icol, 1)); protected Real tableID(start=0); equation when initial() then tableID = dymTableTimeIni(time, 0.0, tableName, fileName, table, 0.0); end when; /*Interpolate with respect to time.*/ for i in 1:nout loop outPort.signal[i] = dymTableTimeIpo(tableID, icol[i], time); end for; end CombiTableTime;
This block generates an output signal by linear interpolation in a table. The time points and function values are stored in a matrix table[i,j], where the first column table[:,1] contains the time points and the other columns contain the data to be interpolated. Via parameter columns it can be defined which columns of the table are interpolated. If, e.g., columns={2,4}, it is assumed that 2 output signals are present and that the first output is computed by interpolation of column 2 and the second output is computed by interpolation of column 4 of the table matrix. The table interpolation has the following proporties:
extrapolation = 0: hold the first or last value of the table, if outside of the range. = 1: extrapolate through the last or first two points of the table. = 2: periodically repeat the table data (periodical function).
Example:
table = [0 0 1 0 1 1 2 4 3 9 4 16]; extrapolation = 1 (default) If, e.g., time = 1.0, the output y = 0.0 (before event), 1.0 (after event) e.g., time = 1.5, the output y = 2.5, e.g., time = 2.0, the output y = 4.0, e.g., time = 5.0, the output y = 23.0 (i.e. extrapolation via last 2 points).
The table matrix can be defined in the following ways:
tableName is "NoName" or has only blanks, fileName is "NoName" or has only blanks.
save tables.mat tab1 tab2 tab3 -V4when the three tables tab1, tab2, tab3 should be used from the model.
Table definition methods (1) and (3) do not allocate dynamic memory, and do not access files, whereas method (2) does. Therefore (1) and (3) are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware). When the constant "NO_FILE" is defined, all parts of the source code of method (2) are removed by the C-preprocessor, such that no dynamic memory allocation and no access to files takes place.
If tables are read from an ASCII-file, the file need to have the following structure ("-----" is not part of the file content):
----------------------------------------------------- #1 double tab1(6,2) # comment line 0 0 1 0 1 1 2 4 3 9 4 16 double tab2(6,2) # another comment line 0 0 2 0 2 2 4 8 6 18 8 32 -----------------------------------------------------
Note, that the first two characters in the file need to be "#1". Afterwards, the corresponding matrix has to be declared with type, name and actual dimensions. Finally, in successive rows of the file, the elements of the matrix have to be given. Several matrices may be defined one after another.
Release Notes:
Name | Default | Description |
---|---|---|
table[:, :] | [0, 0; 1, 1] | table matrix (time = first column) |
tableName | "NoName" | table name on file or in function usertab(optional) |
fileName | "NoName" | file where matrix is stored (optional) |
columns[:] | 2:size(table, 2) | columns of table to be interpolated |
offset[:] | {0} | Offsets of output signals |
extrapolation[1] | {1} | = 0/1/2 constant/last two points/periodic (SAME value for all columns only supported currently) |
startTime[1] | {0} | Output = offset for time < startTime (SAME value for all columns only supported currently) [s] |
model CombiTableTime2 "Table look-up with respect to time and linear/perodic extrapolation methods (data from matrix/file)" parameter Real table[:, :]=[0, 0; 1, 1] "table matrix (time = first column)"; parameter String tableName="NoName" "table name on file or in function usertab(optional)"; parameter String fileName="NoName" "file where matrix is stored (optional)"; parameter Integer columns[:]=2:size(table, 2) "columns of table to be interpolated"; parameter Real offset[:]={0} "Offsets of output signals"; parameter Integer extrapolation[1]( min={0}, max={2}) = {1} "= 0/1/2 constant/last two points/periodic (SAME value for all columns only supported currently)" ; parameter SI.Time startTime[1]={0} "Output = offset for time < startTime (SAME value for all columns only supported currently)" ; extends Modelica.Blocks.Interfaces.MO(final nout=max([size(columns, 1); size( offset, 1)])); final parameter Real p_offset[nout]=(if size(offset, 1) == 1 then ones(nout)* offset[1] else offset); final parameter Integer tableID=tableTimeInit(0.0, startTime[1], 0, extrapolation[1], tableName, fileName, table, 0); final parameter Real t_min=tableTimeTmin(tableID); final parameter Real t_max=tableTimeTmax(tableID); function tableTimeInit input Real timeIn; input Real startTime; input Integer ipoType; input Integer expoType; input String tableName; input String fileName; input Real table[:, :]; input Integer colWise; output Integer tableID; external "C" tableID = dymTableTimeIni2(timeIn, startTime, ipoType, expoType , tableName, fileName, table, size(table, 1), size(table, 2), colWise); end tableTimeInit; function tableTimeIpo input Integer tableID; input Integer icol; input Real timeIn; output Real value; external "C" value = dymTableTimeIpo2(tableID, icol, timeIn); end tableTimeIpo; function tableTimeTmin input Integer tableID; output Real Tmin "minimum time value in table"; external "C" Tmin = dymTableTimeTmin(tableID); end tableTimeTmin; function tableTimeTmax input Integer tableID; output Real Tmax "maximum time value in table"; external "C" Tmax = dymTableTimeTmax(tableID); end tableTimeTmax; equation for i in 1:nout loop outPort.signal[i] = p_offset[i] + tableTimeIpo(tableID, columns[i], time); end for; end CombiTableTime2;
Linear interpolation in one dimension of a table. Via parameter icol it can be defined how many columns of the table are interpolated. If, e.g., icol={2,4}, it is assumed that 2 input and 2 output signals are present and that the first output interpolates the first input via column 2 and the second output interpolates the second input via column 4 of the table matrix.
The grid points and function values are stored in a matrix "table[i,j]", where the first column "table[:,1]" contains the grid points and the other columns contain the data to be interpolated. Example:
table = [0, 0; 1, 1; 2, 4; 4, 16] If, e.g., the input u = 1.0, the output y = 1.0, e.g., the input u = 1.5, the output y = 2.5, e.g., the input u = 2.0, the output y = 4.0, e.g., the input u =-1.0, the output y = -1.0 (i.e. extrapolation).
The table matrix can be defined in the following ways:
tableName is "NoName" or has only blanks, fileName is "NoName" or has only blanks.
save tables.mat tab1 tab2 tab3 -V4when the three tables tab1, tab2, tab3 should be used from the model.
Table definition methods (1) and (3) do not allocate dynamic memory, and do not access files, whereas method (2) does. Therefore (1) and (3) are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware). When the constant "NO_FILE" is defined, all parts of the source code of method (2) are removed by the C-preprocessor, such that no dynamic memory allocation and no access to files takes place.
If tables are read from an ASCII-file, the file need to have the following structure ("-----" is not part of the file content):
----------------------------------------------------- #1 double tab1(5,2) # comment line 0 0 1 1 2 4 3 9 4 16 double tab2(5,2) # another comment line 0 0 2 2 4 8 6 18 8 32 -----------------------------------------------------
Note, that the first two characters in the file need to be "#1". Afterwards, the corresponding matrix has to be declared with type, name and actual dimensions. Finally, in successive rows of the file, the elements of the matrix have to be given. Several matrices may be defined one after another.
Name | Default | Description |
---|---|---|
table[:, :] | [0, 0; 1, 1] | table matrix (grid = first column) |
tableName | "NoName" | table name on file or in function usertab(optional) |
fileName | "NoName" | file where matrix is stored (optional) |
icol[:] | {2} | columns of table to be interpolated |
model CombiTable1D "Table look-up in one dimension (matrix/file) " parameter Real table[:, :]=[0, 0; 1, 1] "table matrix (grid = first column)"; parameter String tableName="NoName" "table name on file or in function usertab(optional)"; parameter String fileName="NoName" "file where matrix is stored (optional)"; parameter Real icol[:]={2} "columns of table to be interpolated"; extends Modelica.Blocks.Interfaces.MIMOs(final n=size(icol, 1)); protected Real tableID(start=0); equation when initial() then tableID = dymTableInit(1.0, 0.0, tableName, fileName, table, 0.0); end when; for i in 1:n loop y[i] = dymTableIpo1(tableID, icol[i], u[i]); end for; end CombiTable1D;
Linear interpolation in one dimension of a table. Via parameter icol it can be defined how many columns of the table are interpolated. If, e.g., icol={2,4}, it is assumed that one input and 2 output signals are present and that the first output interpolates via column 2 and the second output interpolates via column 4 of the table matrix.
The grid points and function values are stored in a matrix "table[i,j]", where the first column "table[:,1]" contains the grid points and the other columns contain the data to be interpolated. Example:
table = [0, 0; 1, 1; 2, 4; 4, 16] If, e.g., the input u = 1.0, the output y = 1.0, e.g., the input u = 1.5, the output y = 2.5, e.g., the input u = 2.0, the output y = 4.0, e.g., the input u =-1.0, the output y = -1.0 (i.e. extrapolation).
The table matrix can be defined in the following ways:
tableName is "NoName" or has only blanks, fileName is "NoName" or has only blanks.
save tables.mat tab1 tab2 tab3 -V4when the three tables tab1, tab2, tab3 should be used from the model.
Table definition methods (1) and (3) do not allocate dynamic memory, and do not access files, whereas method (2) does. Therefore (1) and (3) are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware). When the constant "NO_FILE" is defined, all parts of the source code of method (2) are removed by the C-preprocessor, such that no dynamic memory allocation and no access to files takes place.
If tables are read from an ASCII-file, the file need to have the following structure ("-----" is not part of the file content):
----------------------------------------------------- #1 double tab1(5,2) # comment line 0 0 1 1 2 4 3 9 4 16 double tab2(5,2) # another comment line 0 0 2 2 4 8 6 18 8 32 -----------------------------------------------------
Note, that the first two characters in the file need to be "#1". Afterwards, the corresponding matrix has to be declared with type, name and actual dimensions. Finally, in successive rows of the file, the elements of the matrix have to be given. Several matrices may be defined one after another.
Name | Default | Description |
---|---|---|
table[:, :] | [0, 0; 1, 1] | table matrix (grid = first column) |
tableName | "NoName" | table name on file or in function usertab(optional) |
fileName | "NoName" | file where matrix is stored (optional) |
icol[:] | {2} | columns of table to be interpolated |
model CombiTable1Ds "Table look-up in one dimension (matrix/file) with only single input" parameter Real table[:, :]=[0, 0; 1, 1] "table matrix (grid = first column)"; parameter String tableName="NoName" "table name on file or in function usertab(optional)"; parameter String fileName="NoName" "file where matrix is stored (optional)"; parameter Real icol[:]={2} "columns of table to be interpolated"; extends Modelica.Blocks.Interfaces.SIMO(final nout=size(icol, 1)); protected Real tableID(start=0); equation when initial() then tableID = dymTableInit(1.0, 0.0, tableName, fileName, table, 0.0); end when; for i in 1:nout loop y[i] = dymTableIpo1(tableID, icol[i], u); end for; end CombiTable1Ds;
Linear interpolation in two dimensions of a table. The grid points and function values are stored in a matrix "table[i,j]", where:
Example:
| | | | | 1.0 | 2.0 | 3.0 | // u2 ----*-------*-------*-------* 1.0 | 1.0 | 3.0 | 5.0 | ----*-------*-------*-------* 2.0 | 2.0 | 4.0 | 6.0 | ----*-------*-------*-------* // u1 is defined as table = [0.0, 1.0, 2.0, 3.0; 1.0, 1.0, 3.0, 5.0; 2.0, 2.0, 4.0, 6.0] If, e.g. the input u is [1.0;1.0], the output y is 1.0, e.g. the input u is [2.0;1.5], the output y is 3.0.
The table matrix can be defined in the following ways:
tableName is "NoName" or has only blanks, fileName is "NoName" or has only blanks.
save tables.mat tab1 tab2 tab3 -V4when the three tables tab1, tab2, tab3 should be used from the model.
Table definition methods (1) and (3) do not allocate dynamic memory, and do not access files, whereas method (2) does. Therefore (1) and (3) are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware). When the constant "NO_FILE" is defined, all parts of the source code of method (2) are removed by the C-preprocessor, such that no dynamic memory allocation and no access to files takes place.
If tables are read from an ASCII-file, the file need to have the following structure ("-----" is not part of the file content):
----------------------------------------------------- #1 double tab1(5,2) # comment line 0 0 1 1 2 4 3 9 4 16 double tab2(5,2) # another comment line 0 0 2 2 4 8 6 18 8 32 -----------------------------------------------------
Note, that the first two characters in the file need to be "#1". Afterwards, the corresponding matrix has to be declared with type, name and actual dimensions. Finally, in successive rows of the file, the elements of the matrix have to be given. Several matrices may be defined one after another.
Name | Default | Description |
---|---|---|
table[:, :] | [0, 0, 1; 0, 0, 1; 1, 1, 1] | table matrix (grid = first column/first row) |
tableName | "NoName" | table name on file or in function usertab(optional) |
fileName | "NoName" | file where matrix is stored (optional) |
model CombiTable2D "Table look-up in two dimensions (matrix/file) " extends Modelica.Blocks.Interfaces.SI2SO; parameter Real table[:, :]=[0, 0, 1; 0, 0, 1; 1, 1, 1] "table matrix (grid = first column/first row)"; parameter String tableName="NoName" "table name on file or in function usertab(optional)"; parameter String fileName="NoName" "file where matrix is stored (optional)"; protected Real tableID(start=0); equation when initial() then tableID = dymTableInit(2.0, 0.0, tableName, fileName, table, 0.0); end when; y = dymTableIpo2(tableID, u1, u2); end CombiTable2D;