# Variable for the bounds of region style 'block' and for 'final' style of command 'change_box'

Hello,

In order to save computational resources, I need to resize the simulation box once every N steps for a system with a constant total density. One way of doing this is to run the command ‘change_box’ in a loop of N timesteps. Since the system density is not perfectly homogeneous, one needs to adjust the number of particle deletions or insertions by the commands ‘fix evaporate’ or ’ fix deposit’, respectively, so that the total density remains constant after shrinking the box. These commands need a region to be specified as the deletion/insertion region and a proper style of the region would be ‘block’ if the box dimension is orthogonal.

I think that enabling the equal-style variable for the region bounds of style ‘block’ as well as for the final values of command ‘change_box’ would be one way to achieve the desied constant density. Please see the script below as an example:

``````1- variable rho equal 10
2- variable r_1 equal 90
3- thermo_modify lost ignore

4- region deletion block -95.0 95.0 -95.0 95.0 -95.0 95.0 side out
5- delete_atoms region deletion compress no
6- change_box all x final -95.0 95.0 y final -95.0 95.0 z final -95.0 95.0
7- variable n_All equal count(all)
8- variable n_desired equal \${rho}*\${190}^3
9- region reg1 sphere 0 0 0 \${r_1} side out
10- variable n equal abs(v_n_All-v_n_desired)

11- label loop1
12- variable try1 loop \$n
13- if '\${n_All}<\${n_desired}' then 'fix dep1 all deposit 1 1 1 12345 region reg1' else 'fix evap1 all evaporate 1 1 reg1 54321'
14- run 1
15- next try1
16- jump SELF loop1
``````

In lines 4 and 6, enabling equal-style variables for the new box dimensions allows us to repeat this block of the script in a systematic way such that resizing the box can be performed once a certain condition is met.

I would like to ask the developers to include such changes in the future versions of LAMMPS, in case there is no better way of keeping density constant when resizing the simulation box.

Thank you in advance for any suggestions.

I fail to be convinced by your reasoning.

If you have periodic boundaries then shrinking the box and deleting atoms at the box “surface” will cause unphysical shockwaves due to the sudden change of environment of the neighboring atoms near the boundaries and thus require significant time spent on re-equilibrating the system. So where are the time savings?

In case you have non-periodic boundaries, then density is ill-defined since the boundary is essentially arbitrary (and the density zero since the system is infinite) so why would there be a need to keep it constant within the box?