What happens if you try to use a built in mesh (i.e. IntervalMesh
)? Do you obtain the same error?
Here is a minimal example of reading in a 1D mesh that works with dolfin:
File test.geo
//+
Point(1) = {0, 0, 0, 1.0};
//+
Point(2) = {1, 0, 0, 1.0};
//+
Line(1) = {1, 2};
//+
Physical Curve(1) = {1};
from fenics import *
import meshio
def create_mesh_1D(mesh, cell_type):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={
cell_type: cells}, cell_data={"name_to_read": [cell_data]})
return out_mesh
mesh_out = create_mesh_1D(meshio.read("test.msh"), "line")
meshio.write("mesh.xdmf", mesh_out)
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
domains = MeshFunction("size_t", mesh, mesh.topology().dim())
dx = Measure("dx",domain=mesh, subdomain_data=mf)
print(assemble(Constant(1)*dx))
print(assemble(Constant(1)*dx(1)))