# Prevent free particles to cross triangles(angles)

Hello,

I am trying to write a fix to prevent free particles to cross triangles. The triangle is present by angle. So I need to search the neighbors of each angle. With Steve’s and Axel’s help and advice, I have solve the search problem by uses a full neighbour list with include neighbors of ghosts.

In my cpp file, I implement initial_integrate and end_of_step methods, and their main contents are as follows:

• initial_integrate: search the neighbors of each angle to find the particles which will cross the triangle, and recorded if cross by a bool array ifreflect. if a particle cross a triangle, according to the position and velocity of the triangle and the particle, Compute the new postition xtmp and new velocity vtmp of the particle.
/* ---------------------------------------------------------------------- */
for (i = 0; i < nlocal; i++){
if (mask[i] & groupbit) ifreflect[i] = false;
}

for (n = 0; n < nanglelist; n++) {
i1 = anglelist[n][0];
i2 = anglelist[n][1];
i3 = anglelist[n][2];
for j in the neighbors of n angle’s three atoms.
{
if (ifreflect[j]) continue;

if ( particle i not intersect with triangle (x[i1], x[i2], x[i3]) ) continue;
ifreflect[j] = true;

// Compute the new postition xtmp and new velocity vtmp
vtmp[j] = vfunction(v[i1], v[i2], v[i3]);
xtmp[j] = xfunction(x[i1], x[i2], x[i3]);

}
}
/* ---------------------------------------------------------------------- */

• end_of_step: if a particle’s ifreflect value is true, it means the particle will cross a triangle. To prevent this from happening, update the velocity and position of the paritlce:
/* ---------------------------------------------------------------------- /
if (ifreflect[i]){
v[i][0] = vtmp[i][0]; v[i][0] = vtmp[i][1]; v[i][0] = vtmp[i][2];
x[i][0] = xtmp[i][0]; x[i][0] = xtmp[i][1]; x[i][0] = xtmp[i][2];
}
/
---------------------------------------------------------------------- */

But there is a new problem. In order to track ifreflect, vtmp and xtmp correctly, I implement memory_usage, grow_arrays, copy_arrays, pack_exchange and unpack_exchange methods. But it gives wrong result when I use multi-processors. A few particles’ ifreflect value does not match with its xtmp and vtmp value in the end_of_step. I can’t quite understand what’s wrong with my implement of memory_usage, grow_arrays, copy_arrays, pack_exchange and unpack_exchange methods.

/* ---------------------------------------------------------------------- */
void Fixxxx::copy_arrays(int i, int j, int delflag)
{
xtmp[j][0] = xtmp[i][0]; xtmp[j][1] = xtmp[i][1]; xtmp[j][2] = xtmp[i][2];
vtmp[j][0] = vtmp[i][0]; vtmp[j][1] = vtmp[i][1]; vtmp[j][2] = vtmp[i][2];
ifreflect[j] = ifreflect[i];
}

/* ---------------------------------------------------------------------- */

int Fixxxx::pack_exchange(int i, double buf)
{
buf[0] = xtmp[i][0]; buf[1] = xtmp[i][1]; buf[2] = xtmp[i][2];
buf[3] = vtmp[i][0]; buf[4] = vtmp[i][1]; buf[5] = vtmp[i][2];
buf[6] = ifreflect[i];
return 7;
}
/
---------------------------------------------------------------------- */

int Fixxxx::unpack_exchange(int nlocal, double buf)
{
xtmp[nlocal][0] = buf[0]; xtmp[nlocal][1] = buf[1]; xtmp[nlocal][2] = buf[2];
vtmp[nlocal][0] = buf[3]; vtmp[nlocal][1] = buf[4]; vtmp[nlocal][2] = buf[5];
ifreflect[nlocal] = buf[6];
return 7;
}
/
---------------------------------------------------------------------- */

Regards,
Zhou

Glad you got it to work …

Steve