# Some questions about using PETSc to solve 3D elasticity problems

**URL:** https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825
**Category:** General Discussion
**Created:** [February 24, 2021, 9:41pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825 "2021-02-24T21:41:05Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 24, 2021, 9:41pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/1 "2021-02-24T21:41:05Z")

</div>

Hey FreeFem++ team, as you suggest in our last discussion [https://community.freefem.org/t/iteration-solver-and-direct-solver-results-are-huge-different-with-some-meshes/797/14](https://community.freefem.org/t/iteration-solver-and-direct-solver-results-are-huge-different-with-some-meshes/797/14), I decided to add nullspace to apply the rigid body motion to my code; I test it with simple cantilever case which is working good; However, when I change the mesh to the wing model [some thin film], the residual is no long converged; I guess I have this issue is because that I do not understand the nullspace matrix very well;  
`Wh<real> def(Rb)[6]; [Rb[0], RbB[0], RbC[0]] = [1, 0, 0]; [Rb[1], RbB[1], RbC[1]] = [0, 1, 0]; [Rb[2], RbB[2], RbC[2]] = [0, 0, 1]; [Rb[3], RbB[3], RbC[3]] = [y, x, 0]; [Rb[4], RbB[4], RbC[4]] = [z, 0, x]; [Rb[5], RbB[5], RbC[5]] = [0, z, y];`  
I also attached my script here for your information; Thank you;[3D\_ELASTICITY\_PETSc.edp](https://community.freefem.org/uploads/short-url/fpCg3jfGhqkWxBNhCMu4aeiaV1d.edp) (3.3 KB)  
Because the format, I can not upload the input gmsh file of the wing

---

<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: [February 25, 2021, 7:14am UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/2 "2021-02-25T07:14:02Z")

</div>

Is it any better if you assemble both your RHS and matrix using `tgv = -2`?

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 3:40pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/3 "2021-02-25T15:40:00Z")

</div>

Thx for the replay, it is not working; what does tgv = -2 mean here.

---

<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: [February 25, 2021, 4:43pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/4 "2021-02-25T16:43:10Z")

</div>

See “symmetric elimination” from my [tutorial](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/main.pdf#page=20). I’ll need your mesh file for helping you out further. You could probably upload it somewhere or send it to me directly via private message.

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 6:30pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/5 "2021-02-25T18:30:42Z")

</div>

Thx, after some debugging, I believe the problem is from the mesh file; It seems like the “-pc\_type lu” direct solver gives me the similar strange displacement like the iteration solver. Moreover, when I switch it to the structure mesh, the problem is gonna.So I do not think the issue is from the solver. I think I can solve this issue by myself; Thx for your time;

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 6:42pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/6 "2021-02-25T18:42:13Z")

</div>

For more details about it; the binary file and the ascii file of my mesh result this issue. It sounds strange, but that’s what I find out. I do not know if this problem comes from gmsh or FreeFem; could you please let me know how to send those mesh files to you from the private message.

---

<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: [February 25, 2021, 7:12pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/8 "2021-02-25T19:12:12Z")

</div>

I’ve run the script, with both mesh files. It seems the solver converge, what is the exact issue you are seeing on your end, please?

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 7:15pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/9 "2021-02-25T19:15:35Z")

</div>

Yes, the KSP converged in both cases.if you plot the displacement, you will see the issue; the ASCII file gives the correct displacement since I clamped it on the right-hand side; however, the binary file gives me the wrong displacement;

---

<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: [February 25, 2021, 7:31pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/10 "2021-02-25T19:31:23Z")

</div>

Thanks, you are showcasing an obvious bug in the Gmsh FreeFEM reader.  
The easy solution: use PETSc `DMPlex` reader. Replace:

```auto
mesh3 Th = gmshload3("wing_unst_1300_bi.msh");

```

By:

```auto
DM plex("wing_unst_1300_bi.msh", communicator = mpiCommSelf); // also handles Gmsh v4 format
mesh3 Th = plex; //gmshload3("wing_unst_1300_ac.msh");

```

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 7:33pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/11 "2021-02-25T19:33:04Z")

</div>

I will try this, and let you know if this solves my problems. thanks for your help Prj.

---

<div class="post-metadata">

### Author: ![zcwang6](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zcwang6/32/371_2.png) [@zcwang6](https://community.freefem.org/u/zcwang6)
#### Post date: [February 25, 2021, 9:26pm UTC](https://community.freefem.org/t/some-questions-about-using-petsc-to-solve-3d-elasticity-problems/825/12 "2021-02-25T21:26:11Z")

</div>

I tested my code, every thing good now, Thx for the help;
