# Navier-Stokes periodic boundary conditions

**URL:** <https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327>\
**Category:** General Discussion\
**Created:** [November 15, 2021, 3:44pm UTC](https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327 "2021-11-15T15:44:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msjolly57](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@msjolly57](https://community.freefem.org/u/msjolly57)\
**Post date:** [November 15, 2021, 3:44pm UTC](https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327/1 "2021-11-15T15:44:35Z")

</div>

Hello,

I tried adapting the example NSE.edp in the FreeFem documentation to be fully periodic on the square. I get the error

Problem build of FEspace (2d) (may be : due to periodic Boundary condition missing ) FH  
The number of DF must be 3600 and it is 3803

I am hoping someone can point me to an example. The critical part of my code is below.

Thanks,

## Mike

fespace Xh(Th, P2, periodic=[[2, y], [4, y], [1, x], [3, x]]); //velocity component space  
fespace Mh(Th, P1, periodic=[[2, y], [4, y], [1, x], [3, x]]); //pressure space  
real dt = 0.01, nu=.1;  
real alpha=20/dt;  
Xh u2, v2, up1, up2;  
Xh u1, v1, f1, f2;  
Mh p, q;  
problem NS (u1, u2, p, v1, v2, q, solver=Crout, init=i)  
= int2d(Th)(  
alpha\*(u1_v1 + u2_v2)  
+ nu \* (  
dx(u1)_dx(v1) + dy(u1)dy(v1)  
+ dx(u2)dx(v2) + dy(u2)dy(v2)  
)  
- pq(0.000001)  
- pdx(v1) - p_dy(v2)  
- dx(u1)_q - dy(u2)q  
)  
+ int2d(Th)(  
- (f1v1+f2_v2)  
)  
+ int2d(Th)(  
- alpha\*convect([up1,up2],-dt,up1)_v1  
- alpha_convect([up1,up2],-dt,up2)\*v2  
)  
;

---

<div class="post-metadata">

**Author:** ![UgisL](https://avatars.discourse-cdn.com/v4/letter/u/c0e974/32.png) [@UgisL](https://community.freefem.org/u/UgisL)\
**Post date:** [November 18, 2021, 2:54pm UTC](https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327/2 "2021-11-18T14:54:05Z")

</div>

Hi Mike,

can you show us exactly how you define the mesh?

Best,  
Ugis

---

<div class="post-metadata">

**Author:** ![msjolly57](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@msjolly57](https://community.freefem.org/u/msjolly57)\
**Post date:** [November 18, 2021, 10:40pm UTC](https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327/3 "2021-11-18T22:40:58Z")

</div>

Dear Ugis,

Thanks for taking a look.

Here’s how I define the mesh:

Th = square(npts, npts, [2_x_pi, 2_y_pi]);

Full code is attached.

Kind regards,

Mike

[NSEper.edp](https://community.freefem.org/uploads/short-url/bY9YydwGdR0Mm6aiIlPDxwznsGE.edp) (1.19 KB)

---

<div class="post-metadata">

**Author:** ![UgisL](https://avatars.discourse-cdn.com/v4/letter/u/c0e974/32.png) [@UgisL](https://community.freefem.org/u/UgisL)\
**Post date:** [November 19, 2021, 6:15am UTC](https://community.freefem.org/t/navier-stokes-periodic-boundary-conditions/1327/4 "2021-11-19T06:15:18Z")

</div>

Hi again,

Thanks for the code. Now I see, the mesh should be fine. But the thing is if you use periodic conditions in FreeFEM along with vectorial equations, you had to use mixed FE space definition (vectorial space definition). Otherwise there is a problem with periodicty. I don’t know the exact reason, probably outcome of how the software is constructed.

In essence, instead of individual P1/P2 spaces, use:  
fespace UUPh(Th, [P2,P2,P1], periodic=[[2, y], [4, y], [1, x], [3, x]]); //fluid space

And header in problem definition:  
problem NS ([u1, u2, p], [v1, v2, q], solver=Crout, init=i)

Check the full modified code (seems to work on my computer).

Best,  
Ugis  
[NSEper\_UL.edp](https://community.freefem.org/uploads/short-url/t4V99VYZzVrmpWE5iMootPDEkQD.edp) (1.3 KB)
