# How to convert 3D mesh from Comsol to .xml for legacy fenics?

**URL:** <https://fenicsproject.discourse.group/t/how-to-convert-3d-mesh-from-comsol-to-xml-for-legacy-fenics/15836>\
**Category:** General\
**Created:** [September 19, 2024, 11:42am UTC](https://fenicsproject.discourse.group/t/how-to-convert-3d-mesh-from-comsol-to-xml-for-legacy-fenics/15836 "2024-09-19T11:42:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawz](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dawz](https://fenicsproject.discourse.group/u/dawz)\
**Post date:** [September 19, 2024, 11:42am UTC](https://fenicsproject.discourse.group/t/how-to-convert-3d-mesh-from-comsol-to-xml-for-legacy-fenics/15836/1 "2024-09-19T11:42:34Z")

</div>

I meshed a 3D Cube in COMSOL using a free tetrahedral mesh. I wanted to export this mesh into some format which is readable by legacy fenics.

Unfortunately (cf. p. 6 of [https://www.comsol.com/model/download/1273541/COMSOL\_MeshImportExportGuide.pdf](https://www.comsol.com/model/download/1273541/COMSOL_MeshImportExportGuide.pdf) ) Comsol does just support NASTRAN and Comsol-multiphysics files for the export of full 3D meshes, while the other formats (as .stl or .ply) just support the export of the surface part.

I now wanted to convert the exported .nas file to an .xml file using meshio 5.3.5, i.e.:

```auto
meshio convert foo.nas foo.xml

```

But this gives the error:

```auto
meshio._exceptions.WriteError: DOLFIN XML only supports triangles and tetrahedra. Consider using XDMF instead.

```

However, the .nas file looks like it would contain a tetrahedral mesh (although it is not clear to me, what +CONT means in the element data section), as you can see from the following snippet of the .nas file:

```auto
$ Generated by COMSOL 6.1.0.357
$ Sep 19 2024, 12:52
BEGIN BULK
$ Grid data section
GRID 1 0.0000000.0000000.000000
GRID 2 0.0000000.0000000.100000
GRID 3 0.0000000.0620530.064720
GRID 4 0.0000000.1000000.000000
GRID 5 0.0000000.0000000.200000
[...]
GRID 23665 0.9762760.9757490.899960
GRID 23666 0.9525530.9014980.949920
$ Element data section
CTETRA 1 1 4 7 3 1 4018 5473+CONT
+CONT 3291 3179 4017 3289
CTETRA 2 1 6 3 2 9 5474 3290+CONT
+CONT 5475 5476 3294 3292
CTETRA 3 1 6 9 2 5 5476 3292+CONT
+CONT 5475 5477 3293 3170
CTETRA 4 1 1 3 10 7 3289 5478+CONT
+CONT 3653 4017 5473 5479
[...]
CTETRA 16563 1 3166 3164 3168 3163 4741 4744+CONT
+CONT 3278 5471 23662 5472
$ Property data section
PSOLID 1
ENDDATA

```

Do you have an idea, how I can convert this into a 3D mesh that is usable in legacy fenics, presumably in the .xml format?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 19, 2024, 12:34pm UTC](https://fenicsproject.discourse.group/t/how-to-convert-3d-mesh-from-comsol-to-xml-for-legacy-fenics/15836/2 "2024-09-19T12:34:23Z")

</div>

Without a full grid, it is impossible to reproduce the error or help you.  
Please consider using meshio as a Python package, and consider: [Cannot read facetag when converting .bdf file genarted from hypermesh to xdmf - #22 by dokken](https://fenicsproject.discourse.group/t/cannot-read-facetag-when-converting-bdf-file-genarted-from-hypermesh-to-xdmf/15339/22) for inspiration as to how to use meshio from Python.
