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

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.

See for instance Efficient usage of the Unified Form Language — FEniCS Workshop

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.

You use:

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?

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:

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.

See: Bitbucket
and
Bitbucket

1 Like