如何在没有分析雅可比的情况下从 FMU 或 Dymola 访问模型雅可比 [英] How to access model jacobian from FMU or Dymola without analytical jacobian

查看:77
本文介绍了如何在没有分析雅可比的情况下从 FMU 或 Dymola 访问模型雅可比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法,通过编译的 FMU 或从导出的 Dymola 源代码访问 dymola 中模型的 jacobian.

I am trying to find a way to access the jacobian for a model in dymola either through a compiled FMU or from the exported Dymola source code.

最终目标是使用相同的程序访问更复杂的多体车辆模型(205 个状态)的雅可比.

The final objective is to use the same procedure to access the jacobian for a much more complex multibody vehicle model (205 states).

使用 FMI 标准中的 fmi2GetDirectionalDerivative() 看起来很有希望,所以我制作了一个简单的线性车辆模型来测试这一点.

Using fmi2GetDirectionalDerivative() from the FMI Standard seemed promising so I made a simple linear vehicle model to test this.

model Vehicle "Single-track Linear bicycle vehicle model"
  extends Modelica.Blocks.Icons.Block;
  import SI = Modelica.SIunits;
  import MB = Modelica.Mechanics.MultiBody;

  // model parameters
  parameter SI.Velocity u = 10 "forward velocity";
  parameter SI.Inertia Iz = 2000 "yaw moment of inertia";
  parameter SI.Length L = 3 "wheel base";
  parameter SI.Mass Mf = 900 "front axle mass";
  parameter SI.Mass Mr = 600 "rear axle mass";
  parameter Real Cf(unit="N/rad") = 300000 "front axle cornering stiffness";
  parameter Real Cr(unit="N/rad") = 200000 "rear axle cornering stiffness";

  // calculated parameters
  final parameter SI.Mass M = Mf + Mr "mass";
  final parameter SI.Length a = Mr/Mf*L "CG position front";
  final parameter SI.Length b = L - a "CG position front";

  input SI.Angle delta "steering angle" annotation(Dialog(group="Inputs"));

public 
  SI.Velocity v "lateral velocity";
  output SI.Acceleration ay "lateral acceleration";
  SI.AngularVelocity r "yaw rate";

equation 

  ay = der(v) + u*r;
  M*(der(v) + u*r) = Cf*(delta-(v+a*r)/u) + Cr*(-(v-b*r)/u);
  Iz*der(r) = a*Cf*(delta-(v+a*r)/u) - b*Cr*(-(v-b*r)/u);

end Vehicle;

该模型具有:

  • states - vr
  • 输入 - delta
  • 输出 - ay

对于这个测试,

  • delta=amp*sin(2*Modelica.Constants.pi*freq*time)

  • amp = 1*Modelica.Constants.pi/180
  • freq = 0.5

版本:Dymola 2020x

Version: Dymola 2020x

由于这是一个线性模型,雅可比在整个模拟过程中应该是一个常数值.对于这个模型,当我设置标志 Advanced.GenerateAnalyticJacobian = true 时,我得到了从 fmi2GetDirectionalDerivative() 计算的所有已知和未知组合的模型 jacobian 的以下值.在所有情况下,函数的 dvKnown = 1.

Since this is a linear model, the jacobian should be a constant value throughout the simulation. For this model, when I set the flag Advanced.GenerateAnalyticJacobian = true, I get the following values for the model jacobian computed from fmi2GetDirectionalDerivative() for all combinations of knowns and unknowns. In all cases, dvKnown = 1 for the function.

根据状态空间方程,这些值是正确的:

These values are correct based on the state space equation:

+--------------+----------+
| Derivative   | Value    |
+--------------+----------+
| der(v)/delta | 200      |
+--------------+----------+
| ay/delta     | 200      |
+--------------+----------+
| der(r)/delta | 300      |
+--------------+----------+
| der(v)/v     | -33.3333 |
+--------------+----------+
| ay/v         | -33.3333 |
+--------------+----------+
| der(r)/v     | -20      |
+--------------+----------+
| der(v)/r     | -36.6667 |
+--------------+----------+
| ay/r         | -26.6667 |
+--------------+----------+
| der(r)/r     | -70      |
+--------------+----------+

但是,如果我设置标志 Advanced.GenerateAnalyticJacobian = false,我会得到以下完全垃圾值:

However, if I set the flag Advanced.GenerateAnalyticJacobian = false, I get completely junk values below:

+--------------+-----------+
| Derivative   | Value     |
+--------------+-----------+
| der(v)/delta | -1.57E+11 |
+--------------+-----------+
| ay/delta     | -1.57E+11 |
+--------------+-----------+
| der(r)/delta | 1.52942   |
+--------------+-----------+
| der(v)/v     | -9.12E+08 |
+--------------+-----------+
| ay/v         | -9.12E+08 |
+--------------+-----------+
| der(r)/v     | 14999.8   |
+--------------+-----------+
| der(v)/r     | 5.47E+11  |
+--------------+-----------+
| ay/r         | 5.47E+11  |
+--------------+-----------+
| der(r)/r     | -2.25E+07 |
+--------------+-----------+

我希望该值与分析值不同,因为它是通过数值计算得出的,但我不明白为什么它完全错误.

I expect the value to be different from the analytical value since its numerically calculated but I don't get why its completely wrong.

我尝试启用其他一些标志(Advanced.AllowNumericDifferentiationAdvanced.AutomaticDifferentiation)并将求解器更改为 CVODE、DASSL 等,但值仍然不正确.

I tried enabling some other flags (Advanced.AllowNumericDifferentiation, Advanced.AutomaticDifferentiation) and changing the solver to CVODE, DASSL etc. but the values remain incorrect.

不幸的是,Dymola 无法计算大型模型的分析雅可比,因此我无法使用该选项.我阅读的所有文献都指向 fmi2GetDirectionalDerivative().

Unfortunately, Dymola can't calculate an analytical jacobian for the large model so I can't use that option. All the literature I read point to fmi2GetDirectionalDerivative().

如果您提供有关如何从 FMU 中获取模型 jacobian 的任何意见,我将不胜感激.

I would appreciate any inputs on how to get the model jacobian out of the FMU.

如果还有其他可以通过 Dymola 使用的方法,那也可以,因为我们有源代码导出许可证.

If there are other methods that can be used through Dymola, that would also work since we have a source code export license.

推荐答案

为了将来参考,我能够部分解决这个问题.

For future reference, I was able to partially solve this issue.

当我导出模型交换 FMU 时,我获得了数值雅可比的有意义的值(非常接近分析值).

I get meaningful values for the numerical jacobian (very close to the analytical values) when I export a Model Exchange FMU.

我猜这是 Dymola 的协同仿真实现 w.r.t 数值 jacobian 中的某种错误.

I am guessing this is some kind of bug in Dymola's Co-Simulation implementation w.r.t numerical jacobians.

这篇关于如何在没有分析雅可比的情况下从 FMU 或 Dymola 访问模型雅可比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