ModelicaAdditions.Tables

ModelicaAdditions.Tables.CombiTableTime ModelicaAdditions.Tables.CombiTable1D ModelicaAdditions.Tables.CombiTable2D

Information


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 
   CombiTable1D    Table look-up in one dimension
   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.

Main Author:
Martin Otter
Deutsches Zentrum für Luft und Raumfahrt e.V. (DLR)
Institut für Robotik und Mechatronik
Postfach 1116
D-82230 Wessling
Germany
email: Martin.Otter@dlr.de

Release Notes:


Copyright (C) 2000, 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".


ModelicaAdditions.Tables.CombiTableTime ModelicaAdditions.Tables.CombiTableTime

Table look-up with time as abszissa (matrix/file)

ModelicaAdditions.Tables.CombiTableTime

Information


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:

  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(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.


Parameters

NameDefaultDescription
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

Modelica definition

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;

ModelicaAdditions.Tables.CombiTable1D ModelicaAdditions.Tables.CombiTable1D

Table look-up in one dimension (matrix/file)

ModelicaAdditions.Tables.CombiTable1D

Information


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:

  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.


Parameters

NameDefaultDescription
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

Modelica definition

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;

ModelicaAdditions.Tables.CombiTable2D ModelicaAdditions.Tables.CombiTable2D

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

ModelicaAdditions.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 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.


Parameters

NameDefaultDescription
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)

Modelica definition

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;

HTML-documentation generated by Dymola Tue Jun 20 22:12:20 2000 .