modelica - 有没有办法将参数传递给可替换/重新声明的组件?

标签 modelica

此问题与 this previous question 相关.

我有一些可互换的子模型,我使用可替换/重新声明机制将它们包含在模型中(例如,冷却回路模型中不同类型热交换器的子模型)。

我想将主模型的一些参数(比如管道的长度和直径)“链接”到子模块的相应参数。这通常在定义模型实例时完成(即在 replaceable 行中),但是当重新声明组件时如何应用此链接?特别是如果使用 choicesAllMatching

这是“我的”模型(感谢 previous question 中的帮助者):

package Test
  // Original definition of Component 1 and 2 in the external library
  // COMP1 (COMP2) has a parameter p1 (p2) defined with a default value
  package ReadOnlyLibrary
    model COMP1
      parameter Real p1=1 "";
      Real v "";
    equation 
      v=p1*time;
    end COMP1;

    model COMP2
      parameter Real p2=1 "";
      Real v "";
    equation 
      v=p2*time;
    end COMP2;
  end ReadOnlyLibrary;

  // Interface and variants with modified default values
  partial model Call_Interface
    parameter Real pp = 10; // New parameter definition to have the same name for all variants
    Real v "";
  end Call_Interface;

  // Both Call1 and Call2 parameters (p1 and p2) are linked to pp
  model Call1 "Default"
    extends Call_Interface;
    extends ReadOnlyLibrary.COMP1(p1=pp);
  end Call1;

  model Call2 "Variant"
    extends Call_Interface;
    extends ReadOnlyLibrary.COMP2(p2=pp);
  end Call2;

  // Main module (system)
  model Main
    parameter Real pm=100 "";
    parameter Real pp0=1 ""; //Actual parameter value to be used by submodules for this application -> pp
    Real vm "";

    replaceable Test.Call1 OBJ(pp=pp0) constrainedby Test.Call_Interface annotation (choicesAllMatching); //For default definition, pp, and finally p1, are linked to pp0. But when OBJ is redeclarated, the link is lost and p1/p2 gets its default value.

  equation 
    vm = OBJ.v+pm;
  end Main;

  // Application model, using the main model
  model App
    Main main;
  end App;
end Test;

我可以通过编写例如 choice(redeclare Test.Call2 OBJ(pp=pp0)) 而不是使用 choiceAllMatching 在注释中添加所有可能的重新声明,但这可能当许多子模块可以互换时,变得乏味且容易出错(只写一次“链接”会更容易、更安全)。 我尝试在主模型参数部分添加通用 OBJ.pp = pp0 ,但这不被接受。这样做的正确方法是什么?

最佳答案

您只需将修饰符写入约束类即可:

replaceable Test.Call1 OBJ constrainedby Test.Call_Interface(pp=pp0) 
    annotation (choicesAllMatching);

关于modelica - 有没有办法将参数传递给可替换/重新声明的组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54399265/

相关文章:

modelica - 成功模拟后如何根据结果更新 Dymola 中的迭代变量?

modelica - Modelica 循环模式下的软件

modelica - 如何在 modelica 中进行局部敏感性分析

modelica - 在 Modelica 中为连接器分配特定的连接样式

python - pyFMI参数更改不会改变模拟输出

migration - 当参数为 String 时,Dymola 中的类有条件迁移

Modelica 微分方程

runtime-error - 可以使用参数来设置组件的单位属性吗?

modelica - modelica 中的数值颤振

if-statement - 如果不执行分支中的方程