Opened 9 years ago

Closed 3 years ago

#3189 closed defect (fixed)

Partial function evaluation and arrays not working

Reported by: gustaf Owned by: somebody
Priority: high Milestone: 1.16.0
Component: New Instantiation Version: trunk
Keywords: Cc:

Description

Consider the following example similar to the function passed to function in #3008, but here the return type is an array instead of two values.

package TestArrayP
  partial function DerBase
    input Real x[:];
    output Real dx[size(x)];
  end DerBase;

  function TheDer
    extends DerBase;
    input Real x[:];
    output Real dx[size(x)];
  algorithm
    dx := 0.1 * x;
  end TheDer;

  function Euler
    input Real x[:];
    input DerBase f;
    input Real dt;
    output Real xNext[size(x)];
  protected
    Real dx[size(x)];
  algorithm
    dx := f(x);
    xNext := x + dx * dt;
  end Euler;
end TestArrayP;

model TestArray
  Real x[2] = {1.0, 2.0};
algorithm
  x[1] := 1.0;
  x[2] := 2.0;
  when sample (0, 0.1) then
    x := TestArrayP.Euler(x, TestArrayP.TheDer, 0.1);
  end when;
end TestArray;

Trying to compile it gives

$ omc -s TestArray.mo
Error processing file: TestArray.mo
[.../TestArray.mo:23:5-23:15:writable] Error: Type mismatch in assignment in dx := f(#(x)) of Real[size(x)] := #Real[size(x)]
Error: Error occurred while flattening model TestArray

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

$ omc --version
1.9.2+dev (r24700)

Change History (4)

comment:1 Changed 9 years ago by gustaf

  • Component changed from Unknown to Frontend

comment:2 Changed 9 years ago by gustaf

  • Owner changed from somebody to gustaf
  • Status changed from new to accepted

comment:3 Changed 9 years ago by adrpo

  • Owner changed from gustaf to somebody
  • Status changed from accepted to assigned

comment:4 Changed 3 years ago by perost

  • Component changed from Frontend to New Instantiation
  • Milestone changed from Future to 1.16.0
  • Resolution set to fixed
  • Status changed from assigned to closed

The model is invalid since size(x) should be size(x, 1) everywhere. Once that's fixed it works fine with the new frontend.

Note: See TracTickets for help on using tickets.