How can I add an external force to all the particles in LAMMPS. I want to simulate a particle in a double well. The potential V(x,y) = (x^4+y^4)/4 - (x^2+y^2)/2. I have only one particle
# Define simulation parameters
units real
atom_style full
read_data system.data
include forcefield.in
#variable k equal 10.0
#variable U atom 0.5*${k}*(x-6.0)*(x-6.0)
#variable F atom -${k}*(x-0.6)
variable a equal 0.005
variable b equal 9.0
variable R2 atom (x*x + y*y)
variable T atom (${a} * v_R2 - ${b})
variable U atom T*T
variable Fxx atom -2 * T * 2 * ${a} * x
variable Fyy atom -2 * T * 2 * ${a} * y
fix myadf all addforce v_Fxx v_Fyy 0.0 energy v_U
Hi, is there any fix for this?
if when I am using
variable k equal 10.0
variable U atom 0.5*${k}*(x-6.0)*(x-6.0)
variable F atom -${k}*(x-0.6)
it work fine.
Then its really not clear what you are asking for.
Ok, so as you said, I tried to use the addforce command for the simple potential first. That works. When I am using the potential which depends on x and y both somehow there is an error saying ILLEGAL variable.
Is there any way to fix this illegal variable error?
variable a equal 0.005
variable b equal 9.0
variable R2 atom (x*x + y*y)
variable T atom (${a} * v_R2 - ${b})
variable U atom T*T
variable Fxx atom -2 * T * 2 * ${a} * x
variable Fyy atom -2 * T * 2 * ${a} * y
This one gives error.
ERROR: Illegal variable command: expected 3 arguments but found 5 (../variable.cpp:462)
Last command: variable R2 atom (x*x + y*y)
LAMMPS does not like space:
variable a equal 0.005
variable b equal 9.0
variable R2 atom (x*x+y*y)
variable T atom (${a}*v_R2-${b})
variable U atom T*T
variable Fxx atom -2*T*2*${a}*x
variable Fyy atom -2*T*2*${a}*y
Please in the future indicate your LAMMPS version and the exact error message.
You need to pass the third argument as a string. If you have spaces, quote the expressions:
variable R2 atom x*x+y*y # or remove the spaces
variable T atom "${a} * v_R2 - ${b}"
variable U atom T*T
variable Fxx atom "-2 * T * 2 * ${a} * x"
variable Fyy atom "-2 * T * 2 * ${a} * y"
2 Likes
Oh. My mistake. I am using LAMMPS (2 Aug 2023 - Update 4) version.
Thank you very much.