Using the Simulink to Simcenter Amesim Interface > Using the SL2AMECosim interface - Co-simulation Mode
Generating the code - SL2AMECosim
Automatic export
For people who are not familiar with Simcenter Amesim categories and icon organization, there is a fully automatic export option.
>> sl2amecosim('relay','C:\AMETest\libsl2ame','auto')
With the 'auto' option, Simcenter Amesim takes care of the creation of an icon automatically. This is the ‘short’ way of running the command which takes care of the following:
- Submodel C, SPE and Help files (and compiling the submodel).
Note
The C code does not contain the actual Simulink model.
It is possible to edit the generated submodel with Submodel Editor in order to make minor cosmetic updates.
Library (LIB) file containing the actual Simulink model.
AME.make file instructing Simcenter Amesim to link with the generated library.
The new category icon if not available (SL2AME by default).
The new component icon with the proper number and type of ports (if not available) with a name indicating the number of inputs/outputs.
The submodels.index and AMEIcons files (if not available)
All these files will be stored in themysl2amelib directory where the command is run. As you can edit the submodel using Submodel Editor, it is easy to change icons etc.
Advanced export
To allow greater control over the export process, there are some additional arguments that can be used. You can also link the exported model to an existing component icon instead of creating a new one. In order to achieve this, you must specify the icon name instead of the ‘auto’ argument.
The full syntax is:
>> sl2amecosim(‘system’,’C:\library’,’icon’,’codegenoptions’, debug)
This command exports a C code for system.mdl and links it to the icon of the Simcenter Amesim component library located in C:\library. The generated code is compiled in debug mode if debug equals one.
The systemname, library and iconname are mandatory. Very little is verified in terms of compatibility between the Simulink model and the provided icon name. It is up to the user to verify that the number and type of I/O ports of the Simcenter Amesim component icon and the Simulink model are compatible.
The codegenoptions is a text string containing one or both of hide_params or hide_vars. This can be used for completely hiding the internal parameters and variables in the Simulink system. This makes it possible to send sensitive/confidential models to clients or providers.
The debug flag is also optional. RTW’s verbose flag is forced to on in debug mode, and the generated code is compiled in debug mode. Note that if the RTW verbose flag is set to on, it will never be forced to off by SL2AMECosim
A normal standard output (with RTW Verbose set to off) is similar to the following example:
Copy>> sl2amecosim('relay','here', 'auto', '') ====> STARTING SL2AMECOSIM CODE GENERATION FOR MODEL RELAY... ====> Step #1: Checking system and model... ====> Step #2: Generating code & building OBJ file ### Starting build procedure for model: relay ### Successful completion of build procedure for model: relay ====> Step #3: ====> Step #4: Restoring initial model configuration ====> Step #5: Create Simcenter Amesim submodel - and compile it Solvername = 'FixedStepDiscrete' Stepsize=0.001 1 inputs 1 outputs 4 numrealparams 2 numintparams 0 numbiosignals 1 tot num inputs 1 tot num outputs 0 : relay/In1 0 : relay/Out1 Submodels Windows compilation batch file. ----------------------------------------------------------------------- This batch file is to automate the compile procedure for submodels or other userwritten C files using the Microsoft Visual C++ compiler. ----------------------------------------------------------------------- |
|---|
Copy- Will compile the following file(s): RELAY.c cl -nologo -MT -W3 -EHsc -wd4996 -fp:precise -DWIN32 -DNDEBUG -D "_WINDOWS" -D "_MBCS" -c RELAY.c -Fowin32\ RELAY.c Submodel build completed! INFO: found Icons/sl2ame.ico in here/AMEIcons ====> Step #6: Adding model to here/Icons/sl2ame.ico WARNING : SubModel already referenced for this Icon. Updating files... The option for reusing signal storage is active. This will reduce the number of variables in the AMESim submodel. The option for block reduction is active. This will reduce the number of variables in the AMESim submodel. The option for Parameter Pooling is active. This will reduce the number of parameters in the AMESim submodel. ====> SL2AMECOSIM CODE GENERATION FOR MODEL RELAY FINISHED SUCCESSFULLY. |
In Step 2 there will be a lot of messages about compilation etc. if the RTW options are set to verbose for the model.
Step 5 generates and compiles the actual Simcenter Amesim submodel. The messages here can be useful for understanding how the generated submodel is set up. Information is displayed about the solver used and the stepsize. Note that in this case a version of MATLAB is used that can extract the information about input/output variable names. The term biosignals is short for block input/output signals which are the variables internal to the Simulink system.
In Step 6 some messages about the current options are displayed. Most of them must be considered as normal. They transmit useful information to allow verification that the options used (such as the absence of inputs, outputs, states, parameters or block I/O etc.) are what were intended. In most cases, they do not require any corrective action.
As the code generation process makes temporary modifications to the Simulink model the model will typically be closed and reopened in the process. This is done to ensure that any modifications are really temporary. This also means that the Simulink model must be saved before the SL2AMECosim process is started.
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Simulink/Generating_the_code_SL2AMECosim · retrieved 2026-07-17