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

How to defined conditional Array dimension

How to defined conditional Array dimension

I have tried to fit the size of an array depending on a boolean :

The error message is  :

[1] 09:04:41 Traduction Erreur
[Test16: 16:5-16:14]: Could not evaluate structural parameter (or constant): N which gives dimensions of array: A. Array dimensions must be known at compile time.

package Test16
  model R1
    parameter Integer N (fixed = false)  ;
    parameter Boolean iB = true ;
    equation
    if iB then
    N = 3 ;
    else
    N = 1 ;
    end if ;
  end R1;

  model R2
    extends R1;
    Real x  ;
    Real A[N];
  equation
    x = 2.;
  end R2;
end Test16;

Re: How to defined conditional Array dimension

Hi,
Noboby can help ?
Best Regards

Edited by: JPG84 - Jan-27-21 12:06:14

Re: How to defined conditional Array dimension

Like the error message says the array dimension must be defined at compile time, not by an equation system that's solved during initialization/simulation. So for example:

Code:


  model R1
    parameter Integer N = if iB then 3 else 1;
    parameter Boolean iB = true ;
  end R1;

Re: How to defined conditional Array dimension

Thank you,

It works ! 

I guess that equations are also compiled (Only one ?)

May be this should be explained in some tutorial.

Best Regard

Re: How to defined conditional Array dimension

You seem to be quite new with Modelica and OpenModelica. The book Modelica by Example from Dr. Michael M. Tiller gives a good introduction to Modelica and answers most questions you may have.

Re: How to defined conditional Array dimension

You are rigth I am a beginner in modelica. I find it very diffiult to learn as I usually program in unspecified language like Matlab ...

There are 0 guests and 0 other users also viewing this topic
You are here: