Add an external non-constant force field in lammps

667 Views Asked by At

I want to add a force field that depends on the atom possition. I have tried to compute the atom position, the use that as a variable and then, set the force field but I get the messege:

ERROR: Variable name for fix addforce does not exist

the code I have tried is:

variable a equal c_X
variable extforce equal ${maxforce}*step/${eqrun}*a
fix externforce A  addforce v_extforce 0 0 
1

There are 1 best solutions below

0
On

You need use an atom-style variable if you want it to vary depending on atomic position. I don't know what any of your other variables are, but as an example, this adds a y-component of force as a function of the x-position:

variable addfx atom x*0.2
fix externforce all addforce 0. v_addfx 0.

The error you're getting means you need to "use" the variable first, i.e. output it using the thermo_style command.