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

Array of Components

Array of Components

Hello,
I'm trying to make a 3d look-up table component, by using several CombiTable2d tables whose output will populate an array of ordinates that can be used by the Modelica.Math.Vectors.interpolate function, to give a single Real output.

The CombiTable2d table's data will not be read from file but instead hardwired from values in declared arrays.

I'm using the following sources as guidance:

http://book.xogeny.com/components/subsy … s/#index-0
https://www.modelica.org/events/modelic … sion5a.pdf
Peter Fritzson book (2nd Ed.)

The code below is as far as I've got, but when run in OM the "y" output from each of the two CombiTable2d tables is the same (both 2.63) whereas one should be 1.36. Clicking the "Instantiate Model" button in OMEdit, it confirms that both tables are being feed the same array data.

I haven't used Modelica before so I'm seeking a bit of guidance as to how best to go about this. I have used causal block diagram software before and soon felt the pain and its limitation when is came to model modifications and maintenance. Modelica's equation based components seem like wizardry in comparison.

Thanks for any help,  Bob Flandard

______________________________________________________________________________________________________________________
!!! Start of my sample model code !!!
model testArrays2

Modelica.Blocks.Interfaces.RealInput x1 annotation(Placement(visible = true, transformation(origin = {-100, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-94, 58}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));

Modelica.Blocks.Interfaces.RealInput x2 annotation(Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-92, -2}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));

Modelica.Blocks.Interfaces.RealInput x3 annotation(Placement(visible = true, transformation(origin = {-100, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-92, -58}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));


parameter Integer nTabs=2;
parameter Real MyTable1[4,4]=[0, 0 , 5, 10;
                            0, 1.36, 10, -10;
                            5, 2, 20, -20;
                            10, 3, 30, -30];
                           
parameter Real MyTable2[4,4]=[0, 0 , 5, 10;
                            0, 2.63, 13, -1;
                            5, 3, 15, -6.5;
                            10, 4, 21, -21.2];
                                                   
encapsulated record LUT
      Real table[4,4];
end LUT;


parameter LUT[nTabs] MyLUTs={LUT(MyTable1),LUT(MyTable2)};

Modelica.Blocks.Tables.CombiTable2D My2DTables[nTabs](table= array(MyLUTs[i].table for i in 1:nTabs));
                                                 
equation
for i in 1:nTabs loop
   My2DTables[i].u1 = abs(x1);
   My2DTables[i].u2 = abs(x2);
end for;
end testArrays2;
!!! End of my sample model code !!!

______________________________________________________________________________________________________________________
!!! Start code snippets from "Instantiate Model" !!!
protected Modelica.Blocks.Types.ExternalCombiTable2D My2DTables[1].tableID = Modelica.Blocks.Types.ExternalCombiTable2D.constructor("NoName", "NoName", {{0.0, 0.0, 5.0, 10.0}, {0.0, 2.63, 13.0, -1.0}, {5.0, 3.0, 15.0, -6.5}, {10.0, 4.0, 21.0, -21.2}}, Modelica.Blocks.Types.Smoothness.LinearSegments) "External table object";
  protected parameter Real My2DTables[1].tableOnFileRead(fixed = false) "= 1, if table was successfully read from file";

  protected Modelica.Blocks.Types.ExternalCombiTable2D My2DTables[2].tableID = Modelica.Blocks.Types.ExternalCombiTable2D.constructor("NoName", "NoName", {{0.0, 0.0, 5.0, 10.0}, {0.0, 2.63, 13.0, -1.0}, {5.0, 3.0, 15.0, -6.5}, {10.0, 4.0, 21.0, -21.2}}, Modelica.Blocks.Types.Smoothness.LinearSegments) "External table object";
  protected parameter Real My2DTables[2].tableOnFileRead(fixed = false) "= 1, if table was successfully read from file";
!!! End code snippets from "Instantiate Model" !!!
______________________________________________________________________________________________________________________

Re: Array of Components

Hello matth,

Thanks for the links, they look very interesting.

External C code libraries are possibly a bit beyond my current abilities and I didn't see any spoon fed examples. But definitely one for the future.

Regards, Bob

Re: Array of Components

AFAIK the Modelica tables all use external C code, but in all cases you dont have to configure that, you just stay on the Modelcia side of the wrapper.
There are some examples available: Go to https://bitbucket.org/3DS/simdevtools/src then Modelica, SimDevTools, Examples

Re: Array of Components

Hello Matth,

There seems to be no content in the library and include directories, just ".gitignore" files. Otherwise it does look like a useful package, but I'm weary at this stage (with my limited Modelica experience) of spending too much time on something with such little documentation. But thanks very much for the pointers, and I may well follow them up when I've gained a few more Modelica flying hours.

Regards, Bob

Re: Array of Components

Hi,
I dont want to push you into using that library, I dont even use it myself, but the repository is not empty, there are lots of files, including the Modelica files, and there is plenty of documentation, see also my first post here.
A 3D interpolating table is just not part of the MSL and no matter what solution you are going for will include some work.
Best,
Matthis

Re: Array of Components

Thanks Matthis,

It certainly looks very useful and I will have a play when I've had more Modelica experience.

Regards, Bob

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