# Defining initial condition on 1-D IntervalMesh

**URL:** <https://fenicsproject.discourse.group/t/defining-initial-condition-on-1-d-intervalmesh/7589>\
**Category:** I/O\
**Created:** [February 1, 2022, 2:21pm UTC](https://fenicsproject.discourse.group/t/defining-initial-condition-on-1-d-intervalmesh/7589 "2022-02-01T14:21:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetan\_Chaudhari](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chetan_chaudhari/32/3414_2.png) [@Chetan\_Chaudhari](https://fenicsproject.discourse.group/u/Chetan_Chaudhari)\
**Post date:** [February 1, 2022, 2:21pm UTC](https://fenicsproject.discourse.group/t/defining-initial-condition-on-1-d-intervalmesh/7589/1 "2022-02-01T14:21:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [February 2, 2022, 5:02pm UTC](https://fenicsproject.discourse.group/t/defining-initial-condition-on-1-d-intervalmesh/7589/2 "2022-02-02T17:02:46Z")

</div>

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](https://jorgensd.github.io/dolfinx-tutorial/chapter2/nonlinpoisson_code.html) . 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.
