avoid memory corruption when using mliap unified with ghostneigh_flag == 1

This commit is contained in:
Axel Kohlmeyer
2022-09-24 15:32:25 -04:00
parent ef8090fdd1
commit a02ab6eaa1

View File

@ -245,15 +245,19 @@ MLIAPBuildUnified_t LAMMPS_NS::build_unified(char *unified_fname, MLIAPData *dat
void LAMMPS_NS::update_pair_energy(MLIAPData *data, double *eij)
{
double e_total = 0;
for (int ii = 0; ii < data->nlistatoms; ii++) data->eatoms[ii] = 0;
const auto nlistatoms = data->nlistatoms;
for (int ii = 0; ii < nlistatoms; ii++) data->eatoms[ii] = 0;
for (int ii = 0; ii < data->npairs; ii++) {
int i = data->pair_i[ii];
double e = 0.5 * eij[ii];
// TODO: the if avoids memory corruption with ghostneigh_flag = 1,
if (i < nlistatoms) {
data->eatoms[i] += e;
e_total += e;
}
}
data->energy = e_total;
}