The argument of function "set_local()"

Dear all,

I have read carefully the fenics tutorial. Now I have a very simple but important question. In fenics tutorial, there is a example:

def normalize_solution(u):
"Normalize u: return u divided by max(u)"
u_array = u.vector().array()
u_max = np.max(np.abs(u_array))
u_array /= u_max
u.vector()[:] = u_array
#u.vector().set_local(u_array) # alternative
return u

As far as I know, the function “.vector().array()” has been abandoned by fenics, and it is replaced by “.vector().get_local()”. So the above codes are rewritten as

def normalize_solution(u):
"Normalize u: return u divided by max(u)"
u_array = u.vector().get_local()
u_max = np.max(np.abs(u_array))
u_array /= u_max
u.vector()[:] = u_array
#u.vector().set_local(u_array) # alternative
return u

As can be seen, the argument of function “set_local()” is u_array (it is a numpy. ndarray). However, in many people’s code, I saw them use u.vector() (it is a dolfin.cpp.la.PETScVector) to be the argument of function “set_local()”, and their results are still correct. So we can use numpy. ndarray or dolfin.cpp.la.PETScVector to be the argument of function “set_local()”?

Thank you in advance for your kind help.
Best regards.

Seems to be the case, as you can verify from the following MWE

from dolfin import *

mesh = UnitSquareMesh(2, 3)
V = FunctionSpace(mesh, 'P', 1)
u = Function(V)
u_np = u.vector().get_local()
print(u_np)
u_np += 1.0
u2 = Function(V)
u2.vector().set_local(u_np)
print(u2.vector().get_local())
u3 = Function(V)
u3.vector().set_local(u2.vector())
print(u3.vector().get_local())

OK. I understand now. Thank you very much for your MWE.

Best regards.