LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] summing too many variables in a loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] summing too many variables in a loop

From: Mostafa Nejatolahi <mostafa.nejatolahi@...24...>
Date: Sat, 15 Jul 2017 04:44:30 +0430

Thank you dear Axel.

On Sat, Jul 15, 2017 at 4:35 AM, Axel Kohlmeyer <akohlmey@...24...> wrote:

On Fri, Jul 14, 2017 at 7:40 PM, Mostafa Nejatolahi <mostafa.nejatolahi@...24...> wrote:
Hello all,

I will be appreciated if someone tells me a way to calculate a summation like the following in a shorter way (the number of variables could be higher like 81, 125, ...).

variable        Jx equal v_Jx1+v_Jx2+v_Jx3+v_Jx4+v_Jx5+v_Jx6+v_Jx7&

I used a loop-next-jump command but I got this error:
ERROR: Variable has circular dependency (../variable.cpp:1823)

variable sum equal 0 
variable i loop 27 
label start_of_loop_5 
variable sum equal v_sum+v_Jx$i
jump SELF start_of_loop_5 

​you can escape the circular dependency by using an immediate expansion ​in between to carry the sum value to the next loop. check this out:

cat in.loopme

variable i1 equal 1
variable i2 equal 10
variable i3 equal 100
variable i4 equal 1000

variable sum equal 0.0
variable i loop 4
label  loop
variable hold equal ${sum}
variable sum equal v_hold+v_i$i
print "i=$i sum=${sum}"
next i
jump SELF loop

print "final sum=${sum}"


p.s.: please note, that any input in LAMMPS that requires *that* many variables is probably doing something that is much simpler and more efficiently (and more likely correctly) done in post-processing. script languages like python are much more suitable for such tasks. please also note, that recent LAMMPS versions, if compiled accordingly, also support python style variables to embed python scriptlets.




Check out the vibrant tech community on one of the world's most
engaging tech sites,!
lammps-users mailing list

Dr. Axel Kohlmeyer  akohlmey@...24...
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.