如何在 OMPython 中获取有关“循环相等”的详细错误消息?

问题描述 投票:0回答:1

我有一个 modelica 文件(类似于这个问题中的文件),但无法模拟。给大家参考一下:

circuit.mo

model circuit
    Modelica.Electrical.Analog.Basic.Resistor Resistor_2(R = 1);
    Modelica.Electrical.Analog.Sources.ConstantVoltage ConstantVoltage_3(V = 1);
    Modelica.Electrical.Analog.Basic.Resistor Resistor_4(R = 1);
    Modelica.Electrical.Analog.Basic.Inductor Inductor_5(L = 1);
    Modelica.Electrical.Analog.Sources.SineVoltage SineVoltage_6(V = 1, f = 1, phase = 1, offset = 0);
equation
    connect(Resistor_2.n, ConstantVoltage_3.p);
    connect(ConstantVoltage_3.n, Resistor_4.p);
    connect(Resistor_4.n, Inductor_5.p);
    connect(Inductor_5.n, SineVoltage_6.n);
    connect(Resistor_2.p, SineVoltage_6.p);
end circuit;

我尝试使用如下代码从 Python 运行它:

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = ['loadFile("circuit.mo")',
        'simulate(circuit)']
for cmd in cmds:
    omc.sendExpression(cmd)

然后我在当前目录中找到日志文件并解析它以检查是否有错误。

此代码适用于正确的 .mo 文件。但对于这个,甚至没有创建日志文件。

当我使用

omc -u circuit.mo
运行此文件时,我收到有关“循环等式”的详细错误消息:

Error processing file: circuit.mo
Notification: Automatically loaded package Complex 4.0.0 due to uses annotation from Modelica.
Notification: Automatically loaded package ModelicaServices 4.0.0 due to uses annotation from Modelica.
Notification: Automatically loaded package Modelica 4.0.0 due to usage.
Error: Internal error Circular Equalities Detected for Variables:
----------------------------------
Error: Internal error IndexReduction.pantelidesIndexReduction failed! Found empty set of continuous equations. Use -d=bltdump to get more information.
Error: Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

我希望能够在我的 Python 代码中获取此类消息。

但是,如果我在 OMShell 终端中运行它,我收到的唯一错误消息是

Failed to build model: circuit

>>> loadFile("circuit.mo")
true

>>> simulate(circuit)
record SimulationResult
    resultFile = "",
    messages = "Failed to build model: circuit"
end SimulationResult;

>>> translateModel(circuit)
false

>>> buildModel(circuit)
{"",""}

我还尝试在每个命令后添加

getErrorString()
,但它总是返回空字符串。

回到 Python 代码中,我尝试保存

sendExpression()
的返回值并解析它们,但这给了我与 OMShell 中相同的消息。

那么,是否可以通过

omc
获取详细的错误消息(如
OMPython
中所示)?

openmodelica
1个回答
0
投票

这个答案是由arun3688https://github.com/OpenModelica/OpenModelica/discussions/12265

中建议的

正确的方法是使用较新的 API -

ModelicaSystem
类,例如:

import os
from OMPython import ModelicaSystem
mod = ModelicaSystem(os.path.abspath('circuit.mo'), 'circuit')

它打印详细的错误消息。这是用

OMPython==3.5.1
测试的。

© www.soinside.com 2019 - 2024. All rights reserved.