Opened 10 years ago

Closed 4 years ago

#3189 closed defect (fixed)

Partial function evaluation and arrays not working

Reported by: Gustaf Thorslund 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 by Gustaf Thorslund, 10 years ago

Component: UnknownFrontend

comment:2 by Gustaf Thorslund, 10 years ago

Owner: changed from somebody to Gustaf Thorslund
Status: newaccepted

comment:3 by Adrian Pop, 10 years ago

Owner: changed from Gustaf Thorslund to somebody
Status: acceptedassigned

comment:4 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Milestone: Future1.16.0
Resolution: fixed
Status: assignedclosed

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.