FMU export#

This section contains the classes related to Scade One FMU export.

The FMU export supports the FMI 2.0 version for Model-Exchange and Co-Simulation.

The principle is to build a FMU package from a given Scade One operator. This operator has to be a root operator of a code generation job, and this job must have been executed before FMU export.

For more information about the FMI standard, consult FMU/FMI.

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

with ScadeOne('<install_dir>') as app:
    project = app.load_project('project.sproj')

    fmu = FMU_2_Export(project, 'CodeGen')

    fmu.generate('ME', 'project_ME')
    fmu.build(True)

Limitations

Imported Types

The FMU export is not possible if imported types are used for any of the inputs or outputs of the selected operator, or sensors in the scope of the export.

Supported Platforms

This version only supports gcc compiler on 64-bits Windows platforms.

FMU export command line#

The FMU export can also be performed using the pyscadeone command line, by selecting the fmu command. The command performs the complete export, by running FMU_2_Export.generate() and FMU_2_Export.build() methods of the FMU_2_Export class. All expected arguments can be passed through this command. Complete list is given by –help.

pyscadeone fmu --help
usage: pyscadeone fmu [-h] -inst INSTALL_DIR [-op OPER_NAME]
                      [-max MAX_VARIABLES] [-k KIND] [-o OUTDIR] [-p PERIOD]
                      [-ws] [-args key value]
                      project job_name

positional arguments:
  project               Scade One project
  job_name              Generated Code job name

optional arguments:
  -h, --help            Show this help message and exit
  -inst INSTALL_DIR, --install_dir INSTALL_DIR
                        Scade One installation directory
  -op OPER_NAME, --oper_name OPER_NAME
                        Root operator name
  -max MAX_VARIABLES, --max_variables MAX_VARIABLES
                        Maximum number on FMI variables (flattened sensors,
                        inputs and outputs) supported by the export (1000 by
                        default).
  -k KIND, --kind KIND  FMI kind: ‘ME’ for Model Exchange (default), ‘CS’ for
                        Co-Simulation
  -o OUTDIR, --outdir OUTDIR
                        Directory where the FMU is built (by default,
                        'FMU_Export_<kind>_<job_name>')
  -p PERIOD, --period PERIOD
                        Execution period in seconds
  -ws, --with_sources   Keep the sources in the FMU package
  -args key value, --build_arguments key value
                        Build arguments. Use one -args argument per key. Supported keys are:
                        arch: compiler architecture,
                        user_sources: list (comma separated) of user source files or directories (code, includes),
                        cc_opts: list (comma separated) of extra compiler options,
                        link_opts: list (comma separated) of extra link (dll creation) options,
                        swan_config_begin: data to insert at the beginning of swan_config.h,
                        swan_config_end: data to insert at the end of swan_config.h.

FMU export documentation#

This section gives the API for the FMU export.

Note that the FMU export relies on the Generated code API.

class ansys.scadeone.core.svc.fmu.FMU_2_Export(prj: Project, job_name: str, oper_name: str = '', max_variables: int = 1000)#

Bases: FMU_Export

FMU 2.0 export main class.

Parameters:
prjProject

The Scade One project.

job_namestr

The name of the code generation job for the operator to be exported as an FMU.

oper_namestr, optional

Optional operator name (by default it is the root operator of the job, if provided it has to be a root operator for the job).

max_variablesint, optional

Maximum number on FMI variables (flattened sensors, inputs and outputs) supported by the export (1000 by default).

generate(kind: str, outdir: str | PathLike, period: float = 0.02) None#

Generate the FMI 2.0 XML and C file according to SCADE generated code.

Parameters:
kindstr

The FMI kind (‘ME’ for Model Exchange, ‘CS’ for Co-Simulation).

outdirUnion[str, os.PathLike]

The output directory where the files are generated.

periodfloat, optional

The execution period in seconds (default is 0.02).

build(with_sources: bool = False, args: dict | None = None) None#

Build the FMU package from generated files.

The .FMU is built in the outdir directory provided when code was generated (see method generate), and its name is the name of the selected operator.

Parameters:
with_sourcesbool, optional

True to keep the sources in the FMU package.

argsOptional[dict], optional

Build arguments, provided as a dictionary (default is None): - user_sources: list of user source files or directories (code, includes) - cc_opts: list of extra compiler options - link_opts: list of extra link options - swan_config_begin: data to insert at the beginning of swan_config.h - swan_config_end: data to insert at the end of swan_config.h

create_xml_child(name: str, parent: Node) Element#

Create an XML child element.

property elaboration_function: CFunction | None#

Return the elaboration function of the operator.

get_next_value_reference(fmu_ty: str) str#

Get the next value reference for a given fmu type.

Parameters:
fmu_tystr

The FMU type.

Returns:
str

The next value reference as a string.

property model_id: str#

Returns the name identifier of the operator exported as FMU.

property oper: ModelOperator#

Return the ModelOperator object.

property oper_path: str#

Returns the Scade One path for the operator exported as FMU.

property sensors: List[ModelSensor]#

Return the ModelSensor objects.

codegen#

Associated GeneratedCode object.