Hello, I am trying to define an expression piecewise and see that I need to do that by defining a class. Below is something that I tried, building on what I read, but it has an error, see below. class MyExpression(Expression): def eval(self, value, x): if x[0] <= 0.5: value[0] = 1.0 else: value[0] = 0.0 def value_shape(self): return (1,) f.interpolate(MyExpression()) It fails with the following error: AttributeError: 'FunctionSpace' object has no attribute 'interpolate' Can someone maybe point me in the right direction on how to do tis properly? Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637