Hi Francis,
  What is the function space you are using?

You can build a piecewise constant function using the C-string Expression via the ?: ternary operator in C.

all the best
--cjc

On 26 February 2017 at 22:05, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
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




--
http://www.imperial.ac.uk/people/colin.cotter

www.cambridge.org/9781107663916