FMU workflow in PLECS
PLECS 4.9 supports import and export of Functional Mock-up Units (FMU) of Version 2 (Model Exchange). Support for FMU Version 3 and Co-Simulation will soon be released.
Note: FMU import is available in both PLECS Standalone and PLECS Blockset. FMU export requires an additional PLECS Coder license.
Attached are two examples highlighting the FMU Version 2 export and import workflow in PLECS. Both examples consist of separate export and import models.
- Example 1: Thyristor Rectifier
thy_rect_fmu_export.plecs (89.3 KB)
thy_rect_fmu_import.plecs (103.9 KB)
- Example 2: PMSM with sensorless control
sensorless_vector_control_pmsm_fmu_export.plecs (358.7 KB)
sensorless_vector_control_pmsm_fmu_import.plecs (367.7 KB)
The following is a step-by-step instruction on how to export and import FMU files in PLECS.
Exporting an FMU file from a PLECS model
In this example, the Tyristor Rectifier Circuit is exported as FMU file. Note that the FMU export feature requires a PLECS Coder license.
- The subsystem to be exported is set to atomic with auto sample time.
(This step is preconfigured in the example model)
The auto sample time setting ensures that the subsystem is simulated at variable time-steps with a variable-step solver selected.
- Simulate the model twice: first with a variable-step solver, then with a fixed-step solver. After each simulation save the trace to compare the results in a PLECS Scope. The comparison highlights the loss of accuracy introduced by discretizing the model at a fixed sample time. Variable-step simulation is best practice for almost all offline simulations. With variable-step solvers, the accuracy defined by the solver tolerance settings is guaranteed, as the step size is automatically adapted to meet these tolerances. The quality of the fixed-step results reflects what can be expected from the exported FMU model later.
Note: Fixed-step simulation will fail if the model contains blocks with variable-step discrete tasks. This applies to Example 2 (PMSM with sensorless control). In this case, skip the fixed-step simulation and proceed with the next step. See FMU Validation Workflows
- Right-Click on Subsystem to open the FMU export dialog
- By default, the sample time is set to the fixed-step size configured in the solver settings
- Select the Target platform(s) and enter a name for the FMU File
- Export the FMU file
Importing an FMU File into a PLECS model
- Open the import PLECS model
- Import the FMU file into the configurable “Circuit” subsystem
- Simulate the model and compare “FMU” configuration to “Original” configuration
Due to the discrete-time execution, the accuracy of the FMU model is reduced compared to the “Original” PLECS plant, which is simulated using a variable-step solver. If more accuracy is required, the discretization step size needs to be reduced when exporting the FMU model.
FMU Validation Workflows
When discretizing simulation models, for example, for FMU export or C code generation, the accuracy of the simulation results depends on the chosen discretization step size and is generally reduced compared to variable-step simulations. Therefore, discretized models should be validated by comparison with variable-step simulation results.
Two validation workflows are possible. The first is a direct comparison between variable-step and fixed-step simulation results. This approach is suitable when the model used for FMU export can be simulated with a fixed-step solver and is typically the simplest and fastest validation method. With a fixed-step solver it’s important to note that both the FMU subsystem and other components in the model are simulated with a common step size.
If the export model cannot be simulated with a fixed-step solver, for example, because it contains variable-step discrete tasks, a different approach is required. In this case, the exported FMU must be re-imported, and the simulation results of the re-imported FMU are compared against the results of the original PLECS subsystem used for FMU export. Both the original PLECS circuit and the imported FMU model are simulated with a variable-step solver. However, because the re-imported FMU has the fixed-step size encoded in the FMU, the discrete behavior of the FMU block is simulated correctly. Other components in the PLECS schematic outside of the FMU block will use the variable-step solver and therefore support variable-step discrete tasks.









