Combining expressions

hi, i have a short question,

i want to define the initial conditions for my characteristic function.
but I do not want to do this randomly, so I created conditions for my X expression as below.

X0 = Expression('0.4<=x[0]-x[1] and x[0]-x[1]<=0.6?+1:0', degree=0)
X = Expression('0.4=x[0]+x[1] and x[0]+x[1]<=0.6?+1:0', degree=0)
X = interpolate(X, W)

where W is FunctionSpace(mesh, “DG”, 0).
but I want that initial condition to be complex like having ones only in diagonals (like X shape in a unit box) and zero for the other parts. I couldn’t find a way to do that, how can i combine X0 and X? could you please help me? and is there any easier way to do that for a complex initial guess?
thanks

Consider

from fenics import *
mesh = UnitSquareMesh(10, 10, "crossed")
X0 = Expression('near(x[1], x[0]) || near(x[1], 1.0 - x[0])', degree=1)
V = FunctionSpace(mesh, 'CG', 1)
v = Function(V)
v.interpolate(X0)
with XDMFFile("x0.xdmf") as xdmf:
    xdmf.write(v)

Producing

2 Likes