Working on components of vector elements in FEniCS

Consider the following MWE on mixed spaces

from dolfin import *

mesh = UnitSquareMesh(1,1)
P1 = VectorElement('CG', triangle, 1)
P0 = FiniteElement('DG', triangle, 0)
element = MixedElement([P1, P0, P0])
W = FunctionSpace(mesh, element)

v, w1, w2 = TestFunctions(W)
phi, zx, zy = TrialFunctions(W)

phiI = interpolate(Constant((1,2)), W.sub(0).collapse())
a = FunctionAssigner(W.sub(0), phiI.function_space())
phi0 = Function(W)
a.assign(phi0.sub(0), phiI)

e0 = phi[0]*w1*dx     # phi[0] gives First component of phi, right?
e1 = action(e0, phi0[0])          # Gives error

Error:

Exception has occurred: AttributeError
'Indexed' object has no attribute 'ufl_function_space'
  File "/Users/jaitushar/Documents/myFEniCS/Misc/actionVecComp.py", line 20, in <module>
    e1 = action(e0, phi0[0])

Questions:

  1. Is phi[0] in e0 the first component of phi?
  2. Is there anyway to make e1 work?

Yes, it is

You cannot replace a single component of a variable with another variable.

I am not sure what you want e1 to be. Do you want this to be a vector in the mixed space, with only entries for the dofs in the second space?

Writing the vector \boldsymbol{\phi} in it’s components (\phi_x, \phi_y). Let A := \sum_{K \in \tau_h} \int_{K} \phi_x w_1 dx. Then I am trying to get, A \phi_x , i.e., the action of \phi^k_x (the x-component of k^{th} - iterate of \boldsymbol{\phi}) on A.

The point here is that your matrix A is not just M \times N where M is the number of dofs in subspace 0, component 0, N the number of dofs in subspace 1.

The matrix A an (2M+ N +N )\times (2M + N + N) matrix, as thus you would have to supply the full mixed coefficient to get an action on A