2020-08-18 14:27:28 +02: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.
|
2020-08-18 14:27:28 +02:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <thermo.h>
|
2021-12-01 00:07:45 +01:00
|
|
|
#include <util.h>
|
2024-04-15 16:53:25 +02:00
|
|
|
#include <mpi.h>
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
static int *steparr;
|
2020-11-05 12:41:44 +01:00
|
|
|
static MD_FLOAT *tmparr;
|
|
|
|
static MD_FLOAT *engarr;
|
|
|
|
static MD_FLOAT *prsarr;
|
|
|
|
static MD_FLOAT mvv2e;
|
2021-10-29 16:52:19 +02:00
|
|
|
static MD_FLOAT dof_boltz;
|
2020-11-05 12:41:44 +01:00
|
|
|
static MD_FLOAT t_scale;
|
|
|
|
static MD_FLOAT p_scale;
|
|
|
|
static MD_FLOAT e_scale;
|
|
|
|
static MD_FLOAT t_act;
|
|
|
|
static MD_FLOAT p_act;
|
|
|
|
static MD_FLOAT e_act;
|
2020-08-18 14:27:28 +02:00
|
|
|
static int mstat;
|
2024-04-15 16:53:25 +02:00
|
|
|
static MPI_Datatype type = (sizeof(MD_FLOAT) == 4) ? MPI_FLOAT : MPI_DOUBLE;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2020-08-19 09:00:35 +02:00
|
|
|
/* exported subroutines */
|
2020-08-18 14:27:28 +02:00
|
|
|
void setupThermo(Parameter *param, int natoms)
|
|
|
|
{
|
|
|
|
int maxstat = param->ntimes / param->nstat + 2;
|
|
|
|
|
|
|
|
steparr = (int*) malloc(maxstat * sizeof(int));
|
2020-11-05 12:41:44 +01:00
|
|
|
tmparr = (MD_FLOAT*) malloc(maxstat * sizeof(MD_FLOAT));
|
|
|
|
engarr = (MD_FLOAT*) malloc(maxstat * sizeof(MD_FLOAT));
|
|
|
|
prsarr = (MD_FLOAT*) malloc(maxstat * sizeof(MD_FLOAT));
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2021-10-27 01:38:56 +02:00
|
|
|
if(param->force_field == FF_LJ) {
|
|
|
|
mvv2e = 1.0;
|
|
|
|
dof_boltz = (natoms * 3 - 3);
|
|
|
|
t_scale = mvv2e / dof_boltz;
|
|
|
|
p_scale = 1.0 / 3 / param->xprd / param->yprd / param->zprd;
|
|
|
|
e_scale = 0.5;
|
2022-07-19 04:13:06 +02:00
|
|
|
} else if(param->force_field == FF_EAM) {
|
2021-10-27 01:38:56 +02:00
|
|
|
mvv2e = 1.036427e-04;
|
|
|
|
dof_boltz = (natoms * 3 - 3) * 8.617343e-05;
|
|
|
|
t_scale = mvv2e / dof_boltz;
|
|
|
|
p_scale = 1.602176e+06 / 3 / param->xprd / param->yprd / param->zprd;
|
|
|
|
e_scale = 524287.985533;//16.0;
|
|
|
|
param->dtforce /= mvv2e;
|
|
|
|
}
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void computeThermo(int iflag, Parameter *param, Atom *atom)
|
|
|
|
{
|
2024-04-15 16:53:25 +02:00
|
|
|
MD_FLOAT t_sum = 0.0, t = 0.0, p;
|
|
|
|
int me;
|
|
|
|
|
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &me);
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2022-07-06 01:07:39 +02:00
|
|
|
t += (atom_vx(i) * atom_vx(i) + atom_vy(i) * atom_vy(i) + atom_vz(i) * atom_vz(i)) * param->mass;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2024-04-15 16:53:25 +02:00
|
|
|
MPI_Reduce(&t, &t_sum, 1, type, MPI_SUM, 0 ,MPI_COMM_WORLD);
|
|
|
|
if(me == 0)
|
|
|
|
{
|
|
|
|
t = t_sum * t_scale;
|
|
|
|
p = (t * dof_boltz) * p_scale;
|
|
|
|
int istep = iflag;
|
|
|
|
|
|
|
|
if(iflag == -1){
|
|
|
|
istep = param->ntimes;
|
|
|
|
}
|
|
|
|
if(iflag == 0){
|
|
|
|
mstat = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
steparr[mstat] = istep;
|
|
|
|
tmparr[mstat] = t;
|
|
|
|
prsarr[mstat] = p;
|
|
|
|
mstat++;
|
|
|
|
fprintf(stdout, "%i\t%e\t%e\n", istep, t, p);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void adjustThermo(Parameter *param, Atom *atom)
|
|
|
|
{
|
|
|
|
/* zero center-of-mass motion */
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT vxtot = 0.0; MD_FLOAT vytot = 0.0; MD_FLOAT vztot = 0.0;
|
2024-04-15 16:53:25 +02:00
|
|
|
MD_FLOAT v_sum[3], vtot[3];
|
|
|
|
|
2020-08-18 14:27:28 +02:00
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2022-07-06 01:07:39 +02:00
|
|
|
vxtot += atom_vx(i);
|
|
|
|
vytot += atom_vy(i);
|
|
|
|
vztot += atom_vz(i);
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
2024-04-15 16:53:25 +02:00
|
|
|
|
|
|
|
vtot[0] = vxtot; vtot[1] = vytot; vtot[2] = vztot;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
2024-04-15 16:53:25 +02:00
|
|
|
MPI_Allreduce(vtot, v_sum, 3, type, MPI_SUM, MPI_COMM_WORLD);
|
|
|
|
|
|
|
|
vxtot = v_sum[0] / atom->Natoms;
|
|
|
|
vytot = v_sum[1] / atom->Natoms;
|
|
|
|
vztot = v_sum[2] / atom->Natoms;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2022-07-06 01:07:39 +02:00
|
|
|
atom_vx(i) -= vxtot;
|
|
|
|
atom_vy(i) -= vytot;
|
|
|
|
atom_vz(i) -= vztot;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
2024-04-15 16:53:25 +02:00
|
|
|
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT t = 0.0;
|
2024-04-15 16:53:25 +02:00
|
|
|
MD_FLOAT t_sum = 0.0;
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2022-07-06 01:07:39 +02:00
|
|
|
t += (atom_vx(i) * atom_vx(i) + atom_vy(i) * atom_vy(i) + atom_vz(i) * atom_vz(i)) * param->mass;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
|
2024-04-15 16:53:25 +02:00
|
|
|
MPI_Allreduce(&t, &t_sum, 1,type, MPI_SUM,MPI_COMM_WORLD);
|
|
|
|
|
|
|
|
t = t_sum;
|
2020-08-18 14:27:28 +02:00
|
|
|
t *= t_scale;
|
2020-11-05 12:41:44 +01:00
|
|
|
MD_FLOAT factor = sqrt(param->temp / t);
|
2020-08-18 14:27:28 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < atom->Nlocal; i++) {
|
2022-07-06 01:07:39 +02:00
|
|
|
atom_vx(i) *= factor;
|
|
|
|
atom_vy(i) *= factor;
|
|
|
|
atom_vz(i) *= factor;
|
2020-08-18 14:27:28 +02:00
|
|
|
}
|
|
|
|
}
|