Closed LucasCampos closed 4 years ago
@LucasCampos What format and what tool would you like to export to?
Personally, VTK would be the best. But once there is a way to output by the mesh in a standard format the problem is solved, as there are many tools to convert between different formats.
That said, as a user I would have expected a symmetry in input and output of meshes. Any format that the library can read, it would also be able to write.
@LucasCampos currently you have several options - all of them outside this addon, with the standard installation. You can convert the ElementMesh to a MeshRegion and export that as a VTK file:
Needs["NDSolve`FEM`"]
bmesh = ToBoundaryMesh[Ball[]];
mesh = ToElementMesh[Ball[]];
Export["~/bmesh.vtk", MeshRegion[bmesh]]
Export["~/mesh.vtk", MeshRegion[MeshOrderAlteration[mesh, 1]]]
Export["~/mesh2.vtk", MeshRegion[mesh]]
Another alternative is to export a STEP file, either of the region or the mesh:
Needs["OpenCascadeLink`"]
s1 = OpenCascadeShape[bmesh];
OpenCascadeShapeExport["~/test.step", s1]
s2 = OpenCascadeShape[Ball[]];
OpenCascadeShapeExport["~/test2.step", s2]
A third option would be STL. Again, for this the FEMAddOn is not needed. However, these exports are for (internal) surfaces and not solids. This may or may not be what you are looking for.
Concerning other mesh file formats: The purpose of this (FEMAddOns) package is, among other things, to provide mesh file import/export capabilities to other FEM/CAD software. The issue is that WRI does not and can not have access / licenses to the vast variety of systems. For this reason we dependent on our customers that do have access to these systems to help writing converters. So if a customer contributes an importer for system X but not an exporter then I'd still very gladly take the importer. In other words, if you have an exporter to a system Y that you would like to see in this add on, then I can help you get it to work and into this add on, but since I most likely do not have access to system Y I can not do it myself. I am dependent on collaboration for this; as in all the cases that are currently available in the FEMAddOns. If you do want to work on this by all means let me know.
@ruebenko Thanks for your inputs! Regarding your last points first: I do understand that you are limited by licenses. Unfortunately, I cannot provide any value here, as I only use open source formats, which can be used without licenses. However, it seems like some open source formats are missing from the Export
function. Notably, it seems to not recognize .msh
.
Anyhow, I tested export my mesh with the approach you outlined. It seems like it was a bit hit-or-miss. Exporting to PLY, OBJ, and STL worked, while other (including VTK) failed. The region markers were always lost, but at least this is a step in the right direction.
Unfortunately, I only have Mathematica 12.0, so I do not have OpenCascadeLink
bundled, and have not tested it yet.
I was creating the mesh by manually setting the coordinates and lines. As I suspected that this might have been the issue, I also tried to use ImplicitRegion
, but the results were largely the same. The notebook with both tries is here. Please note that two files will be created in the home folder of the user.
This all said, it seems like that the issue is out of the scope of this add on, and should be upstreamed.
Thanks again for all the help!
TL;DR:
The issues are located on the Export
function, as it
.msh
@LucasCampos The issues have been forwarded to the respective developers. Here is a notebook that addresses some issues but not all.
If you wanted to we could work on the export to *msh
for the FEMAddOns. Otherwise I'd close this issue since the VTK export/import and the region markers that are dropped need to be dealt with in-product.
@ruebenko, thanks once again for all the work your have poured into this, and for forwarding the issues! I cannot run the notebook right now, but will do soon. I am looking forward to reading some well-structured Mathematica code.
I agree with you that the issue should now be closed. However, I suspect that would be nice to have a note somewhere in the documentation pointing to the Export
as the dual of ImportMesh
.
Regarding *msh
formats, they are not specially important to me, and VTK will work just fine. So, for now, there is no need to implement *msh
output, at least on my end. (I still think that the symmetry argument I mentioned earlier is valid, though.)
I just tried following the guidance in this discussion to export VTK meshes, but Mathematica seems to only export the boundary. So, in practice, that approach isn't suitable for FEM meshes!
@samuelpmish I suggest you contact WRI support about this.
Once the mesh is generated with Mathematica, would it be possible to export it to other file formats? This would be very useful for integration with already-existing pipelines.