首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Modelica中参数的FMU输入

Modelica中参数的FMU输入
EN

Stack Overflow用户
提问于 2019-04-30 23:46:31
回答 1查看 415关注 0票数 1

我的电路里有几块"FixedCurrent“。我希望能够通过FMU更改这些块的电流值。我可以使用“参数”来更改一个值,如下面的代码所示:

代码语言:javascript
复制
type Current = Real(unit = "A", min = 0);

parameter Current CurrentTest1(start = 50) "Test current";

PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = CurrentTest1, 
    redeclare package PhaseSystem = PhaseSystem), 
  annotation(...);

PowerSystems.Generic.FixedCurrent fixedCurrent1(
    I = 55, 
    redeclare package PhaseSystem = PhaseSystem), 
  annotation(...);

但我不能为它们分配输入。例如,如果我使用input命令(1)或RealInput block (2)为块fixedCurrent3设置current的值:

代码语言:javascript
复制
// 1) 
input Real TZtest(start=50);
PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = TZtest, 
    redeclare package PhaseSystem = PhaseSystem),
  annotation(...);

// 2) 
Modelica.Blocks.Interfaces.RealInput TZTest2 annotation(...);
PowerSystems.Generic.FixedCurrent fixedCurrent3(
    I = TZtest, 
    redeclare package PhaseSystem = PhaseSystem),
  annotation(...);

我收到相应的错误:

代码语言:javascript
复制
1) Translation Error
Component fixedCurrent3.I of variability PARAM has binding TZtest of higher variability VAR.

2)Translation Error
Component fixedCurrent3.I of variability PARAM has binding TZTest2 of higher variability VAR.

因此,我无法处理通过FMU输入来设置参数的值。对于这个问题,如果有任何解决方案,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2019-05-02 15:17:59

简而言之:问题在于变量的可变性。将FixedCurrent块替换为允许设置可变电流的块。因此,对于当前的I,它需要有一个实数输入,而不是一个参数。

在Modelica中,变量可以具有以下变量之一(从最低到最高):

常规变量常量:用户不可更改,在模拟开始前整个simulation

  • parameter:的相同值可更改,但整个simulation

  • discrete:的相同值仅在事件时更改它们的值(在when-clauses)

  • continuous:

变量只能分配给具有相同或更高可变性的其他变量。例如,参数不能用连续变量设置。在您的示例1)和2)中,您正试图做到这一点。

对于1),您可以使用prefix参数设置input to参数的可变性:

代码语言:javascript
复制
parameter input Real TZtest(start=50);

在情况2)中,您会遇到FMU的输出是连续的问题。因此,您应该将FixedCurrent块替换为某种类型的可变当前块,如本答案开头所述。

请注意,还有一种变通方法,它允许从初始方程中的连续变量设置参数(如this answer中所述),但我只在绝对必要时才使用它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55924538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档