Co-Simulation Components#
FMU Component#
FMI 2.0 Co-Simulation FMU wrapper.
This module exposes FMUComponent, a CoSimComponent
implementation backed by an FMI 2.0 co-simulation FMU via fmpy. The component
derives input/output ports from the FMU model description, handles units for REAL
signals, applies parameter starts during initialization, and supports direct
feedthrough evaluation.
- class syssimx.components.fmu.FMUComponent[source]#
Bases:
CoSimComponentFMU co-simulation wrapper implementing the CoSimComponent interface.
Supports FMI 2.0 co-simulation FMUs, typed input/output ports (REAL, INT, BOOL, STRING), and unit-aware REAL ports via
pint.- __init__(name, fmu_path, group=None)[source]#
Create the FMU component and derive port specifications.
- Parameters:
- Raises:
RuntimeError – If the FMU is not a co-simulation FMU.
NotImplementedError – If the FMU uses an unsupported FMI version.
- _md: ModelDescription#
- _build_port_specs()[source]#
Build input/output PortSpec objects from the model description.
- Return type:
None
- _build_value_reference_map()[source]#
Cache value references for fast typed access.
- Return type:
None
- _analyze_model_structure()[source]#
Populate model structure dependencies for outputs/derivatives/initials.
- Return type:
None
- _initialize_component(t0)[source]#
Initialize and instantiate the FMU for simulation.
Extracts the FMU archive.
Creates the FMU2Slave instance.
Sets up the experiment with the start time.
Enters initialization mode.
Applies parameter start values.
Applies input start values from PortStates.
Exits initialization mode.
- Parameters:
t0 (float) – Simulation start time.
- Return type:
None
- reinitialize_instance(t0)[source]#
Recreate the FMU instance and enter initialized state at
t0.This is intentionally different from FMI
reset(). Some FMUs do not support reliable rollback throughfmi2Resetafter stepping, but can be restored by creating a fresh instance and applying reconstructed initial conditions through parameters.- Parameters:
t0 (float)
- Return type:
None
- _apply_parameters_starts()[source]#
Apply parameter start values to the FMU instance.
- Return type:
None
- _apply_input_starts()[source]#
Push initial input values from PortStates into the FMU.
- Return type:
None
- _abc_impl = <_abc._abc_data object>#
- set_inputs(signals, t=None)[source]#
Set input port values and push them to the FMU.
- Parameters:
- Raises:
KeyError – If an input name is unknown.
TypeError – If a value type does not match the port type.
ValueError – If a REAL input is missing a value after unit conversion.
- Return type:
None
- _update_output_states(t=None, event_names=None)[source]#
Refresh output PortStates from the FMU instance.
- get_state()[source]#
Return FMU variables as a serialized dictionary.
The dictionary includes variables that are not fixed and not local, along with their units and current values pulled from the FMU instance.
- evaluate_outputs(inputs, t=None)[source]#
Evaluate outputs for a given input set without advancing time.
- reset()[source]#
Reset the component and release the FMU instance.
After reset, the component can be reinitialized via
initialize().- Return type:
None
- soft_reset(t0=0.0)[source]#
Reset the FMU to initial state without releasing the instance.
Uses FMI
reset()to return to the instantiated state, then reinitializes with parameter and input starts.- Parameters:
t0 (float) – New start time for the simulation.
- Return type:
None
- syssimx.components.fmu._port_type_from_var(var)[source]#
Determine PortType from ScalarVariable type.
- Parameters:
var (ScalarVariable) – The model variable to determine the port type for.
- Returns:
The corresponding PortType.
- Return type:
- Raises:
NotImplementedError – If the variable type is unsupported.
FEM Component#
- class syssimx.components.fem.FEMComponent[source]#
Bases:
CoSimComponentMinimal abstract base for FEM co-simulation components.
No direct dependency on a specific FEM library (ngsolve/netgen, etc.).
Subclasses implement backend specifics (mesh, FE spaces, solvers, visualization).
- __init__(name, label=None, group=None)[source]#
Initialize a new co-simulation component.
- Parameters:
name (str) – Unique identifier for this component. Must be unique within the containing System. Used for connection definitions and graph construction.
label (str | None) – Human-readable display name for visualization and logging. Defaults to
nameif not provided.group (str | None) – Optional category for grouping related components (e.g., ‘sensors’, ‘actuators’, ‘controllers’). Used for filtering and organization in large systems.
Example
>>> comp = MyComponent("pid_1", label="PID Controller", group="controllers") >>> comp.name 'pid_1' >>> comp.label 'PID Controller'
- abstractmethod _initialize_component(t0)[source]#
Setup mesh, FE spaces, solver, material laws, initial conditions.
- Parameters:
t0 (float)
- Return type:
None
- load_mesh_from_file(path)[source]#
Optional: load mesh from file (GMSH, VTK, XDMF, etc.).
- Parameters:
path (Path)
- Return type:
None
- visualize_state()[source]#
Optional: library-specific visualization (NGSolve Draw, matplotlib, etc.).
- Return type:
None
- _abc_impl = <_abc._abc_data object>#
OpenSim Component#
- class syssimx.components.opensim.OpenSimComponent[source]#
Bases:
CoSimComponentWrapper around an OpenSim model to implement the CoSimComponent interface.
- model: opensim.Model#
- state: opensim.State#
- manager: opensim.Manager#
- _finalize_model(t0)[source]#
Complete OpenSim initialization after model is built/loaded. Call this at the end of subclass _initialize_component().
- Parameters:
t0 (float)
- Return type:
None
- reset()[source]#
Reset the component to a clean state before (before initialization).
- Return type:
None
- get_coordinate_value(coord_name)[source]#
Get current value of named coordinate (generalized position).
- get_coordinate_speed(coord_name)[source]#
Get current speed of named coordinate (generalized velocity).
- _abc_impl = <_abc._abc_data object>#