AttributeError: 'Mesh' object has no attribute 'create_rectangle'

from dolfinx import mesh
from dolfinx.fem import FunctionSpace
from mpi4py import MPI
import numpy as np 

Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
points = [0., 8.]
mesh = mesh.create_interval(MPI.COMM_WORLD,8,points)
domain = mesh.create_rectangle(MPI.COMM_WORLD,[np.array(xL), np.array(xR)],[4, 4], mesh.CellType.triangle)
V = FunctionSpace(mesh,("CG", 2))

There is a create_rectangle in my mesh.py. For some reason I get:

AttributeError: 'Mesh' object has no attribute 'create_rectangle'

for an Anaconda installation to a virtual environment “fenicsx-env”. Anyone can shed some light on what to do to create_rectangle?

I’m using Visual Studio Code and so far the autocomplete dropdown does see create_interval but not create_rectangle although mesh.py does have create_rectangle defenition…

mesh = mesh.create_interval(MPI.COMM_WORLD,8,points)

You’ve overwritten the dolfinx.mesh module name with the mesh object here.

OK…

from dolfinx import mesh
from dolfinx.fem import FunctionSpace
from mpi4py import MPI
import numpy as np 

Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
points = [0., 8.]
domain = mesh.create_rectangle(MPI.COMM_WORLD,[np.array(xL), np.array(xR)],[4, 4], mesh.CellType.triangle)
V = FunctionSpace(mesh,("CG", 2))

things for me turn into a:

AttributeError: module 'dolfinx.mesh' has no attribute 'ufl_cell'

I investigated mesh.CellType to start out with but don’t really know why ufl_cell is no good…
(For the Windows Subsystem for Linux)

Perhaps you should review the dolfinx tutorial and the python documentation on modules.

You’re importing the mesh module

from dolfinx import mesh

But trying to use it as if it were a Mesh object

V = FunctionSpace(mesh,("CG", 2))

You probably mean to use

V = FunctionSpace(domain,("CG", 2))
from dolfinx import mesh
from dolfinx.fem import FunctionSpace
from mpi4py import MPI
import numpy as np 

Lx,Ly = 1,1.1
xL=[0,0]
xR=[Lx,Ly]
points = [0., 8.]
domain = mesh.create_rectangle(MPI.COMM_WORLD,[np.array(xL), np.array(xR)],[4, 4], mesh.CellType.triangle)
V = FunctionSpace(domain,("CG", 2))

Sorry about that I got really confused for a bit… This code works for the new create_rectangle…