# Configure petsc solver options

**URL:** <https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473>\
**Category:** General\
**Created:** [February 1, 2024, 5:07pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473 "2024-02-01T17:07:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbhasan](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@sbhasan](https://fenicsproject.discourse.group/u/sbhasan)\
**Post date:** [February 1, 2024, 5:07pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/1 "2024-02-01T17:07:58Z")

</div>

Hi,

I will appreciate if someone could help me figure how to configure the petsc\_options with following choices:

1. iterative solver: gmres
2. preconditioner: mg
3. presmoother: sor
4. postmoother: soru vector
5. coarse solver: mumps

My installation is dolfinx 0.7.x through conda. In case it helps, I am solving the complex vector helmholtz equation in 3D with Nedelec elements and the model comprises around 10^6 dofs. I would welcome any suggestion for other configurations that might give good convergence.

Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [February 1, 2024, 6:41pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/2 "2024-02-01T18:41:41Z")

</div>

Finding a good preconditioner for FE problems is a research topic. Someone may come in and help (unfortunately, not me, since that is not my field), but you should asking your advisor what they suggest and/or start carrying out a literature review on what the current state of the art is.

> In case it helps, I am solving the complex vector helmholtz equation in 3D with Nedelec elements

That’s relevant information that you must take into account in your literature review.

---

<div class="post-metadata">

**Author:** ![sbhasan](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@sbhasan](https://fenicsproject.discourse.group/u/sbhasan)\
**Post date:** [February 1, 2024, 7:07pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/3 "2024-02-01T19:07:05Z")

</div>

Thanks a lot for your quick feedback! I am going without any advisor on this.

While I will gratefully take any pointer about going further on this subject, my question for now is about how to specify the indicated solver configuration to dolfinx. I suspect it goes somewhat like this:

```auto
{"ksp_type": "gmres", "pc_type": "mg"}

```

but then I do not know how to indicate pre and post smoother as well as the coarse solver type. If it is not possible, that will also be a valuable thing to know.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [February 1, 2024, 9:22pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/4 "2024-02-01T21:22:10Z")

</div>

As DOLFINx uses PETSc4py for solving the problem, you can pass anything into these options than can then be passed to petsc4py and its ksp object. See for instance: [PCMG — PETSc 3.20.4 documentation](https://petsc.org/release/manualpages/PC/PCMG/)  
That being said, to use “mg”, you need to send in extra operators, similar to:  
[maxwell/solver.py at master · jpdean/maxwell · GitHub](https://github.com/jpdean/maxwell/blob/master/solver.py#L108-L162)

However, we do not have out of the box support for multigrid restriction and prolongation operators.  
We hope that we can get some progress on these during this summer’s Google Summer of Code.

---

<div class="post-metadata">

**Author:** ![sbhasan](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@sbhasan](https://fenicsproject.discourse.group/u/sbhasan)\
**Post date:** [September 17, 2024, 11:31am UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/5 "2024-09-17T11:31:45Z")

</div>

Hi dokken,

Has there been any recent progress on this during summer?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [September 17, 2024, 12:31pm UTC](https://fenicsproject.discourse.group/t/configure-petsc-solver-options/13473/6 "2024-09-17T12:31:57Z")

</div>

Yes, there has. Please see @schnellerhase post: [Google Summer of Code 2024 - Multigrid for FEniCSx | schnellerhase](https://schnellerhase.github.io/posts/2024/gsoc/)
