Modelica.Blocks.Tables

Library of blocks to interpolate in one and two-dimensional tables

Information


This package contains blocks for one- and two-dimensional interpolation in tables.

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

NameDescription
Modelica.Blocks.Tables.CombiTable1D CombiTable1D Table look-up in one dimension (matrix/file) with n inputs and n outputs
Modelica.Blocks.Tables.CombiTable1Ds CombiTable1Ds Table look-up in one dimension (matrix/file) with one input and n outputs
Modelica.Blocks.Tables.CombiTable2D CombiTable2D Table look-up in two dimensions (matrix/file)


Modelica.Blocks.Tables.CombiTable1D Modelica.Blocks.Tables.CombiTable1D

Table look-up in one dimension (matrix/file) with n inputs and n outputs

Modelica.Blocks.Tables.CombiTable1D

Information


Linear interpolation in one dimension of a table. Via parameter columns it can be defined how many columns of the table are interpolated. If, e.g., columns={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:

  1. Explicitly supplied as parameter matrix "table", and the other parameters have the following values:
       tableName is "NoName" or has only blanks,
       fileName  is "NoName" or has only blanks.
    
  2. Read from a file "fileName" where the matrix is stored as "tableName". Both ASCII and binary file format is possible. (the ASCII format is described below). It is most convenient to generate the binary file from Matlab (Matlab 4 storage format), e.g., by command
       save tables.mat tab1 tab2 tab3 -V4
    
    when the three tables tab1, tab2, tab3 should be used from the model.
  3. Statically stored in function "usertab" in file "usertab.c". The matrix is identified by "tableName". Parameter fileName = "NoName" or has only blanks.

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 in "usertab.c", 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.

Extends from Modelica.Blocks.Interfaces.MIMOs (Multiple Input Multiple Output continuous control block with same number of inputs and outputs).

Parameters

TypeNameDefaultDescription
Integernsize(columns, 1)Number of inputs (= number of outputs)
table data definition
BooleantableOnFilefalsetrue, if table is defined on file or in function usertab
Realtable[:, :]fill(0.0, 0, 2)table matrix (grid = first column; e.g., table=[0,2])
StringtableName"NoName"table name on file or in function usertab (see docu)
StringfileName"NoName"file where matrix is stored
table data interpretation
Integercolumns[:]2:size(table, 2)columns of table to be interpolated
SmoothnesssmoothnessTypes.Smoothness.LinearSegme...smoothness of table interpolation

Connectors

TypeNameDescription
input RealInputu[n]Connector of Real input signals
output RealOutputy[n]Connector of Real output signals

Modelica definition

model CombiTable1D 
  "Table look-up in one dimension (matrix/file) with n inputs and n outputs "
  import Modelica.Blocks.Types;
  parameter Boolean tableOnFile=false 
    "true, if table is defined on file or in function usertab";
  parameter Real table[:, :]=fill(0.0,0,2) 
    "table matrix (grid = first column; e.g., table=[0,2])";
  parameter String tableName="NoName" 
    "table name on file or in function usertab (see docu)";
  parameter String fileName="NoName" "file where matrix is stored";
  parameter Integer columns[:]=2:size(table, 2) 
    "columns of table to be interpolated";
  parameter Modelica.Blocks.Types.Smoothness smoothness=Types.Smoothness.LinearSegments 
    "smoothness of table interpolation";
  extends Modelica.Blocks.Interfaces.MIMOs(final n=size(columns, 1));

protected 
  Integer tableID;

  function tableInit 
    "Initialize 1-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
    input String tableName;
    input String fileName;
    input Real table[ :, :];
    input Modelica.Blocks.Types.Smoothness smoothness;
    output Integer tableID;
  external "C" tableID=  ModelicaTables_CombiTable1D_init(
                 tableName, fileName, table, size(table, 1), size(table, 2),
                 smoothness);
  end tableInit;

  function tableIpo 
    "Interpolate 1-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
    input Integer tableID;
    input Integer icol;
    input Real u;
    output Real value;
  external "C" value =
                     ModelicaTables_CombiTable1D_interpolate(tableID, icol, u);
  end tableIpo;
equation 
  if tableOnFile then
    assert(tableName<>"NoName", "tableOnFile = true and no table name given");
  end if;
  if not tableOnFile then
    assert(size(table,1) > 0 and size(table,2) > 0, "tableOnFile = false and parameter table is an empty matrix");
  end if;

  for i in 1:n loop
    y[i] = if not tableOnFile and size(table,1)==1 then 
             table[1, columns[i]] else tableIpo(tableID, columns[i], u[i]);
  end for;
  when initial() then
    tableID=tableInit(if tableOnFile then tableName else "NoName",
                      if tableOnFile then fileName else "NoName", table, smoothness);
  end when;
end CombiTable1D;

Modelica.Blocks.Tables.CombiTable1Ds Modelica.Blocks.Tables.CombiTable1Ds

Table look-up in one dimension (matrix/file) with one input and n outputs

Modelica.Blocks.Tables.CombiTable1Ds

Information


Linear interpolation in one dimension of a table. Via parameter columns 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:

  1. Explicitly supplied as parameter matrix "table", and the other parameters have the following values:
       tableName is "NoName" or has only blanks,
       fileName  is "NoName" or has only blanks.
    
  2. Read from a file "fileName" where the matrix is stored as "tableName". Both ASCII and binary file format is possible. (the ASCII format is described below). It is most convenient to generate the binary file from Matlab (Matlab 4 storage format), e.g., by command
       save tables.mat tab1 tab2 tab3 -V4
    
    when the three tables tab1, tab2, tab3 should be used from the model.
  3. Statically stored in function "usertab" in file "usertab.c". The matrix is identified by "tableName". Parameter fileName = "NoName" or has only blanks.

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.

Extends from Modelica.Blocks.Interfaces.SIMO (Single Input Multiple Output continuous control block).

Parameters

TypeNameDefaultDescription
Integernoutsize(columns, 1)Number of outputs
table data definition
BooleantableOnFilefalsetrue, if table is defined on file or in function usertab
Realtable[:, :]fill(0.0, 0, 2)table matrix (grid = first column; e.g., table=[0,2])
StringtableName"NoName"table name on file or in function usertab (see docu)
StringfileName"NoName"file where matrix is stored
table data interpretation
Integercolumns[:]2:size(table, 2)columns of table to be interpolated
SmoothnesssmoothnessTypes.Smoothness.LinearSegme...smoothness of table interpolation

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputy[nout]Connector of Real output signals

Modelica definition

model CombiTable1Ds 
  "Table look-up in one dimension (matrix/file) with one input and n outputs"

  import Modelica.Blocks.Types;
  parameter Boolean tableOnFile=false 
    "true, if table is defined on file or in function usertab";
  parameter Real table[:, :]=fill(0.0,0,2) 
    "table matrix (grid = first column; e.g., table=[0,2])";
  parameter String tableName="NoName" 
    "table name on file or in function usertab (see docu)";
  parameter String fileName="NoName" "file where matrix is stored";
  parameter Integer columns[:]=2:size(table, 2) 
    "columns of table to be interpolated";
  parameter Modelica.Blocks.Types.Smoothness smoothness=Types.Smoothness.LinearSegments 
    "smoothness of table interpolation";
  extends Modelica.Blocks.Interfaces.SIMO(final nout=size(columns, 1));

protected 
  Integer tableID;

  function tableInit 
    "Initialize 1-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
    input String tableName;
    input String fileName;
    input Real table[ :, :];
    input Modelica.Blocks.Types.Smoothness smoothness;
    output Integer tableID;
  external "C" tableID=  ModelicaTables_CombiTable1D_init(
                 tableName, fileName, table, size(table, 1), size(table, 2),
                 smoothness);
  end tableInit;

  function tableIpo 
    "Interpolate 1-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
    input Integer tableID;
    input Integer icol;
    input Real u;
    output Real value;
  external "C" value =
                     ModelicaTables_CombiTable1D_interpolate(tableID, icol, u);
  end tableIpo;

equation 
  if tableOnFile then
    assert(tableName<>"NoName", "tableOnFile = true and no table name given");
  end if;
  if not tableOnFile then
    assert(size(table,1) > 0 and size(table,2) > 0, "tableOnFile = false and parameter table is an empty matrix");
  end if;

  for i in 1:nout loop
    y[i] = if not tableOnFile and size(table,1)==1 then 
             table[1, columns[i]] else tableIpo(tableID, columns[i], u);
  end for;
  when initial() then
    tableID=tableInit(if tableOnFile then tableName else "NoName",
                      if tableOnFile then fileName else "NoName", table, smoothness);
  end when;
end CombiTable1Ds;

Modelica.Blocks.Tables.CombiTable2D Modelica.Blocks.Tables.CombiTable2D

Table look-up in two dimensions (matrix/file)

Modelica.Blocks.Tables.CombiTable2D

Information


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:

  1. Explicitly supplied as parameter matrix "table", and the other parameters have the following values:
       tableName is "NoName" or has only blanks,
       fileName  is "NoName" or has only blanks.
    
  2. Read from a file "fileName" where the matrix is stored as "tableName". Both ASCII and binary file format is possible. (the ASCII format is described below). It is most convenient to generate the binary file from Matlab (Matlab 4 storage format), e.g., by command
       save tables.mat tab1 tab2 tab3 -V4
    
    when the three tables tab1, tab2, tab3 should be used from the model.
  3. Statically stored in function "usertab" in file "usertab.c". The matrix is identified by "tableName". Parameter fileName = "NoName" or has only blanks.

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 table2D_1(3,4)   # comment line
0.0  1.0  2.0  3.0  # u[2] grid points
1.0  1.0  3.0  5.0
2.0  2.0  4.0  6.0

double table2D_2(4,4)   # comment line
0.0  1.0  2.0  3.0  # u[2] grid points
1.0  1.0  3.0  5.0
2.0  2.0  4.0  6.0
3.0  3.0  5.0  7.0
-----------------------------------------------------

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. The matrix elements are interpreted in exactly the same way as if the matrix is given as a parameter. For example, the first column "table2D_1[2:,1]" contains the u[1] grid points, and the first row "table2D_1[1,2:]" contains the u[2] grid points.

Extends from Modelica.Blocks.Interfaces.SI2SO (2 Single Input / 1 Single Output continuous control block).

Parameters

TypeNameDefaultDescription
table data definition
BooleantableOnFilefalsetrue, if table is defined on file or in function usertab
Realtable[:, :]fill(0.0, 0, 2)table matrix (grid u1 = first column, grid u2 = first row; e.g., table=[0,0;0,1])
StringtableName"NoName"table name on file or in function usertab (see docu)
StringfileName"NoName"file where matrix is stored
table data interpretation
SmoothnesssmoothnessTypes.Smoothness.LinearSegme...smoothness of table interpolation

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

model CombiTable2D "Table look-up in two dimensions (matrix/file) "

  import Modelica.Blocks.Types;
  extends Modelica.Blocks.Interfaces.SI2SO;

  parameter Boolean tableOnFile=false 
    "true, if table is defined on file or in function usertab";
  parameter Real table[:, :]=fill(0.0,0,2) 
    "table matrix (grid u1 = first column, grid u2 = first row; e.g., table=[0,0;0,1])";
  parameter String tableName="NoName" 
    "table name on file or in function usertab (see docu)";
  parameter String fileName="NoName" "file where matrix is stored";
  parameter Modelica.Blocks.Types.Smoothness smoothness=Types.Smoothness.LinearSegments 
    "smoothness of table interpolation";
protected 
  Integer tableID;

  function tableInit 
    "Initialize 2-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"

    input String tableName;
    input String fileName;
    input Real table[ :, :];
    input Modelica.Blocks.Types.Smoothness smoothness;
    output Integer tableID;
  external "C" tableID=  ModelicaTables_CombiTable2D_init(
                 tableName, fileName, table, size(table, 1), size(table, 2),
                 smoothness);
  end tableInit;

  function tableIpo 
    "Interpolate 2-dim. table defined by matrix (for details see: Modelica/Resources/C-Sources/ModelicaTables.h)"
    input Integer tableID;
    input Real u1;
    input Real u2;
    output Real value;
  external "C" value =
                     ModelicaTables_CombiTable2D_interpolate(tableID, u1, u2);
  end tableIpo;

equation 
  if tableOnFile then
    assert(tableName<>"NoName", "tableOnFile = true and no table name given");
  end if;
  if not tableOnFile then
    assert(size(table,1) > 0 and size(table,2) > 0, "tableOnFile = false and parameter table is an empty matrix");
  end if;

  y = tableIpo(tableID, u1, u2);
  when initial() then
    tableID=tableInit(if tableOnFile then tableName else "NoName",
                      if tableOnFile then fileName else "NoName", table, smoothness);
  end when;
end CombiTable2D;

Automatically generated Fri Nov 12 16:27:40 2010.