Question Details

No question body available.

Tags

function parameters modelica

Answers (1)

Accepted Answer Available
Accepted Answer
January 28, 2026 Score: 1 Rep: 13,093 Quality: High Completeness: 60%

It's possible to get it to work without any extras by using fixed=false in your example.

  parameter Real vec[:] = {-1, 8, 3, 6, 2};
  parameter Real v1[size(vec,1)](each fixed=false);
  parameter Integer i1[size(vec,1)](each fixed=false);
initial algorithm 
  (v1,i1)  := Modelica.Math.Vectors.sort(vec);

And I see two other possibilities, and in all cases a complication is the need to handle the sizes of the outputs.

Either you create a function returning both as a record, and create an intermediate record variable or you do the same without the intermediate record variable using member access.

  parameter Real vec[:] = {-1, 8, 3, 6, 2};
  parameter Real vec3[:] = {-1, 8, 3, 6}; // Other vector

record R "Helper record" Real v[:]; Integer i[:]; end R; function sortR "Helper function" input Real vec[:]; output R r(redeclare Real v[size(vec, 1)], redeclare Integer i[size(vec, 1)]); algorithm (r.v, r.i) := Modelica.Math.Vectors.sort(vec); end sortR;

// Using member access requires Modelica Language 3.7 parameter Real v2[:]=(sortR(vec)).v; parameter Integer i2[:]=(sortR(vec)).i;

// Using intermediate record variable parameter R r3=sortR(vec3); parameter Real v3[:]=r3.v; parameter Integer i3[:]=r3.i;

The member access is added to Modelica 3.7, but already supported in Dymola 2025x Refresh 1, and even if there are two calls to the function (with the same argument) that's straightforward to optimize.