@@ -11,7 +11,7 @@ Base.start(::PeriodicBoundaryConditions) = 1
1111
1212Base. done (pbc:: PeriodicBoundaryConditions , state) = state > length (pbc. boundary)
1313
14- function Base. next (pbc:: PeriodicBoundaryConditions , state)
14+ function Base. next (pbc:: PeriodicBoundaryConditions , state)
1515 pbc. boundary[state], state + 1
1616end
1717
@@ -38,7 +38,7 @@ function apply_boundary_conditions!(ri, rj, pbc::PeriodicBoundaryConditions, R2)
3838
3939 for dx in [0 ,- pbc[2 ],pbc[2 ]], dy in [0 ,- pbc[4 ],pbc[4 ]], dz in [0 ,- pbc[6 ],pbc[6 ]]
4040 rij = @MVector [ri[1 ] - rj[1 ] + dx, ri[2 ] - rj[2 ] + dy, ri[3 ] - rj[3 ] + dz]
41- for x in (1 , 2 , 3 )
41+ for x in (1 , 2 , 3 )
4242 rij[x] -= (pbc[2 x] - pbc[2 x - 1 ]) * div (rij[x], (pbc[2 x] - pbc[2 x - 1 ]))
4343 end
4444 rij2 = dot (rij, rij)
@@ -51,18 +51,16 @@ function apply_boundary_conditions!(ri, rj, pbc::PeriodicBoundaryConditions, R2)
5151end
5252
5353function apply_boundary_conditions! (ri, rj, pbc:: CubicPeriodicBoundaryConditions , R2)
54- rij = @MVector [ Inf , Inf , Inf ]
54+ rij = SVector {3,typeof(R2)} ( Inf , Inf , Inf )
5555 success = false
56- rij2 = 0
57-
58- shifts = @SVector [0 ,- pbc. L,pbc. L]
59- for dx in shifts, dy in shifts, dz in shifts
60- rij = @MVector [ri[1 ] - rj[1 ] + dx, ri[2 ] - rj[2 ] + dy, ri[3 ] - rj[3 ] + dz]
61- for x in (1 , 2 , 3 )
62- rij[x] -= pbc. L * div (rij[x], pbc. L)
63- end
56+ rij2 = zero (typeof (R2))
57+ shifts = SVector {3,typeof(R2)} (0 , - pbc. L, pbc. L)
58+ for dx ∈ shifts, dy ∈ shifts, dz ∈ shifts
59+ dr = SVector {3,typeof(R2)} (dx, dy, dz)
60+ rij = ri - rj + dr
61+ rij = rij - pbc. L * sign .(rij) .* sign (pbc. L) .* floor .(abs .(rij) / abs (pbc. L))
6462 rij2 = dot (rij, rij)
65- if rij2 < R2
63+ if rij2 < R2
6664 success = true
6765 break
6866 end
7371function apply_boundary_conditions! (ri, rj, pbc:: BoundaryConditions , R2)
7472 rij = ri - rj
7573 (rij, dot (rij,rij),true )
76- end
74+ end
0 commit comments