# Convergence issue with time derivative discretisation

**URL:** <https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167>\
**Category:** variational formulation\
**Created:** [January 6, 2020, 9:20am UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167 "2020-01-06T09:20:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RemDelaporteMathurin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/remdelaportemathurin/32/4543_2.png) [@RemDelaporteMathurin](https://fenicsproject.discourse.group/u/RemDelaporteMathurin)\
**Post date:** [January 6, 2020, 9:20am UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/1 "2020-01-06T09:20:31Z")

</div>

Hi all,

I’d like to solve this system of PDE :  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/1X/dca5199161f92d43a990e7ddb5c5631741571d85.png)

I ended up with this kind of formulation :

```python
from fenics import *

mesh = UnitIntervalMesh(10)
V = VectorFunctionSpace(mesh, 'P', 1, 2)

u = Function(V)
u_n = Function(V)
v = TestFunction(V)

sol = list(split(u))
prev_sol = list(split(u_n))
test = list(split(v))

F = (sol[0] - prev_sol[0])/2*test[0]*dx - 1 * test[0]*dx
F += (sol[0]*sol[1] - prev_sol[0]*prev_sol[1])/2*test[1]*dx - 1 * test[1]*dx

solve(F == 0, u, [])

```

But this doesn’t converge (residual is nan). I reckon there’s something I’m not doing right here. Thanks for the help !

Rem

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [January 6, 2020, 3:37pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/2 "2020-01-06T15:37:35Z")

</div>

Think about what the left-hand side matrix looks like in the first iteration. Since `sol[0]` is zero, the mass matrix that you get from linearizing the `sol[1]*test[1]` term is multiplied by a zero coefficient, and all the rows corresponding to `test[1]` are zero.

---

<div class="post-metadata">

**Author:** ![RemDelaporteMathurin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/remdelaportemathurin/32/4543_2.png) [@RemDelaporteMathurin](https://fenicsproject.discourse.group/u/RemDelaporteMathurin)\
**Post date:** [January 8, 2020, 8:42am UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/3 "2020-01-08T08:42:58Z")

</div>

Ah that makes sense. So I suppose I should developp the time derivative term above as :

```python
(sol[0]*(sol[1] - prev_sol[1]) + sol[1]*(sol[0] - prev_sol[0]))/2*test[1]*dx

```

is that right ?

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [January 8, 2020, 3:03pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/4 "2020-01-08T15:03:07Z")

</div>

That still has the problem of the `sol[0]`–`test[1]` block in the LHS matrix being scaled by zero. There is now a `sol[0]`–`test[1]` block, but it is scaled by `sol[1]`, which is also zero, so this reformulation still crashes in the same way.

Another option might be to have `soln[1]` represent C\_1C\_2, then recover C\_2 as a post-processing step (although that will become undefined when C\_1=0). This would completely decouple the system mentioned in the original post, but I assume it’s really an MWE for something more complicated, where the change-of-variables might not make sense.

---

<div class="post-metadata">

**Author:** ![RemDelaporteMathurin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/remdelaportemathurin/32/4543_2.png) [@RemDelaporteMathurin](https://fenicsproject.discourse.group/u/RemDelaporteMathurin)\
**Post date:** [January 8, 2020, 3:05pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/5 "2020-01-08T15:05:46Z")

</div>

It seems that the following is working:

```python
from fenics import *

mesh = UnitIntervalMesh(10)
V = VectorFunctionSpace(mesh, 'P', 1, 2)

u = Function(V)
u_n = Function(V)
v = TestFunction(V)

sol = list(split(u))
prev_sol = list(split(u_n))
test = list(split(v))

F = (sol[0] - prev_sol[0])/2*test[0]*dx - 1 * test[0]*dx
# F += (sol[0]*sol[1] - prev_sol[0]*prev_sol[1])/2*test[1]*dx - 1 * test[1]*dx
F += sol[0]*(sol[1] - prev_sol[1])/2*test[1]*dx - 1 * test[1]*dx + 1*sol[1]*test[1]*dx
solve(F == 0, u, [])

```

what could be the issue then ?

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [January 8, 2020, 3:11pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/6 "2020-01-08T15:11:23Z")

</div>

The `1*sol[1]*test[1]*dx` is giving you a nonzero mass matrix in the 11 block of the LHS matrix, although I’m not seeing how it follows from applying the product rule to the second equation.

---

<div class="post-metadata">

**Author:** ![RemDelaporteMathurin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/remdelaportemathurin/32/4543_2.png) [@RemDelaporteMathurin](https://fenicsproject.discourse.group/u/RemDelaporteMathurin)\
**Post date:** [January 8, 2020, 3:13pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/7 "2020-01-08T15:13:11Z")

</div>

it is equal to the time derivative of sol[0]

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [January 8, 2020, 3:14pm UTC](https://fenicsproject.discourse.group/t/convergence-issue-with-time-derivative-discretisation/2167/8 "2020-01-08T15:14:31Z")

</div>

Okay, that makes sense.
