Mismatch in subspaces using FunctionAssigner

I am trying to mirror what MiroK proposes in this reply in order to assign values to a function.
Specifically, I only want to set two specific values to function u_n which is a subfunction of U_n.

Ve = FiniteElement("CG", mesh.ufl_cell(),1)
MS = FunctionSpace(mesh, MixedElement([Ve, Ve, Ve])) 
U_n = Function(MS)

u_n, u_t1n, u_t2n = split(U_n)

#MiroK's code
u_v = U_n.vector()
dofs = MS.sub(0).dofmap().dofs()

u_i = u_v[dofs]
u_i[0] = a                 #first value to be set
u_i[len(u_i)-1] = b        #second value to be set
u_v[dofs] = u_i

#Code is wrong starting here
assigner = FunctionAssigner(MS, MS)  

Functions_init = [Function(MS) for dofs_i in dofs]
for f, dofs_i in zip(Functions_init, dofs):
    f.vector()[:] = u_v[dofs_i]

Two issues here:

  • there is a mismatch in the FunctionAssigner. I only need to assign values to u_n but I’m working on U_n here, as I don’t know how to assign only to u_n.
  • I’m not doing things correctly in the last loop either. It’s the same issue, I’m trying to work on u_n only but I can’t find the appropriate syntax.

Here is the error I get

RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to create function assigner.
*** Reason: Expected the same number of sub spaces in the receiving FunctionSpace as the number of assigning FunctionSpaces.
*** Where: This error was encountered inside FunctionAssigner.cpp.
*** Process: 0


*** DOLFIN version: 2019.1.0
*** Git changeset:
*** -------------------------------------------------------------------------

Thanks for your help

Here is a test using FunctionAssigner. This will help you.