Python 方向导数误差(用于模型交换的FMU)

Python 方向导数误差(用于模型交换的FMU),python,openmodelica,fmi,Python,Openmodelica,Fmi,我正在使用OpenModelica从FMPy和PyFMI生成的FMU 当我尝试从FMU获取方向导数时,会出现崩溃(两个库都有) FMU由控制台生成: c:\openmodelica1.13.0-dev-64bit\bin\omc -n=1 -d=-disableDirectionalDerivatives --postOptModules+=wrapFunctionCalls fmu.mos > error_fmu.txt 2>&1 我是做错了什么,还是可能是FMU代码中的

我正在使用OpenModelica从FMPy和PyFMI生成的FMU

当我尝试从FMU获取方向导数时,会出现崩溃(两个库都有)

FMU由控制台生成:

c:\openmodelica1.13.0-dev-64bit\bin\omc -n=1 -d=-disableDirectionalDerivatives --postOptModules+=wrapFunctionCalls fmu.mos > error_fmu.txt 2>&1
我是做错了什么,还是可能是FMU代码中的错误

fmu.mos E10_.mo pyfmi_test_script.py
谢谢

我认为FMU导出的定向衍生工具的实施在大多数平台上没有得到很好的测试。JModelica最近在那里取得了很多进展。您可以尝试使用提供FMU的JModelica生成FMU(它有一个编译器标志)。我们对此进行了测试,并且在大多数测试中都有效

我认为FMU导出的定向衍生工具的实施在大多数平台上没有得到很好的测试。JModelica最近在那里取得了很多进展。您可以尝试使用提供FMU的JModelica生成FMU(它有一个编译器标志)。我们对此进行了测试,并且在大多数测试中都有效

OpenModelica中有一个bug现在已修复。在下一版本1.13中
方向导数应该也能正常工作。

OpenModelica中有一个bug现在已经修复。在下一版本1.13中
方向导数应该也能正常工作。

谢谢@Hubertus!!,我没有尝试,因为我在“Jmodelica.org用户指南”中读到了“支持方向导数,但已知在某些情况下有限制”。很高兴知道:)我想生成大规模流体模型的FMU。您是否粗略估计了JModelica FMU编译器的限制?我找不到在JModelica FMU中启用方向导数的标志。你能给我一个提示吗?谢谢@Hubertus!!,我没有尝试,因为我在“Jmodelica.org用户指南”中读到了“支持方向导数,但已知在某些情况下有限制”。很高兴知道:)我想生成大规模流体模型的FMU。您是否粗略估计了JModelica FMU编译器的限制?我找不到在JModelica FMU中启用方向导数的标志。请给我一个提示?如果FMU是由其他软件生成的,那么脚本“pyfmi_test_script.py”可以正常工作。所以,我认为这是FMU代码中的一个错误。谢谢如果FMU是由其他软件生成的,则脚本“pyfmi_test_script.py”可以正常工作。所以,我认为这是FMU代码中的一个错误。谢谢
loadModel(Modelica);
loadFile("E10_linear.mo");
translateModelFMU(E10_linear,version="2",fmuType="me", platforms={"static"}); 
getErrorString();
model E10_linear
  // Parameters
  parameter Real a = 10.0;
  // Variables
  Real x(start = 1.0, fixed = true);

equation

  der(x) = a;

annotation(
    experiment(StartTime = 0, StopTime = 2, Tolerance = 1e-06, Interval = 1));
end E10_linear;
#!/usr/bin/env python 
# -*- coding: utf-8 -*-

import os as O

import matplotlib
import matplotlib.pyplot as plt

import numpy as N

from pyfmi import load_fmu

curr_dir = O.path.dirname(O.path.abspath(__file__));
path_to_fmus = O.path.join(curr_dir, 'FMUs') # The FMU must be in this folder!!!!!!


def run_fmu_native(filename, list_seed_vector, with_plots=True):
    """E10_linear (native) 

    Based on https://jmodelica.org/pyfmi/_modules/pyfmi/examples/fmi_bouncing_ball_native.html#run_demo

    """
    fmu_name = O.path.join(path_to_fmus, filename)
    model = load_fmu(fmu_name)

    Tstart = 0.0 #The start time.
    Tend   = 2.0 #The final simulation time.

    model.time = Tstart #Set the start time before the initialization.

    #Initialize the model. Also sets all the start attributes defined in the 
    # XML file.
    model.initialize() 

    #Get Continuous States
    x = model.continuous_states
    #Get the Nominal Values
    x_nominal = model.nominal_continuous_states
    #Get the Event Indicators
    event_ind = model.get_event_indicators()

    # Snippet from https://jmodelica.org/pyfmi/pyfmi.html#pyfmi.fmi.FMUModelBase2.get_directional_derivative
    assert model.get_capability_flags()["providesDirectionalDerivatives"]==True #Assert directional derivatives are provided

    states = model.get_states_list()
    states_references = [s.value_reference for s in states.values()]
    derivatives = model.get_derivatives_list()
    derivatives_references = [d.value_reference for d in derivatives.values()]

    print('state_references: {}'.format(states_references))
    print('derivatives_references: {}'.format(derivatives_references))
    print('seed vector: {}'.format(list_seed_vector))

    dd = model.get_directional_derivative(states_references, derivatives_references, list_seed_vector)

    #print('dd: {}'.format(dd))

if __name__ == "__main__":

    run_fmu_native('E10_linear.fmu', [1], with_plots=True)