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

assign function

+1 vote

Dear developer,

When u and u0 are functions,
what is the difference between
u0.assign(u)
and
assign(u0,u)
?
I am confusing because former case
can't be passed for version 1.4.
1.3 is all right.

Best regards,

Oka

asked Oct 15, 2014 by czbebe FEniCS Novice (130 points)

1 Answer

+6 votes

The syntax u0.assign() is typically used when you want to create one function u0 from a superposition of other functions, i.e.

u0, u1, u2 = Function(V), Function(V), Function(V)
u0.assign(FuntionAXPY([(1.0, u1), (2.0, u2)])

is equivalent to u0 = u1 + 2*u2.

On the other hand, 'assign' is used to create a function u0 in a MixedFunctionSpace from functions in the corresponding subspaces, i.e.

W = MixedFunctionSpace([V, V])
u0 = Function(W)
u1, u2 = Function(V), Function(V)
assign(u0, [u1, u2])

will create a function u0 in the mixed function space W, where the subfunctions u0.sub(0) and u0.sub(1) are copied from u1, u2 correspondingly.

answered Oct 16, 2014 by cevito FEniCS User (5,550 points)

Thank you so much.
I understand, but I saw such script may times,

While (t < tmax)

E = function of u and u0

solve (E == 0, u, dE)

u0.assign(u)

I think
assign(u0,u)
is better according to your answer.
if I can write
u0 = u
it is easily understood.

Oka

If you just want to assign a single function, both should work fine, although in this case

u0.assign(u)

should be more efficient. I just noticed that you wrote in the original post, that this didn't work for you in dolfin-1.4. Could you check again, it works here without a problem.

Thank you,

But still I am troubling assign function.
Both
u0.asssign(u)
and
assign(u0,u)
doesn't pass in case of 1.4.
1.3 is all right.
It depends on type of "u" ?
Error is (for Mac)
File "/Applications/FEniCS.app/Contents/Resources/lib/python2.7/site-packages/dolfin/cpp/function.py", line 1950, in assign
return _function.assign(*args)
RuntimeError:
u and u0's type is 'dolfin.functions.function.Function'

Are both u0 and u functions of the same function space? If not, you need to use interpolate.

...