Unclear how to use MeshEditor with pointcloud

Hi, I’m trying to create a pointcloud (mesh that only consists of vertices) using fenics.MeshEditor . I’m a bit unsure whether I should use "vertex" or "point" for the type in fenics.MeshEditor.open(mesh, type, gdim, tdim) . What’s mainly confusing me is that this function seems to only accept point and fenics.CellType also only has a point , but in ufl a ufl.Cell only knows the terminology vertex . This is the code causing me trouble:

import fenics
import numpy as np
from fenics import Mesh, MeshEditor, FunctionSpace

# using https://bitbucket.org/fenics-project/dolfin/src/b55804ecca7d010ff976967af869571b56364975/dolfin/generation/IntervalMesh.cpp#lines-76:98 as template
N = 5 # we want to work with 5 vertices on the mesh
gdim = 2 # geometric dimension
tdim = 0
vertices = np.random.rand(N, gdim)
mesh = Mesh() # empty mesh
editor = MeshEditor()
editor.open(mesh, type="point", tdim=tdim, gdim=gdim)
editor.init_vertices_global(N,N)for i in range(N):
editor.add_vertex(i, vertices[i,:])editor.close()V = FunctionSpace(mesh, "DG", 0)

First of all, you should add the vertices as actual cells in your mesh, as:

mesh = Mesh()  # empty mesh
editor = MeshEditor()
editor.open(mesh, type="point", tdim=tdim, gdim=gdim)
editor.init_vertices_global(N, N)
editor.init_cells_global(N, N)

for i in range(N):
    editor.add_vertex(i, vertices[i, :])
    editor.add_cell(i, [i])

However, you end up with the same issue as you describe above.

As far as I am aware there is very little to no support of point cloud meshes in dolfin.

If you could be more specific as to what you would like to use this point cloud for, someone might have a workaround for your application

2 Likes

Maybe you could use scipy’s Delaunay triangulation to generate the connectivity between the points in the cloud? You’d have to be careful with non-convex geometries though, of course.

2 Likes

Thanks for the help! I will try out both approaches suggested by @dokken and @nate and write back here, as soon as I have an update.

Some context: I’m trying to create something similar to the VertexOnlyMesh that is provided in firedrake in my FEniCS code. In the end, I want to use the approach that was presented by Reuben W. Nixon-Hill at FEniCS21 for using data living on a point cloud as boundary conditions and/or volume forces in my FEniCS based program. I hope that this summarizes my rough idea sufficiently.

I think that will require some work in the dolfin source code, as the cell-type issues you were describing can’t be easily bypassed.
It would require a change in dolfin where “point” is changed to “vertex”.

I observe that there is a similar issue in dolfin-x. If I find some extra time I might have a look at it at some point.

1 Like