Spatially varying parameters

I can define spatially varying parameters using Expression like this:
E = Expression("E0*x[0]", E0=2, degree=0)
How can I do that discretely throughout the domain? I mean it is like:
if x[0]<1 E=1
else E=2

Consider How to implement function with condition? - #3 by dokken

1 Like

If your expression is simple you could also use C++'s ternary operator

something like:

E = Expression("(x[0] < 1.0) ? E1 : E2", E1=E1, E2=E2, degree=0)

Ideally you could use the functional syntax of dolfinx.

1 Like