Dear lammps developers,
I am trying to use the math function sign(x)
in varialbe, which is wrote with
variable i equal sin(2*v_pi*v_frequency*time*1e-15)
variable Ex equal sign(v_i)*v_amplitude
and then I want to check the value of Ex, So I put down the command
thermo_style custom step temp atoms v_wateng c_wtemp c_wtempcom c_patoms c_katoms v_Ex
then I got an error:ERROR: Variable Ex: Invalid math/group/special/feature function 'sign()' in variable formula (../variable.cpp:2100)
If I don’t write down the thermo command, the code will be run successfully. But in this way, I can’t check the value of Ex.
Can anyone help me?
What is your LAMMPS version?
[Update]
To explain, the sign()
function only exists in LAMMPS only since the 4 February 2025 release.
The online documentation always reflects the latest LAMMPS release and if your version is older, you should consult the documentation for that specific version to see which features are supported.
That said, you can easily get the same result as sign(v_i)
by using (v_i>=0.0)
.
CORRECTION: sign(v_i) is
1.0-2.0*(v_i<0)`
Dear Axel,
The version of lammps is LAMMPS (2 Aug 2023)
, and it do not support sign()
, but my machine do not support c++17
, I don’t know how to change the -DLAMMPS_CXX11
in Makefile.
Two things:
- I have shown you a way to have the same functionality as the sign() function with older versions of LAMMPS
- How to compile LAMMPS is documented in the LAMMPS manual.
v_i>=0
returns a boolean value (either 0 or 1) indicating whether the inequalty is satisfied. But sign(v_i)
returns a real value (either 1 or -1) indicating the sign of v_i
. I don’t think they are equal. In my opinion, sign(v_i)
is equal to abs(v_i)/v_i
. To circumvent zero division, abs(v_i)/(v_i+1e-40)
can be used.
So I made a mistake. But the principle is sound. Just use: 1.0-2.0*(v_i<0)