2020-08-18 14:27:28 +02:00
|
|
|
/*
|
|
|
|
* =======================================================================================
|
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* Author: Jan Eitzinger (je), jan.eitzinger@fau.de
|
|
|
|
* Copyright (c) 2020 RRZE, University Erlangen-Nuremberg
|
2020-08-18 14:27:28 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* This file is part of MD-Bench.
|
2020-08-18 14:27:28 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* MD-Bench is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-08-18 14:27:28 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* MD-Bench is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
* details.
|
2020-08-18 14:27:28 +02:00
|
|
|
*
|
2020-08-19 10:47:40 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
* with MD-Bench. If not, see <https://www.gnu.org/licenses/>.
|
2020-08-18 14:27:28 +02:00
|
|
|
* =======================================================================================
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <pbc.h>
|
|
|
|
#include <atom.h>
|
|
|
|
#include <allocate.h>
|
|
|
|
|
|
|
|
#define DELTA 20000
|
|
|
|
|
|
|
|
static int NmaxGhost;
|
|
|
|
static int *BorderMap;
|
|
|
|
static int *PBCx, *PBCy, *PBCz;
|
|
|
|
|
|
|
|
static void growPbc();
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* exported subroutines */
|
2020-08-18 14:27:28 +02:00
|
|
|
void initPbc()
|
|
|
|
{
|
|
|
|
NmaxGhost = 0;
|
|
|
|
BorderMap = NULL;
|
|
|
|
PBCx = NULL; PBCy = NULL; PBCz = NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* update coordinates of ghost atoms */
|
|
|
|
/* uses mapping created in setupPbc */
|
2020-08-18 14:27:28 +02:00
|
|
|
void updatePbc(Atom *atom, Parameter *param)
|
|
|
|
{
|
|
|
|
int nlocal = atom->Nlocal;
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT xprd = param->xprd;
|
|
|
|
MD_FLOAT yprd = param->yprd;
|
|
|
|
MD_FLOAT zprd = param->zprd;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nghost; i++) {
|
2021-03-20 18:32:50 +01:00
|
|
|
set_atom_x(atom, nlocal + i, get_atom_x(atom, BorderMap[i]) + PBCx[i] * xprd);
|
|
|
|
set_atom_y(atom, nlocal + i, get_atom_y(atom, BorderMap[i]) + PBCy[i] * yprd);
|
|
|
|
set_atom_z(atom, nlocal + i, get_atom_z(atom, BorderMap[i]) + PBCz[i] * zprd);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* relocate atoms that have left domain according
|
|
|
|
* to periodic boundary conditions */
|
2020-08-18 14:27:28 +02:00
|
|
|
void updateAtomsPbc(Atom *atom, Parameter *param)
|
|
|
|
{
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT xprd = param->xprd;
|
|
|
|
MD_FLOAT yprd = param->yprd;
|
|
|
|
MD_FLOAT zprd = param->zprd;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2021-03-20 18:32:50 +01:00
|
|
|
MD_FLOAT x = get_atom_x(atom, i);
|
|
|
|
MD_FLOAT y = get_atom_y(atom, i);
|
|
|
|
MD_FLOAT z = get_atom_z(atom, i);
|
|
|
|
|
|
|
|
if(x < 0.0) {
|
|
|
|
set_atom_x(atom, i, x + xprd);
|
|
|
|
} else if(x >= xprd) {
|
|
|
|
set_atom_x(atom, i, x - xprd);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-20 18:32:50 +01:00
|
|
|
if(y < 0.0) {
|
|
|
|
set_atom_y(atom, i, y + yprd);
|
|
|
|
} else if(y >= yprd) {
|
|
|
|
set_atom_y(atom, i, y - yprd);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-20 18:32:50 +01:00
|
|
|
if(z < 0.0) {
|
|
|
|
set_atom_z(atom, i, z + zprd);
|
|
|
|
} else if(z >= zprd) {
|
|
|
|
set_atom_z(atom, i, z - zprd);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* setup periodic boundary conditions by
|
|
|
|
* defining ghost atoms around domain
|
|
|
|
* only creates mapping and coordinate corrections
|
|
|
|
* that are then enforced in updatePbc */
|
2020-08-18 14:27:28 +02:00
|
|
|
#define ADDGHOST(dx,dy,dz) Nghost++; BorderMap[Nghost] = i; PBCx[Nghost] = dx; PBCy[Nghost] = dy; PBCz[Nghost] = dz;
|
|
|
|
void setupPbc(Atom *atom, Parameter *param)
|
|
|
|
{
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT xprd = param->xprd;
|
|
|
|
MD_FLOAT yprd = param->yprd;
|
|
|
|
MD_FLOAT zprd = param->zprd;
|
|
|
|
MD_FLOAT Cutneigh = param->cutneigh;
|
2020-08-18 14:27:28 +02:00
|
|
|
int Nghost = -1;
|
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
|
|
|
|
|
|
|
if (atom->Nlocal + Nghost + 7 >= atom->Nmax) {
|
|
|
|
growAtom(atom);
|
|
|
|
}
|
|
|
|
if (Nghost + 7 >= NmaxGhost) {
|
|
|
|
growPbc();
|
|
|
|
}
|
|
|
|
|
2021-03-20 18:32:50 +01:00
|
|
|
MD_FLOAT x = get_atom_x(atom, i);
|
|
|
|
MD_FLOAT y = get_atom_y(atom, i);
|
|
|
|
MD_FLOAT z = get_atom_z(atom, i);
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
/* Setup ghost atoms */
|
|
|
|
/* 6 planes */
|
2021-03-20 18:32:50 +01:00
|
|
|
if (x < Cutneigh) { ADDGHOST(+1,0,0); }
|
|
|
|
if (x >= (xprd-Cutneigh)) { ADDGHOST(-1,0,0); }
|
|
|
|
if (y < Cutneigh) { ADDGHOST(0,+1,0); }
|
|
|
|
if (y >= (yprd-Cutneigh)) { ADDGHOST(0,-1,0); }
|
|
|
|
if (z < Cutneigh) { ADDGHOST(0,0,+1); }
|
|
|
|
if (z >= (zprd-Cutneigh)) { ADDGHOST(0,0,-1); }
|
2020-08-18 14:27:28 +02:00
|
|
|
/* 8 corners */
|
2021-03-20 18:32:50 +01:00
|
|
|
if (x < Cutneigh && y < Cutneigh && z < Cutneigh) { ADDGHOST(+1,+1,+1); }
|
|
|
|
if (x < Cutneigh && y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(+1,-1,+1); }
|
|
|
|
if (x < Cutneigh && y >= Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(+1,+1,-1); }
|
|
|
|
if (x < Cutneigh && y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(+1,-1,-1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && y < Cutneigh && z < Cutneigh) { ADDGHOST(-1,+1,+1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(-1,-1,+1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && y < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(-1,+1,-1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(-1,-1,-1); }
|
2020-08-18 14:27:28 +02:00
|
|
|
/* 12 edges */
|
2021-03-20 18:32:50 +01:00
|
|
|
if (x < Cutneigh && z < Cutneigh) { ADDGHOST(+1,0,+1); }
|
|
|
|
if (x < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(+1,0,-1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && z < Cutneigh) { ADDGHOST(-1,0,+1); }
|
|
|
|
if (x >= (xprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(-1,0,-1); }
|
|
|
|
if (y < Cutneigh && z < Cutneigh) { ADDGHOST(0,+1,+1); }
|
|
|
|
if (y < Cutneigh && z >= (zprd-Cutneigh)) { ADDGHOST(0,+1,-1); }
|
|
|
|
if (y >= (yprd-Cutneigh) && z < Cutneigh) { ADDGHOST(0,-1,+1); }
|
|
|
|
if (y >= (yprd-Cutneigh) && z >= (zprd-Cutneigh)) { ADDGHOST(0,-1,-1); }
|
|
|
|
if (y < Cutneigh && x < Cutneigh) { ADDGHOST(+1,+1,0); }
|
|
|
|
if (y < Cutneigh && x >= (xprd-Cutneigh)) { ADDGHOST(-1,+1,0); }
|
|
|
|
if (y >= (yprd-Cutneigh) && x < Cutneigh) { ADDGHOST(+1,-1,0); }
|
|
|
|
if (y >= (yprd-Cutneigh) && x >= (xprd-Cutneigh)) { ADDGHOST(-1,-1,0); }
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
// increase by one to make it the ghost atom count
|
|
|
|
atom->Nghost = Nghost + 1;
|
|
|
|
}
|
2020-08-19 09:00:35 +02:00
|
|
|
|
|
|
|
/* internal subroutines */
|
|
|
|
void growPbc()
|
|
|
|
{
|
|
|
|
int nold = NmaxGhost;
|
|
|
|
NmaxGhost += DELTA;
|
|
|
|
|
|
|
|
BorderMap = (int*) reallocate(BorderMap, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
PBCx = (int*) reallocate(PBCx, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
PBCy = (int*) reallocate(PBCy, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
PBCz = (int*) reallocate(PBCz, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
}
|