Unable to Build an XML file that reads in a binary MSH file? #2023
Replies: 27 comments
-
Did you try addressing the error, say by editing the file in |
Beta Was this translation helpful? Give feedback.
-
I don't understand how to edit the file in
Is there a way I can alter this code to ensure all nodes are in a single block? It's hard for me to understand what 'ensuring all nodes are in a single block' even means, especially since the outputted binary .msh file is not human-readable... |
Beta Was this translation helpful? Give feedback.
-
@kurtenkera I have written a Converter If you want to better understand what is going on have a look at hollow_cylinder_ascii.msh and volume.msh Let me know how it goes :) |
Beta Was this translation helpful? Give feedback.
-
@mohammad200h This is brilliant thankyou very much! I have some questions below about Q1: I want to understand the three functions below a little better. I understand that
Q2:
Thus, currently
and then using |
Beta Was this translation helpful? Give feedback.
-
Q1. I used print statements to better understand meshio
I used the information in mesh::cells to understand how i can work with cellblock
Q2. if you view your model in Gmsh App https://gmsh.info/ (Download the app, import your model and look at it) you see the walls are gone. The walls where tetra therefore cellblock.type == "tetra" returns false hence you get None for get_elements.
|
Beta Was this translation helpful? Give feedback.
-
@mohammad200h I have a very strange problem. There are three files in this attached zip folder hollow_cylinder.zip. (1) hollow_cylinder_groups.msh File (2) is an ASCII file of the same hollow cylinder that we've been talking about above. I can use the code that you provided to convert file (2) into a .msh file with only a single volume entity with no problems. HOWEVER, file (1) is a file that was created with 2 physical groups ascribed. Effectively, it is the same as file (2) but with the following additional lines of text:
I can't convert file (1) using your code (but ideally I'd like to). File (3) is literally file (1) but where I manually deleted the lines of text seen above. I'd really expect file (3) to convert using your code, however, it doesn't? It's surprising to me because file (3) and file (2) appear to be identical to me? Why is file (2) converting but file (3) isn't? Separate side question: Is this form of flexcomp modelling used for soft-bodies, whereas the mesh/asset approach is for simulating rigid bodies? |
Beta Was this translation helpful? Give feedback.
-
Q1. Thank you for providing the meshes. The issue seems to be with meshio library. I am trying to rewrite the code with gmsh library which is the official library but harder to work with. |
Beta Was this translation helpful? Give feedback.
-
Okay thanks @mohammad200h. So then if I want to model a rigid body via reading in a binary MSH file - the binary MSH file would have to have the format seen below (link: https://mujoco.readthedocs.io/en/stable/XMLreference.html#asset-mesh): Obviously you have shared code with me that can be used to convert a binary MSH file to an acceptable format for modelling soft bodies - is there a similar If not, are there simple ways to convert a binary MSH file to a binary STL or OBJ file (which could then be used to model a rigid body)? |
Beta Was this translation helpful? Give feedback.
-
@mohammad200h Just following up about the above comment? |
Beta Was this translation helpful? Give feedback.
-
@kurtenkera I have finished implementing the code using gmsh instead of meshio. I also tested it with the files you sent and it works now. Please give it a go. Here is how i created the stl file.
Let me know how it goes :) |
Beta Was this translation helpful? Give feedback.
-
Hi @mohammad200h - I've tested your code and it works with all the files as you say. However, I can't currently get it to work with the .msh file called For reference, there is a .vtu file in that zip folder of the hollow cylinder that we've been discussing. It is called
How can I input the |
Beta Was this translation helpful? Give feedback.
-
Q1. How can I input the vtu_converted_msh41_cyl.msh file into your code so that I get a resulting .msh file that has a single volume and/or surface entity? Is it not working because meshio converted the .vtu file incorrectly? If you try to open vtu_converted_msh41_cyl.msh in GMSHapp you get an error. which tells me it is not a valid file format. Q2. If this is the case, do you know a way to reliably convert a .vtu file into a .msh file that is then readable into converter.py?
and i got this output:
I also tried opening it with this app:
nodes
elements_indexes
connectivity which might be how nodes are connected
offset. Looking at the numbers each number seems to be incremented by 4 which is exact number of nodes you need to create a tetrahedral. Therefore my best guess is that this contains information on how to slice connectivity data.
type. My best guess is this describes the element type (tetrahedral, triangle ... )
If you help me better understand how this file was created I might be able to write a converter. |
Beta Was this translation helpful? Give feedback.
-
The .vtu file was the output of a finite element solve performed with MOOSE (an open-source finite-element framework). Assuming you are familiar with MOOSE/have downloaded the repository (with download instructions detailed here), I generated the file by using the example which can be seen here (link: https://github.com/idaholab/moose/tree/next/examples/ex01_inputfile). The image below shows the relevant files in this simple MOOSE example: Importantly, instead of using the input file
If you are unfamiliar with finite element analysis, then the above might not make any sense to you! Note that I think I have found a rather inefficient, makeshift solution - though I'd be much interested in a better solution if you think there is one? What I did was converted the .vtu file to a .msh file (MSH 2.2) using Meshio, and then I used Gmsh to convert the MSH 2.2 file to MSH 4.1, returning a suitable file. This meshio discussion thread (link: nschloe/meshio#865) talks about how writing various file types to MSH 4.1 is a longstanding issue in meshio. It says that converting to MSH 2.2 with meshio before converting to MSH 4.1 with Gmsh is the current best makeshift solution? FYI, I was able to open the .vtu file in Paraview? See below: |
Beta Was this translation helpful? Give feedback.
-
This link (https://docs.vtk.org/en/latest/design_documents/VTKFileFormats.html#unstructuredgrid) has more information on the explicit .vtu file format that I have above if it helps! |
Beta Was this translation helpful? Give feedback.
-
Can you provide the MSH2.2 and MSH4.1 for the vtu file please. |
Beta Was this translation helpful? Give feedback.
-
Sure - msh22_and_msh41.zip contains the MSH2.2 and MSH4.1 files. The MSH2.2 file is called |
Beta Was this translation helpful? Give feedback.
-
@mohammad200h Do you think there is a more efficient solution than the one I used? |
Beta Was this translation helpful? Give feedback.
-
I am not familiar with vtu format. So I can not comment on that. We might look into it and add it to the converter that we are building. |
Beta Was this translation helpful? Give feedback.
-
No problems - do you know roughly when the converter will be released? |
Beta Was this translation helpful? Give feedback.
-
Can not give an accurate estimate. But hopefully soon! |
Beta Was this translation helpful? Give feedback.
-
Hi @mohammad200h - I know how to convert a MSH file to an STL file using Gmsh (simply open the .msh file and export it to an .stl file). However, I am unable to use this method to convert an STL file to a MSH file. The following zip folder (3d_mbb_STL2MSH.zip) contains an STL file called The root of the problem is converting an STL file to a MSH file - do you know a feasible way of doing this? This is important as I want to model the STL file (visualised below) as a soft body using |
Beta Was this translation helpful? Give feedback.
-
Hey @kurtenkera You can run the following python script:
which will lead to this error. Because there is an issue with your mesh:
or you can follow the following tutorial: which will lead to the same error. You need to clean the mesh and try the above methods or just try ftetwild: which cleans and generate a volumetric mesh: which you need to clean to be useable by mujoco using the converter: |
Beta Was this translation helpful? Give feedback.
-
Thanks @mohammad200h very helpful as always - I will look into mesh cleaning/ftetwild. By the way, the cleaned volumetric mesh and also the mesh useable by mujoco were in Gmsh 2.2 format, whereas we need Gmsh 4.1? Is there any chance you can link me to the tutorials that you followed to use ftetmesh and/or the code that was used for mesh cleaning? |
Beta Was this translation helpful? Give feedback.
-
Mujoco should support 2.2 and 4.1 as long as you have a single entity in the file.
|
Beta Was this translation helpful? Give feedback.
-
@mohammad200h I have MuJoCo version 3.1.2 and I could not import the file
I got the following error:
(1) So which versions of MuJoCo support both Gmsh 2.2 and 4.1? Also, I converted
(2) How do I load in .msh files with a large amount of nodes and elements like this one? Do I need to try run the model on a different machine with more RAM (my machine has 64GB of memory)? Even when I try to load the model with the following setting
This indicates that I can't allocate 20GB of memory even though I should be able to on my machine? |
Beta Was this translation helpful? Give feedback.
-
See item 3 in the 3.1.4 changelog |
Beta Was this translation helpful? Give feedback.
-
Please use gmsh_cleaner to clean gmsh files |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm opening an issue that extends on the discussion related to issue #1492 (as this issue was closed and I'm not a repo collaborator, I cannot re-open the issue).
I'm trying to import a binary .msh file of a hollow cylinder into MuJoCo. Below is the code that I'm trying to execute in a Jupyter notebook environment:
When I run the code above, I get the following error message:
Here is the .msh file that I'm trying to use:
hollow_cylinder_binary.zip
I desperately need to import this binary .msh file into MuJoCo for this project that I'm doing. I've been able to import a binary STL file successfully, however, the binary msh file approach is not working!
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions