2022-03-17 02:44:34 +01:00
|
|
|
/*
|
2022-09-05 10:39:42 +02:00
|
|
|
* Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
* All rights reserved. This file is part of MD-Bench.
|
|
|
|
* Use of this source code is governed by a LGPL-3.0
|
|
|
|
* license that can be found in the LICENSE file.
|
2022-03-17 02:44:34 +01:00
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
//---
|
2022-08-16 18:36:47 +02:00
|
|
|
#include <atom.h>
|
2022-03-17 02:44:34 +01:00
|
|
|
#include <parameter.h>
|
|
|
|
#include <util.h>
|
|
|
|
|
|
|
|
void initParameter(Parameter *param) {
|
|
|
|
param->input_file = NULL;
|
|
|
|
param->vtk_file = NULL;
|
2022-08-17 17:56:31 +02:00
|
|
|
param->xtc_file = NULL;
|
2022-03-17 02:44:34 +01:00
|
|
|
param->eam_file = NULL;
|
|
|
|
param->force_field = FF_LJ;
|
|
|
|
param->epsilon = 1.0;
|
|
|
|
param->sigma = 1.0;
|
|
|
|
param->sigma6 = 1.0;
|
|
|
|
param->rho = 0.8442;
|
|
|
|
param->ntypes = 4;
|
|
|
|
param->ntimes = 200;
|
|
|
|
param->dt = 0.005;
|
|
|
|
param->nx = 32;
|
|
|
|
param->ny = 32;
|
|
|
|
param->nz = 32;
|
2022-07-08 02:30:03 +02:00
|
|
|
param->pbc_x = 1;
|
|
|
|
param->pbc_y = 1;
|
|
|
|
param->pbc_z = 1;
|
2022-03-17 02:44:34 +01:00
|
|
|
param->cutforce = 2.5;
|
|
|
|
param->skin = 0.3;
|
|
|
|
param->cutneigh = param->cutforce + param->skin;
|
|
|
|
param->temp = 1.44;
|
|
|
|
param->nstat = 100;
|
|
|
|
param->mass = 1.0;
|
|
|
|
param->dtforce = 0.5 * param->dt;
|
|
|
|
param->reneigh_every = 20;
|
2022-08-17 17:56:31 +02:00
|
|
|
param->prune_every = 1000;
|
2022-03-17 02:44:34 +01:00
|
|
|
param->x_out_every = 20;
|
|
|
|
param->v_out_every = 5;
|
2022-03-18 01:28:11 +01:00
|
|
|
param->half_neigh = 0;
|
2022-03-17 02:44:34 +01:00
|
|
|
param->proc_freq = 2.4;
|
2022-07-06 01:07:39 +02:00
|
|
|
// DEM
|
|
|
|
param->k_s = 1.0;
|
|
|
|
param->k_dn = 1.0;
|
|
|
|
param->gx = 0.0;
|
|
|
|
param->gy = 0.0;
|
|
|
|
param->gz = 0.0;
|
2022-07-07 02:11:50 +02:00
|
|
|
param->reflect_x = 0.0;
|
|
|
|
param->reflect_y = 0.0;
|
|
|
|
param->reflect_z = 0.0;
|
2022-03-17 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void readParameter(Parameter *param, const char *filename) {
|
|
|
|
FILE *fp = fopen(filename, "r");
|
|
|
|
char line[MAXLINE];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!fp) {
|
|
|
|
fprintf(stderr, "Could not open parameter file: %s\n", filename);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!feof(fp)) {
|
|
|
|
line[0] = '\0';
|
2022-11-08 15:30:37 +01:00
|
|
|
readline(line, fp);
|
2022-03-17 02:44:34 +01:00
|
|
|
for(i = 0; line[i] != '\0' && line[i] != '#'; i++);
|
|
|
|
line[i] = '\0';
|
|
|
|
|
|
|
|
char *tok = strtok(line, " ");
|
|
|
|
char *val = strtok(NULL, " ");
|
|
|
|
|
|
|
|
#define PARSE_PARAM(p,f) if(strncmp(tok, #p, sizeof(#p) / sizeof(#p[0]) - 1) == 0) { param->p = f(val); }
|
|
|
|
#define PARSE_STRING(p) PARSE_PARAM(p, strdup)
|
|
|
|
#define PARSE_INT(p) PARSE_PARAM(p, atoi)
|
|
|
|
#define PARSE_REAL(p) PARSE_PARAM(p, atof)
|
|
|
|
|
|
|
|
if(tok != NULL && val != NULL) {
|
|
|
|
PARSE_PARAM(force_field, str2ff);
|
|
|
|
PARSE_STRING(input_file);
|
|
|
|
PARSE_STRING(eam_file);
|
|
|
|
PARSE_STRING(vtk_file);
|
2022-08-17 17:56:31 +02:00
|
|
|
PARSE_STRING(xtc_file);
|
2022-03-17 02:44:34 +01:00
|
|
|
PARSE_REAL(epsilon);
|
|
|
|
PARSE_REAL(sigma);
|
2022-07-07 02:11:50 +02:00
|
|
|
PARSE_REAL(k_s);
|
|
|
|
PARSE_REAL(k_dn);
|
|
|
|
PARSE_REAL(reflect_x);
|
|
|
|
PARSE_REAL(reflect_y);
|
|
|
|
PARSE_REAL(reflect_z);
|
|
|
|
PARSE_REAL(gx);
|
|
|
|
PARSE_REAL(gy);
|
|
|
|
PARSE_REAL(gz);
|
2022-03-17 02:44:34 +01:00
|
|
|
PARSE_REAL(rho);
|
|
|
|
PARSE_REAL(dt);
|
|
|
|
PARSE_REAL(cutforce);
|
|
|
|
PARSE_REAL(skin);
|
|
|
|
PARSE_REAL(temp);
|
|
|
|
PARSE_REAL(mass);
|
|
|
|
PARSE_REAL(proc_freq);
|
|
|
|
PARSE_INT(ntypes);
|
|
|
|
PARSE_INT(ntimes);
|
|
|
|
PARSE_INT(nx);
|
|
|
|
PARSE_INT(ny);
|
|
|
|
PARSE_INT(nz);
|
2022-07-08 02:30:03 +02:00
|
|
|
PARSE_INT(pbc_x);
|
|
|
|
PARSE_INT(pbc_y);
|
|
|
|
PARSE_INT(pbc_z);
|
2022-03-17 02:44:34 +01:00
|
|
|
PARSE_INT(nstat);
|
|
|
|
PARSE_INT(reneigh_every);
|
2022-08-17 17:56:31 +02:00
|
|
|
PARSE_INT(prune_every);
|
2022-03-17 02:44:34 +01:00
|
|
|
PARSE_INT(x_out_every);
|
|
|
|
PARSE_INT(v_out_every);
|
|
|
|
PARSE_INT(half_neigh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 02:34:33 +02:00
|
|
|
// Update dtforce
|
|
|
|
param->dtforce = 0.5 * param->dt;
|
|
|
|
|
2022-03-17 02:44:34 +01:00
|
|
|
// Update sigma6 parameter
|
|
|
|
MD_FLOAT s2 = param->sigma * param->sigma;
|
|
|
|
param->sigma6 = s2 * s2 * s2;
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printParameter(Parameter *param) {
|
|
|
|
printf("Parameters:\n");
|
|
|
|
if(param->input_file != NULL) {
|
2023-03-28 23:04:11 +02:00
|
|
|
printf("\tInput file: %s\n", param->input_file);
|
2022-03-17 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(param->vtk_file != NULL) {
|
2023-03-28 23:04:11 +02:00
|
|
|
printf("\tVTK file: %s\n", param->vtk_file);
|
2022-03-17 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
2022-08-17 17:56:31 +02:00
|
|
|
if(param->xtc_file != NULL) {
|
2023-03-28 23:04:11 +02:00
|
|
|
printf("\tXTC file: %s\n", param->xtc_file);
|
2022-08-17 17:56:31 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 02:44:34 +01:00
|
|
|
if(param->eam_file != NULL) {
|
2023-03-28 23:04:11 +02:00
|
|
|
printf("\tEAM file: %s\n", param->eam_file);
|
2022-03-17 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\tForce field: %s\n", ff2str(param->force_field));
|
2022-08-17 17:56:31 +02:00
|
|
|
#ifdef CLUSTER_M
|
|
|
|
printf("\tKernel: %s, MxN: %dx%d, Vector width: %d\n", KERNEL_NAME, CLUSTER_M, CLUSTER_N, VECTOR_WIDTH);
|
|
|
|
#else
|
2022-08-16 18:36:47 +02:00
|
|
|
printf("\tKernel: %s\n", KERNEL_NAME);
|
2022-08-17 17:56:31 +02:00
|
|
|
#endif
|
2022-08-16 18:36:47 +02:00
|
|
|
printf("\tData layout: %s\n", POS_DATA_LAYOUT);
|
|
|
|
printf("\tFloating-point precision: %s\n", PRECISION_STRING);
|
2022-03-17 02:44:34 +01:00
|
|
|
printf("\tUnit cells (nx, ny, nz): %d, %d, %d\n", param->nx, param->ny, param->nz);
|
|
|
|
printf("\tDomain box sizes (x, y, z): %e, %e, %e\n", param->xprd, param->yprd, param->zprd);
|
2022-07-08 02:30:03 +02:00
|
|
|
printf("\tPeriodic (x, y, z): %d, %d, %d\n", param->pbc_x, param->pbc_y, param->pbc_z);
|
2022-03-17 02:44:34 +01:00
|
|
|
printf("\tLattice size: %e\n", param->lattice);
|
|
|
|
printf("\tEpsilon: %e\n", param->epsilon);
|
|
|
|
printf("\tSigma: %e\n", param->sigma);
|
2022-07-07 02:11:50 +02:00
|
|
|
printf("\tSpring constant: %e\n", param->k_s);
|
|
|
|
printf("\tDamping constant: %e\n", param->k_dn);
|
2022-03-17 02:44:34 +01:00
|
|
|
printf("\tTemperature: %e\n", param->temp);
|
|
|
|
printf("\tRHO: %e\n", param->rho);
|
|
|
|
printf("\tMass: %e\n", param->mass);
|
|
|
|
printf("\tNumber of types: %d\n", param->ntypes);
|
|
|
|
printf("\tNumber of timesteps: %d\n", param->ntimes);
|
|
|
|
printf("\tReport stats every (timesteps): %d\n", param->nstat);
|
|
|
|
printf("\tReneighbor every (timesteps): %d\n", param->reneigh_every);
|
2023-04-09 01:19:12 +02:00
|
|
|
#ifdef SORT_ATOMS
|
|
|
|
printf("\tSort atoms when reneighboring: yes\n");
|
|
|
|
#else
|
|
|
|
printf("\tSort atoms when reneighboring: no\n");
|
|
|
|
#endif
|
2022-08-17 17:56:31 +02:00
|
|
|
printf("\tPrune every (timesteps): %d\n", param->prune_every);
|
2022-03-17 02:44:34 +01:00
|
|
|
printf("\tOutput positions every (timesteps): %d\n", param->x_out_every);
|
|
|
|
printf("\tOutput velocities every (timesteps): %d\n", param->v_out_every);
|
|
|
|
printf("\tDelta time (dt): %e\n", param->dt);
|
|
|
|
printf("\tCutoff radius: %e\n", param->cutforce);
|
|
|
|
printf("\tSkin: %e\n", param->skin);
|
|
|
|
printf("\tHalf neighbor lists: %d\n", param->half_neigh);
|
2022-08-16 18:36:47 +02:00
|
|
|
printf("\tProcessor frequency (GHz): %.4f\n", param->proc_freq);
|
2022-03-17 02:44:34 +01:00
|
|
|
}
|