我的电路里有几块"FixedCurrent“。我希望能够通过FMU更改这些块的电流值。我可以使用“参数”来更改一个值,如下面的代码所示:
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的值:
// 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(...);我收到相应的错误:
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输入来设置参数的值。对于这个问题,如果有任何解决方案,我将不胜感激。
发布于 2019-05-02 15:17:59
简而言之:问题在于变量的可变性。将FixedCurrent块替换为允许设置可变电流的块。因此,对于当前的I,它需要有一个实数输入,而不是一个参数。
在Modelica中,变量可以具有以下变量之一(从最低到最高):
常规变量常量:用户不可更改,在模拟开始前整个simulation
内
变量只能分配给具有相同或更高可变性的其他变量。例如,参数不能用连续变量设置。在您的示例1)和2)中,您正试图做到这一点。
对于1),您可以使用prefix参数设置input to参数的可变性:
parameter input Real TZtest(start=50);在情况2)中,您会遇到FMU的输出是连续的问题。因此,您应该将FixedCurrent块替换为某种类型的可变当前块,如本答案开头所述。
请注意,还有一种变通方法,它允许从初始方程中的连续变量设置参数(如this answer中所述),但我只在绝对必要时才使用它。
https://stackoverflow.com/questions/55924538
复制相似问题