Rescaling the velocities in LAMMPS

I want to rescale the velocities of atoms in a certain zone of my simulaiton cell. Here are the commands that I use :

region upper_1 block EDGE EDGE EDGE EDGE $(v_z_max_supercell - 1500) $(v_z_max_supercell - 180)
group frozen_upper_1 dynamic all region upper_1 every 500
region upper_2 block EDGE EDGE EDGE EDGE $(v_z_max_supercell - 180) $(v_z_max_supercell - 0)
group frozen_upper_2 dynamic all region upper_2 every 100

# Reducing the velocity of the desorbed gases
variable vx  atom vx*0.9999
variable vy  atom vy*0.9999
# variable vz1 atom vz*${alpha}
variable vz1 atom vz*0.2
velocity frozen_upper_1 set v_vx v_vy v_vz1 sum no
variable vz2 atom vz*0.85
velocity frozen_upper_2 set v_vx v_vy v_vz2 sum no

run 1000 

But the velocities are not rescaled at all. What am I doing wrong?

Like all LAMMPS commands, the velocity command is acted on immediately when it is encountered. Your input looks like you are expecting that the rescaling will happen repeatedly during the run. That is not the documented behavior.

Thank you,
I am aware of what you explained, that’s why I put this commands in a loop. But even putting them in a loop does not make it work

It is very annoying that you don’t provide this information from the beginning.
The quality of help you can get, strongly depends on the quality of information you provide.
The best way to get help is with some simple, small, fast, and complete (!) example script
that has the same code constructs to reproduce the issue (but nothing else).

Here is such a minimal reproducer with a loop and it is rescaling velocities just fine.

units           lj
atom_style      atomic
lattice         fcc 0.8442
region          box block 0 2 0 2 0 2
create_box      1 box
create_atoms    1 box
mass            1 1.0

velocity        all create 3.0 2131513 loop geom

pair_style      lj/cut 2.5
pair_coeff      1 1 1.0 1.0 2.5
neighbor        0.3 bin
neigh_modify    every 20 delay 0 check no

fix             1 all nve

region subset block EDGE EDGE EDGE EDGE 0 1 units lattice
group subset dynamic all region subset every 10

# Reducing the velocity of the desorbed gases
variable vx  atom vx*0.9999
variable vy  atom vy*0.9999
variable vz1 atom vz*0.2

fix             1 all nve
thermo 5

run  100 pre no post no every 10 "velocity subset set v_vx v_vy v_vz1 sum no"
2 Likes

Even in the case where I didn’t originally place the velocity commands inside a loop, the velocities should have been rescaled right after the first step — and that wasn’t happening. That’s why I hadn’t mentioned the loop earlier: it wasn’t the source of the issue. As you said I tried to be simple, small, fast, and complete.

Surprisingly, it started working as expected when I replaced my original run 1000 command with the one you provided:

run  100 pre no post no every 10 "velocity subset set v_vx v_vy v_vz1 sum no"

So thank you — that actually solved the problem.

Your post was far from complete.

If that is the case, then why mention the loops at all?

That means, that your looping code was incorrect.

I wouldn’t be so sure of that. A problem is only really solved when you understand how it came to be. That doesn’t seem to be the case here.

Why are you so rude in all your answers? I do my best to ask questions clearly and concisely, but it’s easy to overlook a detail when sharing code. I genuinely thought the information I provided was sufficient (apologies if it wasn’t). I generally give more details but this time I thought it was enough, and it turns out that it wasn’t. There’s no need to be rude; we’re all here to learn and improve.

I am giving straight and honest feedback. Why do you consider this as being rude?
How can you learn, if people don’t honestly tell you where they think you made mistakes?

I understand your frustration after having made an effort, but the amount of effort you have invested is irrelevant and we are not in school here.

I’m doing this for many years now and have found that being direct is the most effective way to make people learn things. It cuts through a lot of wasted time that happens when people only tell you nice things. Sure, it doesn’t always make me a popular person, but this is not a popularity contest, so that doesn’t matter. Yet there are still plenty of people adding likes to my posts. Apparently, not everybody thinks of my ways as rude.

That said, if you feel you cannot handle my kind of feedback. Just say the word, and I will tell Discourse to not show me any future posts by you and you can live happily ever after.