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

UFL - How to get a user-defined function to return a vector

0 votes

Here is my UFL code

element = FiniteElement("CG", tetrahedron, 2)
v = TestFunction(element)
theta = TrialFunction(element) 

rho = Coefficient(element)
theta_n_1 = Coefficient(element)
idt = Constant(tetrahedron)
kappa = Coefficient(element) 
uflow = ???

heat_a = idt*v*theta*dx + v*dot(uflow, grad(theta))*dx + kappa*dot(grad(v), grad(theta))*dx
heat_L = idt*v*theta_n_1*dx + v*rho*dx

rho, kappa, and theta_n_1 are user-defined functions that return scalars. There are OK (I define these as Expressions in the C++ code).

The problem is that uflow is a user-defined function that returns a vector. The Python version simply defines this as an Expression, but I need to have a UFL/C++ version of this.

How do I define uflow so it is a user-defined vector that works with the dot operator? (Note: VectorConstant complies under UFL, but I need it to be dependent on the coordinate positions, like I do with the ones I define as Coefficients.

Edit: It appears that creating a VectorElement and defining uflow to be a Coefficient based on that element solves the problem.

vector_element = VectorElement("CG", tetrahedron, 2, 3)
uflow = Coefficient(vector_element)

Can anybody confirm this?

asked Jun 7, 2017 by jahulsey FEniCS Novice (150 points)
edited Jun 7, 2017 by jahulsey

1 Answer

0 votes
 
Best answer

Yes, this is the way to do it. For more info, see the UFL manual.

answered Jun 11, 2017 by mdbenito FEniCS User (4,530 points)
selected Jun 12, 2017 by jahulsey
...