# How to change the value of a parameter in weak form during time iteration

**URL:** <https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784>\
**Category:** General\
**Created:** [January 18, 2025, 6:25pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784 "2025-01-18T18:25:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RR\_rr](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rr_rr/32/6571_2.png) [@RR\_rr](https://fenicsproject.discourse.group/u/RR_rr)\
**Post date:** [January 18, 2025, 6:25pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/1 "2025-01-18T18:25:59Z")

</div>

Dear Community,

There is a scalar parameter (let’s call it `a1`) in my weak form, and I want to change its value during the time iteration. How can we do it in Fenics? I defined it as a float and its initial value is 10, like this: `a1=10`, and then I changed its value during the time iteration using assignment, like this `a1=20`. However, it seems that this does not work. Does anyone know why this does not work? Thank you very much in advance.

---

<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:** [January 18, 2025, 7:38pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/2 "2025-01-18T19:38:53Z")

</div>

See for instance [Efficient usage of the Unified Form Language — FEniCS Workshop](http://jsdokken.com/FEniCS-workshop/src/form_compilation.html#time-dependent-constants)

---

<div class="post-metadata">

**Author:** ![RR\_rr](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rr_rr/32/6571_2.png) [@RR\_rr](https://fenicsproject.discourse.group/u/RR_rr)\
**Post date:** [January 18, 2025, 8:35pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/3 "2025-01-18T20:35:59Z")

</div>

Thank you, Dokken. It is helpful. I use Fenics and I am not familiar with Fenicsx code. Do you have any similar Fenics examples? Thank you again for your kind help.

---

<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:** [January 19, 2025, 3:20pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/4 "2025-01-19T15:20:28Z")

</div>

You use:

```python
a = Constant(some_value)
a.assign(Some other value)

```

please note that you in your question do not specify what version of FEniCS (i.e. legacy or DOLFINx), or the version of the respective software you are using, making it very hard to give any guidance.

For further questions, please follow the guidelines in: [Read before posting: How do I get my question answered?](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21)

---

<div class="post-metadata">

**Author:** ![RR\_rr](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/rr_rr/32/6571_2.png) [@RR\_rr](https://fenicsproject.discourse.group/u/RR_rr)\
**Post date:** [January 19, 2025, 3:46pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/5 "2025-01-19T15:46:44Z")

</div>

Thank you, Dokken. I am using Fenics 2019 on Ubuntu. I installed it by the command “sudo apt-get install fenics” in terminal.

In Fenics 2019, if we print a `Constant`, we get something like `f_0`. And if we want to print its value, I realize that we have to convert it to a `float`, like this:

```auto
from dolfin import *

b=Constant(2)
print("b:", b)
print("the value of b:", float(b))

```

I wonder if there are any other ways to print the value of a `Constant`?  
Besides, if we define a vector using `Constant`, like this `c=Constant((2, 7))`, how can we print its value and change its value? The command `c.assign((4, 10))` causes an error.

---

<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:** [January 19, 2025, 3:52pm UTC](https://fenicsproject.discourse.group/t/how-to-change-the-value-of-a-parameter-in-weak-form-during-time-iteration/16784/6 "2025-01-19T15:52:40Z")

</div>

See: [Bitbucket](https://bitbucket.org/fenics-project/dolfin/src/1c52e837eb54cc34627f90bde254be4aa8a2ae17/python/dolfin/function/constant.py?at=master#lines-103)  
and  
[Bitbucket](https://bitbucket.org/fenics-project/dolfin/src/1c52e837eb54cc34627f90bde254be4aa8a2ae17/python/test/unit/function/test_constant.py?at=master#lines-129)
