Are the Neumann boundaries conditions approximate?

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

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?

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.

1 Like

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.

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.