# Periodic boundary conditions on Gmsh mesh

**URL:** <https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413>\
**Category:** General Discussion\
**Created:** [July 25, 2024, 2:43pm UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413 "2024-07-25T14:43:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [July 25, 2024, 2:43pm UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/1 "2024-07-25T14:43:59Z")

</div>

Hello,

I am trying to solve a problem with periodic BCs on a pair of opposite faces. The 3D mesh is built with Gmsh. I was careful to have identical 2D meshes on the two faces when building the mesh (using the Gmsh command `Periodic Surface {...} = {...} Translate {...};`).

Everything works fine if I don’t try to impose periodic BCs, but I get an error message that looks like this if I define a FE space with periodic BCs:

```auto
Exec error : Periodic 3d: the both number of face is not the same
   -- number :1
 err code 8 , mpirank 3
 vertex : 9 31.1703 0 0 214 Abscisses: s = 31.1703 0 2 0
 missing Border element : 555 105 107 194
 vertex : 282 -17.8123 13.1265 0 312 Abscisses: s = -17.8123 13.1265 23 141
 Exec error : periodic: Sorry one vertex of face is losted

```

Here is something close to a MWE:

```auto
load "msh3"
load "PETSc"        
load "gmsh"
int[int] n2oSaved;
int[int] n2oLoaded;
macro dimension()3// EOM            
include "macro_ddm.idp"             
macro def(i)[i, i#B, i#C, i#D]//   
macro init(i)[i, i, i, i]// EOM    
func Pk = [P1b,P1b,P1b,P1];
mesh3 Th = readmesh3("mesh.mesh");

Mat A;
macro ThN2O()n2oSaved//
createMat(Th, A, Pk); 
fespace Wh(Th, Pk); // works 
fespace Wh(Th, Pk, periodic=[[6,x,y],[7,x,y]]); // does not work

```

I can send the mesh if needed.

Has anyone faced the same problem or, conversely, managed to use periodic BCs with a Gmsh mesh?

Thank you.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [July 26, 2024, 8:58am UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/2 "2024-07-26T08:58:03Z")

</div>

Indeed, we need the mesh.

---

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [July 26, 2024, 12:16pm UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/3 "2024-07-26T12:16:43Z")

</div>

Here it is: [mesh.mesh](https://community.freefem.org/uploads/short-url/USIIsDeN466fG89Lxb15sqU1WJ.mesh) (243.5 KB).  
I modified it slightly in the meantime, so the specific numbers (labels, coordinates etc) in the error message are different, but qualitatively it is the same idea.

Thanks.

---

<div class="post-metadata">

**Author:** ![etj](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@etj](https://community.freefem.org/u/etj)\
**Post date:** [August 1, 2024, 9:36am UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/4 "2024-08-01T09:36:29Z")

</div>

Hi,  
Did you prj (or someone else) had the chance to have a look? Thank you.

---

<div class="post-metadata">

**Author:** ![GiacomoSperoni97](https://avatars.discourse-cdn.com/v4/letter/g/ecc23a/32.png) [@GiacomoSperoni97](https://community.freefem.org/u/GiacomoSperoni97)\
**Post date:** [February 7, 2025, 1:30pm UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/5 "2025-02-07T13:30:21Z")

</div>

Dear etj,

I tried running your code snippet with your mesh. The mesh you created is periodic on labels 6 and 7 - indeed, if you execute your code with `ff-mpirun -np 1` it works as expected.  
However, when running in parallel, the decomposition performed by `MatCreate` does not preserve the periodicity that you want to impose on the local mesh - you can also verify this visually using the Medit interface or by saving the `.vtu` of your decomposed mesh.

There are some example that you can follow on the provided FreeFem++ sources, like [diffusion-periodic-2d-PETSc.edp](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/diffusion-periodic-2d-PETSc.edp).

I hope this helps,

Giacomo

---

<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:33pm UTC](https://community.freefem.org/t/periodic-boundary-conditions-on-gmsh-mesh/3413/6 "2025-04-08T14:33:05Z")

</div>

I do a small exemple with your mesh no problem form me

[tt.edp](https://community.freefem.org/uploads/short-url/ikTf6t9LOF1zkthU1MEapACZipp.edp) (426 Bytes)
