# Boundary condition in periodic mesh

**URL:** <https://community.freefem.org/t/boundary-condition-in-periodic-mesh/3880>\
**Category:** General Discussion\
**Created:** [April 24, 2025, 9:43am UTC](https://community.freefem.org/t/boundary-condition-in-periodic-mesh/3880 "2025-04-24T09:43:31Z")\
**Posts on this page:** 3\
**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 24, 2025, 9:43am UTC](https://community.freefem.org/t/boundary-condition-in-periodic-mesh/3880/1 "2025-04-24T09:43:31Z")

</div>

hello everyone, i have juste i small probleme about defining a dirichlet contion in down (y=-1)and up boundary (y=-1 +ny\*L) for the hall domain, it’s a porous media problem and i try to represent the solution in MACRO schele with darcy equation ,this is the code .  
"load “msh3”  
load “iovtk”

// Paramètres  
real r = 0.2;  
int n = 10;

// Définition des bords (identique à votre code macro)  
border C01(t=-r, r){x=-1; y=t; label=10;}  
border C02(t=-1, -r){x=t; y=r; label=1;}  
border C03(t=-1, -r){x=t; y=-r; label=2;}  
border C04(t=r, 1){x=-r; y=t; label=3;}  
border C05(t=-1, -r){x=-r; y=t; label=4;}  
border C06(t=-r, r){x=t; y=1; label=11;}  
border C07(t=-r, r){x=t; y=-1; label=22;}  
border C08(t=-1, -r){x=r; y=t; label=5;}  
border C09(t=r, 1){x=r; y=t; label=6;}  
border C10(t=r, 1){x=t; y=r; label=7;}  
border C11(t=r, 1){x=t; y=-r; label=8;}  
border C12(t=-r, r){x=1; y=t; label=36;}

// Construction du maillage de base  
mesh ThBase = 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));

// Création du domaine périodique macro  
int nx = 10, ny = 10;  
real L = 2.0;  
mesh ThMulti = movemesh(ThBase, [x, y]);

for (int i = 0; i \< nx; i++) {  
for (int j = 0; j \< ny; j++) {  
if (i != 0 || j != 0) {  
mesh ThTmp = movemesh(ThBase, [x + i_L, y + j_L]);  
ThMulti = ThMulti + ThTmp;  
}  
}  
}

plot(ThMulti, wait=true, cmm=“Domaine macro”);

fespace Vh(ThMulti, P1);  
Vh p, q; // Pression  
real K=0.001;  
real mu=1;  
real Pup= 100;  
real Pdown = 200;  
problem Darcy(p, q)  
= int2d(ThMulti)( K \* dx(p)\*dx(q) + K \* dy(p)\*dy(q) )

- on(??, p = Pup)
- on(??, p = Pdown);

// Résolution  
Darcy;

// Champ de vitesse macroscopique  
Vh vx = -K/mu \* dx(p);  
Vh vy = -K/mu \* dy(p);

// Visualisation  
plot(p, fill=true, value=true, wait=true, cmm=“Pression P^0”);  
plot([vx, vy], wait=true, cmm=“Champ de vitesse macroscopique V^0”);

fespace Vh1(ThMulti, P1);  
Vh1 Ux1 = vx, Uy1 = vy, p1 = p;

```
int[int] order = [1, 1, 1]; 
savevtk("StokesSolutionnn.vtu", ThMulti, Ux1, Uy1, p1, 
        dataname="Velocity_X Velocity_Y Pressure", order=order);

        " and thank you so much for your help

```

---

<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 24, 2025, 12:21pm UTC](https://community.freefem.org/t/boundary-condition-in-periodic-mesh/3880/2 "2025-04-24T12:21:43Z")

</div>

Hello,  
You have to use the command `change` to change the labels. For example

```auto
labs=[22,100];
 ThTmp = change(ThTmp,refe=labs);

```

changes the boundary label 22 to the new value 100.  
You can also remove internal edges by  
`ThMulti = change(ThMulti,rmInternalEdges=true);`

I have put the label 100 on the bottom edges, and 200 on the top edges.  
[porous-periodic.edp](https://community.freefem.org/uploads/short-url/r1NEruFUyB63q0F6qquTRyvol2V.edp) (2.0 KB)

---

<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 24, 2025, 1:05pm UTC](https://community.freefem.org/t/boundary-condition-in-periodic-mesh/3880/3 "2025-04-24T13:05:04Z")

</div>

It works perfectly,thank you so much !!
