Book a Demo

Author Topic: Vector Simulation with openmodelica  (Read 26850 times)

DerDybel

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Vector Simulation with openmodelica
« on: September 05, 2023, 10:36:52 pm »
Hello,

I am relatively new to Enterprise Architect and SysML and have started doing parametric analyses using the interface of EA to openmodelica. This works quite well with 1D variables (eg.: x=1) but I seem to be unable to get the simulation to work with 3D vectors (e.g.: x=(1,2,3)).

Here is how my model and simulation are set up:

BDD:


Parametric Diagram of "Block Needing Vetcor" Block:



IBD of "Vector Simulation Context" Block




When I run the simulation with values "1" and "0" for X and Y respectively, everything works fine. When I use (1,1,1) and (0,0,0) instead, I get the following error:

 Error: Tuple expressions may only occur on the left side of an assignment or equation with a single function call on the right side. Got the following expression: (1, 1, 1). (Expression: "      BlockNeedingVector Property1(pY=(0,0,0),pX=(1,1,1),Type="X1") annotation(Documentation(info = ""), Placement(visible = true, transformation( origin = {-70, -221}, extent = {{0, 0}, { 335, 402}})));  ")

What am I doing wrong? The type "Real" should cover vectors as well and even renaming parameters to indicate "extra dimensions" doesn't work (i.e.: pX --> pX[3]).

Thank you in advance.


« Last Edit: September 11, 2023, 08:36:37 pm by DerDybel »

DerDybel

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Vector Simulation with openmodelica
« Reply #1 on: September 11, 2023, 06:10:14 pm »
Update: I recognised my mistake in declaring arrays with "()" instead of the correct form "{}". However, in doing so I only managed to shift the error somewhere else.

If the input is declared like this pX={1,1,1} then the following error is displayed: 

Error: Type mismatch in binding ‘pX = {1, 1, 1}‘, expected array dimensions [], got [3]. (Expression: "      parameter Real pX annotation(Documentation(info = ""), Placement(visible = true, transformation( origin = {-81, -180}, extent = {{0, 0}, { 85, 32}})));  ")

Fair enough, in modelica arrays need to be declared like this: pX[3]={1,1,1}. However, when this is implemented the constraint formula no longer recognises the parameters as inputs ("Not Required Parameters"), no matter how the parameters are used in the formula





Consequently, the error message says that the variable could not be found in the scope of the block "Block Needing Vector".




DerDybel

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Vector Simulation with openmodelica
« Reply #2 on: September 13, 2023, 05:00:53 pm »
Another Update (but still no solution):

I changed the parameters to SysPhs Constants and Variables and was able to use multiplicity and the SysPhs "Multidimensional Element" Stereotype to specify them as vectors:





However, even though it now seemingly looks right in the Sim, modelica still doesn't get it:





Anyone have any suggestions?

fishy

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Vector Simulation with openmodelica
« Reply #3 on: January 14, 2026, 03:05:09 am »
I suspect, based on my own testing, that this is due several a bugs in how EA writes Modelica code...

To understand what's happening, you really need to take a look at the Modelica code generatedby EA when you press 'Solve' or 'Validate' in the 'Configure SysML Simulation' window.

In SysML, the natural way to work with vector quantities (1-d arrays) is to declare multiplicity on a parameter.
In EA, this means setting 'Property > Multiplicity > Upper bound' to a value greater than 1 (or potentially *) for an aribtrary upper bound.

But if you do this, EA messes up the syntax for Modelica definitions...

In your example, the correct definition for your 'ChooseVector' <<constraint>> would be:

    class ChooseVector;
        Real pX[3];
        Real pY[3];
        Real p[3];
        equation
            p = if (Type==X1) then pX else pY;
    end ChooseVector;


However, if you specify SysML multiplicity on the parameter, EA instead generates this:

    class ChooseVector;
        RealU005B3U005D pX;
        RealU005B3U005D pY;
        RealU005B3U005D p;
        equation
            p = if (Type==X1) then pX else pY;
    end ChooseVector;


...it's messing up in two ways:
  • It substitutes Unicode codes rather than using an ASCII square bracket ( U005B = [, in unicode)
  • It uses SysML notation, by putting the dimension next to the type definition (Real in this case), rather than matching the Modelica syntax and placing the dimension next to the variable.

If instead you take your appoach, of using the SysPhS stereotypes, by setting:
  • MultidimensionalElement.dimension = 3
  • Part.Lower Value = 3
  • Part.Upper Value = 3

...then EA just ignores these settings and produces...

    class ChooseVector;
        Real pX;
        Real pY;
        Real p;
        equation
            p = if (Type==X1) then pX else pY;
    end ChooseVector;


Which is why you see the error you do:  Modelica thinks pX, pY and p are single-valued parameters and can't assign a three valued vector.
« Last Edit: January 16, 2026, 03:30:29 am by fishy »
-Neil

fishy

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Vector Simulation with openmodelica
« Reply #4 on: January 14, 2026, 03:28:26 am »
-Neil