blockFileUpdateTimeTable

Table look-up with respect to time and various interpolation and extrapolation methods (data from file)

Extends from CombiTimeTable (Table look-up with respect to time and various interpolation and extrapolation methods (data from matrix/file)).

Information

This block generates an output signal y[:] by constant, linear or cubic Hermite spline 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.

CombiTimeTable.png

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 properties:

  • The interpolation interval is found by a binary search where the interval used in the last call is used as start interval.
  • The time points need to be strictly increasing for cubic Hermite spline interpolation, otherwise monotonically increasing.
  • Discontinuities are allowed for (constant or) linear interpolation, by providing the same time point twice in the table.
  • Via parameter smoothness it is defined how the data is interpolated:
    smoothness = 1: Linear interpolation
               = 2: Akima interpolation: Smooth interpolation by cubic Hermite
                    splines such that der(y) is continuous, also if extrapolated.
               = 3: Constant segments
               = 4: Fritsch-Butland interpolation: Smooth interpolation by cubic
                    Hermite splines such that y preserves the monotonicity and
                    der(y) is continuous, also if extrapolated.
               = 5: Steffen interpolation: Smooth interpolation by cubic Hermite
                    splines such that y preserves the monotonicity and der(y)
                    is continuous, also if extrapolated.
               = 6: Modified Akima interpolation: Smooth interpolation by cubic
                    Hermite splines such that der(y) is continuous, also if
                    extrapolated. Additionally, overshoots and edge cases of the
                    original Akima interpolation method are avoided.
               = 7: Natural cubic spline interpolation, such that der(y) and der2(y)
                    are continuous.
    
  • First and second derivatives are provided, with exception of the following two smoothness options.
    1. No derivatives are provided for interpolation by constant segments.
    2. No second derivative is provided for linear interpolation.
      There is a design inconsistency, that it is possible to model a signal consisting of constant segments using linear interpolation and duplicated sample points. In contrast to interpolation by constant segments, the first derivative is provided as zero.
  • Values outside of the table range, are computed by extrapolation according to the setting of parameter extrapolation:
    extrapolation = 1: Hold the first or last value of the table,
                       if outside of the table scope.
                  = 2: Extrapolate by using the derivative at the first/last table
                       points if outside of the table scope.
                       (If smoothness is LinearSegments or ConstantSegments
                       this means to extrapolate linearly through the first/last
                       two table points.).
                  = 3: Periodically repeat the table data (periodical function).
                  = 4: No extrapolation, i.e. extrapolation triggers an error
    
  • If the table has only one row, no interpolation is performed and the table values of this row are just returned.
  • Via parameters shiftTime and offset the curve defined by the table can be shifted both in time and in the ordinate value. The time instants stored in the table are therefore relative to shiftTime.
  • If time < startTime, no interpolation is performed and the offset is used as ordinate value for all outputs.
  • The table is implemented in a numerically sound way by generating time events at interval boundaries, in case of interpolation by linear segments. This generates continuously differentiable values for the integrator. Via parameter timeEvents it is defined how the time events are generated:
    timeEvents = 1: Always generate time events at interval boundaries
               = 2: Generate time events at discontinuities (defined by duplicated sample points)
               = 3: No time events at interval boundaries
    
    For interpolation by constant segments time events are always generated at interval boundaries. For smooth interpolation by cubic Hermite splines no time events are generated at interval boundaries.
  • Via parameter timeScale the first column of the table array can be scaled, e.g., if the table array is given in hours (instead of seconds) timeScale shall be set to 3600.
  • For special applications it is sometimes needed to know the minimum and maximum time instant defined in the table as a parameter. For this reason parameters t_min/t_minScaled and t_max/t_maxScaled are provided and can be accessed from the outside of the table object. Whereas t_min and t_max define the scaled abscissa values (using parameter timeScale) in SI.Time, t_minScaled and t_maxScaled define the unitless original abscissa values of the table.

Example:

table = [0, 0;
         1, 0;
         1, 1;
         2, 4;
         3, 9;
         4, 16];
extrapolation = 2 (default), timeEvents = 2
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:

  1. Read from a file "fileName" where the matrix is stored as "tableName". CSV, EPW, JSON, text and MATLAB MAT-file format is possible. (Both the limitations on the CSV format and the text format are described below). The MAT-file format comes in four different versions: v4, v6, v7 and v7.3. The library supports at least v4, v6 and v7 whereas v7.3 is optional. It is most convenient to generate the MAT-file from FreeMat or MATLAB® by command
    save tables.mat tab1 tab2 tab3
    
    or Scilab by command
    savematfile tables.mat tab1 tab2 tab3
    
    when the three tables tab1, tab2, tab3 should be used from the model.
    Note, a fileName can be defined as URI by using the helper function loadResource.

