Function assign is confusing or does not work for MixedFunctionSpace and split

Issue #235 invalid
Chaffra Affouda created an issue
from dolfin import *

mesh = UnitIntervalMesh(10)

Q = FunctionSpace(mesh,'CG',1)
W = MixedFunctionSpace([Q,Q])

f = Function(W)
f_0,f_1 = f.split(deepcopy=False)
g = Function(W)


g.vector()[:] = 0.0
f.assign(g)
plot(f_0,title='f_0 should be 0.0')

g.vector()[:] = 1.0
f.assign(g)
plot(f_1,title='f_1 should be 1.0 but is still 0.0')
plot(f[1], title='f[1] is 1.0')

f.vector()[:] = 2.0
plot(f_0, title="f_0 is should be 2.0 (assigning vector with scalar")

Comments (5)

  1. Jan Blechta

    I was wrong. The correct reason is that f.assign(g) breaks f_0, f_1 pointers to f. This is how Function.assign is designed. You should do f.assign(g); f_0, f_1 = f.split()

    Nevertheless, f_0, f_1 could be invalidated so that referring to them in any way would raise an error. But this could be tricky to implement.

  2. Chaffra Affouda reporter

    Ok then I should only do vector assignments if I want to keep the pointers like

    f.vector()[:] = g.vector()
    
  3. Log in to comment