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

Gradient in cpp

0 votes

Hi, I have been trying to compute the gradient of scalar entity in c++ code. There is a relative example in python code in fenics book at page 20. To be more specific, i solved the laplace equation and i found the electric potential and now i want to compute the corresponding electric field. So I'm writing in ufl form:

helem = FiniteElement("Lagrange", tetrahedron, 1)
V_helem = VectorElement("Lagrange", tetrahedron, 1)

w = TrialFunction(V_helem)
v = TestFunction(V_helem)
u = Coefficient(helem)

a = inner(w,v)dx
L = -inner(nabla_grad(u),v)
dx # Gradient of potential

where as coefficient u i put in my c++ code the computed electric potential. I run the program and as a result i take:

*** Error: Unable to assemble form.
*** Reason: Wrong type of function space for argument 0.
*** Where: This error was encountered inside Form.cpp.
*** Process: unknown

Does anyone have any idea how to accomplice this task??

Thank you

asked Jun 20, 2015 by paschal91 FEniCS Novice (240 points)
...