This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

What's the difference between assign() and direct substitutions of vectors?

+5 votes

I have a code where I have to save the solution from 'previous' time step for time integration purpose. I found two ways to achieve this

# set up function spaces
Pu = VectorFunctionSpace(mesh, "Lagrange", p_order)
Pp = FunctionSpace(mesh, "Lagrange", p_order)
V  = MixedFunctionSpace([Pu,Pp])  
up   = Function(V)
u_1 = Function(Pu)

### solve a problem for up...

# first method
assign(u_1, up.sub(0))
# second method
v_1.vector()[:]= up.sub(0,deepcopy=True).vector()

Both first and second methods work fine in parallel. Is one preferable than the other? Is one faster than the other?

Also, are they guaranteed to work for any case? For example, what happens if there are two processors working in parallel, and two processors have elements with different indices for the vector up_sub(0) and v_1?

asked Jun 4, 2014 by ysakamoto FEniCS Novice (260 points)
...