### How to use FEniCS to calculate the normal vector in level set function problems?

398
views
1
13 months ago by
Dear all,

I have been working with FEniCS to solve problems which involve level set functions and I am stuck in the following implementation:

To calculate the normal vector $\hat{n}$ I have to use the integral $\int_{\Omega} \frac{\nabla \Phi }{|\nabla \Phi|} \cdot \vec{v} dx= \int_{\Omega} \hat{n}\cdot \vec{v} dx$ and I don't known how to implement it.

Thanks for the support.
Community: FEniCS Project

### 1 Answer

4
13 months ago by
You can simply try something like this:

from dolfin import *

mesh = UnitSquareMesh(10,10)
F = FunctionSpace(mesh, "CG", 1)
phi = interpolate(Expression("1+x[0]*x[0]+x[1]*x[1]", degree=2), F)

V = VectorFunctionSpace(mesh, "DG", 0, dim=2)
n = project(grad(phi)/sqrt(phi.dx(0)**2 + phi.dx(1)**2), V)

plot(phi)
plot(n)
interactive()​
2
Thanks for your help!
written 13 months ago by Paulo Vicente
Please login to add an answer/comment or follow this question.

Similar posts:
Search »