What is the best way to calculate the divergent of a particular unit vector?

12 months ago by
Dear all,

How can I integrate the  relationship above? (\( \phi\) is known)
\nabla\cdot\frac{\nabla \phi}{|\nabla \phi|} = \nabla\cdot\vec{n}
This is the algorithm:

F = FiniteElement("Lagrange", mesh.ufl_cell(), 2)
V = VectorFunctionSpace(mesh, "DG", 0, dim=2)   
FE = FunctionSpace(mesh,F)

# Norma of the gradient
norm_grad = project(sqrt(phi0.dx(0)**2.0 + phi0.dx(1)**2.0), FE) 

# Normal vector
n = project(grad(phi0)/(sqrt(phi0.dx(0)**2.0 + phi0.dx(1)**2.0)), V)

# Divergent of n
dver = div(n)

# our divergent of the gradient
dver = div(grad(phi0))/norm_grad​
Community: FEniCS Project

1 Answer

12 months ago by
You can do this, which also looks cleaner:

normal_phi = grad(phi)/sqrt(dot(grad(phi), grad(phi)))
out = assemble(div(normal_phi)*dx)​

Integration is performed by assemble, and will only work if the result is scalar, i.e, phi must be a scalar function. 

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

Similar posts:
Search »