Direct solver without recalculating matrix factorization

8 months ago by
Hello, I'm very new to FEniCS and therefore it's being a bit hard to find in the documentation a solution to my problem, which first of all I would like to know if it is solvable within FEniCS.

I'm solving the elastic equilibrium equations, which I need to solve many times during a single program run. However, in between calls to the solver, only the RHS of the FEM formulation is changing, i.e. the body forces or Neumann conditions. As in this case the stiffness matrix is constant, I would like to use a direct solver (e.g. umfpack) to calculate the matrix factorization (i.e. setup the solver) only once, an then simply call the solver many times with different body forces. I would really appreciate if some of you could point me in the right direction, or provide me with a couple of lines of code showing how this can be (more or less) achieved with this really nice module.

Thank very much!
Community: FEniCS Project

2 Answers

8 months ago by
Hello Rubí,

  You could set the body forces in an expression and update them later:
# Set the force.
force_val = 3.0
force = Expression("force_val", degree=0, force_val=force_val)

# Use for a simulation.


# Change the value of the force.
force.force_val = 2.0​
8 months ago by
You first assemble your matrix A and create a solver

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

After this you can repeatedly solve A*u=b

solver.solve(u.vector(), b)​
The 'reuse_factorization' doesn't seem to be necessary, at least with petsc. In all cases I've seen/used, even with this parameter set to False, direct solvers seem to reuse the factorization.

When/why exactly is this setting taken into account?

Sorry for the late comment.
written 11 weeks ago by David Nolte  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »