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

initialisation array

initialisation array

model Test
parameter Integer nbr_reaction = 3;
parameter Integer nbr_espece_aq = 7;
Integer nu_aq[nbr_reaction, nbr_espece_aq] = fill(0,nbr_reaction, nbr_espece_aq);

equation
//
  nu_aq[1,1] = -1 ;
  nu_aq[1,2] = -1 ;


end Test;

I have not found how to assign values to nu_aq

Re: initialisation array

Nobody can help me  ?

Re: initialisation array

You really need to learn more about Modelica, see a tutorial: https://openmodelica.org/images/M_image … OD2020.pdf
or an online book: http://mbe.modelica.university/

You need to do it in an "initial equation" section or using (start=value) for the component if you want the array to have certain values at initialization.
Note that fill(0,nbr_reaction, nbr_espece_aq) is a binding equation for the array.

Code:


model Test
  parameter Integer nbr_reaction = 3;
  parameter Integer nbr_espece_aq = 7;
  Integer nu_aq[nbr_reaction, nbr_espece_aq] = fill(0,nbr_reaction, nbr_espece_aq);
initial equation
  nu_aq[1,1] = -1 ;
  nu_aq[1,2] = -1 ;
end Test;

Code:


model Test
  parameter Integer nbr_reaction = 3;
  parameter Integer nbr_espece_aq = 7;
  Integer nu_aq[nbr_reaction, nbr_espece_aq](each start = -1);
equation
  ....
end Test;

Re: initialisation array

Thank you for the answer,

in fact this is not exactly what I need to do.

Most of the matric nu_aq should be zero and for some specific element another value, for example aq_nu[1,1] = -1,  aq_nu[3,1] = -4,  aq_nu[4,4] = -3

I managed to do it like this for a 2x2 matrix  :

parameter Integer nbr_reaction = 2;
  parameter Integer nbr_espece_aq = 2;
  parameter Integer nu_aq[nbr_reaction, nbr_espece_aq] = [1,2;3,4];

But this is very awkward and cumbersome when the matrix is large and you have only very few element to set

Re: initialisation array

Then use an initial algorithm section:

Code:


initial algorithm // only called at initialization
  // in algorithm sections the order is kept and these are assignments
  // fill everything with zero
  nu_aq := fill(0,nbr_reaction, nbr_espece_aq);
  // set some elements to some other values
  nu_aq[1,1] := -1 ;
  nu_aq[1,2] := -1 ;
equation
  ...

Edited by: adrpo - Jan-14-21 15:42:28
There are 0 guests and 0 other users also viewing this topic