# Compute Vorticity from Velocity in Dolfinx

Hello,

I have a 2D velocity field and a pressure field combined in a mixed element function:

velocity_element = VectorElement("Lagrange", self.mesh.ufl_cell(), 2)
pressure_element = FiniteElement("Lagrange", self.mesh.ufl_cell(), 1)

# mixed function space and mixed function
W = FunctionSpace(self.mesh, MixedElement([velocity_element, pressure_element]))
w = Function(W)


How could I compute the vorticity field (scalar field, hence on pressure_element I suppose) from the velocity field ? I have seen a topic about it but it was in FEniCS, not FEniCSx and the syntax seemed to have changed.

Thanks and regards

How do you define vorticity?

You can see my comments about 2D vorticity wrt to chosing an appropriate space:

As for moving the ufl-expression in to a function space, see for instance: Gradients and divergences in fenicsx - #4 by Gianna

Mathematically, in my case (2D velocity field), the vorticity is a scalar defined everywhere by:

\forall (x,y)\in\Omega\subset\mathbb R^2,\quad\mathbf u(x,y)=u_x(x,y)\mathbf e_x + u_y(x,y)\mathbf e_y\qquad(\text{velocity})\\ \omega(x,y) = \frac{\partial u_y}{\partial x}(x,y) - \frac{\partial u_x}{\partial y}(x,y)\qquad(\text{vorticity})

So I suppose it is computable with ufl.dx or ufl.curl.

Since it is 2D, doing something along the lines of

ux, uy = u_n.split(deepcopy=True)
vortex = ux.dx(1)-uy.dx(0)


and putting vortex inside a dolfinx.fem.Expression and interpolate into a suitable function space (DG, velocity degree -1).

1 Like

Ok thanks a lot again. Now I have a little and not important problem, but I would like to solve it.

With a Function that is not defined on a mixed function space, I am able to set its name:

vort = Function(V, name="vorticity")


And when written to an xdmf file, I can see in paraview my function is well named.

But when it comes to my mixed-element function w, naming each sub function seems not to work, for example I have this strange result:

w = Function(W, name="mixed_function") # creating my mixed element function (first element correspond to velocity, and second to pressure)
w.sub(0).name = "velocity"  # renaming the first sub function
print(w.sub(0).name) # returns "f_0", but I would like "velocity"


Is that normal ?

I cannot reproduce this, consider the following mwe:

from ufl import VectorElement, MixedElement, FiniteElement
from mpi4py import MPI
import dolfinx
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)

velocity_element = VectorElement("Lagrange", mesh.ufl_cell(), 2)
pressure_element = FiniteElement("Lagrange", mesh.ufl_cell(), 1)

# mixed function space and mixed function
W = dolfinx.fem.FunctionSpace(mesh, MixedElement([velocity_element, pressure_element]))
w = dolfinx.fem.Function(W)
w.name = "up"
u = w.sub(0)
u.name = "u"
uy = u.sub(1)
print(f"{w.name=} {u.name=} {uy.name=}")


returning

w.name='up' u.name='u' uy.name='u_1'