Hello, I am using the user-drude package. I am writing a custom fix in which I am trying to extract the atom ID of a core atom’s drude partner. (I could also do the other way around - a drude’s core partner ID).
In fix_drude.cpp, I am seeing these lines:
FixDrude *fdptr = (FixDrude *) ptr;
…
tagint *drudeid = fdptr->drudeid;
int *drudetyle = fdptr->drudetype;
My question is: if I want to access these same vectors in another fix, how would I go about it? It looks like the syntax is specific to fix_drude.cpp.
not really. this is a bit unusual, but that is due to its use in combination with a ring communication, which requires passing a function pointer with a specific calling sequence.
in LAMMPS, there are two ways of accessing internal data of other fix instances.
- you can access the class member variables/pointers directly, if they are declared public
- you can export them cast to a void pointer through an “extract” function.
in both cases, you first need to look up a pointer to the fix and for that you need the “fix id”, i.e. the string that is the first argument to the fix command, when creating the fix. a typical piece of code looks like this:
char *fixid = arg[iarg];
int ifix = modify->find_fix(fixid);
if (ifix < 0)
error->all(FLERR,“Illegal fix id for XXX fix”);
FixMyStyle *fixptr = (FixMyStyle *) modify->fix[ifix];
tagint *taglist = fixptr->tagdata;
from there on you can access public members of the FixMyStyle class, or protected members, if you class is listed as a friend class.
for private data, you the last two lines would change to:
Fix *fixptr = modify->fix[ifix];
int dim = 0;
tagint *taglist = (tagint *)fixptr->extract(“tagdata”,dim);
if ((taglist == NULL) || (dim != 1))
error->all(FLERR,“cannot access ‘tagdata’ from fix”);
and you would have to add/extend the extract function to return a void * of the internal data.
If you search through the LAMMPS sources you will find several examples of either use.
There are advantages and disadvantages to both variants.
Axel.