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

298

views

0

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.

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

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()
```

1

Thanks for your help!

written
10 months ago by
Paulo Vicente

Please login to add an answer/comment or follow this question.