Hello everybody!
I am looking at the demo_poisson.py demo and instead of using a source term defined by:
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)")
I would like to have a source that is 1.0 in the first half of the problem and 0 everywhere else. And I couldn't really see how this could be done using 'Expression' so I used:
def f(x):
if x[0] < 0.5:
return 1.0
else:
return 0.0
But it returns an error:
TypeError: unsupported operand type(s) for *: 'function' and
'Argument'
It may be a very basic question so I'm sorry if it is obvious but I haven't been able to find any examples in the demos or answer in the Q&A explaining how to define functions for the variational form, except using 'Expression' or 'Constant'.
Could someone please give me a hint?
Thanks a lot!
Vincent