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

96

views

0

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

for 2D problems. Instead you could do

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

curl seems to be already implemented correctly for 2d also. You dont need to check the dimension. See the Fenics book, Chapter 17.

`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

written
4 months ago by
Praveen C

### 1 Answer

4

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.