Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Look up Table content

Look up Table content

Hey,

I just started to use Open Modelica with Sim Forge. I actually try to write a table which should be looked up in another block. How can I do that? I know it seems to be a very easy thing to do, but it would be nice if somebody could help me out!

Thanx Markus

Re: Look up Table content

I also just started to use OpenModelica, and am having difficulty with CombiTable1Ds. I have this line in my model:
   Tables.CombiTable1Ds Table2(tableOnFile=false,table = [0,0,1,0;1,2,3,1;1.5,4,10,2],columns={1,3}) - it won't compile
I also tried
   Tables.CombiTable1Ds Table2(tableOnFile=false,table = [0,0,1,0;1,2,3,1;1.5,4,10,2],columns=[1;3])  and
   Tables.CombiTable1Ds Table2(tableOnFile=false,table = [0,0,1,0;1,2,3,1;1.5,4,10,2],columns=[1,3])
The  last two compiled, but give me run time errors. Can someone give me a working example?
Thanks in advance, Phil

Re: Look up Table content

I got CombiTable1Ds to compile and run with the following declaration

Tables.CombiTable1Ds Table1(tableOnFile=false,table=[0,0;1,1;2,4;3,10])

However, the simulation result is wrong --- CombiTable1Ds simply sets the output equal to its input.

I am sure many people have used CombiTable1Ds successfully. Can someone tell me what I am doing wrong? Here's the rest of the model

model Table1
   import Modelica.Blocks.Sources;
   import Modelica.Blocks.Tables;
   Tables.CombiTable1Ds Table1(tableOnFile=false,table=[0,0;1,1;2,4;3,10]);
   Sources.Ramp Ramp22(height=1,duration=3); 
equation
   connect(Ramp22.y,Table1.u);
end Table1;

Re: Look up Table content

Hi guys,

the thing is, that the 1ds table is interpolating.

This works fine for me in dymola:

  Modelica.Blocks.Tables.CombiTable1Ds combiTable1Ds(table=[0,5; 1,1; 2,1; 5,2;10,8]);
equation
  combiTable1Ds.u = time;
end Unnamed;

The problem lies in your parametrization, which is by coincidence equal to input. Change it and see. If it doesnt work in openModelica, then blame it.


Documentation follows:

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 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 strict monotonically increasing.
The table matrix can be defined in the following ways:
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.
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.
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).

Re: Look up Table content

Thanks, jez, for looking into this. There is something strange about the Ramp block, or I am not using it correctly. Here's what I did:
model Table1
   import Modelica.Blocks.Sources;
   import Modelica.Blocks.Tables;
   Tables.CombiTable1Ds Table1(table=[0,0;1,1;2,2;3,10]);
   Tables.CombiTable1Ds Table2(table=[0,0;1,1;2,2;3,10]);
   Sources.Ramp Ramp22(height=1,duration=3);
equation
   Table1.u=Ramp22.y;
   Table2.u=time;
end Table1;

I plotted the output from Table1 and Table2. As I expected, Table2.y[1] is correct, but Table1.y[1] is not. Any thoughts?

Thanks
Phil

Re: Look up Table content

Hi, as a followup, I replaced the Ramp block with a Clock with no offset, and it also gave me the right result. - Thanks, again.
Phil

Re: Look up Table content

Hey Folks, thanx for the replies. I actually trying to modelate it with SimForge! Do you use that programm or some other? I tried to copy your equation and run them, but I only get some error messages which I dont understand.

Re: Look up Table content

Ahh, I just found my mistace! Thanx again Markus!

Re: Look up Table content

Hi beckling,
I use OpenModelica with the SimForge user interface and sometimes just omcshell. I takes a while to learn the in's and out's of the system.
Phil

There are 0 guests and 0 other users also viewing this topic