FMPy | Simulate Functional Mockup Units in Python
kandi X-RAY | FMPy Summary
kandi X-RAY | FMPy Summary
FMPy is a free Python library to simulate Functional Mock-up Units (FMUs) that...
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of FMPy
FMPy Key Features
FMPy Examples and Code Snippets
Community Discussions
Trending Discussions on FMPy
QUESTION
I have a simple motor model in Modelica which gives expected velocity output when run in Dymola for constant voltage. But when I export it as a co-simulation fmu (with Dymola's dassl solver) it gives different answer in other environments like fmpy and Simulink.
...ANSWER
Answered 2021-Jul-05 at 07:31I think the root of the issue is the implementation of the state-space equations. The posted equations use a delay
operator within a continuous system. As far as I understand, this is not correct.
The continuous version should be
QUESTION
About FMPy which is a python package for FMU simulation. I need one clarification : What is the purpose of cswrapper code, sundials solver or functions? Is it only required for ModelExchange type FMU simulation and not for Co-simulation type FMU simulation? https://github.com/CATIA-Systems/FMPy
...ANSWER
Answered 2021-Apr-06 at 09:38With the cswrapper code you can "wrap" a ME FMU as a CS FMU by adding a (sundials) solver, see https://github.com/CATIA-Systems/FMPy/issues/127. So you get from a ME a CS FMU. Additionally, the CVODE solver can be used to simulate ME FMUs in fmpy.
QUESTION
With Python libraries like FMPy I am able to simulate fmus (using fmpy.simulate_fmu
) for given start_time
and stop_time
. In such case, the function simulate_fmu completes the simulation and return the time-series results.
However, I want to create a closed loop between fmu and a Python function (i.e. in a Python script initialize the fmu, get the results from fmu after every 0.1s and based on that update the input value to the fmu for the next timestep). Is there a way to achieve this using existing libraries like fmpy or pyfmi?
...ANSWER
Answered 2021-Feb-05 at 15:26The short answer is yes the tools you mention are set up to do what you are asking.
A long answer can be found for FMPy:
But the gist is to perform changes during simulation like you are asking the
approach you want you need to go a layer deeper than simulate_fmu
and use doStep
and associated setup. The functions/approach needed for these are defined by the FMI standard while highler level implmentations like simulate_fmu
are not and are therefore tool dependent implementations of the standard.
The cliff notes are:
- Prep the Simulation Inputs
- e.g., unzip the FMU, define simulation setup, and instantiate the FMU
QUESTION
I simulated a batch of 5 FMUs by putting a function containing the fmpy simulate in a loop. 4 of them simulate correctly. The fifth one due to a wrong parameter shows an error.
My question is, is there any way to find out in which FMU the error comes during simulation
Ideally the output should look like: FMU1: OK FMU2: OK FMI3: 'Error' and so on
...ANSWER
Answered 2020-Sep-17 at 11:17You can catch the exception and return the status message together with the result like so
QUESTION
I have a python script that filters and lists the parameters, their units and default values from a fmu using the read_model_description
function from FMPy library and writes in an excel sheet (related discussion). Then using the simulate_fmu
function the script simulates the fmu and writes the results with units back in the excel sheet.
In filtering the parameters and output variable, I use this line to get their units.
unit = variable.declaredType.unit if hasattr(variable.declaredType,'unit') else '-'
While interacting with the fmu, the parameter and variable values are in default SI units. I guess this is according to the FMI standard. However, in the modelDescription.xml
under I see that there is information regarding the default SI unit to displayUnit conversion. For example:
ANSWER
Answered 2020-Apr-11 at 08:46In the FMPy source I did not find any place where unit conversion is implemented.
But all the relevant information is read in model_description.py.
The display unit information ends up in modelDescription.unitDefinitions
. E.g. to convert a value val = 1.013e5 # Pa
to all defined display units, the following might work:
QUESTION
I have a FMU of a model and the use case is to change parameter values of the FMU to see the impact on the results. Is there a way to list top level parameters of the FMU using either FMPy or pyFMI if I dont' have access to the Modelica model?
One of the process I have been following is to open the FMU using FMPy.gui and go through the list of parameters and then use them in the script but I would like to know if there an easier way of doing it so that I can list then in the Jupyter notebook and change the parameters as needed?
...ANSWER
Answered 2020-Mar-02 at 19:10In FMI there is no distinction between top level parameters and other parameters. To list all available parameters in the model using PyFMI (FMI 2.0):
QUESTION
I am trying to test a simple fmu to save and restore the states.
For example openmodelica:
...ANSWER
Answered 2020-Jan-12 at 07:51With respect to fmi2GetFMUstate/fmi2SetFMUstate, the FMI Specification, section 2.1.8. states:
These functions are only supported by the FMU, if the optional capability flag
in the XML file is explicitly set to true (see sections 3.3.1 and 4.3.1).
You can unzip the fmu file and take a look at the modelDescription.xml file to find out if the flag is set: If it is false or not set all, the get and set functions are not supported.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install FMPy
Install with conda: conda install -c conda-forge fmpy
Install with from PyPI: python -m pip install fmpy[complete]
Install a development build
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page