Opened 7 years ago

Closed 7 years ago

#4748 closed defect (invalid)

OM will pass values from a multiple-output function to “parameters”

Reported by: ali.shirazi@… Owned by: Adrian Pop
Priority: high Milestone: 1.13.0
Component: Frontend Version: v1.13.0-dev-nightly
Keywords: Cc: john.pye@…

Description

Hello,

I have come across an issue in relation to calling a function with multiple outputs and assigning the outputs to multiple “parameters” – not variables. To demonstrate this, I made 3 test cases as below. In the first one (i.e. TestFuncMulti_1.mo), the variables n_req, n_ub and C_cap are defined as “variables”. This way using the following command line (in the “equation section”) I can call the function C_V() and get the outputs and pass them to the above variables.

(n_req, n_ub, C_cap) = C_V(V_req);

So far so good! However, what I really want is to declare n_req, n_ub and C_cap as parameters not variables. This way their values will not need to be calculated at every time-step. Apparently, the above command line will not work when the above terms are defined as parameters. I have shown this in the second test case i.e. TestFuncMulti_2.mo.

I found a workaround though by defining a vector of size 3 as the output of the function, and used the following lines to pass its value to n_req, n_ub, C_cap parameters as shown in TestFuncMulti_3.mo:

parameter Real outs[3] = C_V(V_req);

parameter Integer n_req = integer(outs[1]);
parameter Integer n_ub = integer(outs[2]);
parameter Real C_cap = outs[3];

Surely, this is not the best workaround for this issue. Hence, I wanted to know if there is a proper way to do it for parameters like what I have shown in the first test case for variables??

Thanks,
Ali Shirazi

Attachments (3)

TestFuncMulti_1.mo (640 bytes ) - added by Ali Shirazi <ali.shirazi@…> 7 years ago.
TestCase 1
TestFuncMulti_2.mo (852 bytes ) - added by Ali Shirazi <ali.shirazi@…> 7 years ago.
TestCase 2
TestFuncMulti_3.mo (744 bytes ) - added by Ali Shirazi <ali.shirazi@…> 7 years ago.
TestCase 3

Download all attachments as: .zip

Change History (7)

by Ali Shirazi <ali.shirazi@…>, 7 years ago

Attachment: TestFuncMulti_1.mo added

TestCase 1

by Ali Shirazi <ali.shirazi@…>, 7 years ago

Attachment: TestFuncMulti_2.mo added

TestCase 2

by Ali Shirazi <ali.shirazi@…>, 7 years ago

Attachment: TestFuncMulti_3.mo added

TestCase 3

comment:1 by Adeel Asghar, 7 years ago

Component: OMEditFrontend
Owner: changed from Adeel Asghar to Adrian Pop
Status: newassigned

comment:2 by Francesco Casella, 7 years ago

Have you tried it this way?

  parameter Integer n_req(fixed = false);
  parameter Integer n_ub(fixed = false);
  parameter Real C_cap(fixed = false);
...
initial equation
  (n_req, n_ub, C_cap) = C_V(V_req);

As far as I understand, you can't use binding equations in declarations if there are multiple output functions involved.

comment:3 by Ali Shirazi <ali.shirazi@…>, 7 years ago

Hi Casella,

Yes, It works now, thanks. I did actually try to put it in the initial equation section, but did not set the "fixed" flag to false. It's all good now.

Regards,
Ali Shirazi

comment:4 by Adeel Asghar, 7 years ago

Milestone: Future1.13.0
Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.