# Neumann BC and P1, P2 FE

**URL:** https://community.freefem.org/t/neumann-bc-and-p1-p2-fe/4175
**Category:** General Discussion
**Created:** [December 31, 2025, 7:31am UTC](https://community.freefem.org/t/neumann-bc-and-p1-p2-fe/4175 "2025-12-31T07:31:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pi.3.141](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@pi.3.141](https://community.freefem.org/u/pi.3.141)
#### Post date: [December 31, 2025, 7:31am UTC](https://community.freefem.org/t/neumann-bc-and-p1-p2-fe/4175/1 "2025-12-31T07:31:42Z")

</div>

Hello Freefemers,

Testing the solver for Laplace equation with Neumann BC in 3d (in a cube). I observe a strange behavior: while the solution is perfect (error~10^-14) when using P2 FE, it is incorrect (error~10^0) when using P1 elements.

Of course, we expect a difference when using P1/P2 FE but not at at this order. So definitely there is an error with my code but I am unable to identify it. I have attached the code in the case anyone would like to have a look at it.

Thank you.

```auto
load “msh3”

int nn = 5;
mesh3 Th = cube(nn, nn, nn);

fespace Uh(Th, P2);	// must be P2 for Neumann BC to work well
Uh u, ue, uh, f, err;

ue = -(x^2 + y^2 + z^2);
f = ue + 6; // f = ue - \Delta ue

macro grad(u) [dx(u),dy(u),dz(u)] //

solve neumann(u, uh) // solve u - Delta(u) = f, dn(u)=dn(ue)
= int3d(Th) ( u*uh + grad(u)'*grad(uh) )
- int3d(Th) ( f*uh )
- int2d(Th, 1,2,3,4,5,6) ( (N’*grad(ue))*uh ); // works well if P2

err = u - ue;
cout << " ******* error = " << err[].linfty << endl;

```

---

<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: [January 3, 2026, 7:12am UTC](https://community.freefem.org/t/neumann-bc-and-p1-p2-fe/4175/2 "2026-01-03T07:12:23Z")

</div>

Your exact solution is quadratic, so the interpolation `err = u - ue` is exact with second-order finite elements, but it’s not with first-order finite elements. Increase `nn` to make the error smaller with first-order finite elements.

---

<div class="post-metadata">

### Author: ![pi.3.141](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@pi.3.141](https://community.freefem.org/u/pi.3.141)
#### Post date: [January 12, 2026, 5:16am UTC](https://community.freefem.org/t/neumann-bc-and-p1-p2-fe/4175/3 "2026-01-12T05:16:49Z")

</div>

Thank you - I missed this detail of u being just a second order polynomial.
