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

How to access normal components to create a Neumann boundary condition ?

+3 votes

Dear All,

Assume we have a cube with a cubic hole at the centre (i.e. two concentric cubes) for which we would like to solve Laplace equation with the following applied boundary conditions (BC):
1) a u=0 Dirichlet BC on the surface of the external cube.
2) On the inner cube surface, we would like to apply Neumann BC using 3 known functions gx(x,y,z), gy(x,y,z) and gz(x,y,z), such that the applied boundary condition is : g(x,y,z) = gx(x,y,z)nx + gy(x,y,z)ny + gz(x,y,z)*nz where n = (nx, ny, nz) is the normal on each node (x,y,z) of the inner cubic surface mesh.
How would one access the normal components and write the corresponding Neumann boundary condition ?

Thanks a lot for any help.

asked Jun 12, 2015 by Thx2u FEniCS Novice (290 points)

1 Answer

+4 votes
 
Best answer

You have to
-) make the known functions gx, gy, gz available as dolfin Expressions or Functions
-) create a dolfin SubDomain that describes the inner cube boundary and mark a FacetFunction with it, so that the inner cube boundary corresponds to some integer value, e.g. 1 (see this demo).
Then creating the Neumann condition you desire can accomplished with the following code (assuming you have already defined the mesh, the function space V and the FacetFunction boundaries).

ds = Measure('ds', domain=mesh, subdomain_data=boundaries)
n = FacetNormal(mesh)
v = TestFunction(V)

L = (gx*n[0] + gy*n[1] + gz*n[2])*v*ds(1)

Now L can be used as a right hand side for the equation you want to solve (or added to an additional right hand side, something like fvdx) and will then act as the Neumann boundary condition.

answered Jun 17, 2015 by Gregor Mitscha-Baude FEniCS User (2,280 points)
selected Jun 17, 2015 by Thx2u
...