Add EAM force field

Signed-off-by: Rafael Ravedutti <rafaelravedutti@gmail.com>
This commit is contained in:
Rafael Ravedutti
2021-10-26 00:40:39 +02:00
parent 9d16bb46c8
commit 2dac10469c
5 changed files with 538 additions and 6 deletions

View File

@@ -39,13 +39,17 @@
#include <thermo.h>
#include <pbc.h>
#include <timers.h>
#include <eam.h>
#define HLINE "----------------------------------------------------------------------------\n"
extern double computeForce(Parameter*, Atom*, Neighbor*, Stats*, int, int);
extern double computeForceEam(Eam* eam, Atom *atom, Neighbor *neighbor, Stats *stats, int first_exec, int timestep);
void init(Parameter *param)
{
param->input_file = NULL;
param->force_field = FF_LJ;
param->epsilon = 1.0;
param->sigma6 = 1.0;
param->rho = 0.8442;
@@ -67,6 +71,7 @@ void init(Parameter *param)
double setup(
Parameter *param,
Eam *eam,
Atom *atom,
Neighbor *neighbor,
Stats *stats)
@@ -78,6 +83,7 @@ double setup(
param->zprd = param->nz * param->lattice;
S = getTimeStamp();
if(param->force_field == FF_EAM) { initEam(eam, param->input_file, param->ntypes); }
initAtom(atom);
initNeighbor(neighbor, param);
initPbc();
@@ -153,9 +159,24 @@ void printAtomState(Atom *atom)
/* } */
}
int main (int argc, char** argv)
int str2ff(const char *string)
{
if(strncmp(string, "lj", 2) == 0) return FF_LJ;
if(strncmp(string, "eam", 3) == 0) return FF_EAM;
return -1;
}
const char* ff2str(int ff)
{
if(ff == FF_LJ) { return "lj"; }
if(ff == FF_EAM) { return "eam"; }
return "invalid";
}
int main(int argc, char** argv)
{
double timer[NUMTIMER];
Eam eam;
Atom atom;
Neighbor neighbor;
Stats stats;
@@ -172,6 +193,19 @@ int main (int argc, char** argv)
for(int i = 0; i < argc; i++)
{
if((strcmp(argv[i], "-f") == 0))
{
if((param.force_field = str2ff(argv[++i])) < 0) {
fprintf(stderr, "Invalid force field!\n");
exit(-1);
}
continue;
}
if((strcmp(argv[i], "-i") == 0))
{
param.input_file = strdup(argv[++i]);
continue;
}
if((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--nsteps") == 0))
{
param.ntimes = atoi(argv[++i]);
@@ -192,7 +226,7 @@ int main (int argc, char** argv)
param.nz = atoi(argv[++i]);
continue;
}
if((strcmp(argv[i], "-f") == 0))
if((strcmp(argv[i], "--freq") == 0))
{
param.proc_freq = atof(argv[++i]);
continue;
@@ -201,17 +235,24 @@ int main (int argc, char** argv)
{
printf("MD Bench: A minimalistic re-implementation of miniMD\n");
printf(HLINE);
printf("-f <string>: force field (lj or eam), default lj\n");
printf("-i <string>: input file for EAM\n");
printf("-n / --nsteps <int>: set number of timesteps for simulation\n");
printf("-nx/-ny/-nz <int>: set linear dimension of systembox in x/y/z direction\n");
printf("-f <real>: processor frequency (GHz)\n");
printf("--freq <real>: processor frequency (GHz)\n");
printf(HLINE);
exit(EXIT_SUCCESS);
}
}
setup(&param, &atom, &neighbor, &stats);
setup(&param, &eam, &atom, &neighbor, &stats);
computeThermo(0, &param, &atom);
computeForce(&param, &atom, &neighbor, &stats, 1, 0);
if(param.force_field == FF_EAM) {
computeForceEam(&eam, &atom, &neighbor, &stats, 1, 0);
} else {
computeForce(&param, &atom, &neighbor, &stats, 1, 0);
}
timer[FORCE] = 0.0;
timer[NEIGH] = 0.0;
@@ -226,7 +267,12 @@ int main (int argc, char** argv)
timer[NEIGH] += reneighbour(&param, &atom, &neighbor);
}
timer[FORCE] += computeForce(&param, &atom, &neighbor, &stats, 0, n + 1);
if(param.force_field == FF_EAM) {
timer[FORCE] += computeForceEam(&eam, &atom, &neighbor, &stats, 0, n + 1);
} else {
timer[FORCE] += computeForce(&param, &atom, &neighbor, &stats, 0, n + 1);
}
finalIntegrate(&param, &atom);
if(!((n + 1) % param.nstat) && (n+1) < param.ntimes) {
@@ -238,6 +284,7 @@ int main (int argc, char** argv)
computeThermo(-1, &param, &atom);
printf(HLINE);
printf("Force field: %s\n", ff2str(param.force_field));
printf("Data layout for positions: %s\n", POS_DATA_LAYOUT);
#if PRECISION == 1
printf("Using single precision floating point.\n");