Dear all,
A research project requires me to manipulate coordinates and forces
step by step which is better done by using lammps as library, coupling
with some of my simple c++ codes. I am looking at the given
simple.cpp, especially the 2 lines:
double *x = new double[3*natoms];
lammps_get_coords(lmp,x);
I would like to do similar things for force and potential energy, like:
double *force = new double[3*natoms];
double potE;
lammps_get_force(lmp,force);
lammps_get_potE(lmp,potE);
I have two questions.
(1)
If the potential energy can be extracted out by using the existing
"lammps_extract_variable" function, should it be used like ?
double potE = lammps_extract_variable(lmp, pe, group1);
(suppose I have defined "group1" to be the atoms that I want the pe of)
If the potential energy cannot be extracted out by using the
"lammps_extract_variable" function, what should I do ?
(2)
For the force I think I have to define a new function
"lammps_get_force" in library.cpp, I suppose it should be similar to
the definition of lammps_get_coords (copied below), but I really don't
know how and where I should change or not change to get what I want.
Could any expert please tell me how ? appreciate a lot!
/* ---------------------------------------------------------------------- */
void lammps_get_coords(void *ptr, double *coords)
{
LAMMPS *lmp = (LAMMPS *) ptr;
// error if tags are not defined or not consecutive
if (lmp->atom->tag_enable == 0 || lmp->atom->tag_consecutive() == 0) return;
if (lmp->atom->natoms > MAXSMALLINT) return;
int natoms = static_cast<int> (lmp->atom->natoms);
double *copy = new double[3*natoms];
for (int i = 0; i < 3*natoms; i++) copy[i] = 0.0;
double **x = lmp->atom->x;
int *tag = lmp->atom->tag;
int nlocal = lmp->atom->nlocal;
int id,offset;
for (int i = 0; i < nlocal; i++) {
id = tag[i];
offset = 3*(id-1);
copy[offset+0] = x[i][0];
copy[offset+1] = x[i][1];
copy[offset+2] = x[i][2];
}
MPI_Allreduce(copy,coords,3*natoms,MPI_DOUBLE,MPI_SUM,lmp->world);
delete [] copy;
}
/* ---------------------------------------------------------------------- */
Thanks.
L.Zhang
UF Physics