This repository Produces a monolithic MADS agent that can run a simulation model (a .fmu file) in FMI3 format.
Functional Mockup Units (.fmu files) can be exported from a large number of simulation softwares like MATLAB Simulink.
This agent has been updated for MADS v2
NOTE: Only the last format of FMI format, i.e. FMI 3.0, is supported.
As usual for MADS plugins and agents:
cmake -Bbuild
cmake --build build -j6A few notes:
- The default install prefix is the MADS folder (as for
mads -p) - The option
MADS_INSTALL_AGENT(default: off) enables installation in the prefix directory of themads-fmuagent, so that you can call it asmads fmu - The option
MADS_BUILD_FMU(default: off) enables compilation and creation of the FMU units from the source files available in themodelsdirectory; those are intended for testing purposes
Currently, only model exchange FMUs are supported. Co-simulation FMUs are not supported.
FMUs are actuallt zipped folders that contain some XML file providing model description and a compiled dynamic library, which is supposed to be run-time loaded by the software using it.
FMU files are typically exported from simulation software in the compiled format, which is only compatible with the working platform. In other words, a FMU file generatd on Intel Windows won't run on a Silicon macOS (and vice-versa).
The project model directory contains example FMUs in source format, so that they can be compiled on the working machine producing a usable .fmu file. When you enable the CMake switch MADS_BUILD_FMU, the compiled FMUs are created and saved in the models/fmu directory.
Once the agent is compiled and you have a valid FMI3.0 compatible my_model.fmu file, you shall chek it for the actual naming of internal variables. Assuming that the agent has been installed (with cmake --install build), and that the FMU file is in your current working directory:
mads fmu my_model.fmu --inspectThis is giving you a table of model variables and a suitable stub section for the mads.ini file. Copy that into your settings file, update the fields as needed and launch the mads broker command, if it is not running already.
Note: the inspect command reports the file name and the model name. The latter can be different from the file name, and it is set by the software that generated the FMU. On the MADS network, the agent running the FMU will have the name
fmu_<model name>, also reported by the inspect command. Inless overridden by the--nameswitch, this is the expected section name in the INI settings filemads.ini.
Now you can run the agent:
mads fmu my_model.fmuNote that by default the model runs at 100 ms period. You can change that either via the period value in the INI section, or override that via the -p|--period command line option.
The model is routinely evaluated and forward integrated at variable timestep, and the new status is published on the pub_topic. At any time, a new input can be gived via the MADS network, by publising to the sub_topic a JSON message as:
{
"fmu_input": {
"in_var1": 123.0,
"in_var2": 0.123
}
}To reset the model, send the following:
{"fmu_reset": true}It is suggested to use the rerunner plugin to visualize the model state in real time.
NOTE: the model is suppsed to run in real time, i.e. the solution time for each timestep shall be shorter than the timestep itself. Relax the tolerances in the INI section if your model cannot keep up with the real time.