How to set the user defined variable to zero and broadcasted before every step

Hi users forum,
int index1,flag,cols,index2;
const char nameflip,nametheta;
nameflip=“flip”;
flip = atom->ivector[index1];
nametheta=“theta”;
index2=atom->find_custom(nametheta, flag, cols);
theta=atom->dvector[index2];
I have defined two variables like this. How do I make sure that before every step it is reset to zero and broadcasted like the force variable( f
)? These two variables are like the force variable where I need to sum the values from neighbours of a given particle. How do I do this when I use fix langevin and fix brownian?
Any help is appreciated.
Thank you
Parvathy

It sounds like you are trying to write code to do the following:

  1. Calculate a per-atom quantity for each atom on its “own” processor (looping over atom indices as for (int i=0; i++; i<nlocal))
  2. Send this quantity to neighbouring processors so that ghost atoms get a copy of these results
  3. Calculate another per-atom quantity from the neighbours’ values of this first quantity.

This is a “forward” communication. See the section on LAMMPS communication patterns in the documentation for examples of how this is done in various fixes.

Also, in future, it will help us if you specify that you are trying to write source code in C++ (sometimes people here use “code” to mean a LAMMPS input script) and use backticks to enable code block formatting (Google it!).

Thank you srtree, for the message.
Yes you are right, I want to do the same loop and also get the values from its neighbour, like a compute function does. I am trying to edit the original LAMMPS
code. I am a bit confused since it is a user defined variable. Otherwise adding another variable is the only option like the force variable.

It sounds like you are either not familiar or not confident with programming in C++. You have a few options:

  1. Keep trying on your own and keep wading through error messages.
  2. Tell us exactly what you want to do*, and see if we can help using existing LAMMPS capabilities. The per-atom variable syntax is very powerful and expressive, and together with fix addforce it is possible to prototype almost anything sensible (and many things that aren’t).
  3. Find a local expert to mentor you in coding and tell them exactly what you want to do*, and ask them for help.

*That is, you don’t actually want to write C++. You want to impose some particular forces on some particles in terms of a quantity you can compute based on the properties of other particles around them. Tell us what that particular calculation should look like. Even if we cannot get you all the way there, the act of writing out exactly what you need to do is often clarifying and helpful to your own brain.

1 Like

There are four major problems with your message:

  • it is not property formatted
  • you are not providing any context of what you are doing where and how and
  • you are not using the same “labels” that LAMMPS developers and the LAMMPS documentation use
  • you don’t provide any information about how you are doing your programming, which LAMMPS version you use and what modifications you did, and - most importantly - how somebody else can reproduce the issue that you are having

You are not talking about “variables” here (at least not in the sense of variables created by the “variable” command in LAMMPS), but about custom per-atom properties that you have created by using fix property/atom (one integer, one double).

What you do with custom per-atom properties is entirely up to you. LAMMPS just provides the framework to allocate the data and migrate it with the atom that owns it.

This step is called a “reverse communication” in LAMMPS and whether it is needed depends on the choice of the “newton” command and how you set values to these properties. What you are showing in your (misformatted) code sample is just how you access those properties, neither how you create them, nor how you assign data to them.

This makes no sense in combination with your previous statement. Neither fix langevin nor fix brownian access any data that is pairwise or from ghost atoms.

Whether you can get help with your problems strongly depends on how well you can describe your issues and how well somebody else can understand and reproduce them. At the moment, your efforts in that respect are insufficient and people have to make guesses which have a significant chance of being wrong (e.g. the statement that @srtee has made about a forward communication).

We have put together a list of guidelines and suggestions for people to have a good chance of getting help here: Please Read This First: Guidelines and Suggestions for posting LAMMPS questions

You should have a good look at those and a follow (all of) them closely. This post starts with “Please read this first” for a good reason…