Borrar filtros
Borrar filtros

How to Repackage the files in FMU for cross-platform use?

46 visualizaciones (últimos 30 días)
Jintu el 19 de Mzo. de 2024
Respondida: Christian Bertsch el 12 de Abr. de 2024
I exported a Simulink model to Standalone FMU with source code by following the link
My aim was to reuse the standalone co-simulation FMU with source code on another platform (Linux).
Initially the FMU was created on windows platform and followed the procedure in the above link on Linux platform.
Three steps were provided:
  1. Unzip the standalone co-simulation FMU with source code and compile the source code to generate the platform specific binary files.
  2. Move the generated binary file in the binaries folder.
  3. Repackage the files in FMU for cross-platform use
First two steps were succsfully executed.
I need some help in how to Repackage the files in FMU.
I attempted the following approach: I copied the .so file into the 'binaries > linux64' directory. Then, I compressed all the files including binaries, documentation, sources, model.png, and modelDescription.xml. Finally, I changed the extension of the compressed file to .fmu. However, when I attempted to read this FMU in STAR CCM+, I encountered an error message indicating that the .xml file was not found.
It seems that I may have made a mistake during the repackaging process. I would appreciate it if you could provide detailed instructions on how to properly repackage the files.
  2 comentarios
Marina Espejo
Marina Espejo el 28 de Mzo. de 2024
Hi! Do you know if those steps are necessary when working on windows? I am trying to do a cosimulation between Simulink and STAR-CCM+ as well and i am not being able to find the origin of this mistake:
"INFO: Processing event 'Step FMU'
Connection reset by peer
Connection reset
Server connection failed. This is usually due to a fatal error in the server or a network issue.
Design Simcenter STAR-CCM+ simulation completed
Server process exited with code : -1073741571"
Thanks and good luck!
Jintu el 29 de Mzo. de 2024
Those steps are necessary only when you are doing a cross-platform compilation. If you are using both Simulink and STAR-CCM in windows platform, then you do not need to carryout any of the steps indicated in the link.
But, I am not sure about the resons for your error indicated above.
In my case, I could succesfully carry out the FMU creation and co-simulation in windows platform. So you could confirm the following steps.
  • Create FMU with fixed time step. (Not variable time step )
  • follow the tutorial from Simcenter under 'Tutorials > coupling with CAE codes > FMU Co-Simulation: Temperature Controller.
This might be useful in setting up it correctly.

Iniciar sesión para comentar.

Respuesta aceptada

Yash el 2 de Abr. de 2024
Hello @Jintu,
Thank you for reaching out and detailing the process you've followed so far in exporting your Simulink model to a standalone FMU with source code for cross-platform use. Based on your description, it appears that the issue you're encountering with STAR CCM+ not being able to find the `.xml` file may stem from how the FMU was repackaged after inserting the compiled `.so` file for Linux.
Repackaging an FMU requires careful attention to ensure that the file structure within the FMU (which is essentially a ZIP file) is preserved according to the FMI standard. Here's a step-by-step guide to ensure the FMU is repackaged correctly:
1. Correct Directory Structure
First, it's crucial to maintain the correct directory structure inside the FMU. The `modelDescription.xml` file must be at the root level of the FMU, and the `.so` file should be placed in the `binaries/linux64` directory, as you've done. This structure is essential for the FMU to be recognized correctly by simulation tools.
2. Repackaging the FMU
To correctly repackage the FMU, follow these steps:
Step 1: Navigate to the root directory where you've extracted the FMU contents. This directory should directly contain the `modelDescription.xml` file and the `binaries/`, `documentation/`, `sources/`, and any other directories.
Step 2: Use the `zip` command to create the FMU file, ensuring you're zipping the contents of the directory and not the directory itself. Run the following command from within the root directory of your FMU contents:
% Change directory to the path where modelDescription.xml and other fmu artifacts are present
cd my_model/
zip -r -0 ../my_model.fmu *
% -0 is the flag used for the store compression method to create the zip archive without actual compression.
This command creates the FMU file named `my_model.fmu` one directory level up from your current location, ensuring that the structure is preserved as required.
Important Note: Do not zip the folder that contains the FMU contents; zip the contents directly. This ensures that when the FMU is unzipped by STAR CCM+ or any other tool, the `modelDescription.xml` file and other necessary directories are immediately accessible at the root level of the archive.
3. Verify the FMU Structure
After repackaging, you can verify the structure of the FMU by listing its contents with:
unzip -l my_model.fmu
Ensure that the `modelDescription.xml` file is listed at the root and that the directory structure matches what is expected.
4. Testing the Repackaged FMU
Once repackaged, try loading the FMU in STAR CCM+ again. If the issue persists, double-check the FMU's directory structure and ensure that no steps were missed during the repackaging process.
By following these steps, you should be able to repackage your FMU correctly for cross-platform use, ensuring that simulation tools like STAR CCM+ can properly read and execute the FMU without encountering errors about missing files.
If you have any further questions or encounter additional issues, feel free to reach out.
I hope this helps.
  1 comentario
Jintu el 3 de Abr. de 2024
Hello @Yash
I successfully repacked the required files to generate the FMU by following the steps you provided. I was able to import the file into STAR CCM+ without any errors.
Thank you very much for your assistance in resolving the issue.

Iniciar sesión para comentar.

Más respuestas (1)

Christian Bertsch
Christian Bertsch el 12 de Abr. de 2024
Adding a platform binary to a source code FMU is easist done with fmpy on the target system ( either from the command line or within the GUI. When WSL is installed, you can also add Linux binaries on you Windows machine. With this there is no need to repack manually.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by