Hi,
I am using 'lmp.extract_compute' in the python. This function could give the right value belong to compute class, but the return value is not ordered by ID. So I checked the library.cpp. I modify the cpp like the function 'data = lmp.gather_atoms(name,type,count)' which could return the value ordered by ID. But I failed. I will appreciate if anyone could help me.
The original cpp shows as follows:
void *lammps_extract_compute(void *ptr, char *id, int style, int type)
{
LAMMPS *lmp = (LAMMPS *) ptr;
int icompute = lmp->modify->find_compute(id);
if (icompute < 0) return NULL;
Compute *compute = lmp->modify->compute[icompute];
if (style == 1) {
if (!compute->peratom_flag) return NULL;
if (type == 1) {
if (compute->invoked_peratom != lmp->update->ntimestep)
compute->compute_peratom();
return (void *) compute->vector_atom;
}
if (type == 2) {
if (compute->invoked_peratom != lmp->update->ntimestep)
compute->compute_peratom();
return (void *) compute->array_atom;
}
}
return NULL;
}
And the cpp modified by me is as follows:
void *lammps_extract_compute(void *ptr, char *id, int style, int type, void **data)
{
LAMMPS *lmp = (LAMMPS *) ptr;
int icompute = lmp->modify->find_compute(id);
if (icompute < 0) return NULL;
Compute *compute = lmp->modify->compute[icompute];
int natoms = static_cast (lmp->atom->natoms);
int i,j,offset;
if (style == 1) {
if (!compute->peratom_flag) return NULL;
if (type == 1) {
if (compute->invoked_peratom != lmp->update->ntimestep)
compute->compute_peratom();
return (void *) compute->vector_atom;
}
if (type == 2) {
double **array = NULL;
double *copy;
if (compute->invoked_peratom != lmp->update->ntimestep)
compute->compute_peratom();
array=compute->array_atom;
// void *vptr =compute->array_atom;
// array= (double **) vptr;
//***********
lmp->memory->create(copy,6*natoms,"lib/extract:copy");
for (i = 0; i < 6*natoms; i++) copy[i] = 0.0;
int *tag = lmp->atom->tag; //tag is atom id
int nlocal = lmp->atom->nlocal;
for (i = 0; i < nlocal; i++) {
offset = 6*(tag[i]-1);
for (j = 0; j < 6; j++)
copy[offset++] = array[i][j];
}
MPI_Allreduce(copy,data,6*natoms,MPI_DOUBLE,MPI_SUM,lmp->world);
lmp->memory->destroy(copy);
return (void **) data;
}
}
strathclyde | Mon, 10/05/2015 - 14:39
I am looking forward to the
I am looking forward to the help.......
aaigner | Mon, 10/05/2015 - 15:51
Hehe ... don't be inpatient.
Hehe ... don't be inpatient. ;-)
I am not sure, how many users can help you with this very specific question. It is out of range for a 'normal' user. Maybe the development forum would be a better place for this thread.
Back on topic... I did not check your code, but isn't it easier to get also the per-atom array with the ID (in python) and use it along with the compute array?
Sry, if my answer is not satisfying, but even I do not use the python interface.
strathclyde | Mon, 10/05/2015 - 22:31
Hi,
Hi,
Thank you for your input. I will work on it.
Leo