# Periodic Neumann Boundary Conditions (2D Channel)

**URL:** https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855
**Category:** General Discussion
**Created:** [December 27, 2023, 1:04pm UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855 "2023-12-27T13:04:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![C98](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@C98](https://community.freefem.org/u/C98)
#### Post date: [December 27, 2023, 1:04pm UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/1 "2023-12-27T13:04:23Z")

</div>

Hi, I am new to FreeFem++, and I am trying to simulate the unsteady Navier-Stokes equations in a 2D channel [0,1]\times[0,1] with some periodic boundary conditions. I denote the tangential velocity by u\_1, the normal velocity by u\_2, and the pressure by Pr.

The boundary conditions are  
u\_1(0, y) = u\_1 (1, y),  
u\_2(0, y) = u\_2 (1, y),   
\partial\_xu\_2(0, y) = \partial\_xu\_2(1, y),  
Pr(0, y) = Pr(1, y) + a,  
u\_1(x, 0) = 0,  
u\_1(x, 1) = 0,   
u\_2(x, 0) = f(x,t),  
u\_2(x, 1) = 0,  
where a is some nonnegative constant, and f(x,t) is a given function.

To deal with the periodic Dirichlet boundary conditions, I use the ‘periodic’ function in the definition of the element space. Since we cannot mix periodic and non-periodic elements, I define p := Pr - Pbar, where Pbar = -ax+1, so that p is periodic, and I use p in the variational formulation.

My big problem now is how to implement the periodic Neumann boundary condition? In my code, everything runs without problem but I did not specify anywhere the periodic Neumann boundary condition, so I guess the simulated solution is just wrong. How to specify periodic Neumann boundary conditions?

My code is below (with f=0 and a=0.5):

```auto
// Parameters
real dt = 0.5; // Time step
int meshSize = 50;
real L= 1;
real RE = 1000;

// Mesh boundary
border b1(s = 0, 1){x=s*L; y=0; label=1;}
border b2(s= 0, 1){x=L; y= s; label=2;}
border b3(s= 0, 1){x=L-s*L; y= 1; label=3;}
border b4(s= 0, 1){x=0; y= 1-s; label=4;}

func perio=[[4,y],[2,y]];

mesh Th = buildmesh(b1(meshSize) + b2(meshSize) + b3(meshSize) + b4(meshSize));

plot(Th, wait=true);

fespace Vh(Th, P1, periodic=perio);
Vh u1, v1, u2, v2, p, q, up1, up2, pp;

int i=0;
real alpha=1/dt;
real nu = 1/RE;
real epsi = 0.00001;
real a = 0.5;
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)
        )
        - p*q*(epsi)
        - p*dx(v1) - p*dy(v2)
        - dx(u1)*q - dy(u2)*q
        )
    + int2d(Th)(a*x*q*(epsi) + a*x*dx(v1) + a*x*dy(v2))
    - int2d(Th)(1*q*(epsi)+1*dx(v1)+1*dy(v2))
    + int2d(Th)(
        - alpha*convect([up1,up2],-dt,up1)*v1
        - alpha*convect([up1,up2],-dt,up2)*v2)
    + on(1, 3, u1=0)
    + on(3, u2=0)
    + on(1, u2=0);

u1 = -cos(pi*x/4.0)*exp(-y*y/2.0);
u2 = 0;
p = -cos(pi*x/4.0)*exp(-y*y/2.0)+a*x-1;

for (i = 0; i <= 500000; i++){
    // Update
    pp = p;
    up1 = u1;
    up2 = u2;
    //vort = dx(u2)-dy(u1);
    // Solve
    NS;

    // Plot
    plot([u1,u2], fill=true);
  }

```

Thank you in advance for your answers,

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [December 27, 2023, 3:57pm UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/2 "2023-12-27T15:57:24Z")

</div>

1. just a first remark, the characteristics method in not correctly implemented with periodic probem ( no way to day).

2. no problem with Periodic Neumann become the function u will be peridic so dx(u)  
is also periodic.

3. the characteristic method need a CFL close too 1 , a here the velocity is proportional to RE.

4. p is defined through a constant so int2d(Th)(p) == 0 to set this constante.

Some correction but you have to change the method for do the Non linear part.

[perio-NS.edp](https://community.freefem.org/uploads/short-url/uq2cK2b1aki5WmvF1YSy68WfOET.edp) (1.4 KB)

---

<div class="post-metadata">

### Author: ![C98](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@C98](https://community.freefem.org/u/C98)
#### Post date: [December 29, 2023, 12:18pm UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/3 "2023-12-29T12:18:07Z")

</div>

Thank you very much for your answer! It is very clear now. I will see how to implement the convective part.

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [December 29, 2023, 3:48pm UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/4 "2023-12-29T15:48:21Z")

</div>

you can just do for the term u.\nabla u the previous u like up.\nabla u ,  
in this cas you mush rebuild the matrix in the loop so init = 1

---

<div class="post-metadata">

### Author: ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)
#### Post date: [November 24, 2025, 8:52am UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/5 "2025-11-24T08:52:25Z")

</div>

Dear Prof. Hecht,  
The **characteristics method** is **not correctly implemented** when combined with **periodic boundary conditions** in FreeFem++. Is it fixed in the recent development?  
Thank you.

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [January 28, 2026, 10:30am UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/6 "2026-01-28T10:30:05Z")

</div>

No, because it is too hard to do.

---

<div class="post-metadata">

### Author: ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)
#### Post date: [January 29, 2026, 2:06am UTC](https://community.freefem.org/t/periodic-neumann-boundary-conditions-2d-channel/2855/7 "2026-01-29T02:06:21Z")

</div>

OK. Thank you so much.
