summaryrefslogtreecommitdiff
path: root/putParticleInBox.f90
diff options
context:
space:
mode:
authorConnor Moore <connor@hhmoore.ca>2026-03-23 01:40:30 -0400
committerConnor Moore <connor@hhmoore.ca>2026-03-23 01:40:30 -0400
commit5b08f435327695bb633cd21ae8252b25528de3f6 (patch)
tree7eb5cdfa0acded8eaf8f1881e8542fe7b441d67c /putParticleInBox.f90
parentf7ad40d801e30f542baaf471e0b0d08aacc212ee (diff)
New report and code for final submission.HEADmaster
Diffstat (limited to 'putParticleInBox.f90')
-rw-r--r--putParticleInBox.f9033
1 files changed, 33 insertions, 0 deletions
diff --git a/putParticleInBox.f90 b/putParticleInBox.f90
new file mode 100644
index 0000000..d98a116
--- /dev/null
+++ b/putParticleInBox.f90
@@ -0,0 +1,33 @@
+ ! intakes coordinates and outputs index
+ integer function indexfxn(px, py) result(idx)
+ double precision, intent(in) :: px, py
+ double precision :: boxSize,yCoord
+ integer :: ix, iy
+
+ !> Check if particle is in box
+ if(abs(px).GT.L/2 .OR. abs(py).GT.L/2) then
+ !> Particle is outside, don't track it
+ idx=b*b ! This is the "recycle bin" for untracked particles.
+ else
+ ! the sector size
+ ! M = floor(L / rc)
+ yCoord = - py
+ ! coordinate + half length of boundary [-L/2,L/2] -> [0,L]
+ ! divided by effective particle size to give coordinate
+ boxSize=L/real(b,8)
+ ix = floor((px + L/2.0d0)/boxSize)
+ iy = floor((yCoord + L/2.0d0)/boxSize)
+
+ ! for particles on the boundary
+ ix = min(max(ix, 0), b-1)
+ iy = min(max(iy, 0), b-1)
+ if (ix < 0 .or. ix >= b .or. iy < 0 .or. iy >= b) then
+ print *, "ERROR: particle outside sector grid"
+ print *, "px, py =", px, py
+ stop
+ end if
+
+ ! call rey's function
+ idx = TWOtoONE(ix,iy)
+ end if
+ end function indexfxn