# Are the Neumann boundaries conditions approximate?

**URL:** <https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618>\
**Category:** General Discussion\
**Created:** [July 21, 2023, 1:03pm UTC](https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618 "2023-07-21T13:03:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)\
**Post date:** [July 21, 2023, 1:03pm UTC](https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618/1 "2023-07-21T13:03:28Z")

</div>

Hello,

I need to use Neumann BC so i want to be sure of the operation.  
to do this I took a simple example :

![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/f/f7f1f373bb1efa0e5d00e4b55f7f69b560599392.png)

```auto
load "iovtk"
mesh Th = square(10,10);

fespace SpaceP2(Th,P2);

macro mGrad1(u1) ([dx(u1),dy(u1)]) // EOM

SpaceP2 u,v;

solve a(u,v) = int2d(Th)(mGrad1(u)'*mGrad1(v)) - int1d(Th,1)(5*v);

int[int] fforder = 1;
savevtk("mysol.vtu", Th, [dx(u),dy(u)] , dataname = " u ",order=fforder);
real longueur = int1d(Th,1)(1);
real MyValue = int1d(Th,1)(mGrad1(u)'*[N.x,N.y])/longueur;
cout << "My neumann : " << MyValue << endl;

```

and i m expecting the output to be My neumann : 5 but i get

> My neumann : 5.15764

Is something wrong with my code?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [July 21, 2023, 1:24pm UTC](https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618/2 "2023-07-21T13:24:27Z")

</div>

The natural BCs are not exact at the discrete level because the definition of the gradient in the BC depends on the discretization. You should see that the agreement gets much better if you increase the mesh resolution.

---

<div class="post-metadata">

**Author:** ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)\
**Post date:** [July 21, 2023, 2:17pm UTC](https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618/3 "2023-07-21T14:17:42Z")

</div>

Thanks for your reply, it is true that by refining the mesh i m getting closer to the exact value but there is always an error.

I m working on flow simulation and i was afraid that my mass conservation equation was not respected (incoming flow was a bit different from the outflow) even with a fine mesh.

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [July 21, 2023, 2:32pm UTC](https://community.freefem.org/t/are-the-neumann-boundaries-conditions-approximate/2618/4 "2023-07-21T14:32:21Z")

</div>

It is true that there is always an error. However, you should note that your test is also not exact, since it depends on the approximation of the derivative.
