Tutorials
LAMMPS uses ascii input files for setting up all simulations.
Please be aware that there may be some issues with the - symbols in the pdf. Depending on your operating system, it may be best to type out the commands rather than copying directly from the pdf.
Additional examples can be found in the online documentation.
Installation via CMake
LAMMPS is supported on Linux-based systems. On these supported systems, LAMMPS can typically be installed with just a few commands:
mkdir lammps
cd lammps
git clone -b release https://github.com/lammps/lammps.git mylammps
cd mylammps
mkdir build
cd build
cmake ../cmake -D PKG_GRANULAR=yes -D PKG_BPM=yes -D PKG_VTK=yes -D PKG_MOLECULE=yes
make -j 8Full installation instructions can be found here. Full build instructions are here.
This assumes that you already have VTK installed on your system.
Tutorials
The following four tutorials are provided to help familiarise yourself with LAMMPS.
Tutorial 1 - Pouring Spherical Particles
Simulates pouring two different types of particles on a rigid wall. One material is cohesionless while the other is cohesive.
Code
# pour two types of particles (cohesive and non-cohesive) on flat wall
atom_style sphere
units lj
boundary p p f
comm_modify vel yes
region boxreg block 0 20 0 20 0 30
create_box 2 boxreg
pair_style granular
pair_coeff 1 * jkr 1000.0 50.0 0.3 10 tangential mindlin 800.0 1.0 0.5 rolling sds 500.0 200.0 0.5 twisting marshall
pair_coeff 2 2 hertz 200.0 20.0 tangential linear_history 300.0 1.0 0.1 rolling sds 200.0 100.0 0.1 twisting marshall
region insreg1 cylinder z 6 10 5 15 30
region insreg2 cylinder z 14 10 5 15 30
fix 1 all nve/sphere
fix grav all gravity 10.0 vector 0 0 -1
fix ins1 all pour 5000 1 3123 region insreg1 diam range 0.5 1 dens 1.0 1.0
fix ins2 all pour 5000 2 3123 region insreg2 diam range 0.5 1 dens 1.0 1.0
fix 3 all wall/gran granular hertz/material 1e5 1e3 0.3 tangential mindlin NULL 1.0 0.5 zplane 0 NULL
thermo_style custom step atoms ke
thermo_modify lost warn
thermo 100
timestep 0.001
dump 1 all custom 100 pour_two_types.dump id type radius mass x y z
dump 2 all vtk 100 pour_two_types*.vtk id type radius mass x y z
dump_modify 2 binary yes
run 10000Tutorial 2 - Filling a Rotating Drum
Simulates pouring particles into a drum made from multiple rigid walls. A rotational motion is then applied to the drum.
Code
atom_style sphere
units lj
boundary p p f
region boxreg block 0 30 0 30 0 30
create_box 2 boxreg
comm_modify vel yes
pair_style granular
pair_coeff 1 * jkr 1e5 0.1 0.3 50 tangential mindlin NULL 1.0 0.5 rolling sds 1e3 1e3 0.1 twisting marshall
pair_coeff 2 2 hertz/material 1e5 0.2 0.3 tangential mindlin NULL 1.0 0.5 damping tsuji
variable theta equal 0
region curved_wall cylinder z 15 15 15 0 20 side in rotate v_theta 15 15 0 0 0 1 open 2
region insreg cylinder z 15 15 14 20 30 side in
fix 1 all balance 1000 1.0 shift xyz 5 1.1
fix 2 all nve/sphere
fix grav all gravity 10 vector 0 0 -1
fix ins1 all pour 2000 1 1234 region insreg diam range 0.5 1 dens 1 1
fix ins2 all pour 2000 2 1234 region insreg diam range 0.5 1 dens 1 1
fix 3 all wall/gran/region granular hertz/material 1e5 0.1 0.3 tangential mindlin NULL 1.0 0.5 damping tsuji region curved_wall
thermo_style custom step atoms ke v_theta
thermo_modify lost warn
thermo 100
timestep 0.001
dump 1 all custom 100 rotating_drum.dump id type radius mass x y z
run 1000
#Add top lid, turn off pouring, 'turn' drum by switching the direction of gravity
region top_wall plane 15 15 20 0 0 -1 side in rotate v_theta 15 15 0 0 0 1
fix 5 all wall/gran/region granular hertz/material 1e5 0.1 0.3 tangential mindlin NULL 1.0 0.5 damping tsuji region top_wall
unfix grav
unfix ins1
unfix ins2
fix grav all gravity 10 vector 0 -1 0
variable theta equal 2*PI*elapsed/20000.0
run 130000Tutorial 3 - Pouring Rod-like Particles
Simulates pouring non-spherical particles created using bonded spheres. A “molecule” template is used to define the particle shape.
Code
units lj
dimension 3
boundary m m m
atom_style bpm/sphere
special_bonds lj 0.0 1.0 1.0 coul 1.0 1.0 1.0
newton on off
comm_modify vel yes cutoff 3.3
region box block -15 15 -15 15 0 60.0
create_box 1 box bond/types 1 extra/bond/per/atom 15 extra/special/per/atom 50
molecule my_mol "rect.mol"
region wall_cyl cylinder z 0.0 0.0 10.0 EDGE EDGE side in
region dropzone cylinder z 0.0 0.0 10.0 40.0 50.0 side in
pair_style gran/hertz/history 1.0 NULL 0.5 NULL 0.1 1
bond_style bpm/rotational break no smooth no
pair_coeff 1 1
bond_coeff 1 1.0 0.2 0.01 0.01 0.0 0.0 0.0 0.0 0.2 0.04 0.002 0.002
fix 1 all wall/gran hertz/history 1.0 NULL 0.5 NULL 0.1 1 zplane 0.0 NULL
fix 2 all wall/gran/region hertz/history 1.0 NULL 0.5 NULL 0.1 1 region wall_cyl
fix 3 all gravity 1e-4 vector 0 0 -1
fix 4 all deposit 40 0 1500 712511343 mol my_mol region dropzone near 2.0 vz -0.05 -0.05
fix 5 all nve/bpm/sphere
compute nbond all nbond/atom
compute tbond all reduce sum c_nbond
thermo_style custom step ke pe pxx pyy pzz c_tbond
thermo 100
dump 1 all custom 500 pour_bpm.dump id type radius mass x y z mol
timestep 0.05
run 100000Please note that rect.mol file needs to be present in the same folder as the input script for this example to run.
Tutorial 4 - Plate Impact
Simulates impact between a bonded particle and a bonded surface. Uses spring bond instead of rotational bonds.
Code
units lj
dimension 3
boundary s s s
atom_style bond
special_bonds lj 0.0 1.0 1.0 coul 0.0 1.0 1.0
newton on off
comm_modify vel yes cutoff 2.6
lattice fcc 1.0
region box block -25 15 -22 22 -22 22
create_box 1 box bond/types 2 extra/bond/per/atom 20 extra/special/per/atom 50
region disk cylinder x 0.0 0.0 20.0 -0.5 0.5
create_atoms 1 region disk
group plate region disk
region ball sphere 8.0 0.0 0.0 6.0
create_atoms 1 region ball
group projectile region ball
mass 1 1.0
velocity projectile set -0.05 0.0 0.0
displace_atoms all random 0.1 0.1 0.1 134598738
neighbor 1.0 bin
pair_style bpm/spring
pair_coeff 1 1 1.0 1.0 1.0
fix 1 all nve
create_bonds many plate plate 1 0.0 1.5
create_bonds many projectile projectile 2 0.0 1.5
neighbor 0.3 bin
special_bonds lj 0.0 1.0 1.0 coul 1.0 1.0 1.0
bond_style bpm/spring store/local brkbond 100 time id1 id2
bond_coeff 1 1.0 0.04 1.0
bond_coeff 2 1.0 0.2 1.0
velocity projectile set -0.05 0.0 0.0
fix 1 all nve
dump 1 all custom 100 impact_bpm.dump id type x y z
dump 2 all local 100 brokenDump f_brkbond[1] f_brkbond[2] f_brkbond[3]
dump_modify 2 header no
thermo 100
timestep 0.1
run 20000Additional Exercise
All of the above examples can be run using the syntax provided in the handout:
lammps -in pour_drum.inThis will run LAMMPS on your computer using a single cpu core. If your computer has many cpu cores, you may wish to use these to speed up the computation. This can be achieved by using the mpirun command.
For example, if your computer has 4 available cpu cores, you could run LAMMPS on all 4 cores by using the following command:
mpirun -n 4 lammps -in pour_drum.inIn various documentation you may see the use of either mpirun or mpiexec. Please note that mpirun and mpiexec are links to the same executable and can be used interchangeably.
To explore this, you may to run one of the longer examples such as tutorial 2 or tutorial 3 with different number of cores. At the end of each run LAMMPS provides the following output:
Performance: 3364489.533 tau/day, 778.817 timesteps/s, 1.963 Matom-step/s
99.6% CPU use with 8 MPI tasks x 1 OpenMP threads
MPI task timing breakdown:
Section | min time | avg time | max time |%varavg| %total
---------------------------------------------------------------
Pair | 0.028405 | 0.53791 | 1.9355 | 109.9 | 0.42
Bond | 106.27 | 109.54 | 111.81 | 20.2 | 85.31
Neigh | 2.1543 | 2.1788 | 2.2056 | 1.1 | 1.70
Comm | 1.3421 | 3.538 | 5.9911 | 96.0 | 2.76
Output | 0.32734 | 0.4669 | 1.0963 | 34.9 | 0.36
Modify | 0.54034 | 3.2479 | 10.005 | 210.6 | 2.53
Other | | 8.887 | | | 6.92
Nlocal: 315 ave 1284 max 0 min
Histogram: 6 0 0 0 0 0 0 0 0 2
Nghost: 196.875 ave 585 max 0 min
Histogram: 4 0 0 2 0 0 0 0 0 2
Neighs: 1215.88 ave 4959 max 0 min
Histogram: 6 0 0 0 0 0 0 0 0 2
Total # of neighbors = 9727
Ave neighs/atom = 3.8599206
Ave special neighs/atom = 36.31746
Neighbor list builds = 4832
Dangerous builds = 0
Total wall time: 0:02:08
You can use the Performance metrics and Total wall time to investigate the multicore performance and scaling of LAMMPS on your computer.


