Modelica - 如何扩展(最小)媒体包

问题描述 投票:1回答:1

我想有一个从另一个基本包扩展的包。基本包包含向量类型和常量整数,其中包含向量的每个索引号的名称。它还包含一个向量常量,它为每个元素赋予一个值(描述元素的某些属性)。在扩展包中,我想添加一个向量类型的元素并为新索引添加一个新名称,并且还向向量常量添加一个具有特定值的元素(描述该物质的某些属性)。

使用具有可替换 - extend - redeclare的技术,可以直接使用元素扩展向量类型,并且还为包附加一个新的常量整数用于附加元素。但我不知道如何使用新元素追加常量向量。

下面的代码适用于JModelica(2.4),但涉及重新声明和原始基本包中值的复制。但是在Medium3中,JModelica不接受常量向量mw的第四个重新声明语句。但是如果我在扩展完成后将重新声明语句作为第一行,那么它确实有效(参见Fritzson第4.3.1节)。但是,重新声明应该是原始的子类型,Real3]不是Real [2]的子类型,但编译器似乎无论如何都要管理。

当我在OpenModelica(1.13)中尝试相同的代码时,我收到错误消息,因为我重新声明了一个常量,并且在Medium3的第一次重新声明中已经出错。我不确定这是一个正确的错误消息,并不会出现在JModelica中。

否则,OpenModelica(和JModelica)接受两个Medium2,没有任何警告或错误。而这些测试只需更改LiquidCon中使用的介质即可。

我的主要问题是,如果这是一个更直接的解决方案,使用上面描述的一种物质扩展媒体包,而不是我的代码,这是更标准的(并且当然可以同时使用JModelica和OpenModelica以及Modelica) )。

当然,理解Modelica标准在此处所说的内容然后我们可以将这些信息作为错误报告提供给JModelica和OpenModelica背后的组织。

非常感谢您的意见/ Jan Peter

下面是DEMO_v8包的摘录

package Medium2
    replaceable constant String name = "Two components"    "Medium name";
    replaceable constant Integer nc = 2                    "Number of substances";
    replaceable type Concentration = Real[nc]              "Substance conc";
    replaceable constant Real[nc] mw = {10, 20}            "Substance weight";  
    constant Integer A = 1                                 "Substance index";
    constant Integer B = 2                                 "Substance index";   
end Medium2;

package Medium3 
    import M2 = DEMO_v8.Medium2;
    extends M2
        (redeclare constant String name="Three components" "Medium name",
         redeclare constant Integer nc=3                   "Number of substances",
         redeclare type Concentration = Real[nc]           "Substance conc");
    redeclare constant Real[nc] mw = cat(1,M2.mw,{30})     "Substance weight";
    constant Integer C = 3                                 "Substance index";   
end Medium3;

connector LiquidCon
    replaceable package medium=DEMO_v8.Medium3; 
    medium.Concentration c                                 "Substance conc";
    flow Real F (unit="m3/s")                              "Flow rate";
end LiquidCon;
modelica openmodelica jmodelica
1个回答
1
投票

您可以(因为Modelica语言3.2 - 它在3.1中是非法的)只需修改常量的值,如下所示:

package Demo_v8

  package Medium2
    replaceable constant String name="Two components" "Medium name";
    constant Integer nc=2 "Number of substances";
    replaceable type Concentration = Real[nc] "Substance conc";
    constant Real[nc] mw={10,20} "Substance weight";
    constant Integer A=1 "Substance index";
    constant Integer B=2 "Substance index";
  end Medium2;

  package Medium3
    import M2 = Demo_v8.Medium2;
    extends M2(
      name="Three components" "Medium name",
      nc=3 "Number of substances",
      mw=cat(1, M2.mw, {30}),
      redeclare type Concentration = Real[nc] "Substance conc");
    constant Integer C=3 "Substance index";
  end Medium3;

  connector LiquidCon
    replaceable package medium = Demo_v8.Medium3;
    medium.Concentration c "Substance conc";
    flow Real F(unit="m3/s") "Flow rate";
  end LiquidCon;
end Demo_v8;

但是,我还没有确认JModelica.org或O​​penModelica可以处理它。

顺便说一句:错误信息是正确的,因为自Modelica 1.2以来重新声明一个常量是非法的。

© www.soinside.com 2019 - 2024. All rights reserved.