# Problem with grad and interpolate

**URL:** <https://fenicsproject.discourse.group/t/problem-with-grad-and-interpolate/8479>\
**Category:** Errors\
**Created:** [June 7, 2022, 9:24pm UTC](https://fenicsproject.discourse.group/t/problem-with-grad-and-interpolate/8479 "2022-06-07T21:24:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 7, 2022, 9:59pm UTC](https://fenicsproject.discourse.group/t/problem-with-grad-and-interpolate/8479/2 "2022-06-07T21:59:51Z")

</div>

The `div` and `grad` operators are `ufl.operators`, and work on ufl objects. You are trying to use them inside a function that takes in numpy arrays (values and x), and therefore you see the error message.

I would suggest computing the div(grad(your\_expression)) by hand, or use sympy to do it.

Please note that it is easier to do these things in DOLFINx, which is our new recommended software to use if you are just starting with DOLFINx,  
see: [The new DOLFINx solver is now recommended over DOLFIN](https://fenicsproject.discourse.group/t/the-new-dolfinx-solver-is-now-recommended-over-dolfin/8249)

There I would create the expression with ufl:

```python
from ufl import pow, exp, div, grad, as_vector

# Define mesh, V and u
# …
x = ufl.SpatialCoordinate(mesh)
v0 = exp(-(pow((x[0]-0.5),2)+pow((x[1]-0.5),2)))
v1 = 200*(exp(-(pow((x[0]-0.5),2)+pow((x[1]-0.5),2))))*(1-exp(-(pow((x[0]-0.5),2)+pow((x[1]-0.5),2))))*(1-2*exp(-(pow((x[0]-0.5),2)+pow((x[1]-0.5),2))))-lmbda*div(grad(exp(-(pow((x[0]-0.5),2)+pow((x[1]-0.5),2)))))
v = as_vector([v0,v1])
u_init = dolfinx.fem.Expression(v, V.element.interpolation_points)
u.interpolate(u_init)

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/problem-with-grad-and-interpolate/8479)._
