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>
|
2022-01-31 17:49:22 +01:00
|
|
|
#include <math.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
#include <pbc.h>
|
|
|
|
#include <atom.h>
|
|
|
|
#include <allocate.h>
|
2022-01-25 21:00:11 +01:00
|
|
|
#include <neighbor.h>
|
2022-03-09 17:23:49 +01:00
|
|
|
#include <util.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
#define DELTA 20000
|
|
|
|
|
|
|
|
static int NmaxGhost;
|
|
|
|
|
2021-11-03 00:57:24 +01:00
|
|
|
static void growPbc(Atom*);
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* exported subroutines */
|
2022-01-25 00:43:10 +01:00
|
|
|
void initPbc(Atom* atom) {
|
2020-08-18 14:27:28 +02:00
|
|
|
NmaxGhost = 0;
|
2021-11-03 00:57:24 +01:00
|
|
|
atom->border_map = NULL;
|
2022-01-25 12:19:28 +01:00
|
|
|
atom->PBCx = NULL; atom->PBCy = NULL; atom->PBCz = NULL;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* update coordinates of ghost atoms */
|
|
|
|
/* uses mapping created in setupPbc */
|
2022-02-02 00:49:55 +01:00
|
|
|
void updatePbc(Atom *atom, Parameter *param, int firstUpdate) {
|
2022-03-10 01:31:50 +01:00
|
|
|
DEBUG_MESSAGE("updatePbc start\n");
|
2021-11-03 00:57:24 +01:00
|
|
|
int *border_map = atom->border_map;
|
2022-01-25 00:43:10 +01:00
|
|
|
int nlocal = atom->Nclusters_local;
|
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
|
|
|
|
2022-01-31 17:49:22 +01:00
|
|
|
for(int cg = 0; cg < atom->Nclusters_ghost; cg++) {
|
|
|
|
const int ci = nlocal + cg;
|
2022-03-09 02:25:39 +01:00
|
|
|
int ci_vec_base = CI_VECTOR_BASE_INDEX(ci);
|
|
|
|
int bmap_vec_base = CI_VECTOR_BASE_INDEX(border_map[cg]);
|
|
|
|
MD_FLOAT *ci_x = &atom->cl_x[ci_vec_base];
|
|
|
|
MD_FLOAT *bmap_x = &atom->cl_x[bmap_vec_base];
|
2022-01-31 17:49:22 +01:00
|
|
|
MD_FLOAT bbminx = INFINITY, bbmaxx = -INFINITY;
|
|
|
|
MD_FLOAT bbminy = INFINITY, bbmaxy = -INFINITY;
|
|
|
|
MD_FLOAT bbminz = INFINITY, bbmaxz = -INFINITY;
|
2022-01-25 00:43:10 +01:00
|
|
|
|
2022-03-09 17:23:49 +01:00
|
|
|
for(int cii = 0; cii < atom->iclusters[ci].natoms; cii++) {
|
2022-03-09 02:25:39 +01:00
|
|
|
MD_FLOAT xtmp = bmap_x[CL_X_OFFSET + cii] + atom->PBCx[cg] * xprd;
|
|
|
|
MD_FLOAT ytmp = bmap_x[CL_Y_OFFSET + cii] + atom->PBCy[cg] * yprd;
|
|
|
|
MD_FLOAT ztmp = bmap_x[CL_Z_OFFSET + cii] + atom->PBCz[cg] * zprd;
|
2022-01-31 17:49:22 +01:00
|
|
|
|
2022-03-09 02:25:39 +01:00
|
|
|
ci_x[CL_X_OFFSET + cii] = xtmp;
|
|
|
|
ci_x[CL_Y_OFFSET + cii] = ytmp;
|
|
|
|
ci_x[CL_Z_OFFSET + cii] = ztmp;
|
2022-01-31 17:49:22 +01:00
|
|
|
|
2022-02-02 00:49:55 +01:00
|
|
|
if(firstUpdate) {
|
2022-01-31 17:49:22 +01:00
|
|
|
// TODO: To create the bounding boxes faster, we can use SIMD operations
|
|
|
|
if(bbminx > xtmp) { bbminx = xtmp; }
|
|
|
|
if(bbmaxx < xtmp) { bbmaxx = xtmp; }
|
|
|
|
if(bbminy > ytmp) { bbminy = ytmp; }
|
|
|
|
if(bbmaxy < ytmp) { bbmaxy = ytmp; }
|
|
|
|
if(bbminz > ztmp) { bbminz = ztmp; }
|
|
|
|
if(bbmaxz < ztmp) { bbmaxz = ztmp; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-02 00:49:55 +01:00
|
|
|
if(firstUpdate) {
|
2022-03-09 17:23:49 +01:00
|
|
|
for(int cii = atom->iclusters[ci].natoms; cii < CLUSTER_M; cii++) {
|
2022-03-09 02:25:39 +01:00
|
|
|
ci_x[CL_X_OFFSET + cii] = INFINITY;
|
|
|
|
ci_x[CL_Y_OFFSET + cii] = INFINITY;
|
|
|
|
ci_x[CL_Z_OFFSET + cii] = INFINITY;
|
2022-02-02 00:49:55 +01:00
|
|
|
}
|
|
|
|
|
2022-03-09 02:25:39 +01:00
|
|
|
atom->iclusters[ci].bbminx = bbminx;
|
|
|
|
atom->iclusters[ci].bbmaxx = bbmaxx;
|
|
|
|
atom->iclusters[ci].bbminy = bbminy;
|
|
|
|
atom->iclusters[ci].bbmaxy = bbmaxy;
|
|
|
|
atom->iclusters[ci].bbminz = bbminz;
|
|
|
|
atom->iclusters[ci].bbmaxz = bbmaxz;
|
2022-01-25 00:43:10 +01:00
|
|
|
}
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
2022-03-10 01:31:50 +01:00
|
|
|
|
|
|
|
DEBUG_MESSAGE("updatePbc end\n");
|
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 */
|
2022-01-25 00:43:10 +01: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-23 10:03:55 +01:00
|
|
|
if(atom_x(i) < 0.0) {
|
|
|
|
atom_x(i) += xprd;
|
|
|
|
} else if(atom_x(i) >= xprd) {
|
|
|
|
atom_x(i) -= xprd;
|
2022-01-25 12:19:28 +01:00
|
|
|
}
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2021-03-23 10:03:55 +01:00
|
|
|
if(atom_y(i) < 0.0) {
|
|
|
|
atom_y(i) += yprd;
|
|
|
|
} else if(atom_y(i) >= yprd) {
|
|
|
|
atom_y(i) -= yprd;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-23 10:03:55 +01:00
|
|
|
if(atom_z(i) < 0.0) {
|
|
|
|
atom_z(i) += zprd;
|
|
|
|
} else if(atom_z(i) >= zprd) {
|
|
|
|
atom_z(i) -= 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 */
|
2022-01-31 23:46:20 +01:00
|
|
|
#define ADDGHOST(dx,dy,dz); \
|
|
|
|
Nghost++; \
|
2022-03-09 17:23:49 +01:00
|
|
|
const int cg = atom->Nclusters_local + Nghost; \
|
2022-03-09 02:25:39 +01:00
|
|
|
const int natoms_ci = atom->iclusters[ci].natoms; \
|
2022-01-31 23:46:20 +01:00
|
|
|
border_map[Nghost] = ci; \
|
|
|
|
atom->PBCx[Nghost] = dx; \
|
|
|
|
atom->PBCy[Nghost] = dy; \
|
|
|
|
atom->PBCz[Nghost] = dz; \
|
2022-03-09 17:23:49 +01:00
|
|
|
atom->iclusters[cg].natoms = natoms_ci; \
|
2022-03-09 02:25:39 +01:00
|
|
|
Nghost_atoms += natoms_ci; \
|
|
|
|
int ci_sca_base = CI_SCALAR_BASE_INDEX(ci); \
|
|
|
|
int cg_sca_base = CI_SCALAR_BASE_INDEX(cg); \
|
|
|
|
for(int cii = 0; cii < natoms_ci; cii++) { \
|
|
|
|
atom->cl_type[cg_sca_base + cii] = atom->cl_type[ci_sca_base + cii]; \
|
2022-01-25 00:43:10 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 12:19:28 +01:00
|
|
|
/* internal subroutines */
|
|
|
|
void growPbc(Atom* atom) {
|
|
|
|
int nold = NmaxGhost;
|
|
|
|
NmaxGhost += DELTA;
|
|
|
|
|
|
|
|
atom->border_map = (int*) reallocate(atom->border_map, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
atom->PBCx = (int*) reallocate(atom->PBCx, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
atom->PBCy = (int*) reallocate(atom->PBCy, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
atom->PBCz = (int*) reallocate(atom->PBCz, ALIGNMENT, NmaxGhost * sizeof(int), nold * sizeof(int));
|
|
|
|
}
|
|
|
|
|
2022-01-25 00:43:10 +01:00
|
|
|
void setupPbc(Atom *atom, Parameter *param) {
|
2022-03-10 01:31:50 +01:00
|
|
|
DEBUG_MESSAGE("setupPbc start\n");
|
2021-11-03 00:57:24 +01:00
|
|
|
int *border_map = atom->border_map;
|
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;
|
2022-01-31 23:46:20 +01:00
|
|
|
int Nghost_atoms = 0;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2022-01-25 00:43:10 +01:00
|
|
|
for(int ci = 0; ci < atom->Nclusters_local; ci++) {
|
2022-01-27 03:07:31 +01:00
|
|
|
if (atom->Nclusters_local + Nghost + 7 >= atom->Nclusters_max) {
|
2022-01-25 00:43:10 +01:00
|
|
|
growClusters(atom);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
2022-01-25 00:43:10 +01:00
|
|
|
|
2022-01-27 03:07:31 +01:00
|
|
|
if (Nghost + 7 >= NmaxGhost) {
|
2021-11-03 00:57:24 +01:00
|
|
|
growPbc(atom);
|
|
|
|
border_map = atom->border_map;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-09 02:25:39 +01:00
|
|
|
MD_FLOAT bbminx = atom->iclusters[ci].bbminx;
|
|
|
|
MD_FLOAT bbmaxx = atom->iclusters[ci].bbmaxx;
|
|
|
|
MD_FLOAT bbminy = atom->iclusters[ci].bbminy;
|
|
|
|
MD_FLOAT bbmaxy = atom->iclusters[ci].bbmaxy;
|
|
|
|
MD_FLOAT bbminz = atom->iclusters[ci].bbminz;
|
|
|
|
MD_FLOAT bbmaxz = atom->iclusters[ci].bbmaxz;
|
2022-01-27 03:07:31 +01:00
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
/* Setup ghost atoms */
|
|
|
|
/* 6 planes */
|
2022-01-25 00:43:10 +01:00
|
|
|
if (bbminx < Cutneigh) { ADDGHOST(+1,0,0); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh)) { ADDGHOST(-1,0,0); }
|
|
|
|
if (bbminy < Cutneigh) { ADDGHOST(0,+1,0); }
|
|
|
|
if (bbmaxy >= (yprd-Cutneigh)) { ADDGHOST(0,-1,0); }
|
|
|
|
if (bbminz < Cutneigh) { ADDGHOST(0,0,+1); }
|
|
|
|
if (bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(0,0,-1); }
|
2020-08-18 14:27:28 +02:00
|
|
|
/* 8 corners */
|
2022-01-25 00:43:10 +01:00
|
|
|
if (bbminx < Cutneigh && bbminy < Cutneigh && bbminz < Cutneigh) { ADDGHOST(+1,+1,+1); }
|
|
|
|
if (bbminx < Cutneigh && bbmaxy >= (yprd-Cutneigh) && bbminz < Cutneigh) { ADDGHOST(+1,-1,+1); }
|
|
|
|
if (bbminx < Cutneigh && bbminy < Cutneigh && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(+1,+1,-1); }
|
|
|
|
if (bbminx < Cutneigh && bbmaxy >= (yprd-Cutneigh) && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(+1,-1,-1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbminy < Cutneigh && bbminz < Cutneigh) { ADDGHOST(-1,+1,+1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbmaxy >= (yprd-Cutneigh) && bbminz < Cutneigh) { ADDGHOST(-1,-1,+1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbminy < Cutneigh && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(-1,+1,-1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbmaxy >= (yprd-Cutneigh) && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(-1,-1,-1); }
|
2020-08-18 14:27:28 +02:00
|
|
|
/* 12 edges */
|
2022-01-25 00:43:10 +01:00
|
|
|
if (bbminx < Cutneigh && bbminz < Cutneigh) { ADDGHOST(+1,0,+1); }
|
|
|
|
if (bbminx < Cutneigh && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(+1,0,-1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbminz < Cutneigh) { ADDGHOST(-1,0,+1); }
|
|
|
|
if (bbmaxx >= (xprd-Cutneigh) && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(-1,0,-1); }
|
|
|
|
if (bbminy < Cutneigh && bbminz < Cutneigh) { ADDGHOST(0,+1,+1); }
|
|
|
|
if (bbminy < Cutneigh && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(0,+1,-1); }
|
|
|
|
if (bbmaxy >= (yprd-Cutneigh) && bbminz < Cutneigh) { ADDGHOST(0,-1,+1); }
|
|
|
|
if (bbmaxy >= (yprd-Cutneigh) && bbmaxz >= (zprd-Cutneigh)) { ADDGHOST(0,-1,-1); }
|
|
|
|
if (bbminy < Cutneigh && bbminx < Cutneigh) { ADDGHOST(+1,+1,0); }
|
|
|
|
if (bbminy < Cutneigh && bbmaxx >= (xprd-Cutneigh)) { ADDGHOST(-1,+1,0); }
|
|
|
|
if (bbmaxy >= (yprd-Cutneigh) && bbminx < Cutneigh) { ADDGHOST(+1,-1,0); }
|
|
|
|
if (bbmaxy >= (yprd-Cutneigh) && bbmaxx >= (xprd-Cutneigh)) { ADDGHOST(-1,-1,0); }
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
2022-01-25 00:43:10 +01:00
|
|
|
|
2022-03-09 02:25:39 +01:00
|
|
|
if(atom->Nclusters_local + Nghost + 2 >= atom->Nclusters_max) {
|
2022-02-02 18:00:44 +01:00
|
|
|
growClusters(atom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add dummy cluster at the end
|
2022-03-09 02:25:39 +01:00
|
|
|
int ci_vec_base = CI_VECTOR_BASE_INDEX(atom->Nclusters_local + Nghost + 1);
|
|
|
|
MD_FLOAT *ci_x = &atom->cl_x[ci_vec_base];
|
|
|
|
for(int cii = 0; cii < MAX(CLUSTER_M, CLUSTER_N); cii++) {
|
|
|
|
ci_x[CL_X_OFFSET + cii] = INFINITY;
|
|
|
|
ci_x[CL_Y_OFFSET + cii] = INFINITY;
|
|
|
|
ci_x[CL_Z_OFFSET + cii] = INFINITY;
|
2022-02-02 18:00:44 +01:00
|
|
|
}
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
// increase by one to make it the ghost atom count
|
2022-01-31 23:46:20 +01:00
|
|
|
atom->Nghost = Nghost_atoms;
|
2022-01-25 00:43:10 +01:00
|
|
|
atom->Nclusters_ghost = Nghost + 1;
|
|
|
|
atom->Nclusters = atom->Nclusters_local + Nghost + 1;
|
2022-01-25 21:00:11 +01:00
|
|
|
|
2022-01-27 03:07:31 +01:00
|
|
|
// Update created ghost clusters positions
|
2022-01-31 17:49:22 +01:00
|
|
|
updatePbc(atom, param, 1);
|
2022-03-10 01:31:50 +01:00
|
|
|
DEBUG_MESSAGE("setupPbc end\n");
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|