blockCombiTable1Ds_ForStepMeteo

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

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

Information

Modification of CombiTable1Ds Modelica model in order to have a piecewise constant function adapted to meteorological data files

Hypothesis and equations

Constant piecewise 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.

Notes:

  • The interpolation is efficient, because a search for a new interpolation starts at the interval used in the last call.
  • If the table has only one row, the table value is returned, independent of the value of the input signal.
  • If the input signal u is outside of the defined interval, i.e., u > table[size(table,1),1] or u < table[1,1], the corresponding value is also determined by linear interpolation through the last or first two points of the table.
  • The grid values (first column) have to be strictly increasing.

Bibliography

Derived from the Modelica.Blocks.Tables.CombiTable1Ds model .

Instructions for use

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:
  2.    tableName is "NoName" or has only blanks,
       fileName  is "NoName" or has only blanks.
  3. Read from a file "fileName" where the matrix is stored as "tableName". Both ASCII and MAT-file format is possible. (The ASCII format is 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
  4.    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.

  5. Statically stored in function "usertab" in file "usertab.c". The matrix is identified by "tableName". Parameter fileName = "NoName" or has only blanks. Row-wise storage is always to be preferred as otherwise the table is reallocated and transposed. See the Tables package documentation for more details.

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 tables are read from an ASCII-file, the file needs 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" (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. 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 ( ), comma (,), or semicolon (;). Several matrices may be defined one after another. Line comments start with the hash symbol (#) and can appear everywhere. Other characters, like trailing non comments, are not allowed in the file.

MATLAB is a registered trademark of The MathWorks, Inc.

Known limits / Use precautions

none

Validations

Validated model

--------------------------------------------------------------
Licensed by EDF under a 3-clause BSD-license
Copyright © EDF 2009 - 2023
BuildSysPro version 3.6.0
Author : Hassan BOUIA, Amy LINDSAY, EDF (2014)
--------------------------------------------------------------

Parameters

TypeNameDefaultDescription
Integernout (from SIMO)1Number of outputs
Realdelta_t3600Constant time step of the file in [s]
Integer[nout]optionfill(1, nout)=0 if piecewise constant function
Table data definition
BooleantableOnFilefalse= true, if table is defined on file or in function usertab
Real[:,:]tablefill(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
BooleanverboseReadtrue= true, if info message that file is loading is to be printed
Table data interpretation
Integer[:]columns2:size(table, 2)Columns of table to be interpolated
Modelica.Blocks.Types.SmoothnesssmoothnessModelica.Blocks.Types.Smoothness.LinearSegmentsSmoothness of table interpolation

Connectors

TypeNameDefaultDescription
RealInputu (from SIMO)Connector of Real input signal
RealOutput[nout]y (from SIMO)Connector of Real output signals

Components

TypeNameDefaultDescription
Realu1integer(u/delta_t)*delta_t + delta_t/2

Contents

NameDescription
readTableDataprotectedRead table data from ASCII text or MATLAB MAT-file
getTableValueprotectedInterpolate 1-dim. table defined by matrix
getTableValueNoDerprotectedInterpolate 1-dim. table defined by matrix (but do not provide a derivative function)
getDerTableValueprotectedDerivative of interpolated 1-dim. table defined by matrix

Revisions

12/2014 H. Bouia, A. Lindsay : modification du modèle CombiTable1Ds de Modelica afin que la fonction en escaliers corresponde bien à ce qu'on attend en sortie d'un fichier météo