This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Update parameters in DirichletBC and a nonlinear form

0 votes

Hello
In my problem I have certain parameters involved in DirichletBC (defined through an Expression) and nonlinear form. In each time step, I have to set new values to these parameters. What is the best way to do this ? Do I have to redefine the DirichletBC and the form ?

asked Apr 15, 2014 by praveen FEniCS User (2,760 points)

1 Answer

0 votes

Hi,

Let's say your expression for the boundary condition is $c_1 x+ c_2 y$. Where $c_1, c_2$ are your parameters.
You code might look something like this

#initial parameter values
c1 = 1.0; c2 = 1.0;    

#Apply parameters to your expression
f = Expression("{}*x[0] + {}*x[1]".format(c1,c2))
bc = DirichletBC(V, f, u0_boundary)

for i in range(max_iterations):
    #Solve problem with current bc
    <solver>

    #update boundary condition
    c1 = newValue; c2 = newValue;
    f = Expression("{}*x[0] + {}*x[1]".format(c1,c2))
    bc = DirichletBC(V, f, u0_boundary)
answered Apr 15, 2014 by sixtysymbols FEniCS User (2,280 points)

You can also use constants in an Expression which you have to give as parameters. This has the advantage that it does not require recompilation.

Example: e = Expression('a*x[0]', a=42)

Thanks to sixtysymbols and Christian. I am using Christian's suggestion.

...