#!/usr/bin/env python # coding: utf-8 # # Getting started with FMI # # Simulate the BouncingBall.fmu from the [Reference FMUs](https://github.com/modelica/Reference-FMUs) with [FMPy](https://github.com/CATIA-Systems/FMPy). # In[1]: #@title Install FMPy and clone repository if necessary try: import fmpy except: import subprocess subprocess.check_output(['pip', 'install', 'fmpy']) import os if not os.path.exists('BouncingBall.fmu'): subprocess.check_output(['git', 'clone', 'https://github.com/t-sommer/fmi-getting-started.git']) os.chdir('fmi-getting-started') # In[2]: from fmpy import * # path to the FMU filename = 'BouncingBall.fmu' # simulate the default experiment result = simulate_fmu(filename) # plot the result plot_result(result) # In[3]: # get information about the model dump(filename) # In[4]: # simulate again with different start values result = simulate_fmu(filename, start_values={'h': 2}, fmi_type='ModelExchange', solver='Euler') # plot the events plot_result(result, events=True) # In[5]: # log the FMI calls to the console simulate_fmu(filename, fmi_call_logger=print) # In[6]: # explore the API help(simulate_fmu) # In[ ]: