0

I am trying to implement periodic boundary conditions for 2d lattice.

I did:

```
int boundary2d(int xpos,int ypos,int stepx,int stepy){
int x=4,y=4; //grid size
int **matrix; //the grid matrix
int i=stepx+xpos;
int j=stepy+ypos;
if (i<0) {
do {
i+=Nx;
}while (i>Nx-1);
}
if (i>Nx-1) {
do{
i-=Nx;
}while(i>Nx-1);
}
if (j<0) {
do {
j+=Ny;
}while (j>Ny-1);
}
if (j>Ny-1) {
do{
j-=Ny;
}while(j>Ny-1);
}
return matrix[i][j];
}
```

I don't know if i have the conditions right.

Could you help me?

Thank you!