When meshes are generated using external tools like gmsh, dmsh, pygalmesh, etc, a common recommendation is to use meshio to handle format conversion so the mesh can be read into dolfin.Mesh().
But all examples involve mesh data transfer via file, e.g.
import dmsh
import meshio
import dolfin
triangle = dmsh.Polygon([[0,0],[1,0],[1,1]])
points,cells = dmsh.generate(triangle,0.1)
meshFile="triangle_dmsh.xdmf"
mesh_meshio = meshio.Mesh(points, {"triangle": cells})
meshio.write(meshFile, mesh_meshio)
mesh_dolfin = dolfin.Mesh()
f = dolfin.XDMFFile(dolfin.MPI.comm_world, "triangle_dmsh.xdmf")
f.read(mesh_dolfin)
f.close()
V = dolfin.FunctionSpace(mesh_dolfin, "CG", 1)
Is it possible to create a dolfin.Mesh
mesh directly in memory without having to save to file? I imagine there could be some small performance improvement if you could, or at the very least you wouldn’t have to keep track of and remove the intermediate mesh files.
mshr can do it,
import mshr
import dolfin
triangle_mshr = mshr.Polygon([dolfin.Point([0,0]),dolfin.Point([1,0]),dolfin.Point([1,1])])
mesh_dolfin = mshr.generate_mesh(triangle_mshr, 30)
V = dolfin.FunctionSpace(mesh_dolfin, "CG", 1)
but of course mshr was created specifically for FEniCS.
mshr is considered deprecated so I’m interested to know if the equivalent in-memory functionality can be reproduced using the other tools, whether via meshio.Mesh
or via points,cells
.