WARNING:UFL:Couldn't map 'c_3' to a float, returning ufl object without evaluation

I have the following code to interpolate a constant function.

one_constant = fem.Constant(Vh.mesh, ScalarType(1.))
ones = fem.Function(Vh)
ones.interpolate(one_constant)

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.e.: ones.x.set(1.0)

1 Like

@CastriMik, Thanks for your reply. I tried ones.x.set(1.0) and printed ones.vector.getArray(). I got some entries being zero. Why is it so?

Following is what I get with

    comm = MPI.COMM_WORLD
    domain = mesh.create_unit_square(comm, 4, 4, mesh.CellType.quadrilateral)
    Vh = FunctionSpace(domain, ("CG", 1))

    ones = fem.Function(Vh)
    ones.x.set(1.0)
    ones = ones.vector
    print(ones.getArray())
[4.64487029e-310 0.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000 1.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000 1.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000 1.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000 1.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000 1.00000000e+000 1.00000000e+000 1.00000000e+000
 1.00000000e+000]


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
1 Like