# How to check that the Neumann boundary condition is correctly applied

**URL:** <https://fenicsproject.discourse.group/t/how-to-check-that-the-neumann-boundary-condition-is-correctly-applied/7632>\
**Category:** variational formulation\
**Created:** [February 8, 2022, 1:01pm UTC](https://fenicsproject.discourse.group/t/how-to-check-that-the-neumann-boundary-condition-is-correctly-applied/7632 "2022-02-08T13:01:11Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 8, 2022, 3:21pm UTC](https://fenicsproject.discourse.group/t/how-to-check-that-the-neumann-boundary-condition-is-correctly-applied/7632/4 "2022-02-08T15:21:08Z")

</div>

Consider the following example:

```python
from dolfin import *

mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, "CG", 2)
u, v = TrialFunction(V), TestFunction(V)

a = dot(grad(u), grad(v))*dx
L = Constant(1.0)*v*dx

LEFT, RIGHT, TOP, BOTTOM = 1, 2, 3, 4
ff = MeshFunction("size_t", mesh, mesh.topology().dim()-1, 0)
AutoSubDomain(lambda x: x[0] < DOLFIN_EPS).mark(ff, LEFT)
AutoSubDomain(lambda x: x[0] > 1.0 - DOLFIN_EPS).mark(ff, RIGHT)
AutoSubDomain(lambda x: x[1] < DOLFIN_EPS).mark(ff, BOTTOM)
AutoSubDomain(lambda x: x[1] > 1.0 - DOLFIN_EPS).mark(ff, TOP)

bcs = [DirichletBC(V, Constant(0.0), ff, BOTTOM)]

uh = Function(V)
solve(a == L, uh, bcs)

n = FacetNormal(mesh)
ds = Measure("ds", subdomain_data=ff)
solution_trace_norm = assemble(dot(grad(uh), n)**2*ds((LEFT, RIGHT, TOP)))**0.5
print(f"Homogeneous Neumann BC trace: {solution_trace_norm}")

```

which gives me:

```auto
Homogeneous Neumann BC trace: 1.0071881730182207e-13

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/how-to-check-that-the-neumann-boundary-condition-is-correctly-applied/7632)._
