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

assembling multiple right-hand sides

+1 vote

I need to solve a linear system with multiple right-hand sides, e.g.,

    b_list = []
    for f in f_list:
        L = f * v * dx
        b_list.append(assemble(L))

and a substantial share of the "computation" is taken by the JIT compiler at assemble(). Is there a way to speed this up, by, e.g., compiling all bs at once?

asked Feb 20, 2014 by nschloe FEniCS User (7,120 points)

What do your right hand sides look like, i.e., how are the f_list[i] constructed? If they e.g. differ only by a constant factor, then it often pays to wrap this constant in Constant() such that the code is generated only once, but the constant can be replaced in subsequent runs.

The only commonality of the fs is that they live on the same domain.

1 Answer

+1 vote

I assume v is a trial function? You can introduce f as a fake test function, and then calculate the vector using matrix multiplication:

b_list = []
f_placeholder = TestFunction(V)
L_op = assemble(f_placeholder * v * dx)
for f in f_list:
    b_list.append(L_op * f.vector())

It's possible that you have to use the transponse of L_op in the last line, I always get the index order wrong.

answered Feb 24, 2014 by Nikolaus Rath FEniCS User (2,100 points)
...