Problem of definition of variable parameters

Hi, I tried to define some variable parameter:

variable sbox equal (${volfra}/2)^(1/3)+0.002

variable lbox equal 2*(${sbox}-0.002)+0.002

region box block 0 {lbox} 0 {sbox} 0 {sbox} units box

but when I execute the script, I got an error:
ERROR: Variable sbox: Invalid syntax in variable formula (src/variable.cpp:3267)
Last command: variable lbox equal 2*(${sbox}-0.002)+0.002

I really don’t figure out the reason. So I would like to ask for help. Thanks very much.

You post is illegible. However, there is a simple way how you can debug things yourself:

  • make a copy of the input and take the whole failing block out and make certain you have an input that works
  • then put things back in small pieces and run LAMMPS quickly after each addition
  • if necessary do this on a tiny test input with just a few atoms
  • as you incrementally add things back, you will quickly see which part is failing
  • for complex inputs like yours it is often a missing $ or _ or a typo in a reference to the name of a fix, compute or variable.

This is a very general debugging strategy and should always be applied. Unless the error is easy to spot from just looking at it (most are not with complex inputs), it is not likely that somebody will solve that problem for you. Contacting the forum (or the mailing list) is a step that should only be needed when the behavior of LAMMPS disagrees with its documentation (that may still be caused by misunderstanding the docs, but that is different from just doing your due diligence and apply an obvious debugging strategy).

I am sorry for this. I attached my script here.
when I execute the script, I got an error:
ERROR: Variable sbox: Invalid syntax in variable formula (src/variable.cpp:3267)
Last command: variable lbox equal 2*(${sbox}-0.002)+0.002
creat.in (4.3 KB)

well, obviously your definition of the “sbox” variable is failing.

so do as I suggested and start with

variable sbox equal 0.002
print "${sbox}"
quit

and incrementally put everything back. at some point it should be failing or you will have fixed the bug and see the difference. Once this passes you can remove the quit command and check the next line.

Thanks very much for you help.
Best regards.