Defining initial condition on 1-D IntervalMesh

Hello,
I am a FEniCS beginner. I am implementing Phase Field PDEs in 1-D. The initial condition is profile for each phase. Following would be my initial conditions:

eta_Cu = np.zeros([256]) # Cu
eta_Cu3Sn = np.zeros([256]) # Cu3Sn
eta_Cu6Sn5 = np.zeros([256]) # Cu6Sn5
eta_Sn = np.zeros([256]) # Sn

eta = [eta_Cu, eta_Cu3Sn, eta_Cu6Sn5, eta_Sn]

eta[0][0:108] = 1
eta[1][108:128] = 1
eta[2][128:148] = 1
eta[3][148:256] = 1

eta = np.reshape(eta, (4, 256))

So, I want these initial conditions to be imbeded in, mesh = IntervalMesh(256, 0, 256e-6).

I request some insight about how to do it. Thank you.

It sounds like you want to have each of your eta profiles set as a defined Function over the domain. One way of doing that is to construct a simple function (a python function) that expresses your condition (1 in the appropriate subregion, otherwise 0), and then interpolate it into your Function.

You can see an example of that at Implementation — FEniCSx tutorial . Look at how the u_D function is set there.

It’s also possible to inject the values as a numpy array directly into the properties of the Function, but the interpolation approach is arguably simpler.