### fenics form, parameter update later

115

views

0

Hi:

I am wondering if I write a form and then update them later, ex, in the time loop, update dt, will the form be updated also?

for example:

Will the dt, a.x and u that is update be reflected in the final form before solve? As far as I know, the update u will do, as that provide a initial condition for newton solver if the problem is nonlinear.

Any advise would be appreciated

I am wondering if I write a form and then update them later, ex, in the time loop, update dt, will the form be updated also?

for example:

```
from dolfin import *
...
mesh=...
V=VectorFunctionSpace(mesh, str, order)
u=Function(V)
u_trial=TrialFunction(V)
u_test=TestFunction(V)
dt=0.1
a=Expression(..., x=1)
A=some_combination_of(u, split(u), dt, a)
F=derivative(A, u, u_test)
J=derivative(F, u, u_trial)
bc=...
for t<T:
update(dt)
update(a.x)
update(u)
solve(F==0, u, bc=bc, J=J)
t+=dt
```

Will the dt, a.x and u that is update be reflected in the final form before solve? As far as I know, the update u will do, as that provide a initial condition for newton solver if the problem is nonlinear.

Any advise would be appreciated

Community: FEniCS Project

### 1 Answer

2

Use

Edited to include an example of

`Constant`

and `Constant::assign`

. `Function`

s can also be assigned with another `Function`

. Edited to include an example of

`Expression`

```
from dolfin import *
mesh = UnitSquareMesh(1, 1)
V = FunctionSpace(mesh, "CG", 1)
u, v = TrialFunction(V), TestFunction(V)
c = Constant(1.0)
a = u*v*dx
L = c*v*dx
u = Function(V)
print("u(0.5, 0.5):", u(0.5, 0.5))
solve(a == L, u)
print("u(0.5, 0.5):", u(0.5, 0.5))
c.assign(5.0)
w = Function(V)
solve(a == L, w)
print("w(0.5, 0.5):", w(0.5, 0.5))
u.assign(w)
print("u(0.5, 0.5):", u(0.5, 0.5))
e = Expression("val", val=1.0, degree=1)
j = e*v*dx
solve(a == j, u)
print("u(0.5, 0.5):", u(0.5, 0.5))
e.val = 5.0
solve(a == j, u)
print("u(0.5, 0.5):", u(0.5, 0.5))
```

1

If you use

`Constant`

, `Function`

and `Expression`

, then yes. I will edit and add an example of Expression to my original answer.
written
3 months ago by
Nate

Please login to add an answer/comment or follow this question.

F=derivative(A, u, u_test)

J=derivative(F, u, u_trial)

will the F and J be updated after update dt, u,and expression?