Reputation: 23
is it possible to use a connector as function input argument? Somehow I am not able to get the following minimal example to run.
In the f.mo file I have
function f
input Modelica.Electrical.Analog.Interfaces.Pin t;
output Real p;
algorithm
p:=t.i*t.v;
end f;
In the test.mo I have
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(t);
end test;
When I run the check of test.mo I get the error message
[1] 11:15:38 Translation Error
[f: 2:3-2:52]: Invalid type .Modelica.Electrical.Analog.Interfaces.Pin for function component t.
[2] 11:15:38 Translation Error
[test: 5:3-5:16]: Class f not found in scope test (looking for a function or record).
[3] 11:15:38 Translation Error
Error occurred while flattening model test
Thanks!
Upvotes: 2
Views: 257
Reputation: 12517
The previous answer is good and works, but in Modelica 3.4 section 12.6.1. another possibility was added that is closer to the original.
record R
Real i,v;
end R;
function f
input R t;
output Real p;
algorithm
p:=t.i*t.v;
end f;
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(R(t));
end test;
This was primarily motivated by models where you have more elements and it becomes tedious to list all of them. Since it is new functionality in Modelica 3.4 it is currently only active in Dymola if you set the flag Advanced.RecordModelConstructor = true;
Upvotes: 4
Reputation: 4231
Connectors cannot be used as function inputs. You can however do this:
function f
input Real i;
input Real v;
output Real p;
algorithm
p:=i*v;
end f;
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(t.i, t.v);
end test;
Upvotes: 2