When the constant "NO_FILE_SYSTEM" is defined, all file I/O related parts of the source code are removed by the C-preprocessor, such that no access to files takes place.

If the table is read from a CSV file, the following limitations apply

  1. Non-numeric data is silently considered as value 0.0.

If tables are read from a text file, the file needs 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" (a line comment defining the version number of the file format). Afterwards, the corresponding matrix has to be declared with type (= "double" or "float"), name and actual dimensions. A valid matrix name (e.g., "tab1") must be ASCII encoded and not contain blanks, line breaks, tab (\t), comma (,) or parentheses. Finally, in successive rows of the file, the elements of the matrix have to be given. The elements have to be provided as a sequence of numbers in row-wise order (therefore a matrix row can span several lines in the file and need not start at the beginning of a line). Numbers have to be given according to C syntax (such as 2.3, -2, +2.e4). Number separators are spaces, tab (\t), comma (,), or semicolon (;). Several matrices may be defined one after another. Line comments start with the hash symbol (#) and can appear everywhere. Text files should either be ASCII or UTF-8 encoded, where UTF-8 encoded strings are only allowed in line comments and an optional UTF-8 BOM at the start of the text file is ignored. Other characters, like trailing non comments, are not allowed in the file.

MATLAB is a registered trademark of The MathWorks, Inc.

Parameters

TypeNameDefaultDescription
Integernout (from MO)1Number of outputs
Modelica.Units.SI.Timet_min (from CombiTimeTable)t_minScaled*timeScaleMinimum abscissa value defined in table
Modelica.Units.SI.Timet_max (from CombiTimeTable)t_maxScaled*timeScaleMaximum abscissa value defined in table
Realt_minScaled (from CombiTimeTable)Internal.getTimeTableTmin(tableID)Minimum (scaled) abscissa value defined in table
Realt_maxScaled (from CombiTimeTable)Internal.getTimeTableTmax(tableID)Maximum (scaled) abscissa value defined in table
Table data definition
BooleantableOnFile (from CombiTimeTable)false= true, if table is defined on file or in function usertab
Real[:,:]table (from CombiTimeTable)fill(0.0, 0, 2)Table matrix (time = first column; e.g., table=[0, 0; 1, 1; 2, 4])
StringtableName (from CombiTimeTable)"NoName"Table name on file or in function usertab (see docu)
StringfileName (from CombiTimeTable)"NoName"File where matrix is stored
Stringdelimiter (from CombiTimeTable)","Column delimiter character for CSV file
IntegernHeaderLines (from CombiTimeTable)0Number of header lines to ignore for CSV file
BooleanverboseRead (from CombiTimeTable)true= true, if info message that file is loading is to be printed
BooleanforceReadfalse= true: Force reading of table data; = false: Only read, if not yet read.
Table data interpretation
Integer[:]columns (from CombiTimeTable)2:size(table, 2)Columns of table to be interpolated
ModelicaTableAdditions.Blocks.Types.Smoothnesssmoothness (from CombiTimeTable)ModelicaTableAdditions.Blocks.Types.Smoothness.LinearSegmentsSmoothness of table interpolation
Modelica.Blocks.Types.Extrapolationextrapolation (from CombiTimeTable)Modelica.Blocks.Types.Extrapolation.LastTwoPointsExtrapolation of data outside the definition range
Modelica.Units.SI.TimetimeScale (from CombiTimeTable)1Time scale of first table column
Real[:]offset (from CombiTimeTable){0}Offsets of output signals
Modelica.Units.SI.TimestartTime (from CombiTimeTable)0Output = offset for time < startTime
Modelica.Units.SI.TimeshiftTime (from CombiTimeTable)startTimeShift time of first table column
Modelica.Blocks.Types.TimeEventstimeEvents (from CombiTimeTable)Modelica.Blocks.Types.TimeEvents.AlwaysTime event handling of table interpolation
BooleanverboseExtrapolation (from CombiTimeTable)false= true, if warning messages are to be printed if time is outside the table definition range

Connectors

TypeNameDefaultDescription
RealOutput[nout]y (from MO)Connector of Real output signals
Modelica.Blocks.Interfaces.BooleanInputupdateTriggerConnector of Boolean input signal for reading table data from file

Components

TypeNameDefaultDescription
RealreadSuccessTable read success