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

Indexing part of FunctionSpace

0 votes

Hi all,

I am currently solving a PDE problem, where I seek a solution as a combination of a function u on the domain and a vector U of R, say of dimension 4. My problem is the following: If i define the function space as follows:

no_of_electrodes = 4
mesh = UnitSquareMesh(nx, ny)
V = FunctionSpace(mesh, 'Lagrange', 1)
R1 = FunctionSpace(mesh, "R", 0)
R = R1
for i in range(no_of_electrodes-1):
    R = MixedFunctionSpace([R,R1])
W = V*R

Now when defining my variational problem, I construct trial and test-function as follows:

ut = TrialFunction(W)
vt = TestFunctions(W)

Now ut should consist of a function u on the space V and a vector U on R⁴, right? So lets say i want to construct the following:

a = (inner(grad(u), grad(v)))dx + sum((u-U(i))(v-V(i))*ds(i),i=0..3)

My problem is that I cannot figure out how to extract u and U(i) from ut and v and V(i) from vt, such that i can compute a. Should I define my function-space differently? Here, ds(i) is a part of the boundary for all i.

asked Sep 22, 2015 by Jeppe FEniCS Novice (190 points)

1 Answer

+1 vote
 
Best answer

The test- and trialfunctions can be indexed in a natural way if you simplify the definition of the functionspace:

m = 4

V = FunctionSpace(mesh, "CG", 1)
Rm = VectorFunctionSpace(mesh, "R", 0, m)

W = MixedFunctionSpace([V, Rm])

u, U = TrialFunctions(W)
v, V = TestFunctions(W)

a = inner(grad(u), grad(v)) * dx \
  + sum([(u-U[i]) * (v - V[i]) * ds(i) for i in xrange(m)])
answered Sep 22, 2015 by Magne Nordaas FEniCS Expert (13,820 points)
selected Sep 22, 2015 by Jeppe

Thanks, that worked.

...