# Periodic conditions boundary

**URL:** <https://community.freefem.org/t/periodic-conditions-boundary/3841>\
**Category:** General Discussion\
**Created:** [April 8, 2025, 12:32pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841 "2025-04-08T12:32:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://community.freefem.org/u/taha)\
**Post date:** [April 8, 2025, 12:32pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/1 "2025-04-08T12:32:03Z")

</div>

hello everyone, i’m trying to put periodic condition on stokes equation "real Mu = 1.;   
real pEps = 1.e-10;

border C01(t=-0.05, 0.05){x=-1; y=t; label=10;}  
border C02(t=-1, -0.05){x=t; y=0.05; label=1;}  
border C03(t=-1, -0.05){x=t; y=-0.05; label=2;}  
border C04(t=0.05, 1){x=-0.05; y=t; label=3;}  
border C05(t=-1, -0.05){x=-0.05; y=t; label=4;}  
border C06(t=-0.05, 0.05){x=t; y=1; label=11;}  
border C07(t=-0.05, 0.05){x=t; y=-1; label=22;}  
border C08(t=-1, -0.05){x=0.05; y=t; label=5;}  
border C09(t=0.05, 1){x=0.05; y=t; label=6;}  
border C10(t=0.05, 1){x=t; y=0.05; label=7;}  
border C11(t=0.05, 1){x=t; y=-0.05; label=8;}  
border C12(t=-0.05, 0.05){x=1; y=t; label=36;}

int n = 100;  
plot(C01(-n)+C02(-n)+ C03(-n)+C04(n)+C05(n)+ C06(n)

- C07(n)+ C08(n)+ C09(n)+ C10(n)+C11(n)+C12(n) , wait=true);

mesh Th = buildmesh(C01(-n)+C02(-n)+C04(-n)+ C06(-n)  
+C09(n)+C10(-n)+C12(n)+C11(n)+C08(n)+ C07(n)+C05(-n) + C03(n));

plot(Th, wait=true);

// Fespace  
fespace Uh(Th, P2,periodic=[[10,y],[36,y],[11,x],[22,x]]);  
Uh Ux, Uy;  
Uh Uhx, Uhy;

fespace Ph(Th, P1);  
Ph p;  
Ph ph;

// Macro  
macro grad(u) [dx(u), dy(u)] //  
macro Grad(U) [grad(U#x), grad(U#y)] //  
macro div(ux, uy) (dx(ux) + dy(uy)) //  
macro Div(U) div(U#x, U#y) //

// Problem  
problem Stokes ([Ux, Uy, p], [Uhx, Uhy, ph])  
= int2d(Th)(  
Mu \* (Grad(U) : Grad(Uh))  
- p _Div(Uh)  
- ph \* Div(U)  
- pEps \* p \* ph  
)  
+ int2d(Th)( 1 \* Uhx + 1_ Uhy)  
+ on(1,2,3,4,5,6,7,8, Ux=0, Uy=0)  
;

// Solve  
Stokes;

// Plot  
plot(Ux, fill=true, value=true, wait=true);

real area = int2d(Th)(1.0);

real Kxx = -int2d(Th)(Ux) / 4;  
real Kyy = -int2d(Th)(Uy) / 4;

cout \<\< "Kxx = " \<\< Kxx \<\< endl;  
cout \<\< “Kyy = " \<\< Kyy \<\< endl;  
" but it always give me this error"esh: Nb of Triangles = 132, Nb of Vertices 125  
Problem build of FEspace (2d) (may be : due to periodic Boundary condition missing ) FH  
The number of DF must be 811 and it is 887  
current line = 61  
Assertion fail : (snbdf == NbOfDF)  
line :937, in file ../femlib/FESpace.cpp  
Assertion fail : (snbdf == NbOfDF)  
line :937, in file ../femlib/FESpace.cpp  
err code 6 , mpirank 0” i have been struggling for a long time with this ,i really need your help ,and thank you so much in advance

---

<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:** [April 8, 2025, 2:01pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/2 "2025-04-08T14:01:51Z")

</div>

Use the composite tool to solve this problem  
see:

> **[Composite finite element spaces NEW!](https://doc.freefem.org/documentation/composite.html#composite-finite-element-spaces-new)**

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 8, 2025, 2:05pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/3 "2025-04-08T14:05:11Z")

</div>

It seems to me that the pressure space should be periodic also.  
Then you can use

```auto
fespace UPh(Th,[P2,P2,P1],periodic=[[10,y],[36,y],[11,x],[22,x]]);
UPh [Ux,Uy,p],[Uhx,Uhy,ph];

problem Stokes ([Ux, Uy, p], [Uhx, Uhy, ph])
= int2d(Th)(
Mu * (grad(Ux)'*grad(Uhx)+grad(Uy)'*grad(Uhy))
- p * div(Uhx,Uhy)
- ph * div(Ux,Uy)
- pEps * p * ph
)
+ int2d(Th)( 1 * Uhx + 1 * Uhy)
+ on(1,2,3,4,5,6,7,8, Ux=0, Uy=0)
;

```

---

<div class="post-metadata">

**Author:** ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://community.freefem.org/u/taha)\
**Post date:** [April 8, 2025, 3:30pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/4 "2025-04-08T15:30:31Z")

</div>

thank you so much it worked

---

<div class="post-metadata">

**Author:** ![taha](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@taha](https://community.freefem.org/u/taha)\
**Post date:** [April 8, 2025, 3:30pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/5 "2025-04-08T15:30:51Z")

</div>

thanks for your help

---

<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:** [April 10, 2025, 2:34pm UTC](https://community.freefem.org/t/periodic-conditions-boundary/3841/6 "2025-04-10T14:34:17Z")

</div>

I agree with François
