result = fmiCoSimulate(fmu, tStop)
result = fmiCoSimulate(fmu, tStop, dt)
result = fmiCoSimulate(fmu, tStop, dt, inputs)
| Parameter | Description |
|---|---|
| fmu | a string scalar or character row vector: the path to a .fmu archive, or to an already-extracted FMU directory. The FMU must provide the Co-Simulation interface (see fmiInfo). |
| tStop | a positive real scalar: the stop time of the simulation, in the FMU time unit (seconds). The simulation starts at time 0. |
| dt | an optional positive real scalar: the communication step size. When omitted it defaults to tStop / 100 (one hundred steps). It is clamped to tStop when larger. |
| inputs | an optional scalar structure whose field names are FMU Float64 input variables and whose values are the constant values held on those inputs for the whole run, for example struct('u', 2.5). Inputs not listed keep their FMU start values. |
| Parameter | Description |
|---|---|
| result | a scalar structure holding the recorded trajectory, with the fields time, outputNames, and outputs described below. |
fmiCoSimulate runs a Co-Simulation of a Functional Mock-up Unit (FMU) that follows the FMI 2.0 or 3.0 standard and returns the values of every Float64 output at each communication point.
The FMU is instantiated, initialized between time 0 and tStop, and then advanced with a fixed communication step dt. At the start of each step the current Float64 outputs are recorded; the FMU is then advanced by one step. The loop stops at tStop, or earlier if the FMU requests termination. The FMU is always terminated and freed before the function returns, including on error.
No external inputs are applied: the parameters and inputs of the FMU keep the start values declared in its model description. The function therefore reproduces the free response of the model as packaged. Applying custom inputs is not yet supported by this entry point.
The fmu argument accepts either a .fmu archive or an already-extracted directory. A .fmu archive is unpacked with a ZIP-slip-hardened extractor into a fresh temporary directory that is removed automatically when the function returns; entries with absolute paths, drive letters, or .. traversal are rejected.
The returned structure result has the following fields:
| Field | Size | Details |
|---|---|---|
| time | N x 1 | the communication points, starting at 0 and strictly increasing by dt (the last point may be shorter when the FMU terminates early). |
| outputNames | 1 x nOut | a cell of the names of the Float64 output variables, in declaration order. |
| outputs | N x nOut | the recorded output values; column j is the trajectory of outputNames{j}, row i corresponds to time(i). |
The number of rows N is floor(tStop / dt) + 1 for a run that completes at tStop. When the FMU declares no Float64 output, outputNames is empty and outputs has zero columns while time is still returned.
Use fmiInfo first to inspect the variables and confirm the Co-Simulation interface. An error is raised when tStop is not positive, when the FMU does not support Co-Simulation, or when any FMI call fails.
result = fmiCoSimulate('VanDerPol.fmu', 20)
r = fmiCoSimulate('VanDerPol.fmu', 20, 0.01);
plot(r.time, r.outputs);
legend(r.outputNames);
xlabel('time');
title('FMU Co-Simulation outputs');
r = fmiCoSimulate('VanDerPol.fmu', 20, 0.01);
col = find(strcmp(r.outputNames, 'x0'));
x0 = r.outputs(:, col);
fmu = [modulepath('nflow_fmi', 'root'), '/examples/Feedthrough.fmu'];
r = fmiCoSimulate(fmu, 2, 0.1, struct('Float64_continuous_input', 2.5));
col = find(strcmp(r.outputNames, 'Float64_continuous_output'));
r.outputs(end, col)
| Version | Description |
|---|---|
| 2.0.0 | initial version |