Elementwise multiplication in weak formulation

Hi! I’m having trouble writing the code for
\frac{(\Delta t)^2}{2}\int_{\Omega}((u^n\cdot\nabla)u^n)(\nabla v\cdot u^n) \ d\Omega
where (the weak form is larger but i think it’s not worth writting it all)

V = VectorFunctionSpace(mesh, "Lagrange", 2)
u = TrialFunction(V)
v = TestFunction(V)
u_n = Function(V)
dt=0.1
k=Constant(dt)
F1 =  k*k/2*inner(grad(v)*u_n,grad(u_n)*u_n)*dx

Here, i want to write the elementwise product (u^n\cdot\nabla)u^n)*elem_prod*(\nabla v\cdot u^n). I guess that inner form i used is not okay, how can i do it?
Thanks.

I would suggest having a look at the ufl documentation for the inner operator.
What would you expect an element product to do?

I want something like F1= k^2/2*(grad(v)*u_n) .* (grad(u_n)u_n))*dx
Using the Octave or Matlab notation " .* " . I couldn’t find that kind of operation in the ufl documentation though. As u_n and v are 2-dimensional function vectors, i tried
F1 = k*k/4
((grad(u_n)*u_n)[0]*(grad(v)*u_n)[0],(grad(u_n)*u_n)[1]*(grad(v)*u_n)[1])*dx
but it doesn’t work

So what shape are you expecting your output to have?
Your weak formulation is missing a dot between the two vectors, as your integral should be scalar valued.
One of the fundamental principles in fenics is that you write your variational form as a scalar variational form. I.e. lets say u and v come frome a vector function space, then the vector-Poisson weak formulation is written as:
-\nabla \mathbf{u} -f = \mathbf{0}, u=(u_0, u_1,u_2), then
inner(grad(u), grad(v))*dx - inner(f,v)*dx

2 Likes

Oh i thought i was integrating a 2-dimensional vector function. I got it now, thank you!