Adding new atom array

Hi lammps users,

Sorry this might be a stupid question, but I would like to know how to add a new atom array so that I can use it throughout the execution of the program?
For example, I would like to create a double * MCvalue, and use it this way atom->MCvalue[i]. I tried adding the double * MCvalue field in atom.h and initialize MCvalue = NULL in atom.cpp’s constructor, but I received a segmentation fault when I used MCvalue[i] somewhere else in the code. Any suggestion would be appreciated.

Thanks,

Sheng-En Lin

Hi lammps users,

Sorry this might be a stupid question, but I would like to know how to add a
new atom array so that I can use it throughout the execution of the program?

you probably want to avoid that are rather use fix property/atom instead.

http://lammps.sandia.gov/doc/fix_property_atom.html

this allows to store arbitrary integer or floating point data and
takes care of memory management and bookkeeping when atoms migrate
between processors.

For example, I would like to create a double * MCvalue, and use it this way
atom->MCvalue[i]. I tried adding the double * MCvalue field in atom.h and
initialize MCvalue = NULL in atom.cpp's constructor, but I received a
segmentation fault when I used MCvalue[i] somewhere else in the code. Any
suggestion would be appreciated.

i don't understand the question. if you initialize a pointer variable
with NULL, you *deserve* to get a segmentation fault, when you try to
dereference it. that is just basic C/C++ programming knowledge.

axel.

Thank you very much sir for the suggestion. I have another question.

How to access the new atom array created by property/atom command inside .cpp files? I saw on the documentation it says that compute property/atom can access the atom array, so I am guessing the atom array resides in compute_property_atom.cpp?

Many thanks,

Sheng-En Lin

Thank you very much sir for the suggestion. I have another question.

How to access the new atom array created by property/atom command inside
.cpp files? I saw on the documentation it says that compute property/atom
can access the atom array, so I am guessing the atom array resides in
compute_property_atom.cpp?

no. you are guessing wrong. very wrong. you call:

idx = atom->find_custom("propertyname",int_or_double);

that gives you an index and a flag whether this is an int or a double
and then you can access it as

dlist = atom->dvector[idx];

or

ilist = atom->ivector[idx];

please see atom.h/.cpp and how compute_property_atom.cpp accesses it.

axel.

Thank you very much sir. Sorry there's another problem: When I tried to step through the find_custom function, I noticed that the code does not go into
any of the three loops. As a result I got -1 for my idx. Any suggestion?

Many thanks,

Sheng-En Lin

Hello sir,

Sorry for all the questions, I would like to know in any time step, when is command_style class called? Is it possible to call a command_style class after fix_property_atom command has been invoked? so I can use the custom per atom array in my customized command_style class.

Hello sir,

Sorry for all the questions, I would like to know in any time step, when is command_style class called? Is it possible to call a command_style class after fix_property_atom command has been invoked? so I can use the custom per atom array in my customized command_style class.

Please read the developer’s guide and look at the lecture notes from the lammps developers workshop at ICTP this spring.