Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Modelica Dymola中的记录调用问题_Modelica_Dymola_Openmodelica - Fatal编程技术网

Modelica Dymola中的记录调用问题

Modelica Dymola中的记录调用问题,modelica,dymola,openmodelica,Modelica,Dymola,Openmodelica,下面的包“RecordTest”(复制较大模型错误的示例)包含一条用于定义某些数据结构的记录。此外,在包“DataDefinition”中定义了两组数据。最后,该数据应在“UseOfData”包中使用。在此读取数据集,并在函数“FunctionWithData”中计算所有数组A的总和 “FunctionCall”模型的模拟在OpenModelica中运行良好。在Dymola中,我得到错误:“对于变量包常量RecordTest.UseOfData.ReadData[1]。数组变量的下标Record

下面的包“RecordTest”(复制较大模型错误的示例)包含一条用于定义某些数据结构的记录。此外,在包“DataDefinition”中定义了两组数据。最后,该数据应在“UseOfData”包中使用。在此读取数据集,并在函数“FunctionWithData”中计算所有数组A的总和

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

我错过什么了吗?常量“Index”在记录“DataStructure”中定义为整数。此外,该模型在OpenModelica中运行。我不理解迪莫拉的错误

提前谢谢

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;

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

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;
问题是在记录的包内常量数组中使用的“索引”,以及包常量记录Set1和Set2的修饰符(而不是绑定等式)。 (它也将在Dymola的未来版本中处理,我知道答案有点晚。)