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

Assemble vector?

+2 votes

I'm trying to integrate a vector function:

V = VectorFunctionSpace(mesh, 'Lagrange', 1)
f = Function(V)
# do stuff that defines f
result = assemble(f * dx)

I would have hoped that this would give me a three element result vector. Instead, it gives me an error:

UFLException: Trying to integrate expression of rank 1 with free indices ().

Evaluating the components one-by-one works fine:

result = [ assemble(f[0] * dx), assemble(f[1] * dx), assemble(f[2]* dx) ]

Is there a way to avoid the repeated calls to assemble?

asked Jan 30, 2014 by Nikolaus Rath FEniCS User (2,100 points)

1 Answer

+3 votes
 
Best answer

You could do like this:

V = VectorFunctionSpace(mesh, 'Lagrange', 1)
R = VectorFunctionSpace(mesh, 'R', 0)
f = Function(V)
c = TestFunction(R)
result = assemble(dot(f, c)*dx)
answered Jan 30, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Jan 31, 2014 by Nikolaus Rath

Thanks! Could you explain how/why this works?

Be advised however that Real spaces can lead, with the current implementation of dolfin (Jan 2014), to very bad performances with big meshes. See the thread starting at http://fenicsproject.org/pipermail/fenics/2013-September/000526.html and the follow-up thread http://fenicsproject.org/pipermail/fenics/2013-October/000657.html

I don't think it will be case here. This happens for mixed spaces with R-space when reordering/insertion with dense row/column is costly. Here R-space is just a placeholder for small amount of DOFs. Nevertheless, I did not test it.

...