1

问题描述

我想在经济建模(例如系统动力学)中使用非国际单位制单位。虽然我当然可以花几秒钟s)然后使用,但据我所知,在我主要使用的 System Modeler 中displayUnit没有很好的方法来修改displayUnit时间。

因此,在编写一个库时,我希望用户选择一个全局type调用ModelTime,理想情况下它会被声明为inner某个replaceable顶级类。然后模型中的任何组件都可以使用全局type来一致地处理任何与时间相关的变量。

最小的例子

下面的例子展示了我想如何实现它。

  • package Units声明了两种非国际单位制单位类型( Time_year, Time_month)
  • package Interfaces包含一个部分模型类GenericSimulationModel,它将成为使用该库编写的任何模型的顶级范围。它应该提供type ModelTimeasinnerreplaceable
  • package Components定义一个简单的block类,该类ModelTime通过outer定义来定义其在全局选择的时间单位中的output y简单显示time
  • model Example将所有这些联系在一起,以提供一个示例,使用该库的任何模型应该如何工作

这是代码:

model MinimalExample

  package Units
    type Time_year = Real(final quantity = "Time", final unit = "yr");    
    type Time_month = Real(final quantity = "Time", final unit = "mo");
  end Units;

  package Interfaces
    partial model GenericSimulationModel "Top-level model scope providing global vars"
      inner replaceable type ModelTime = Years "Set to : Months, Years";
    protected
      type Years = Units.Time_year;
      type Months = Units.Time_month;
    end GenericSimulationModel;
  end Interfaces;

  package Components
    block ComponentUsingTime
      outer type ModelTime = MinimalExample.Units.Time_year;
      output ModelTime y;
    equation
      y = time;
    end ComponentUsingTime;
  end Components;

  model Example
    extends Interfaces.GenericSimulationModel(
      redeclare replaceable type ModelTime = Months
    );
    Components.ComponentUsingTime c;
  end Example;
equation

end MinimalExample;

虽然在 System Modeler 和 OpenModelica 中一切都编译没有错误,但不幸的是它没有成功:在Example上面给出的模型中的组件 c 中没有使用重新声明的类型。

我能做些什么来实现我想做的事情?

4

1 回答 1

0

我从 Wolfram MathCore 的某个人(系统建模器的开发人员)那里收到了一些关于 Wolfram 社区的反馈:

您看到的 MinimalExample.example 和 MinimalLibrary.Example 的行为是错误,据我所见,它们应该可以工作,我已将它们转发给从事这些工作的开发人员。

于 2019-07-03T16:44:11.533 回答