# Equivalent for Expression in dolfinx

**URL:** <https://fenicsproject.discourse.group/t/equivalent-for-expression-in-dolfinx/2641>\
**Category:** dolfinx\
**Created:** [March 14, 2020, 9:53am UTC](https://fenicsproject.discourse.group/t/equivalent-for-expression-in-dolfinx/2641 "2020-03-14T09:53:11Z")\
**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:** [March 14, 2020, 10:36am UTC](https://fenicsproject.discourse.group/t/equivalent-for-expression-in-dolfinx/2641/2 "2020-03-14T10:36:21Z")

</div>

The Expression class has been removed, as it caused a headache for developers and it is not clear what it does.  
The new way of doing this is to interpolate an expression into a function:

```auto
from dolfinx import UnitSquareMesh, Function, FunctionSpace, MPI, Constant
from dolfinx.fem import assemble_vector
from ufl import TestFunction, dx, inner
import numpy as np

class MyExpression:
    def __init__ (self):
        self.t = 0.0

    def eval(self, x):
        # Added some spatial variation here. Expression is sin(t)*x
        return np.full(x.shape[1], np.sin(self.t)*x[0])

# If your Expression is not spatially dependent, use Constant
# f = Constant(mesh, 0)
# L = inner(f, v)*dx
# f.value = np.sin(2)
mesh = UnitSquareMesh(MPI.comm_world, 10, 10)
V = FunctionSpace(mesh, ("CG", 1))
f = MyExpression()
f.t = 0
w = Function(V)
v = TestFunction(V)
L = inner(w, v)*dx
w.interpolate(f.eval)

print(assemble_vector(L).array)
f.t = 2
w.interpolate(f.eval)
print(assemble_vector(L).array)

```

---

_[View the full topic](https://fenicsproject.discourse.group/t/equivalent-for-expression-in-dolfinx/2641)._
