# Averaging over local variables

Hello,

I am having some difficulty trying to find a fix or compute which will allow me to perform and output averaging over a local variable I have defined. I have looked into fix ave/chunk and fix ave/histo among others, but it seems that these require global or atom variables.

Essentially, I am trying to perform some functions of a local angle vector. For example:

compute ANGLES all local/angle theta
variable ANGLE_FUNCT vector 0.5*cos(c_ANGLES)

# some fix or compute which will allow me to output an average of ANGLE_FUNCT

If anyone has a solution for this, I would very much appreciate it.

Jack Goldman

Have you looked at compute/reduce?

Hello Axel,

Thank you for the swift response. I have looked into compute/reduce, but it seems to also only accepts atom style variables. If I am missing something, please let me know.

Thanks,

Jack

Hello Axel,

Thank you for the swift response. I have looked into compute/reduce, but it
seems to also only accepts atom style variables. If I am missing something,
please let me know.

you are missing that it does accept computes returning local data.

compute ang all angle/local theta
compute avg all reduce ave c_ang

after this c_avg will contain the average angle across the whole system

axel.

I would like to use this, but the problem is the average of my angle function will not be the same as the average over the angles. Compute reduce, to my knowledge, accepts local computes but not local variables.

I would like to extend this in the future to more complicated functions of the angle than just cosine, so a simple formula to relate the two means may not be tractable. I could always do post-processing from a dump file, I suppose.

Thank you,

Jack

I would like to use this, but the problem is the average of my angle
function will not be the same as the average over the angles. Compute
reduce, to my knowledge, accepts local computes but not local variables.

I would like to extend this in the future to more complicated functions of
the angle than just cosine, so a simple formula to relate the two means may
not be tractable. I could always do post-processing from a dump file, I
suppose.

then you'll have to modify source code accordingly and recompile.

axel.

I don’t know what you mean by “local” variables.

Nothing like that exists in LAMMPS.

You write this:
variable ANGLE_FUNCT vector 0.5*cos(c_ANGLES)

That’s a vector variable in LAMMPS lingo. It has a fixed

(small) length. Like 10. The same values exist on every proc.
You cannot construct if

from c_ANGLES which is a local compute storing data for all

the angles in the system. A local quantity (again in LAMMPS

lingo) is distributed. A portion of the values live on each proc.

Even if local variables existed, the conceptual problem

with time averaging them is that the ordering of

the local info (angles/atom) would change as atoms

migrated around. So the ordering of the list of local

quantities (angles in this case) would change from

timestep to timestep.

Steve