# Error assembling a matrix 3d surface mesh

**URL:** <https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325>\
**Category:** General Discussion\
**Created:** [April 9, 2020, 12:39pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325 "2020-04-09T12:39:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 9, 2020, 12:39pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/1 "2020-04-09T12:39:39Z")

</div>

Hello,  
I came across a segmentation fault when trying to get a matrix from varf when using a 3d surface mesh. The following code gives the error, using the torus given as example in the doc. I have tried with both FreeFem++4.5 and the recent 4.6.  
Any ideas on how to solve this ?  
Thank you.

```
load"msh3"                                                                                                                                                                               
real R = 3, r=1;                                                                                                                                                                         
real h = 0.2; //                                                                                                                                                                         
int nx = R*2*pi/h;                                                                                                                                                                       
int ny = r*2*pi/h;                                                                                                                                                                       
func torex= (R+r*cos(y*pi*2))*cos(x*pi*2);                                                                                                                                               
func torey= (R+r*cos(y*pi*2))*sin(x*pi*2);                                                                                                                                               
func torez= r*sin(y*pi*2);                                                                                                                                                               
meshS ThS=square3(nx,ny,[torex,torey,torez],orientation=-1) ;                                                                                                                            
                                                                                                                                                      
fespace Vh(ThS,[P1,P1]);                                                                                                                                                                 
                                                                                                                                                                                     
macro grad(u) [dx(u),dy(u),dz(u)] //EOM                                                                                                                                                  
                                                                                                                                                                                     
func f1 = 10;                                                                                                                                                                            
func f2 = -15;                                                                                                                                                                           
                                                                                                                                                                                     
varf vP([u1,u2],[v1,v2]) = int2d(ThS)(grad(u1)'*grad(v1)+ grad(u2)'*grad(v2)) - int2d(ThS)(f1*v1+f2*v2);                                                                                 
                                                                                                                                                                                     
matrix A = vP(Vh,Vh);
```

---

<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:** [April 9, 2020, 12:43pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/2 "2020-04-09T12:43:07Z")

</div>

```auto
varf vP([u1,u2],[v1,v2]) = int2d(ThS)(grad(u1)'*grad(v1)+ grad(u2)'*grad(v2)) - int2d(ThS)(f1*v1+f2*v2);

```

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 9, 2020, 1:12pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/3 "2020-04-09T13:12:53Z")

</div>

I corrected the code, thank you.

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 21, 2020, 12:00pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/4 "2020-04-21T12:00:27Z")

</div>

Hi,  
Does someone have an explanation for this?  
Thank you,  
Rémi

---

<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:** [April 21, 2020, 7:14pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/5 "2020-04-21T19:14:58Z")

</div>

What is the problem right now?

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 27, 2020, 8:00am UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/6 "2020-04-27T08:00:56Z")

</div>

The problem is:

> matrix A = vP(Vh,Vh);

provokes a Segmentation fault (core dumped).

---

<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:** [April 27, 2020, 8:12am UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/7 "2020-04-27T08:12:32Z")

</div>

Not with the correct variational formulation, does it?

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 27, 2020, 10:12am UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/8 "2020-04-27T10:12:39Z")

</div>

No, even with the correct formulation (I corrected it in the initial post) the error still arises.  
Any other clue?

---

<div class="post-metadata">

**Author:** ![AFourmont](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/afourmont/32/56_2.png) [@AFourmont](https://community.freefem.org/u/AFourmont)\
**Post date:** [April 27, 2020, 12:30pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/9 "2020-04-27T12:30:15Z")

</div>

Hello,  
I amn’t able to reproduce your bug,  
can you give me information about your system please  
Do you use binary package or compile FreeFEM?

---

<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:** [April 27, 2020, 1:10pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/10 "2020-04-27T13:10:17Z")

</div>

Same for me: I can reproduce the segmentation fault with your initial code, but not with the new one.

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 27, 2020, 1:30pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/11 "2020-04-27T13:30:07Z")

</div>

Thank you for your help.

I have compiled Freefem++ 4.5 on Ubuntu 18.04.

---

<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:** [April 27, 2020, 1:53pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/12 "2020-04-27T13:53:10Z")

</div>

Could you please try version 4.6?

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.freefem.org/u/Remi)\
**Post date:** [April 27, 2020, 2:41pm UTC](https://community.freefem.org/t/error-assembling-a-matrix-3d-surface-mesh/325/13 "2020-04-27T14:41:18Z")

</div>

Alright, it works with the 4.6 installed from the binary package. Thank you very much.
