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.