This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Can we apply Neumann BC to only one component of a vector field?

+1 vote

Is there a way to apply Neumann BC to only 1 component of the vector field? I know you can easily do this with DirichletBC. Can we do the same for Neumann?

asked Dec 13, 2016 by quangha FEniCS Novice (490 points)

1 Answer

0 votes

This depends heavily on your problem, so I will assume you are using a primal formulation. In this case, Neumann conditions are natural, which means that they arise naturally in your problem after you integrate by parts. Again, if this is the case, say your solution is a scalar field $u$ which must verify $\partial_x u = g\quad \in \partial \Omega$. Then, somewhere in your problem you will find a term that looks (maybe) like

$$ \int v \nabla u \cdot \nu, $$

where $\nu$ is you facet normal. Then, your code should have something like this:

n = FacetNormal(mesh)
boundary_gradient = as_vector(g, u.dx(1))
bilinear_form += v * dot(boundary_gradient , n) * dx

If it shows some strage errors in the partial derivative (I have had this problem sometimes), you can use

u_x = dot(grad (u), Constant([1.,0.]))

Let me know if it works. Best regards!

answered Jun 1, 2017 by nabarnaf FEniCS User (2,940 points)
...