# HPDDM 3D periodic Cube

**URL:** <https://community.freefem.org/t/hpddm-3d-periodic-cube/228>\
**Category:** General Discussion\
**Created:** [January 21, 2020, 10:51am UTC](https://community.freefem.org/t/hpddm-3d-periodic-cube/228 "2020-01-21T10:51:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abrunk](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@abrunk](https://community.freefem.org/u/abrunk)\
**Post date:** [January 21, 2020, 10:51am UTC](https://community.freefem.org/t/hpddm-3d-periodic-cube/228/1 "2020-01-21T10:51:23Z")

</div>

Hi,

I’m trying to use the HPDDM solver by PETSC on a full periodic cube in 3D. So far I tried to orient myself on this example:

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/diffusion-periodic-balanced-2d-PETSc.edp>

  
If I use the unbalanced one the mesh creation takes like forever.  
Unfortunately, it is not working. Has somebody tried this or even has code for this. I mean the periodic cube should be the easiest example.

---

<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:** [January 21, 2020, 12:24pm UTC](https://community.freefem.org/t/hpddm-3d-periodic-cube/228/2 "2020-01-21T12:24:44Z")

</div>

Are all of your faces using periodic boundary conditions? What is you 3D script, and what are its performance? There are things that can be improved in this example, it will depend on your exact geometry.

---

<div class="post-metadata">

**Author:** ![abrunk](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@abrunk](https://community.freefem.org/u/abrunk)\
**Post date:** [January 21, 2020, 1:55pm UTC](https://community.freefem.org/t/hpddm-3d-periodic-cube/228/3 "2020-01-21T13:55:02Z")

</div>

Yes all faces use periodic BC. The simple starting example is:

// run with MPI: ff-mpirun -np 4 script.edp  
// NBPROC 4

load “PETSc” // PETSc plugin  
macro dimension()3// EOM // 2D or 3D  
include “macro\_ddm.idp” // additional DDM functions  
include “cube.idp”  
macro def(i)[i, i#B, i#C, i#D]// // vector field definition  
macro init(i)[i, i, i, i]// EOM // vector field initialization  
macro grad(u)[dx(u), dy(u), dz(u)]//// two-dimensional gradient  
real Sqrt = sqrt(2.);  
macro div(u)(dx(u) + dy(u#B) + dz(u#C))// EOM  
int[int] labPeriodic = [1, 3, 2, 4, 5, 6];  
macro Pk() [P1,P1,P1,P1], periodic=[[labPeriodic[0],x,z], [labPeriodic[1],x,z],[labPeriodic[2],y,z],[labPeriodic[3],y,z],[labPeriodic[4],x,y],[labPeriodic[5],x,y]]// EOM

int[int] LL = [1,2,3,4,5,6];  
real a=128.0;  
int ref = 128;  
mesh3 Th = cube(ref,ref,ref,[a_x,a_y,a\*z],label=LL);

fespace Wh(Th, Pk); // local finite element space  
int[int][int] intersection; // local-to-neighbors renumbering  
real[int] D; // partition of unity  
{  
buildPeriodic(Th, 1, intersection, D, Pk, mpiCommWorld, labPeriodic)  
}  
//fespace Wh(Th, Pk); // local finite element space  
varf vPb([u, uB, uC, p], [v, vB, vC, q]) = intN(Th)(grad(u)’ \* grad(v) + grad(uB)’ \* grad(vB) + grad(uC)’ \* grad(vC) - div(u) \* q - div(v) \* p + 1e-10 \* p \* q);  
matrix Loc = vPb(Wh, Wh);  
real[int] rhs = vPb(0, Wh);  
Mat A(Loc, intersection, D);

set(A, sparams = “-pc\_type lu -pc\_factor\_mat\_solver\_type mumps”);  
Wh def(u);

A = Loc;  
u[] = A^-1 \* rhs;

macro def1(u)u// EOM  
plotMPI(Th, u, P2, def1, real, cmm = “Global solution”)

In this way it takes several hours only for the partion of the mesh and space. Later I want to upgrade to more complex porblems, but for start this one is quite nice.

---

<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:** [January 21, 2020, 6:51pm UTC](https://community.freefem.org/t/hpddm-3d-periodic-cube/228/4 "2020-01-21T18:51:12Z")

</div>

How about the “balanced” equivalent, have you implemented it yourself?
