How to Repackage the files in FMU for cross-platform use?
24 次查看(过去 30 天)
显示 更早的评论
HI,
I exported a Simulink model to Standalone FMU with source code by following the link https://www.mathworks.com/help/releases/R2022b/slcompiler/gs/export-model-to-standalone-fmu-with-source-code.html
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:
- Unzip the standalone co-simulation FMU with source code and compile the source code to generate the platform specific binary files.
- Move the generated binary file in the binaries folder.
- 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.
Thanks!
2 个评论
Marina Espejo
2024-3-28
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!
采纳的回答
Yash
2024-4-2
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 个)
Christian Bertsch
2024-4-12
Adding a platform binary to a source code FMU is easist done with fmpy on the target system (https://github.com/CATIA-Systems/FMPy) 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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Standalone FMU 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!