在Dymola录制电话的问题

时间:2015-05-28 09:23:45

标签: modelica dymola openmodelica

以下包'RecordTest'(重现较大模型的错误的示例)包含一个Record来定义某些数据的结构。进一步在'DataDefintion'包中定义了两组数据。最后,这些数据应该用在'UseOfData'包中。这里读取数据集,并在函数'FunctionWithData'中计算所有数组A的总和。

模型'FunctionCall'的模拟在OpenModelica中运行良好。在Dymola中我得到错误:'对于变量包常量RecordTest.UseOfData.ReadData [1]。数组变量的下标RecordTest.UseOfData.ReadData.Index不是整数。'

我错过了什么吗?常量'Index'被定义为记录'DataStructure'中的整数。此外,该模型在OpenModelica中运行。我不明白Dymola的错误。

提前致谢。

package RecordTest

record DataStructure
  constant Integer Index;
  Real A[Index];
end DataStructure;

package DataDefinition
  constant DataStructure Set1(Index=2, A={1,2});
  constant DataStructure Set2(Index=2, A={3,4});
end DataDefinition;

package UseOfData
  constant Integer N=2;
  constant DataStructure ReadData[N]={DataDefinition.Set1, DataDefinition.Set2};

  function FunctionWithData
    input Real b;
    output Real Result;
  protected
    Real Array[2];
  algorithm
    Array := {sum(ReadData[1].A), sum(ReadData[2].A)};
    Result := b*sum(Array);
  end FunctionWithData;

  model FunctionCall
    parameter Real b=2;
    Real FunctionResult;
  equation
    FunctionResult = FunctionWithData(b);
  end FunctionCall;
end UseOfData;

end RecordTest;

1 个答案:

答案 0 :(得分:0)

解决方法是按如下方式重写包:

package RecordTest

record DataStructure
  constant Integer Index;
  Real A[:];
end DataStructure;

package DataDefinition
  constant DataStructure Set1=DataStructure(Index=2, A={1.0,2.0});
  constant DataStructure Set2=DataStructure(Index=2, A={3.0,4.0});
end DataDefinition;

package UseOfData
  constant Integer N=2;
  constant DataStructure ReadData[N]={DataDefinition.Set1, DataDefinition.Set2};

  function FunctionWithData
    input Real b;
    output Real Result;
    protected 
    Real Array[2];
  algorithm 
    Array := {sum(ReadData[1].A), sum(ReadData[2].A)};
    Result := b*sum(Array);
  end FunctionWithData;

  model FunctionCall
    parameter Real b=2;
    Real FunctionResult;
  equation 
    FunctionResult = FunctionWithData(b);
  end FunctionCall;
end UseOfData;

end RecordTest;

问题是包中常用的记录数组中的A中使用的“索引”,以及修饰符而不是包常量记录Set1和Set2的绑定方程。 (它也将在Dymola的未来版本中处理,我理解答案有点晚。)