But I got the following warning. What does it mean? Does this lead to errors?
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation.
Couldn't map 'c_3' to a float, returning ufl object without evaluation.
interpolate requires a function as its input, while you are providing dolfinx.fem.Constant object. If you want to fill your function with ones, I guess you can do something like this:
I do not honestly know why it shows this weird behaviour. From the few tests I have run, it seems that something goes wrong when you try to assign ones.vector to ones itself. In that case, I get the same problem you have. Changing the name of the object solves the problem. For instance, the following code runs fine in my environment (complex build):
from mpi4py import MPI
from dolfinx import fem, mesh
comm = MPI.COMM_WORLD
domain = mesh.create_unit_square(comm, 4, 4, mesh.CellType.quadrilateral)
Vh = fem.FunctionSpace(domain, ("CG", 1))
ones = fem.Function(Vh)
ones.x.set(1.0)
print(ones.vector.getArray()) # get all ones
new_ones = ones.vector
print(new_ones.getArray()) # get all ones