variable 		dt 		equal 1e-6
variable        m_chamber 	equal 1.07e-5
variable        m_chamber2 	equal 1.07e-5

variable		t_set		equal	0.01			#time to initialise the simulation		[sec]
variable		t_set2		equal	1.00			#time to initialise the simulation		[sec]
variable		dump_rate	equal	0.001/${dt}			#rate of writing dump rate				[]
variable		st_set		equal	${t_set}/${dt}		#steps to initialise the simulation		[]
variable		st_set2		equal	${t_set2}/${dt}		#steps to initialise the simulation		[]

echo            both

atom_style      granular
atom_modify     map array
communicate     single vel yes

boundary        f f f
newton          off
units           si

region          reg block -0.09 0.09 &
                          -0.09 0.09 &
                          -0.09 0.09 &
                          units box

create_box      1 reg

include         matprops.lmp

#neighbor        ${dp} bin
neigh_modify    delay 0


# timestep, gravity
timestep        ${dt}
fix             gravi all gravity 0. vector 0. 0. 1.

# particle distributions and insertion, large numbers are primes used for RNG startup
fix             pts1 all particletemplate/sphere 67867979                  &
                                                atom_type 1                &
                                                density constant ${rhop}   &
                                                radius  constant ${rp}
												
fix             pts2 all particletemplate/sphere 67867979                  &
                                                atom_type 1                &
                                                density constant ${rhop}   &
                                                radius  constant ${rp}
												
fix             pdd1 all particledistribution/discrete 15485863 1 pts1 1

fix             pdd2 all particledistribution/discrete 15485863 1 pts2 1

variable        xmin_ch equal -.001
variable        ymin_ch equal -.001
variable        xmax_ch equal  .001
variable        ymax_ch equal  .001 

variable        zmin_cA equal  .011
variable        zmax_cA equal  .013

variable        zmin_cB equal  -.013
variable        zmax_cB equal  -.011

region          cA block  ${xmin_ch} ${xmax_ch} &
                          ${ymin_ch} ${ymax_ch} &
                          ${zmin_cA} ${zmax_cA} 

region          cB block  ${xmin_ch} ${xmax_ch} &
                          ${ymin_ch} ${ymax_ch} &
                          ${zmin_cB} ${zmax_cB} 

fix             ins_cA all insert/pack seed                 6028157      &
                                       distributiontemplate pdd1         &
                                       vel constant         0. 0. 0.    &
                                       insert_every         once         &
                                       overlapcheck         yes          &
                                       all_in               yes          &
                                       mass_in_region       ${m_chamber} &
                                       region               cA

fix             ins_cB all insert/pack seed                 6028157      &
                                       distributiontemplate pdd2         &
                                       vel constant         0. 0. 0.    &
                                       insert_every         once         &
                                       overlapcheck         yes          &
                                       all_in               yes          &
                                       mass_in_region       ${m_chamber2} &
                                       region               cB

# apply nve integration to all particles that are inserted as single particles
fix             integr all nve/sphere

group          particlesInRegionCB region cB

# screen output
thermo_style    custom step atoms ke
thermo          5000
thermo_modify   lost ignore norm no

# insert the first particles so that dump is not empty
shell   mkdir ./post
shell	mkdir ./restart

dump	     dmp all custom/vtk ${dump_rate} ./post/particles_*.vtk id type x y z vx vy vz fx fy fz radius mass
dump_modify     dmp sort id

#-------Run---------------------------------------------------------------------------------------------------------------------------------------------------------#

run 	${st_set}

unfix		ins_cA
unfix		ins_cB

velocity       particlesInRegionCB set NULL NULL -1.0
#-------Write restart file------------------------------------------------------------------------------------------------------------------------------------------#

run 	${st_set2}

write_restart   ./restart/restart.liggghts