Export FMU#

This section presents how to build an FMU package for FMI 2.0 (see FMU export).

This can also be done through the command line, see how at the end of the section.

The QuadFlightControl example is used. To set up the example see QuadFlightControl example setup code.

The following package must be used:

from ansys.scadeone.core.svc.fmu import FMU_2_Export

The example relies on a code generation job named CodeGen. A FMU_2_Export object is created for this job:

app = ScadeOne(install_dir=s_one_install)

project = app.load_project(quad_flight_project)

print("Create FMU_Export object")
fmu = FMU_2_Export(project, "CodeGen")

To generate and build the FMU, ensure to have the code generation job executed, which produces the C code from the Swan model (execution is done from the Scade One IDE). The script can then access the generated code data.

Note

The GeneratedCode object is accessible using the FMU_2_Export.codegen property. From there, you can check if code is generated with the GeneratedCode.is_code_generated property.

if not fmu.codegen.is_code_generated:
    print("FMU package cannot be generated if the job is not executed first.")
    exit()

The FMI 2.0 files are generated using the FMU_2_Export.generate() method:

fmu.generate("ME", "QuadFlight_FMU_ME")

The FMU package is built from the FMI 2.0 and the Scade One generated files using the FMU_2_Export.build() method:

fmu.build(True, args)

Important

The FMU is built using the gcc compiler provided with Scade One, unless it is already in the PATH. Explicit compiler path can also be provided using the gcc_path key args build argument.

For the QuadFlightControl example, some library operators are defined in an include file. This file must be added to the swan_config.h file. This is done using the args build argument, by setting the swan_config_end key to the proper #include directive:

library_include = s_one_install / r"libraries\Math\resources\math_stdc.h"
args = {"swan_config_end": f'#include "{library_include}"'}

The FMU package is named QuadFlightControl_QuadFlightControl.fmu and is located under QuadFlight_FMU_ME sub directory.

Note

The FMU package has been built for Model Exchange (ME). To build it for Co-Simulation (CS), set the kind parameter of the FMU_2_Export.generate() method to “CS”.

fmu.generate("CS", "QuadFlight_FMU_CS")
fmu.build(False, args)

Example with command line#

The FMU package can be built using the pyscadeone command line as follow:

pyscadeone fmu "<s_one_install>/examples/QuadFlightControl/QuadFlightControl/QuadFlightControl.sproj"
CodeGen --install_dir "<s_one_install> --outdir QuadFlight_FMU_ME --with_sources
--build_arguments swan_config_end '#include "<s_one_install>/libraries/Math/resources/math_stdc.h"'

Refer to FMU export command line for more details on command line usage.