Creating a new global array: Declaration?

Hello everyone,

I wanted to know in which file of LAMMPS, can one create a new global array? Like the file I would have to declare it in, to be able to use it elsewhere in the code/fix again and again. Would really appreciate if someone can point me to that.

Dev

Hello everyone,

I wanted to know in which file of LAMMPS, can one create a new global
array? Like the file I would have to declare it in, to be able to use it
elsewhere in the code/fix again and again. Would really appreciate if
someone can point me to that.

​there is no such thing. data in LAMMPS is tied to individual class
instances or classes that manage their data. there are some ways to access
such data, but which is the option you need depends on what you want to do.
thus please explain a bit more what you are trying to achieve with this
"global" storage, i.e. what kind of data do you want to communicate from
where to where and for what purpose.

axel.

Hi Axel,

The idea is as follows:

In the pair_lj module, I want to store the values of force in two different arrays. Later I want to access these two arrays in a different cpp file.

So can I create a separate header like below as myfile.h and access it in myfile.cpp. Will that be a correct approach? I will keep both the files in src directory and recompile LAMMPS.

//myfile.h
extern int a[100];

//myfile.cpp
int a[100]

Also if I make changes to the LAMMPS source file (in my case pair_LJ), what all things I should keep in mind- to avoid possible errors? The changes I am looking to make is to check the force interaction between any two particles and run it through an ‘if-else’- condition. If it goes through, I will add it to my array else it will go as zero in my array for that particular interaction.

Have I been able to explain my question?

Hi Axel,

The idea is as follows:

In the pair_lj module, I want to store the values of force in two
different arrays. Later I want to access these two arrays in a different
cpp file.

​what force? the total force on each atom? or the force between each pair
of atoms?​ and what do you want to do with this information?
remember, that in LAMMPS data is scattered across MPI processes and the
number and order of atoms on a processor can change.

So can I create a separate header like below as myfile.h and access it in
myfile.cpp. Will that be a correct approach? I will keep both the files in
src directory and recompile LAMMPS.

//myfile.hextern int a[100];
//myfile.cppint a[100]

Also if I make changes to the LAMMPS source file (in my case pair_LJ),
what all things I should keep in mind- to avoid possible errors? The
changes I am looking to make is to check the force interaction between any
two particles and run it through an 'if-else'- condition. If it goes
through, I will add it to my array else it will go as zero in my array for
that particular interaction.


​how will this work in​ parallel?

Have I been able to explain my question?

not entirely. if you have to go over each pair of atoms, you may want to
look into the various computes in the USER-TALLY package, that can install
a callback into the pairwise tally of energy and forces. that may be a
cleaner approach, provided you just want that information for analysis and
not modify the force inside the pair style.

axel.