How to check if a Function/TrialFunction/TestFunction is a 2D or 3D vector field

12 months ago by
I am interested in computing vorticity (i.e. the curl of a velocity field). Because the cross product is not defined in 2D, you cannot use

omega = curl(u)​

for 2D problems. Instead you could do

omega = u[1].dx(0) - u[0].dx(1)​

Is there a simple way to check if u is a 2D or 3D vector field? I want to define a function like this

def vorticity(u):
    d = ???
    if d == 2:
        return u[1].dx(0) - u[0].dx(1)
    elif d == 3:
        return curl(u)​
Community: FEniCS Project
curl seems to be already implemented correctly for 2d also. You dont need to check the dimension. See the Fenics book, Chapter 17.
written 12 months ago by Praveen C  

1 Answer

12 months ago by
Hi, you may query u.ufl_shape[0] to get the required value for d.
Please login to add an answer/comment or follow this question.

Similar posts:
Search »