# Convective term unsteady 2D NS equations

**URL:** https://community.freefem.org/t/convective-term-unsteady-2d-ns-equations/2655
**Category:** General Discussion
**Created:** [August 14, 2023, 2:44pm UTC](https://community.freefem.org/t/convective-term-unsteady-2d-ns-equations/2655 "2023-08-14T14:44:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Erika](https://avatars.discourse-cdn.com/v4/letter/e/47e85d/32.png) [@Erika](https://community.freefem.org/u/Erika)
#### Post date: [August 14, 2023, 2:44pm UTC](https://community.freefem.org/t/convective-term-unsteady-2d-ns-equations/2655/1 "2023-08-14T14:44:50Z")

</div>

Hi everyone, I am implementing unsteady 2D Navier-Stokes equations but I am having troubles with the convective term.  
Looking at the FreeFem documentation, I have found the built-in function _convect_ that works pretty well for my kind of problem. The code that implements the convective term in this way is the following one:

```auto
varf navierstokes([ux, uy, p], [vx, vy, q]) = int2d(Th)(
      rho/dt* [ux, uy]'* [vx, vy]
    + mu* (Grad(u):Grad(v))
    - p* div(v)
    - q* div(u)
    - 1e-10 *p*q    
	)
	+ int2d(Th) (
      [fx, fy]' * [vx, vy]
    + rho/dt* [convect([upx, upy], -dt, upx), convect([upx, upy], -dt, upy)]'* [vx, vy]
    )
  + on(noslip, ux=0, uy=0)
  + on(inflow, ux=uin, uy=0)
 ;

```

where up variables are the ones related to the previous time-step.  
Thus, I have tried to directly implement the weak formulation of my problem, but it does not work. The related code is the following one:

```auto
varf navierstokes([ux, uy, p], [vx, vy, q]) = int2d(Th)(
      rho/dt* [ux, uy]'* [vx, vy] 
    + mu* (Grad(u):Grad(v))
    - p* div(v)
    - q* div(u)
    - 1e-10 *p*q    
	)
	+ int2d(Th) (
      [fx, fy]' * [vx, vy]
    - rho/dt* [upx,upy]'*[vx, vy] 
	)
	+int2d(Th)(
	[upx,upy]'*Grad(u)*[vx, vy]
	)
  + on(noslip, ux=0, uy=0)
  + on(inflow, ux=uin, uy=0)
 ;

```

Have someone ever had the same problem? Can you help me?

Thanks in advance

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [August 14, 2023, 3:05pm UTC](https://community.freefem.org/t/convective-term-unsteady-2d-ns-equations/2655/2 "2023-08-14T15:05:24Z")

</div>

Without the whole script it is impossible to sort out the error.

Is your problem is small and 2D, you can use the following approach:

> <https://github.com/denissipp/AMR_Sipp_Schmid_2016/blob/master/Codes/Cavity/DNS/dns.edp>

This code uses implicit time stepping and LU factorization, and solves the perturbation for of the equations (stationary base flow and solves for the fluctuations). It worked for me nicely.
