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

Repeated use of matrix with LU decomposition

+1 vote

I solve a time dependent problem with LU decomposition. My matrix is constant in time, so I want to reuse LU factorization. I also have to apply boundary condition in each time step. My code looks somewhat like this

F2 = some linear form
a  = lhs(F2)
L  = rhs(F2)

A  = assemble(a)
solver = LUSolver(A)
solver.parameters['reuse_factorization'] = True

while t < Tf:
   b  = assemble(L)
   [bc.apply(A,b) for bc in bcs]
   solver.solve(up2.vector(), b)

Question:

Is this correct way to do it ?

Doesn't the matrix A get modified when bc is applied, necessitating recomputation of matrix A for next time step ?

asked Nov 21, 2014 by praveen FEniCS User (2,760 points)

1 Answer

0 votes
 
Best answer

Yes, it is correct. You should apply bc on A outside the loop though. It just idents the rows of A that live on the Dirichlet boundary.

answered Nov 21, 2014 by mikael-mortensen FEniCS Expert (29,340 points)
selected Nov 21, 2014 by praveen
...