Opened 14 years ago

Closed 10 years ago

#1531 closed defect (fixed)

expanding array equation in when clauses

Reported by: Willi Braun Owned by: Lennart Ochel
Priority: high Milestone:
Component: Backend Version:
Keywords: Cc: Willi Braun

Description

The following does not work, while the comment stuff does:

function f
  input Real[:] a;
  output Real[size(a,1)] b;
algorithm
  for i in 1:size(a,1) loop
    b[i] := a[i] + 1;
  end for;
end f;
model ArrayWhenFunction
parameter Real a[3]={3,1,2};
//parameter Real a1[3]={3,1,2};
//parameter Real b[3]={1,1,1};
Real res[3];
Real x(start =1);
equation
  der(x) = x;
  when time > 0.5 then 
    res = f(a);
    //res = a1+b;
  end when;  
end ArrayWhenFunction;

All array's are expand, beside the lhs in a when clause.
I'm not sure has this to be done in while the instantiation or in the Backend while create the BackendDAE structure.
My guess is while the instantiation, because all other expression are also expanded there:

$ omc ../Modelica/FunctionWhen.mo
function f
  input Real[:] a;
  output Real[size(a,1)] b;
algorithm
  for i in 1:size(a,1) loop
    b[i] := 3.0 + a[i];
  end for;
end f;
class ArrayWhenFunction
  parameter Real a[1] = 3.0;
  parameter Real a[2] = 1.0;
  parameter Real a[3] = 2.0;
  Real res[1];
  Real res[2];
  Real res[3];
  Real x(start = 1.0);
equation
  der(x) = x;
  when time > 0.5 then
  res = f({a[1],a[2],a[3]});
  end when;
end ArrayWhenFunction;

Change History (5)

comment:1 by Martin Sjölund, 14 years ago

This is just a problem with the equation count, right?

comment:2 by Willi Braun, 14 years ago

yes, it seems so.

comment:3 by Martin Sjölund, 12 years ago

Cc: wbraun, → wbraun
Component: Backend

This now fails code generation (pre(array)?)

comment:4 by Willi Braun, 10 years ago

Owner: changed from Willi Braun to Lennart Ochel
Status: newassigned

Now it works, although only with numerical initialization.

Notification: The given system is mixed-determined.   [index > 0]
Notification: The given system is mixed-determined.   [index > 1]
Notification: The given system is mixed-determined.   [index > 2]
Notification: The given system is mixed-determined.   [index > 3]
Warning: No system for the symbolic initialization was generated. A method using numerical algorithms will be used instead.

comment:5 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: assignedclosed

This got fixed in the meantime.

Note: See TracTickets for help on using tickets.