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

How do I calculate the divergence of a user defined vector field?

0 votes

I have a vector field, say

def W(x,y,z):
    return [x^2,y*z, 2*z]

I want to include the divergence in the statement of my problem, for example

F = inner(grad(u),grad(v))*dx - div(W(x[0], x[1], u)*v*dx
problem = NonlinearVariationalProblem(F, u_, bcs, J)

and so forth. My function space is two-dimensional, u is a function of x[0] and x[1]. I think that is my problem? The built in divergence function is expecting 2 variables, but my vector field has 3. I don't want to calculate it by hand because my actual vector field is much worse.

asked Feb 11, 2016 by srody FEniCS Novice (180 points)

1 Answer

+1 vote
 
Best answer

Yes. You need to create and Expression to represent your vector field. Take a look at the demos - most use an Expression object.

answered Feb 23, 2016 by Garth N. Wells FEniCS Expert (35,930 points)
selected Apr 24, 2017 by srody
...