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

Evaluate nabla_div of a vector?

0 votes

This seems like a silly question, but I can't seem to get the array values from the divergence of a vector. Here's essentially what I'm trying to do:

V = VectorFunctionSpace(mesh, "CG", 2, dim=3)
Q = FunctionSpace(mesh, "CG", 1)
W = V*Q

w = Function(W)

true_solution = Expression(('cos(pi*x[2])','sin(pi*x[0])','cos(pi*x[1])'),t=0.0)
(u,p) = w.split(0)

u.assign(true_solution)
p.assign(nabla_div(u)) #this is the important line

which, obviously results in an error because nabla_div doesn't produce that kind of object.

There simply must be an easy way to do this. Suggestions? (Thanks again!)

asked May 4, 2016 by qwetico FEniCS Novice (360 points)

1 Answer

0 votes
 
Best answer

The gradient of CG2 function is DG1 - not CG1, but you can do

p.assign(project(nabla_div(u),Q))
answered May 4, 2016 by KristianE FEniCS Expert (12,900 points)
selected Aug 2, 2016 by qwetico
...