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)
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.
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.