Currently, I have a dolfin.function.function.Function that I obtain from solving a variational problem. What I want to do is normalize it, i.e. divide each entry by the largest entry. The following page suggests there is a function to do so but the documentation is not clear enough for me: https://fenicsproject.org/olddocs/dolfin/1.4.0/python/programmers-reference/cpp/la/normalize.html
The following code doesn’t use the normalize function, but it does what it sounds like you’re looking for:
from dolfin import *
# Function in a CG1 space going from 0 to 2:
mesh = UnitIntervalMesh(4)
u = project(2.0*SpatialCoordinate(mesh)[0],FunctionSpace(mesh,"CG",1))
# The $\ell^\infty$ ("linf") norm is the maximum absolute
# value of all entries in a vector.
u_vec_max = u.vector().norm("linf")
print(u_vec_max)
# The `*` operator is overloaded to implement scalar
# multiplication, returning another vector.
u_vec_normalized = (1.0/u_vec_max)*u.vector()
print(u_vec_normalized.get_local())
That is indeed what I meant by “normalizing”, however, this returns a different type, namely dolfin.cpp.la.PETScVector, while I need it to remain dolfin.function.function.Function
triggering the error looks like a typo, where the right-hand argument to the assignment (=) should be a vector (e.g., u_vec_normalized in my earlier example), but is instead a Function (and the same one you are attempting to assign the vector of, which wouldn’t make sense).