2021-03-25 06:49:28 +01:00
|
|
|
/*
|
|
|
|
* =======================================================================================
|
|
|
|
*
|
|
|
|
* Author: Jan Eitzinger (je), jan.eitzinger@fau.de
|
|
|
|
* Copyright (c) 2021 RRZE, University Erlangen-Nuremberg
|
|
|
|
*
|
|
|
|
* This file is part of MD-Bench.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* =======================================================================================
|
|
|
|
*/
|
|
|
|
#include <likwid-marker.h>
|
|
|
|
|
|
|
|
#include <timing.h>
|
|
|
|
#include <neighbor.h>
|
|
|
|
#include <parameter.h>
|
|
|
|
#include <atom.h>
|
2021-12-01 00:07:45 +01:00
|
|
|
#include <stats.h>
|
2021-03-25 06:49:28 +01:00
|
|
|
|
2022-03-18 01:28:11 +01:00
|
|
|
double computeForceLJFullNeigh(Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) {
|
2021-03-25 06:49:28 +01:00
|
|
|
int Nlocal = atom->Nlocal;
|
|
|
|
int* neighs;
|
2021-10-26 09:11:17 +02:00
|
|
|
#ifndef EXPLICIT_TYPES
|
2021-03-25 06:49:28 +01:00
|
|
|
MD_FLOAT cutforcesq = param->cutforce * param->cutforce;
|
|
|
|
MD_FLOAT sigma6 = param->sigma6;
|
|
|
|
MD_FLOAT epsilon = param->epsilon;
|
2021-10-26 09:11:17 +02:00
|
|
|
#endif
|
2021-03-25 06:49:28 +01:00
|
|
|
|
|
|
|
for(int i = 0; i < Nlocal; i++) {
|
2022-03-18 01:40:51 +01:00
|
|
|
atom_fx(i) = 0.0;
|
|
|
|
atom_fy(i) = 0.0;
|
|
|
|
atom_fz(i) = 0.0;
|
2021-03-25 06:49:28 +01:00
|
|
|
}
|
|
|
|
|
2021-10-11 16:57:02 +02:00
|
|
|
double S = getTimeStamp();
|
2021-06-30 13:44:02 +02:00
|
|
|
LIKWID_MARKER_START("force");
|
2021-10-12 22:39:54 +02:00
|
|
|
|
2021-10-26 09:11:17 +02:00
|
|
|
#pragma omp parallel for
|
|
|
|
for(int i = 0; i < Nlocal; i++) {
|
|
|
|
neighs = &neighbor->neighbors[i * neighbor->maxneighs];
|
|
|
|
int numneighs = neighbor->numneigh[i];
|
|
|
|
MD_FLOAT xtmp = atom_x(i);
|
|
|
|
MD_FLOAT ytmp = atom_y(i);
|
|
|
|
MD_FLOAT ztmp = atom_z(i);
|
|
|
|
MD_FLOAT fix = 0;
|
|
|
|
MD_FLOAT fiy = 0;
|
|
|
|
MD_FLOAT fiz = 0;
|
|
|
|
|
|
|
|
#ifdef EXPLICIT_TYPES
|
|
|
|
const int type_i = atom->type[i];
|
|
|
|
#endif
|
2021-10-12 22:39:54 +02:00
|
|
|
|
2021-10-26 09:11:17 +02:00
|
|
|
for(int k = 0; k < numneighs; k++) {
|
|
|
|
int j = neighs[k];
|
|
|
|
MD_FLOAT delx = xtmp - atom_x(j);
|
|
|
|
MD_FLOAT dely = ytmp - atom_y(j);
|
|
|
|
MD_FLOAT delz = ztmp - atom_z(j);
|
|
|
|
MD_FLOAT rsq = delx * delx + dely * dely + delz * delz;
|
2021-10-12 22:39:54 +02:00
|
|
|
|
2021-10-26 09:11:17 +02:00
|
|
|
#ifdef EXPLICIT_TYPES
|
|
|
|
const int type_j = atom->type[j];
|
|
|
|
const int type_ij = type_i * atom->ntypes + type_j;
|
|
|
|
const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij];
|
|
|
|
const MD_FLOAT sigma6 = atom->sigma6[type_ij];
|
|
|
|
const MD_FLOAT epsilon = atom->epsilon[type_ij];
|
|
|
|
#endif
|
2021-06-16 00:56:00 +02:00
|
|
|
|
2021-10-26 09:11:17 +02:00
|
|
|
if(rsq < cutforcesq) {
|
|
|
|
MD_FLOAT sr2 = 1.0 / rsq;
|
|
|
|
MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6;
|
|
|
|
MD_FLOAT force = 48.0 * sr6 * (sr6 - 0.5) * sr2 * epsilon;
|
|
|
|
fix += delx * force;
|
|
|
|
fiy += dely * force;
|
|
|
|
fiz += delz * force;
|
2022-02-25 14:40:33 +01:00
|
|
|
#ifdef USE_REFERENCE_VERSION
|
|
|
|
addStat(stats->atoms_within_cutoff, 1);
|
|
|
|
} else {
|
|
|
|
addStat(stats->atoms_outside_cutoff, 1);
|
|
|
|
#endif
|
2021-10-12 22:39:54 +02:00
|
|
|
}
|
2021-04-07 00:46:51 +02:00
|
|
|
}
|
2021-10-26 09:11:17 +02:00
|
|
|
|
2022-03-18 01:40:51 +01:00
|
|
|
atom_fx(i) += fix;
|
|
|
|
atom_fy(i) += fiy;
|
|
|
|
atom_fz(i) += fiz;
|
2021-12-01 00:07:45 +01:00
|
|
|
|
|
|
|
addStat(stats->total_force_neighs, numneighs);
|
|
|
|
addStat(stats->total_force_iters, (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH);
|
2021-03-25 06:49:28 +01:00
|
|
|
}
|
2021-10-12 22:39:54 +02:00
|
|
|
|
2021-06-30 13:44:02 +02:00
|
|
|
LIKWID_MARKER_STOP("force");
|
2021-05-19 23:51:02 +02:00
|
|
|
double E = getTimeStamp();
|
|
|
|
return E-S;
|
2021-03-25 06:49:28 +01:00
|
|
|
}
|
2022-03-10 16:30:37 +01:00
|
|
|
|
2022-03-18 01:28:11 +01:00
|
|
|
double computeForceLJHalfNeigh(Parameter *param, Atom *atom, Neighbor *neighbor, Stats *stats) {
|
2022-03-10 16:30:37 +01:00
|
|
|
int Nlocal = atom->Nlocal;
|
|
|
|
int* neighs;
|
|
|
|
#ifndef EXPLICIT_TYPES
|
|
|
|
MD_FLOAT cutforcesq = param->cutforce * param->cutforce;
|
|
|
|
MD_FLOAT sigma6 = param->sigma6;
|
|
|
|
MD_FLOAT epsilon = param->epsilon;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(int i = 0; i < Nlocal; i++) {
|
2022-03-18 01:40:51 +01:00
|
|
|
atom_fx(i) = 0.0;
|
|
|
|
atom_fy(i) = 0.0;
|
|
|
|
atom_fz(i) = 0.0;
|
2022-03-10 16:30:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double S = getTimeStamp();
|
|
|
|
LIKWID_MARKER_START("forceLJ-halfneigh");
|
|
|
|
|
|
|
|
for(int i = 0; i < Nlocal; i++) {
|
|
|
|
neighs = &neighbor->neighbors[i * neighbor->maxneighs];
|
2022-03-10 17:06:45 +01:00
|
|
|
int numneighs = neighbor->numneigh[i];
|
2022-03-10 16:30:37 +01:00
|
|
|
MD_FLOAT xtmp = atom_x(i);
|
|
|
|
MD_FLOAT ytmp = atom_y(i);
|
|
|
|
MD_FLOAT ztmp = atom_z(i);
|
|
|
|
MD_FLOAT fix = 0;
|
|
|
|
MD_FLOAT fiy = 0;
|
|
|
|
MD_FLOAT fiz = 0;
|
|
|
|
|
|
|
|
#ifdef EXPLICIT_TYPES
|
|
|
|
const int type_i = atom->type[i];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(int k = 0; k < numneighs; k++) {
|
|
|
|
int j = neighs[k];
|
|
|
|
MD_FLOAT delx = xtmp - atom_x(j);
|
|
|
|
MD_FLOAT dely = ytmp - atom_y(j);
|
|
|
|
MD_FLOAT delz = ztmp - atom_z(j);
|
|
|
|
MD_FLOAT rsq = delx * delx + dely * dely + delz * delz;
|
|
|
|
|
|
|
|
#ifdef EXPLICIT_TYPES
|
|
|
|
const int type_j = atom->type[j];
|
|
|
|
const int type_ij = type_i * atom->ntypes + type_j;
|
|
|
|
const MD_FLOAT cutforcesq = atom->cutforcesq[type_ij];
|
|
|
|
const MD_FLOAT sigma6 = atom->sigma6[type_ij];
|
|
|
|
const MD_FLOAT epsilon = atom->epsilon[type_ij];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(rsq < cutforcesq) {
|
|
|
|
MD_FLOAT sr2 = 1.0 / rsq;
|
|
|
|
MD_FLOAT sr6 = sr2 * sr2 * sr2 * sigma6;
|
|
|
|
MD_FLOAT force = 48.0 * sr6 * (sr6 - 0.5) * sr2 * epsilon;
|
|
|
|
fix += delx * force;
|
|
|
|
fiy += dely * force;
|
|
|
|
fiz += delz * force;
|
|
|
|
|
2022-03-18 01:28:11 +01:00
|
|
|
// We do not need to update forces for ghost atoms
|
|
|
|
if(j < Nlocal) {
|
2022-03-18 01:40:51 +01:00
|
|
|
atom_fx(j) -= delx * force;
|
|
|
|
atom_fy(j) -= dely * force;
|
|
|
|
atom_fz(j) -= delz * force;
|
2022-03-18 01:28:11 +01:00
|
|
|
}
|
2022-03-10 16:30:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-18 01:40:51 +01:00
|
|
|
atom_fx(i) += fix;
|
|
|
|
atom_fy(i) += fiy;
|
|
|
|
atom_fz(i) += fiz;
|
2022-03-10 16:30:37 +01:00
|
|
|
|
|
|
|
addStat(stats->total_force_neighs, numneighs);
|
|
|
|
addStat(stats->total_force_iters, (numneighs + VECTOR_WIDTH - 1) / VECTOR_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIKWID_MARKER_STOP("forceLJ-halfneigh");
|
|
|
|
double E = getTimeStamp();
|
|
|
|
return E-S;
|
|
|
|
}
|