Consider the following:
import dolfin as dl
N = 100
X = 1.0
mesh = dl.IntervalMesh(N, 0, X)
degree = 1 # linear basis functions
Vh = dl.FunctionSpace(mesh, "Lagrange", degree)
u = dl.interpolate(dl.Expression("x[0]", degree = 1), Vh)
alpha = 2.0
class user_expr(dl.UserExpression):
def set_alpha(self, u, alpha): # in the user_expr class
self.u = u
self.alpha = alpha
def eval(self, value, x): # in the user_expr class
"set value[0] to value at point x"
value[0] = self.alpha * self.u(x)* self.u(x)
user_expr2 = user_expr(degree = 0)
user_expr2.set_alpha(u, alpha)
q = dl.interpolate(user_expr2, dl.FunctionSpace(mesh, "Lagrange", 1))
d_to_v = dl.dof_to_vertex_map(q.function_space())
print(q.vector()[:][d_to_v])