# Initialize function to 0 in dolfinx

**URL:** <https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491>\
**Category:** dolfinx\
**Created:** [October 12, 2022, 11:22am UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491 "2022-10-12T11:22:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lclaire](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lclaire/32/1615_2.png) [@lclaire](https://fenicsproject.discourse.group/u/lclaire)\
**Post date:** [October 12, 2022, 11:22am UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491/1 "2022-10-12T11:22:27Z")

</div>

Hello,

I am working on a 2D hyperelasticity problem.

```auto
L = 1. # total length
d = L/10. # thickness
h = d/6. # size of a cell

my_domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, -0.5*d), (L, 0.5*d)), n=(int(L/h), int(d/h)),
                            cell_type=dolfinx.mesh.CellType.triangle)
V = dolfinx.fem.VectorFunctionSpace(my_domain, ("CG", 2))
u = dolfinx.fem.Function(V)

```

I used to initialize my displacement function to zero using

```auto
u.interpolate(dolfinx.fem.Constant((0.,0.)))

```

But this now yields an error

```auto
TypeError: __init__ () missing 1 required positional argument: 'c'

```

Many thanks in advance for your help with this!

---

<div class="post-metadata">

**Author:** ![conpierce8](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/conpierce8/32/2464_2.png) [@conpierce8](https://fenicsproject.discourse.group/u/conpierce8)\
**Post date:** [October 12, 2022, 2:45pm UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491/2 "2022-10-12T14:45:32Z")

</div>

You need to provide the domain to `dolfinx.fem.Constant`, i.e.

```python
u.interpolate(dolfinx.fem.Constant(my_domain, (0., 0.)))

```

See [dolfinx/function.py at main · FEniCS/dolfinx · GitHub](https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/fem/function.py#L33)

---

<div class="post-metadata">

**Author:** ![lclaire](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lclaire/32/1615_2.png) [@lclaire](https://fenicsproject.discourse.group/u/lclaire)\
**Post date:** [October 12, 2022, 2:53pm UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491/3 "2022-10-12T14:53:53Z")

</div>

thanks! now I get this strange warning:

```auto
WARNING:UFL:Couldn't map 'c_4' to a float, returning ufl object without evaluation.

```

I’ll try to write a minimal code to reproduce the error…

---

<div class="post-metadata">

**Author:** ![hawkspar](https://avatars.discourse-cdn.com/v4/letter/h/b487fb/32.png) [@hawkspar](https://fenicsproject.discourse.group/u/hawkspar)\
**Post date:** [October 13, 2022, 8:52am UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491/4 "2022-10-13T08:52:58Z")

</div>

Did you take care to be consistent between real and complex numbers ? If you have `PETSc` compiled for real numbers, and feed it a complex it will understandably complain.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [October 13, 2022, 9:47am UTC](https://fenicsproject.discourse.group/t/initialize-function-to-0-in-dolfinx/9491/5 "2022-10-13T09:47:13Z")

</div>

If you simply want to initialize it to zero, I would suggest  
`u.x.set(0)`
