Search code examples
functionmodelicaopenmodelica

Connector as function input argument in modelica


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!


Solution

  • 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;