How to access fix property/atom in own code: Workaround

Submitted by pedro_krawallneck2 on Tue, 09/15/2020 - 16:55

Hello all,

I have modified LIGGGHTS with a custom fix, that modifies a per-particle scalar variable.
You can think of particles interacting with spacially varying radiation, where it is of interest, how much radiation dose each particle "collects".
To access per-particle properties has been easy, however, i needed an extra variable to store the radiation dose each particle gets.
The documentation suggests to create this via the fix property/atom as

int index = atom->find_custom(char *name, int &flag);
int *ivector = atom->ivector[index];
double *dvector = atom->dvector[index];
For me, atom->find_custom doesn't find the fix i created. Looking through the source code, i found, that its counterpart atom->add_custom seems not to be called in fix_property_atom.cpp, (In LAMMPS, it IS called, however.).
So i tinkered around a bit, looking at how other methods and fixes access per atom variables added by fix property/atom and came to the following workaround:

Fix *raddosefix = modify->fix[modify->find_fix("raddose")];
double *raddose = raddosefix->vector_atom;

I can access my dose by e.g.
raddose[i] += some_value;
This is my first post in this forum, I'm looking forward to hang around for a while.
(I am on LIGGGHTS Public 3.8.0)

Daniel Queteschiner's picture

Daniel Queteschiner | Wed, 09/16/2020 - 12:56

The section of the manual refers to the fix property/atom implementation of LAMMPS which works slightly different from the implementation of the fix property/atom in LIGGGHTS. Looks like the manual was never updated to reflect the different behaviour.
Btw., you should always check that the return value of Modify::find_fix is >= 0 before using it as an index into any array.