Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Directional derivatives error (FMU for model exchange)

Directional derivatives error (FMU for model exchange)

Hello,

I'm using FMUs generated by OpenModelica from FMPy and PyFMI.

When I try to get directional derivatives from the FMUs, there are crashes (with both libraries).

The FMUs are generated from console: c:\openmodelica1.13.0-dev-64bit\bin\omc -n=1 -d=-disableDirectionalDerivatives --postOptModules+=wrapFunctionCalls fmu.mos > error_fmu.txt 2>&1

Files are attached.

Am I doing something wrong or could it be a bug in the FMU code?

Thanks!!!
E10-linear.mo

fmu.mos


Edited by: Neotake - Jun-04-18 14:10:57

Re: Directional derivatives error (FMU for model exchange)

# Python test script

#!/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/py … l#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# … 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)

Re: Directional derivatives error (FMU for model exchange)

Fixed with commit 4c49398.

Re: Directional derivatives error (FMU for model exchange)

Thanks!!!!!!!

Re: Directional derivatives error (FMU for model exchange)

Awesome fix!

Is it possible to give those flag to OMEDit FMU export? When exporting from OMEdit, I don't get the provides directional derivatives flag but going through omc with -d=-disableDirectionalDerivatives  works.

Re: Directional derivatives error (FMU for model exchange)

Tool->Options->Simulation->OMC Flags. Add it to the flags there.

There are 0 guests and 0 other users also viewing this topic
You are here: