summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--class/class-langevin-motion.f9069
-rw-r--r--class/makefile19
-rw-r--r--class/mod_globals.f908
-rw-r--r--class/mod_sectors.f9065
-rw-r--r--class/mod_sectors_test.f9038
5 files changed, 130 insertions, 69 deletions
diff --git a/class/class-langevin-motion.f90 b/class/class-langevin-motion.f90
index 0b97d2d..fcdc77a 100644
--- a/class/class-langevin-motion.f90
+++ b/class/class-langevin-motion.f90
@@ -1,72 +1,3 @@
-module globals
-! Global variables
-implicit none
-integer, parameter :: n=100
-double precision, parameter :: pi=2q0*asin(1q0) ! numerical constant
-double precision, parameter :: L=1.0
-logical, dimension(n) :: is_tracked = .TRUE.
-end module globals
-
-module sectors
-use globals
-implicit none
-contains
-
-subroutine ONETO2(id, box_size, x, y)
- implicit none
- integer, intent(in) :: id
- integer, intent(in) :: box_size
- integer, intent(out) :: x, y
-
- y = id / box_size
- x = mod(id, box_size)
-end subroutine ONETO2
-
-function TWOtoONE(x, y, box_size) result(id)
- implicit none
- integer, intent(in) :: x, y, box_size
- integer :: id
-
- id = y * box_size + x
-end function TWOtoONE
-
-function get_neighbour_ids(p, N) result (neighbours)
- integer, intent(in) :: p !> The sequential position
- integer, intent(in) :: N !> The grid size (i.e., NxN sectors)
- integer, allocatable, dimension(:) :: neighbours !> The list of neighbours
- integer :: i,j,k=0
- integer :: x_cell, y_cell, x_test, y_test
- integer :: max_list(8)=-1
-
- call ONETO2(p,N,x_cell,y_cell)
- max_list(
-
- !> Start by just getting all of the neighbours
- do i = -1, 1
- do j = -1,1
- if(i == 0 .and. j == 0) cycle !> Skip the cell itself
-
- !> The "test" coordinate
- x_test = x_cell + i
- y_test = y_cell + j
-
- !> If the coordinates are real (within the expected range), add them to the list:
- if((x_test .ge. 0 .and. x_test .lt. N) .and. (y_test .ge. 0 .and. y_test .lt. N)) then
- !> Increment the number of correct coordinates
- k = k + 1
- !> Flip a zero to the new coordinate in the max list
- max_list(k) = TWOtoONE(x_test, y_test, N)
- end if
- end do
- end do
-
- !> Return a vector of all non-zero elements
- neighbours = pack(max_list, max_list.ge.0)
-
-end function get_neighbour_ids
-
-end module sectors
-
module langevin
! Initialization and update rule for Langevin particles
use globals
diff --git a/class/makefile b/class/makefile
new file mode 100644
index 0000000..935d1c6
--- /dev/null
+++ b/class/makefile
@@ -0,0 +1,19 @@
+FC = gfortran
+FFLAGS = -Wall -Wextra
+
+all: test
+
+mod_globals.o: mod_globals.f90
+ $(FC) $(FFLAGS) -c mod_globals.f90
+
+mod_sectors.o: mod_sectors.f90
+ $(FC) $(FFLAGS) -c mod_sectors.f90
+
+test_sectors: mod_sectors_test.f90 mod_globals.o mod_sectors.o
+ $(FC) $(FFLAGS) -o test_sectors.x mod_sectors_test.f90 mod_globals.o mod_sectors.o
+
+tests: test_sectors
+ ./test_sectors.x
+
+clean:
+ rm -f *.o *.x *.mod
diff --git a/class/mod_globals.f90 b/class/mod_globals.f90
new file mode 100644
index 0000000..7717c88
--- /dev/null
+++ b/class/mod_globals.f90
@@ -0,0 +1,8 @@
+module globals
+! Global variables
+implicit none
+integer, parameter :: n=100
+double precision, parameter :: pi=2q0*asin(1q0) ! numerical constant
+double precision, parameter :: L=1.0
+logical, dimension(n) :: is_tracked = .TRUE.
+end module globals
diff --git a/class/mod_sectors.f90 b/class/mod_sectors.f90
new file mode 100644
index 0000000..d32a75a
--- /dev/null
+++ b/class/mod_sectors.f90
@@ -0,0 +1,65 @@
+module sectors
+use globals
+implicit none
+contains
+
+subroutine ONETO2(id, box_size, x, y)
+ implicit none
+ integer, intent(in) :: id
+ integer, intent(in) :: box_size
+ integer, intent(out) :: x, y
+
+ y = id / box_size
+ x = mod(id, box_size)
+end subroutine ONETO2
+
+function TWOtoONE(x, y, box_size) result(id)
+ implicit none
+ integer, intent(in) :: x, y, box_size
+ integer :: id
+
+ id = y * box_size + x
+end function TWOtoONE
+
+function get_neighbour_ids(p, N) result (neighbours)
+ integer, intent(in) :: p !> The sequential position
+ integer, intent(in) :: N !> The grid size (i.e., NxN sectors)
+ integer, allocatable, dimension(:) :: neighbours !> The list of neighbours
+ integer :: i,j,k
+ integer :: x_cell, y_cell, x_test, y_test
+ integer :: max_list(9)
+
+ !> Don't save the values between calls
+ k = 1
+ max_list = -1
+
+ call ONETO2(p,N,x_cell,y_cell)
+ max_list(k) = p
+
+ !print *, max_list
+
+ !> Start by just getting all of the neighbours
+ do i = -1,1
+ do j = -1,1
+ if(i == 0 .and. j == 0) cycle !> Skip the cell itself
+
+ !> The "test" coordinate
+ x_test = x_cell + i
+ y_test = y_cell + j
+
+ !> If the coordinates are real (within the expected range), add them to the list:
+ if((x_test .ge. 0 .and. x_test .lt. N) .and. (y_test .ge. 0 .and. y_test .lt. N)) then
+ !> Increment the number of correct coordinates
+ k = k + 1
+ !> Flip a zero to the new coordinate in the max list
+ max_list(k) = TWOtoONE(x_test, y_test, N)
+ end if
+ end do
+ end do
+
+ !> Return a vector of all non-zero elements
+ neighbours = pack(max_list, max_list>= 0.0)
+
+end function get_neighbour_ids
+
+end module sectors
diff --git a/class/mod_sectors_test.f90 b/class/mod_sectors_test.f90
new file mode 100644
index 0000000..1f490df
--- /dev/null
+++ b/class/mod_sectors_test.f90
@@ -0,0 +1,38 @@
+program sectors_test
+
+ use, intrinsic :: iso_fortran_env
+ use :: sectors
+ implicit none
+
+ integer(int32), allocatable, dimension(:) :: neighbours_list
+
+ !> Testing get_neighbor_ids function
+ !> list = get_neighbor_ids(p,N)
+ !> input: p,n
+ !> Output: variable-length vector
+
+ print *, "Neighbours of 0:"
+ neighbours_list = get_neighbour_ids(0,4)
+ print *, neighbours_list
+
+ print *, "Neighbours of 1:"
+ neighbours_list = get_neighbour_ids(1,4)
+ print *, neighbours_list
+
+ print *, "Neighbours of 5:"
+ neighbours_list = get_neighbour_ids(5,4)
+ print*, neighbours_list
+
+ print *, "Neighbours of 12:"
+ neighbours_list = get_neighbour_ids(12,4)
+ print*, neighbours_list
+
+ print *, "Neighbours of 13:"
+ neighbours_list = get_neighbour_ids(13,4)
+ print*, neighbours_list
+
+ print *, "Neighbours of 15:"
+ neighbours_list = get_neighbour_ids(15,4)
+ print*, neighbours_list
+
+end program sectors_test