2

以下三个问题捆绑在一起,所以请原谅帖子的长度。

使用 Dymola 2016。

在模型中使用可替换的函数调用为用户提供了拥有下拉选项的机会。下面的例子:

model Test1
  parameter Real x = 1;
  Real y;
  replaceable function a=b constrainedby d annotation(choicesAllMatching=true);
equation 
  y = a(x);
end Test1;

在函数中执行相同的可替换函数调用似乎不允许与调用函数相同的下拉功能(即在包浏览器中右键单击调用函数。我认为这是故意的,因为通常在其他函数/模型中调用函数. 示例如下:

function Test2
  input Real x;
  output Real y;
  replaceable function a=b constrainedby d annotation(choicesAllMatching=true);
algorithm 
  y :=a(x);
end Test2;

问题 #1。是否可以像使用模型一样在函数中使用可替换的函数调用?如果是这样,适当的语法是什么?替代方法?

或者,另一种选择是在模型中执行可替换的函数调用,然后将结果传递给另一个函数,然后由该函数进行适当的调用。示例如下所示:

model Test3mod
  parameter Real x = 1;
  Real y;
  replaceable function a=b constrainedby d annotation(choicesAllMatching=true);
equation 
  y = Test3func(x,a);
end Test3mod;

它将参数 x 和函数句柄 a 传递给:

function Test3func
  input Real x;
  input ???? a;
  output Real y;
algorithm 
  y :=a(x);
end Test3func;

问题2。这在 Modelica 中是否允许,如果允许,如何?替代方法?

问题 #3。是否可以定义一个字符串并将其转换为函数的名称。下面的例子:

model Test4
  parameter String 'functionname';
  parameter Real x = 1;
  Real y;
equation
  y = functionname(x);
end Test4;

先感谢您!感谢您的反馈,因为我将继续探索 Modelica 的使用。

4

1 回答 1

1

这应该可以正常工作:

model Test3mod
  parameter Real x = 1;
  Real y;
  replaceable function a=b constrainedby d annotation(choicesAllMatching=true);
equation 
  y = Test3Func(x,a);
end blah;

function Test3func
  input Real x;
  input d f;
  output Real y;
algorithm 
  y := f(x);
end Test3func;
于 2015-12-04T15:16:36.680 回答