# Poor residuals from PETSc iterative solver for 3D elasticity equation

**URL:** <https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288>\
**Category:** General Discussion\
**Created:** [October 27, 2021, 7:42pm UTC](https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288 "2021-10-27T19:42:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [October 27, 2021, 7:42pm UTC](https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288/1 "2021-10-27T19:42:50Z")

</div>

Hello all,

I am experiencing poor residuals with my iterative solver in PETSc when solving the elasticity equation. I normally use -pc\_gamg and -ksp\_gmres, and I have not had issues with solving 3D meshes when my Young’s modulus was an arbitrary normalized value. Now, however, I cannot seem to achieve good residuals using realistic properties (MPa) and under an applied traction (kN) and steady state thermal load. I can only achieve good residuals when my load is much smaller (small traction and no thermal), but that does not satisfy the goal of my research. From my understanding, there is no apparent singularity in the [K] matrix, and finite element analysis should be feasible to solve given the units of the problem.

I have attached an example script with my formulation. I would appreciate any guidance on how I can solve the system of elasticity using an appropriate iterative solver in PETSc.

Thank you

- Kaela. [Testing.edp](https://community.freefem.org/uploads/short-url/rMyncn3PIZarIHt0FzBjaMdjKYt.edp) (3.3 KB)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [October 27, 2021, 8:40pm UTC](https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288/2 "2021-10-27T20:40:51Z")

</div>

Please consider:

- using a lower `-ksp_rtol`, e.g., `-ksp_rtol 1e-8` (default is 1e-5);
- setting `bs = 3` in your `set(AFEA);` command
- switching to `-ksp_pc_side right` (default is left).

Does that give you a good enough solution?

---

<div class="post-metadata">

**Author:** ![KBarrett](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KBarrett](https://community.freefem.org/u/KBarrett)\
**Post date:** [October 27, 2021, 9:57pm UTC](https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288/3 "2021-10-27T21:57:55Z")

</div>

Thanks, that is much better! If you don’t mind, what does adding `bs=3` and switching to` -ksp_pc_side right` do that makes the solver perform better?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [October 28, 2021, 6:50am UTC](https://community.freefem.org/t/poor-residuals-from-petsc-iterative-solver-for-3d-elasticity-equation/1288/4 "2021-10-28T06:50:45Z")

</div>

> If you don’t mind, what does adding `bs=3`

It sets the blocksize, as strongly suggested by the [https://petsc.org/release/docs/manualpages/PC/PCGAMG.html](https://petsc.org/release/docs/manualpages/PC/PCGAMG.html) manual page “In order to obtain good performance for [PCGAMG](https://petsc.org/release/docs/manualpages/PC/PCGAMG.html#PCGAMG) for vector valued problems you must call [MatSetBlockSize](https://petsc.org/release/docs/manualpages/Mat/MatSetBlockSize.html#MatSetBlockSize)() to indicate the number of degrees of freedom per grid point”.

> switching to` -ksp_pc_side right`

Please refer to the [https://petsc.org/release/docs/manualpages/PC/PCSide.html](https://petsc.org/release/docs/manualpages/PC/PCSide.html) manual page.
