This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Integration of cross product

+3 votes

Hi,

I'm starting to use FEniCS and i'm modelling a flow machine using FEniCS and i have to solve:

enter image description here

where, omega is a vector, for example ( 0.0, 0.0, 10.0), u is the velocity, W the test function.

So i'm trying to use (first part):

 from dolfin import *
 from dolfin_adjoint import *
 set_log_level(INFO)

 omega = Constant((0.0, 0.0, vel_angular))
 rho = 1.0

 rect = Rectangle(0.0,0.0,1.0,1.0)
 mesh = Mesh(rect,100)

 U = VectorFunctionSpace(mesh, "CG", 3) # velocity function space    -U
 P = FunctionSpace(mesh, "CG", 1)       # pressure function space    -P
 W = MixedFunctionSpace([U, P])         # mixed Taylor-Hood function space

 def BC_1(x, on_boundary):    
     return on_boundary and \
          near(x[0],0.0) or near(x[1],1.0) or near(x[0],1.0)

 def BC_2(x, on_boundary):    
     return on_boundary and \
          near(x[1],0.0)

 Gamma1 = DirichletBC(W.sub(1),0.0,BC_1)    
 Gamma2 = DirichletBC(W.sub(1),10.0,BC_2)   

 bcs = [Gamma1, Gamma2]

 def forward(rho):
   w = Function(W)
   (u, p) = split(w)
   (v, q) = TestFunctions(W)

   F = (2.0*rho*inner(cross(omega,u),v)*dx)

   solve(F == 0, w, bcs)
   return w

 if __name__ == "__main__":
   w   = forward(rho)
   (u, p) = split(w)

Then i get the error:
ufl.log.UFLException: Cross product requires arguments of rank 1

I think this is because i'm trying to use u on the cross product. I've also tried to use:

F=(2.0*rho*inner(-omega[2]*u[1] + omega[2]*u[0] , v)*dx )

Is it possible to solve this kind of functionals that have cross products of valued vectors using fenics?

I really appreciate any help you can provide

asked Jul 15, 2014 by Luis FEniCS Novice (170 points)
edited Jul 15, 2014 by Luis

2 Answers

0 votes

Actually, I would expect an error message that refers to the fact that the cross product is defined in 3D but your u is only a 2D vector.

To get started, I suggest you expand the products by hand and write the form coordinatewise.

If you want to use the built-in functionality you should have a look at how the cross product is implemented.

answered Jul 15, 2014 by Jan FEniCS User (8,290 points)

Jan, thank you for your answer.

I've created a function to do the cross product:

def my_cross(v,w):
     return (v[1]*w[2]-v[2]*w[1],v[2]*w[0]-v[0]*w[2],v[0]*w[1]-v[1]*w[0])

(...)

F = (2.0*rho*inner(my_cross(omega,u),v)*dx)

and then the error changed to:
"IndexError: tuple index out of range"

Am I doing something wrong?

Edit*: I want to solve it in a 2D domain. So, i'll try to change the my_cross() function

0 votes

hi,did you solve this problem about how to use outer product? I'm also meet the same problem.
And I have no idea where is wrong.
I'll appreciate your answer.

answered Nov 7, 2016 by fanronghong FEniCS User (1,680 points)

Hi, to solve this problem I've changed the function return to a fenics 2D vector, such as:

def my_cross(v,w):
       return as_vector(( v[1]*w[2]-v[2]*w[1],  v[2]*w[0]-v[0]*w[2] ))
...