#12 The mathematical function power "^"

v1.0_(example)
open
nobody
None
5
2013-10-19
2013-10-11
Jon
No

Hi,
I had many problems because I was adding a complex external force to my system and had always errors with it. I realized then that LAMMPS does not interpret well the function power "^" of my forces (at least in the LAMMPS version that I have). For checking the problem, I defined the next variables:

variable prueba equal "-(2)^2"
variable prueba2 equal "-(2^2)"
variable prueba3 equal "-2^2"

print "${prueba}"
print "${prueba2}"
print "${prueba3}"

And what it prints is
4
-4
4

This was very strange for me, as I would expect to get the value "-4" in all cases and makes it quite messy for adding complex equations. I do not know if this is already fixed, but if it is not, hope it is helpful for developers.

Discussion

  • Axel Kohlmeyer
    Axel Kohlmeyer
    2013-10-19

    this may be unexpected to you, but is consistent with the documented precedence rules. changing this would break compatibility and you can always use parentheses to enforce the desired precedence.

    if you have that complex a formula for your external force, it may be better to implement this as a custom fix instead and then benefit from better performance in the process.