程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Modelica 模型及其 fmu 对于相同的输入给出不同的结果大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Modelica 模型及其 fmu 对于相同的输入给出不同的结果?

开发过程中遇到Modelica 模型及其 fmu 对于相同的输入给出不同的结果的问题如何解决?下面主要结合日常开发的经验,给出你关于Modelica 模型及其 fmu 对于相同的输入给出不同的结果的解决方法建议,希望对你解决Modelica 模型及其 fmu 对于相同的输入给出不同的结果有所启发或帮助;

我在 Modelica 中有一个简单的电机模型,它在 Dymola 中以恒定电压运行时给出了预期的速度输出。但是当我将它导出为联合仿真 fmu(使用 Dymola 的 dassl 求解器)时,它在 fmpy 和 Simulink 等其他环境中给出了不同的答案。

@H_594_5@model motor
  Modelica.blocks.Interfaces.Realinput vol "voltage" Annotation (Placement(
        transformation(extent={{-140,-20},{-100,20}})));
  Modelica.blocks.Interfaces.RealOutput v[1] "veLocity" Annotation (Placement(
        transformation(extent={{100,-10},{120,10}})));
  Real x[2](start={0,0}) "stateVector";
  parameter Real A[:,:]=[1.511,-0.5488;1,0];
  parameter Real B[:] = {0.0625,0};
  parameter Real C[:,:] = [0.03294,0.02697];
  parameter Modelica.SIunits.Time dT = 0.1 "samplingTime";
equation 
  x = A*delay(x,dT) + B*vol;
  v = C*x;
  Annotation (Icon(coordinateSystem(preserveAspectRatio=falsE)),Diagram(
        coordinateSystem(preserveAspectRatio=falsE)));
end motor;

只有当输入(此处为 vol)是常量输入时,才能看到这种差异。对于阶跃或斜坡输入,Modelica 模型和 fmu 给出相同的答案。因此我认为这可能与 Dymola vs fmu 中 vol 的起始值有关。因此,我在输入端口上添加了起始值,但这没有帮助。

  Modelica.blocks.Interfaces.Realinput vol( start= 110) "voltage" Annotation (Placement(
    transformation(extent={{-140,20}})));

例如,Modelica 测试给我 v = 0.2264

@H_594_5@model example
  motor motor1 Annotation (Placement(transformation(extent={{-20,0},{0,20}})));
  Modelica.blocks.sources.Constant const(k=110)
    Annotation (Placement(transformation(extent={{-60,{-40,20}})));
equation 
  connect(const.y,motor1.vol)
    Annotation (line(points={{-39,10},{-22,10}},color={0,127}));
  Annotation (
    Icon(coordinateSystem(preserveAspectRatio=falsE)),Diagram(coordinateSystem(preserveAspectRatio=falsE)));
end example;

在 fmpy 中运行的 motor.fmu(从 motor.mo 导出)给出 v = 10.8963

import fmpy as fm
import pandas as pd
import numpy as np

filename = 'motor.fmu'
input = np.array([(   0,110),(30,110)],dtype=[('time','<i4'),('vol','<i4')])
output = ['v[1]',]

result = fm.simulate_fmu(filename,input = input,output=output,stop_time=30.0)
df = pd.DataFrame(result)
print(df.tail())

有人见过类似的行为吗?

解决方法

我认为问题的根源在于状态空间方程的实现。发布的方程在连续系统中使用 delay 运算符。据我了解,这是不正确的。

连续版应该是

  der(X) = A*x + B*vol;
  v = C*x;

或者离散应该是

  when sampletrigger then
    x = A*pre(X) + B*u;
    y = C*pre(X) + D*u;
  end when;

完整代码可以分别在@H_594_5@modelica.blocks.ConTinuous.StateSpace和@H_594_5@modelica.blocks.Discrete.StateSpace中查找。

我不完全确定,不同结果的确切来源是什么(它们是不同的,我可以确认)。但问题是,这是否值得研究,如果方程本身可能不是它们应有的样子......

大佬总结

以上是大佬教程为你收集整理的Modelica 模型及其 fmu 对于相同的输入给出不同的结果全部内容,希望文章能够帮你解决Modelica 模型及其 fmu 对于相同的输入给出不同的结果所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。