Computing a unit vector field

Asked by Heitor Pina

I have a FE Function v on a VectorFunctionSpace V and I need to compute u=v/||v||, i.e., a unit vector field which will be used in a variational form. I am writing u=v/sqrt(dot(v,v)) but this is not working. It seems that I am missing something very trivial here and would appreciate any help.

Best

Heitor

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Best Johan Hake (johan-hake) said :
#1

Have you tried:

   u = project(v/sqrt(dot(v,v)), V)

Also make sure you do not divide by zero.

Johan

On 05/29/2012 11:40 AM, Heitor Pina wrote:
> New question #198751 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/198751
>
> I have a FE Function v on a VectorFunctionSpace V and I need to
> compute u=v/||v||, i.e., a unit vector field which will be used in a
> variational form. I am writing u=v/sqrt(dot(v,v)) but this is not
> working. It seems that I am missing something very trivial here and
> would appreciate any help.
>
> Best
>
> Heitor
>

Revision history for this message
Heitor Pina (hpina) said :
#2

Thanks Johan Hake, that solved my question.