# Export generated mesh

Say I have generated a mesh using ToElementMesh, following one of the examples here: http://reference.wolfram.com/language/FEMDocumentation/ref/ToElementMesh.html

How do I export it to a text file? Say I get my mesh using

<< NDSolveFEM
ToElementMesh[Disk[]]

• What is your precise goal with exporting it? What format do you want to export it to? – Szabolcs Feb 4 '15 at 14:07
• @Szabolcs I would like just to have a datafile with the mesh. The format I would like are the coordinates of the nodes on each row of the data file, $x_i, y_i, z_i$ – BillyJean Feb 4 '15 at 14:14
• Let me be more explicit: what do you want to do with that file? Store it and later re-import it into Mathematica? Or use with other software? Just exporting the coordinates is easy: extract them (em["Coordinates"]), then use Export with the "Table" format. But the coordinates don't contain full information about the mesh and in the original version of the question you asked about exporting the "mesh", not just the "coordinates". – Szabolcs Feb 4 '15 at 15:15

Based on the comment, is this what you are looking for?

<< NDSolveFEM
em = ToElementMesh[Disk[]]
Export["mesh.txt", em["Coordinates"], "Table"]


em["Coordinates"] extracts the coordinates and the Table export format is just a tab-separated plaint text table.

This method will not preserve the precise cells, only the vertex coordinates.

To Export the full information contained in ToElementMesh you have to convert it into a list, then transform all the possible exponentials to plain decimals so that you can export the whole list as a string without notation issues.

mesh = ToElementMesh[Disk[]]
Export["diskmesh.txt",NumberForm[#, ExponentFunction -> (Null &)] & /@ List @@ mesh, "String"]


Now, note that the mesh you created has four elements

In[175]:= Length@mesh
Out[175]= 4


These are "Coordinates", "MeshElements", "BoundaryElements", "PointElements" Therefore, when you recreate ToElementMesh from the imported .txt file you gotta specify what is what, like this

In[177]:= #1->#2 & ~MapThread~{{"Coordinates", "MeshElements","BoundaryElements","PointElements"},ToExpression@Import["diskmesh.txt"]}//ToElementMesh@@#&

Out[177]= ElementMesh[{{-1., 1.}, {-1., 1.}}, {TriangleElement[<504>]}]