I would like to know if there’s a way to create a 1D mesh directly from a list of vertices in dolfinx?
In dolfin I used to do:
import fenics as f
vertices = [1, 2, 3, 4]
nb_points = len(vertices)
nb_cells = nb_points - 1
editor = f.MeshEditor()
mesh = f.Mesh()
editor.open(mesh, "interval", 1, 1) # top. and geom. dimension are both 1
editor.init_vertices(nb_points) # number of vertices
editor.init_cells(nb_cells) # number of cells
for i in range(0, nb_points):
editor.add_vertex(i, np.array([vertices[i]]))
for j in range(0, nb_cells):
editor.add_cell(j, np.array([j, j+1]))
editor.close()
Traceback (most recent call last):
File "/home/test_generate_mesh.py", line 14, in <module>
V = FunctionSpace(mesh, ("P", 1))
File "/usr/local/dolfinx-real/lib/python3.8/dist-packages/dolfinx/fem/function.py", line 440, in __init__
super().__init__(mesh.ufl_domain(), ufl_element)
File "/usr/local/lib/python3.9/dist-packages/ufl/functionspace.py", line 45, in __init__
error("Non-matching cell of finite element and domain.")
File "/usr/local/lib/python3.9/dist-packages/ufl/log.py", line 158, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Non-matching cell of finite element and domain.
This is because you send in three-dimensional coordinates, while the VectorElement defaults to a 2D mesh (not a manifold in 3D).
With some slight alterations to your code:
Using domain = ufl.Mesh(ufl.VectorElement("Lagrange", cell, degree)) produces a lot of UFL warnings along the way (when restricting the dx measurement eg. dx(1)):
DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
Do you know what would be the equivalent for this in basix?
Thanks,
Rem
EDIT: nvm managed to find the basix equivalent, it was more straightforward than I thought!