# Newtons methods for unsteady problem

**URL:** https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873
**Category:** General Discussion
**Created:** [July 4, 2022, 7:17am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873 "2022-07-04T07:17:36Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![DongweiYe](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dongweiye/32/1073_2.png) [@DongweiYe](https://community.freefem.org/u/DongweiYe)
#### Post date: [July 4, 2022, 7:17am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/1 "2022-07-04T07:17:36Z")

</div>

Hi everyone,

I meet a problem with implementing the unsteady NS equation with Newton method. I need to implement a periodical boundary condition on the inlet. However it seems that with Newton method, the convergence is not very well, the message shows that the SNES Function norm is always at a high value like XXe-1 to XXe+1 and it doesn’t go further down. Do you have any suggestions to improve the situation? Thank you!

I here enclose my code for checking, thank you!  
[NewtonNS.edp](https://community.freefem.org/uploads/short-url/KYymYAiSWneMSBXazdtZtHSudF.edp) (5.2 KB)

Best wishes  
Dongwei

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [July 4, 2022, 7:33am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/2 "2022-07-04T07:33:36Z")

</div>

I cannot run your script because it needs an input file that you didn’t share. You mention that you have periodic boundary conditions, but I don’t see any periodic `fespace` in your file.

---

<div class="post-metadata">

### Author: ![DongweiYe](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dongweiye/32/1073_2.png) [@DongweiYe](https://community.freefem.org/u/DongweiYe)
#### Post date: [July 4, 2022, 7:48am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/3 "2022-07-04T07:48:08Z")

</div>

Sorry I forgot to attach the inlet, here it is:  
[LCA\_inlet\_FreeFem\_new.zip](https://community.freefem.org/uploads/short-url/vkgNuZPBSjqyC15thIv1g5VDU0Q.zip) (10.4 KB)  
[mesh.zip](https://community.freefem.org/uploads/short-url/z5hStzBTyI76mcP3Kp8Bh0FljJs.zip) (80.5 KB)

This is a txt file where I read in the inlet max velocity (it’s a parabolic profile). The way that I implemented the periodical BC is using this data repeatedly by `+ on(4, ux = uaugm[(tstep-1)%1000]*(y-1)^2-uaugm[(tstep-1)%1000], uy = 0);`

Also due to the implementation of Newtons method, I calculate the augmentation of the velocity of each timestep from the velocity list `ulist` which is the argument `uaugm` here.

But I am not sure it is the correct implementation for the situation

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [July 4, 2022, 7:50am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/4 "2022-07-04T07:50:38Z")

</div>

Still does not run as there is no mesh. But that’s not the proper way to impose periodic boundary conditions anyway.

---

<div class="post-metadata">

### Author: ![DongweiYe](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dongweiye/32/1073_2.png) [@DongweiYe](https://community.freefem.org/u/DongweiYe)
#### Post date: [July 4, 2022, 7:56am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/5 "2022-07-04T07:56:11Z")

</div>

I added the mesh to my previous reply.

Ok, I see. Could you point me to an example of implementing periodic BC in the context of Newton methods?  
Thank you in advance!

---

<div class="post-metadata">

### Author: ![DongweiYe](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/dongweiye/32/1073_2.png) [@DongweiYe](https://community.freefem.org/u/DongweiYe)
#### Post date: [July 4, 2022, 8:03am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/6 "2022-07-04T08:03:46Z")

</div>

Sorry I just realise that my question may not be precise. I may have used a wrong term. The periodic BC I mean is having a repeating pattern inlet velocity using the data like a pulsatile flow instead of having the outlet as another inlet.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [July 4, 2022, 2:42pm UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/7 "2022-07-04T14:42:58Z")

</div>

Even the first nonlinear system cannot be solved. How did you implement your two varf? Does it work with a Newton linearization implemented “by hand”? My best advice would be to start from something that works, e.g., a steady-state Navier–Stokes script, and then add time discretization and then your forcing term. It’s difficult otherwise to debug these multiline varf.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [July 4, 2022, 2:50pm UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/8 "2022-07-04T14:50:47Z")

</div>

I highly doubt your `vRes` varf is correct. Your Dirichlet boundary condition on label 4 does not depend on the previous residual, which can never go to 0, hence the stagnation. At convergence of `SNESSolve`, keep in mind that `vRes(0, v)` should evaluate to a vector whose norm is close to 0. Here, that’s impossible since you have `on(4, ux = uaugm[(tstep-1)%1000]*(y-1)^2-uaugm[(tstep-1)%1000], uy = 0)`. Maybe it should be `on(4, ux = ucx-uaugm[(tstep-1)%1000]*(y-1)^2-uaugm[(tstep-1)%1000], uy = 0)`?

---

<div class="post-metadata">

### Author: ![zetaoma7](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zetaoma7/32/1407_2.png) [@zetaoma7](https://community.freefem.org/u/zetaoma7)
#### Post date: [November 8, 2022, 10:24am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/9 "2022-11-08T10:24:05Z")

</div>

Dear sir,

i have a quetion, what’s the default precision of a real number in FreeFem? Can i change the precision of it? May the default precision setting influence the results?

For example, in MATLAB, format long means 16 significant digits.

Thank you in advance!

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [November 9, 2022, 6:43am UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/10 "2022-11-09T06:43:57Z")

</div>

This is the same, i.e., double-precision floating point.

---

<div class="post-metadata">

### Author: ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)
#### Post date: [August 31, 2024, 2:20pm UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/11 "2024-08-31T14:20:52Z")

</div>

Dear sir,

I have a question, for example  
we define that  
real a = 10.0014 and real b = 0.00001  
then we compute a+b by using FreeFem  
we obtain a+b = 10.0014, however the ture is 10.00141

so how can we avoid such error during the use of FreeFem.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [August 31, 2024, 2:22pm UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/12 "2024-08-31T14:22:05Z")

</div>

You can try [Kahan summation algorithm - Wikipedia](https://en.wikipedia.org/wiki/Kahan_summation_algorithm).

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [August 31, 2024, 2:30pm UTC](https://community.freefem.org/t/newtons-methods-for-unsteady-problem/1873/13 "2024-08-31T14:30:19Z")

</div>

But what you are saying is not correct, I get with FreeFEM:

```auto
10.00141

```
