# Pass variables to the expression for the initial condition

**URL:** <https://fenicsproject.discourse.group/t/pass-variables-to-the-expression-for-the-initial-condition/8313>\
**Category:** I/O\
**Created:** [May 14, 2022, 9:53am UTC](https://fenicsproject.discourse.group/t/pass-variables-to-the-expression-for-the-initial-condition/8313 "2022-05-14T09:53:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BEQ](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BEQ](https://fenicsproject.discourse.group/u/BEQ)\
**Post date:** [May 14, 2022, 9:53am UTC](https://fenicsproject.discourse.group/t/pass-variables-to-the-expression-for-the-initial-condition/8313/1 "2022-05-14T09:53:52Z")

</div>

I’m new to Fenics and I’m trying to solve the 1D Burgers equation using [this script](https://people.math.sc.edu/Burkardt/fenics_src/burgers_time_viscous/burgers_time_viscous.py)

I’m having problems passing variables to the expression for the initial condition. For instance, if I try to set the initial condition u(x,0) = np.pi \* x as follows,

```auto
# Define the initial condition.
#
  # u_init = Expression ( "x[0]", degree = 1 ) # <- the original IC, which works
  PI = np.pi  
  u_init = Expression ( "PI * x[0])", degree = 1 ) # <- my IC, which doesn't work

```

then the code doesn’t work and I get this error message:

```auto
------------------- Start compiler output ------------------------
/tmp/tmpi4_ubx8m/dolfin_expression_e1b233f340eedca27ef2c4df85830884.cpp: In member function ‘virtual void dolfin::dolfin_expression_e1b233f340eedca27ef2c4df85830884::eval(Eigen::Ref<Eigen::Matrix<double, -1, 1> >, Eigen::Ref<const Eigen::Matrix<double, -1, 1> >) const’:
/tmp/tmpi4_ubx8m/dolfin_expression_e1b233f340eedca27ef2c4df85830884.cpp:61:23: error: ‘PI’ was not declared in this scope; did you mean ‘pi’?
   61 | values[0] = PI * x[0]);
      | ^~
      | pi

```

And I have the same problem if I try to give the viscosity, nu, as an argument.

Why does this happen? How could it be fixed?

---

<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:** [May 14, 2022, 9:56am UTC](https://fenicsproject.discourse.group/t/pass-variables-to-the-expression-for-the-initial-condition/8313/2 "2022-05-14T09:56:05Z")

</div>

> [@BEQ](#):
>
> ` u_init = Expression ( "PI * x[0])", degree = 1 ) `

Should be:

```python
u_init = Expression ( "PI * x[0])", PI=PI, degree = 1 ) 

```

---

<div class="post-metadata">

**Author:** ![BEQ](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@BEQ](https://fenicsproject.discourse.group/u/BEQ)\
**Post date:** [May 14, 2022, 10:03am UTC](https://fenicsproject.discourse.group/t/pass-variables-to-the-expression-for-the-initial-condition/8313/3 "2022-05-14T10:03:36Z")

</div>

Ok, thank you very much, this way it works perfectly!
