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

Restrict 3D vector for using it in dot() with a 2D grad

0 votes

I would like to form a dot product of the first two components of a three-dimenstional vector with grad(u) from a two-dimensional mesh. How can I select the components of conv such that the following code works?

from dolfin import *

mesh = UnitSquareMesh(10, 10)

V = FunctionSpace(mesh, 'CG', 1)

conv = Constant([1.0, 2.0, 3.0])  # comes from elsewhere

u = TrialFunction(V)
# ufl.log.UFLException: Dimension mismatch in dot product.
dot(conv, grad(u))
asked Jun 6, 2017 by nschloe FEniCS User (7,120 points)

1 Answer

+1 vote
 
Best answer

I can't run this at the moment to check it but this might work:

conv2 = as_vector((conv[0], conv[1]))

dot(conv2, grad(u))

Source: https://media.readthedocs.org/pdf/fenics-ufl/latest/fenics-ufl.pdf

answered Jun 6, 2017 by alexmm FEniCS User (4,240 points)
selected Jun 6, 2017 by nschloe

It's missing brackets, but that does the trick. Thanks!

I changed the answer to add the missing brackets. Is that what you used?

...