modelicaToFmu
Compile a Modelica model to an FMU with OpenModelica.
📝Syntax
fmu = modelicaToFmu(model)
fmu = modelicaToFmu(model, modelName)
fmu = modelicaToFmu(model, modelName, name, value)
📥Input Arguments
Parameter Description
model a string scalar or character row vector: the path to a .mo file, or inline Modelica source text.
modelName a string: the Modelica class to build. Optional; when omitted it is the .mo base name (file input) or is parsed from the first model / block / class / package declaration (inline source).
name, value option pairs: 'FmiVersion' ('2.0' default, or '3.0'), 'FmuType' ('cs' default Co-Simulation, 'me', or 'me_cs'), 'Libraries' (a string or cell of extra .mo files to load before building), 'Rebuild' (false default; true ignores the cache).
📤Output Arguments
Parameter Description
fmu the path to the produced .fmu file.
📄Description

modelicaToFmu compiles a Modelica model to a Functional Mock-up Unit (FMU) using an installed OpenModelica compiler and returns the path to the produced .fmu. It is the compilation half of the nflow Modelica bridge: a modelica block calls it so that the resulting FMU can be simulated through nflow's FMI path.

The result is cached under the temporary directory, keyed by a hash of the source, the model name, the OpenModelica version and the FMU options, so an unchanged model is compiled only once.

For a Modelica variable to become a usable output port after import, declare it output (for example output Real vC;); an ordinary variable is exported with causality local.

Two typed errors can be raised. Nelson:nflow_fmi:modelicaUnavailable when OpenModelica is missing or cannot export an FMU (the build is blocked); check the installation with modelicaInfo and set it with modelicaConfigure. Nelson:nflow_fmi:modelicaCompileFailed when omc ran but did not produce the FMU; the message carries the OpenModelica diagnostics.

💡Examples
Compile an inline first-order model.
src = sprintf('model FO\n  output Real x(start = 1.0);\nequation\n  der(x) = -x;\nend FO;\n');
fmu = modelicaToFmu(src);
info = fmiInfo(fmu)
Compile a model from a .mo file.
moFile = [modulepath('nflow_fmi'), '/examples/modelica/RLC.mo'];
fmu = modelicaToFmu(moFile, 'RLC')
🔗See Also
modelicaInfomodelicaConfigurefmiInfo
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub