# Second derivative of numerical solution

**URL:** https://community.freefem.org/t/second-derivative-of-numerical-solution/1937
**Category:** General Discussion
**Created:** [August 10, 2022, 9:33am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937 "2022-08-10T09:33:16Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 10, 2022, 9:33am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/1 "2022-08-10T09:33:16Z")

</div>

Hello  
I’m sorry to bother you. How does freeem + + calculate the Second derivative of numerical solution?  
Thank you very much.

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [August 10, 2022, 12:06pm UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/2 "2022-08-10T12:06:26Z")

</div>

If the solution is finite element yes in general thought operator dxx, dyy, dxy, … otherwise no.

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 10, 2022, 2:51pm UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/3 "2022-08-10T14:51:24Z")

</div>

Assuming that u is the solution calculated by finite element method, I use dxx (u) to calculate all 0 .

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [August 10, 2022, 4:08pm UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/4 "2022-08-10T16:08:27Z")

</div>

It is a bug, so to debug,  
can you say the version of freefeM++ and the type of finie element.

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 10, 2022, 4:42pm UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/5 "2022-08-10T16:42:57Z")

</div>

The version of freefeM++ is 4.10, the type of finie element is P1.

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 11, 2022, 4:48am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/6 "2022-08-11T04:48:19Z")

</div>

I just reinstalled freeem + + 4.11, but the calculated dxx (u) is still 0 .

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [August 11, 2022, 7:22am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/7 "2022-08-11T07:22:43Z")

</div>

I think you should use higher order elements - P1 means that the solution consists of first order polynomial basis functions, and the second derivative of a first order polynomial is zero.

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 11, 2022, 7:49am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/8 "2022-08-11T07:49:33Z")

</div>

When I use P2 or P3,the calculated dxx(u) is still 0.

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [August 11, 2022, 8:11am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/9 "2022-08-11T08:11:09Z")

</div>

I have tested of “P3” on mesh,MeshL,mshS,mesh3 dxx is ok,  
and  
I have tested of “P2” on mesh,MeshL,mesh3 dxx is ok,

on meshS you get assert not

```auto
  current line = 5
Assertion fail : (0)
	line :248, in file ../femlib/P012_3dSurf.cpp
Assertion fail : (0)
	line :248, in file ../femlib/P012_3dSurf.cpp
 err code 6 , mpirank 0
logout

```

the code :  
[testP2-P3.edp](https://community.freefem.org/uploads/short-url/yw7kBPykKk46PmHfNRBL4STlYST.edp) (222 Bytes)

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 11, 2022, 8:50am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/10 "2022-08-11T08:50:29Z")

</div>

func ue=-y^2_exp(b1_(x-1)/epsilon)-x_exp(b2_(y-1)/epsilon)-z_exp(b3_(z-1)/epsilon)+exp((b1\*(x-1)+b2\*(y-1)+b3\*(z-1))/epsilon)+x_y^2_z^3;  
fespace Vh (Th,P1);  
Vh u,v;  
problem Lap3d (u, v)  
= int3d(Th)(  
epsilon\*(dx(u)_dx(v)+dy(u)dy(v)+dz(u)dz(v))  
)  
+int3d(Th)(  
(b1dx(u)+b2dy(u)+b3_dz(u))\*v  
)  
- int3d(Th)(  
f \* v  
)  
+ on(0, 1, u=ue)  
;

I’m sorry，I didn’t make it clear before,I want to caculate the second derivative of u，not of ue.

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [August 12, 2022, 11:46am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/11 "2022-08-12T11:46:56Z")

</div>

You want to compute the Hessian of u for doing mesh adaptation with mmg3.

It is not so simple because u is P1 , so de Hessian is just Dirac mass on edge of the mesh.  
this is why we use real[int] met=mshmet(Th,u,hmin=1e-8,hmax=0.2,err=lerr,aniso=1);  
`

---

<div class="post-metadata">

### Author: ![wanglongfei](https://avatars.discourse-cdn.com/v4/letter/w/ea666f/32.png) [@wanglongfei](https://community.freefem.org/u/wanglongfei)
#### Post date: [August 13, 2022, 5:54am UTC](https://community.freefem.org/t/second-derivative-of-numerical-solution/1937/12 "2022-08-13T05:54:16Z")

</div>

Ok,thank you very much.
