### Direct solver without recalculating matrix factorization

312

views

1

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!

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

0

Hello Rubí,

You could set the body forces in an expression and update them later:

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
```

0

You first assemble your matrix A and create a solver

After this you can repeatedly solve A*u=b

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

After this you can repeatedly solve A*u=b

`solver.solve(u.vector(), b)`

Please login to add an answer/comment or follow this question.

When/why exactly is this setting taken into account?

Sorry for the late comment.