Simcenter 3D Solutions FMU/FMI - Export a cosimulation FMU from the AMESim & Import it in the Simulink

2022-06-27T20:40:01.000-0400
Samcef Desktop Samcef Wind Turbines Simcenter Nastran Simcenter Samcef Simcenter 3D Simcenter 3D Solutions Marketing TEA Pipe BOSS Quattro Simcenter Multimech Teamcenter Share CAESAM Simcenter FLOEFD SC

Summary


Details


Summery
FMU is the new standard in the industry, which provides the common standardized framework for co-simulation between the different tools. The Functional Mock-up Interface (FMI) is a free standard that defines a container and an interface to exchange dynamic models using a combination of XML files, binaries, and C code zipped into a single file. AMESim can export Co-simulation as well as Model exchange FMUs. GUI designed in AMESim is easy and interactive which helps to export FMU seamlessly. This FMU can be imported into any other tool provided that the FMU standard has been implemented in that tool.

To know more about FMU Click here

This demo will help users to
  • How to create the FMU in AMESim?
  • How to export co-simulation FMU from AMESim?
  • How to import this created FMU in Simulink?
  • How to carry out co-simulation?
Pre-requisite: -
  • At least AMESim base with FMU add on license
  • Simulink with FMU license
  • In addition to these other libraries as per your modeling requirements.
Short description of Demo –

The electrical vehicle is gaining popularity and it is seeing as a technology of the future. Battery pack design is playing very important from the safety and performance point of view. Generally, a separate Battery management control unit is used to manage the performance of the battery. MIL, SIL, HIL, etc method is generally used to verify the algorithm and logic of the Battery management control unit. Simulink is generally used as a graphical language for coding of most of the electronic control units.  In this demo, a simplified BMC for battery cell balancing control algorithm is developed in Simulink; the model of the battery pack is implemented in Simcenter AMESim. By coupling between AMESim and Simulink, one can verify the effectiveness of code in the design stage. AMESim can be coupled with Simulink in several ways. In this demo, we will see “How AMESim can be coupled with Simulink to verify your control unit logic”. AMESim model is giving voltages of various cells as an output. This output is sent to the Simulink model. At every time step Simulink processes this output and give the optimum command to each cell so that cell balancing can be achieved.

Before moving ahead, please remember the limitation of MATLAB Simulink FMU: -
  • Simulink doesn’t comply with the so-called “structured variable naming” of FMUs (also known as “dotted convention” or “Modelica-like convention”). Apparently, Simulink mistakenly treats IO names as bus components. These issues do not arise with 3rd party open-source toolboxes like DS’ FMI Kit for Simulink. Hence, you may face the issue while importing FMU.
Considering the above facts, ame2slcosim’ is nearly providing similar options into the AMESim. These options will provide you more flexibility with solver selection and a simple process to carry out co-simulation. For more details about these options, please visit the AMESim help file.

We will use the existing demo from Simulink. You can download this demo from the help file. This is also available in the file attached to this article
image.png
Step 01 – Replace the Interface with FMU interface
  • Right-click on “interface block and click on the “Edit Interface”. This should open below the window. Change the “AME2SL” interface to the “FMI” interface.
image.png        
  • Connect all the ports and complete the model.
  • If you wanted to change some of the parameters directly from the Simulink, then you can add them in the “watch parameter”. Similarly, you can also add the “Watch variable”. In this way, you can directly change these parameters from Simulink without opening AMESim
Step 02 – Create co-simulation FMU
  • Compile your model.
  • Go to Interface >> FMU Export Assistant
image.png
  • FMU type and version – Select the Co-simulation 2.0 option from here.
  • Visibility level: Exposed elements – select the required option depending on “how many parameters and variables do you want to expose?
  • Tick mark required option
  • Select the output directory, where you wanted to save the .fmu file
  • Click on the next.
  • Select the targeted compiler. Please note, you should use the same compiler in Simulink.
image.png
  • Click on Generate.
image.png
  • It should generate the .fmu file in the targeted directory.
Step 03 – Import co-simulation FMU in the Simulink.
  • Open existing .slx file and delete AME2SL block. This block needs to be replaced with FMU.
  • Add FMU submodel into the Simulink sketch and double click on the FMU.
  • It should open the below window. Browse the .fmu file here. It will load the co-simulation fmu.
image.png
  • It will display only “1 input” and “1 output” ports instead of your expectation of “10 inputs” and “10 outputs” ports. Here you will have to create a bus in order to overcome this issue.
  • Run below command to create a bus
       >> fmudialog.createBusType('ImportAMECosimFMU/FMU')
          Bus Object for Input Port 1: expseu__1
          Bus Object for Output Port 1: expseu__2
  • Connect all signals line properly. Your model is ready for co-simulation.
Step 04 – Run the model
  • Since it is a co-simulation example, hence, AMESim FMU will use a AMESim solver and the Simulink model will use a Simulink solver. Double click on FMU. It will open the “Block parameters” window.
  • You can see here all run parameters from AMESim. AMESim run parameter setting can be directly controlled from here. If you scroll down in this window, then you can also see the parameters which you added in the “watch parameter” list before exporting FMU. You can directly change these parameters from here.
image.png
  • Set the proper solver setting for the Simulink model.
  • Run the model. You can see the results now
Some important instruction
  • We have tested this FMU in MATLAB 2019b version, hence this instruction may applicable till 2019b or higher version (If MATLAB will not improve on this). If MATLAB will do some improvement in the future version, then, you may not see this issue.
Simulink doesn’t comply with the so-called “structured variable naming” of FMUs (also known as “dotted convention” or “Modelica-like convention”). Apparently, Simulink mistakenly treats IO names as bus components. We would suggest to contact MathWorks directly if it is really needed. These issues do not arise with 3rd party open-source toolboxes like DS’ FMI Kit for Simulink.
There are two things users can do to mitigate this issue:
  • Use Simulink bus extractor components to retrieve the individual signals
  • Use the two MATLAB commands below:
    set_param('MyModel/FMU','FMUInputMapping','Flat')
        set_param('MyModel/FMU','FMUOutputMapping','Flat')
MyModel” is the name of the Simulink model, “FMU” is the name of the FMU block. Please adapt appropriately. These commands will force the FMU block to switch to the flat naming convention.
Conclusion
  • "Ame2slcosim" can provide better options compared to this option provided in this article.
  • Till 2019b, Simulink doesn’t comply with the so-called “structured variable naming” of FMUs
  • All process related to the FMU import and export is simple and more interactive in AMESim compare to Simulink.
CLICK HERE to download the demo files

If you are interested to know the other method of cosimulation with Simulink, then please visit below VIDEO articles.

CLICK HERE to know about “Cosimulation between Simulink & AMESim (AME2SLCosim) using MinGW-w64 (gcc 64 bit) compiler
CLICK HERE to know about “Model exchange (AME2SL) between MATLAB Simulink and AMESim with MinGw 64bit compiler
CLICK HERE to know about “Import MATLAB Simulink Model to AMESim (SL2AMECOSIM) using MinGW 64-bit compiler”.
CLICK HERE to know about “Export the AMESim model Blackbox to MATLAB Simulink using GNU MinGW gcc x64 bit compiler.
CLICK HERE to know about “FMU/FMI - Export a Model Exchange FMU from the AMESim & import in the Simulink
CLICK HERE to know about “Import MATLAB Simulink FMU to AMESim
If you still need support or clarification, then click here to raise the case on the support portal.
 

KB Article ID# KB000046599_EN_US

Contents

SummaryDetails

Associated Components

Samcef Desktop