How modelon-community/pyfmi works
Main Components
• Core Library Modules:
• The “src/pyfmi” directory contains the heart of the package. Identify submodules that deal with different FMI standards (e.g., fmi.pyx, fmi1.pyx, fmi2.pyx, fmi3.pyx) and FMU import functionality (fmil*_import.pxd files).
• The “src/pyfmi/simulation” module manages simulation routines and provides an interface to simulation tools (e.g., Assimulo integration).
• The “src/pyfmi/debug.py”, “src/pyfmi/fmi_algorithm_drivers.py”, etc., are integrated parts that drive the algorithmic aspect of FMU simulation.
• Common Utilities:
• “src/common” holds shared functionality such as algorithm drivers, I/O handling, logging (with submodules for parsing, pretty printing, and tree views), and plotting (e.g., the plot_gui module).
• Example and Demonstration Components:
• “src/pyfmi/examples” contains sample scripts and FMU files for demonstrating capabilities (including native simulation examples and FMU-based examples).
• Testing Infrastructure:
• The “tests” directory provides unit tests along with sample FMUs and auxiliary files to verify that the package complies with the FMI standard.
• Documentation:
• The Sphinx documentation in the “doc” folder shows that there's an organized effort for technical documentation and user guidance.
Relationships and Interactions
• FMU Loading and Parsing:
• How a client (or user script) interacts with the PyFMI API (in “src/pyfmi”) to load an FMU. This component then delegates to lower-level routines (possibly c or cython code given the .pyx and .pxd files) for interfacing with the native FMU binary.
• Simulation Flow:
• After loading, the FMU instance is managed by simulation modules which provide support for both Model Exchange and Co-Simulation. Include how simulation configuration, time-stepping, and state updates occur.
• Utilities & Support Features:
• External Dependencies / Integration:
• External engines such as Assimulo (required for some simulation aspects) and FMU SDK/FMI Library (which is required during installation). Show their interaction with PyFMI’s core simulation layer.
• Testing & Continuous Integration:
• Test suite in “tests” which verifies the functionality of all these components using various FMU samples, ensuring compliance with FMI standards and even working with external tools like the Optimica Compiler Toolkit.
Architectural Patterns and Design Principles
• Modularization & Separation of Concerns:
• The package cleanly separates core simulation functionality from utility functions, testing, examples, and documentation.
• Interface Abstraction:
• Notice the usage of Cython (.pyx and .pxd files), which suggests that performance-critical parts have a clear interface with Python—and may interface with native libraries. Represent this boundary with a clear “Native Interface” or “Cython Wrapper” layer.
• Extensibility:
• That new FMU types or simulation strategies can be added by extending the respective submodules in the “src/pyfmi” and “src/common” directories.
Including Relevant Technologies
• Python and Cython:
• That the package is implemented in Python with performance-sensitive parts in Cython.
• External Libraries:
• Assimulo, FMI Library, wxPython, and matplotlib (the latter two being optional for certain examples) should be indicated as interacting with PyFMI.
• Documentation Tools:
• The use of Sphinx (in the “doc/sphinx” directory) should be noted as part of the development and user documentation ecosystem.