RMPCDMD
test_neighbor_list_1.f90
Go to the documentation of this file.
1 ! This file is part of RMPCDMD
2 ! Copyright (c) 2015-2016 Pierre de Buyl and contributors
3 ! License: BSD 3-clause (see file LICENSE)
4 
6  use common
7  use cell_system
9  use hilbert
10  use neighbor_list
11  use threefry_module
12  use iso_c_binding
13  use tester
14  implicit none
15 
16  type(tester_t) :: test
17 
18  type(particle_system_t) :: solvent
19  type(particle_system_t) :: colloids
20  type(cell_system_t) :: solvent_cells
21  type(neighbor_list_t) :: neigh
22 
23  integer, parameter :: rho = 20
24  integer :: N_solvent, N_colloids
25 
26  integer :: L(3)
27  integer :: i, j, n_neigh
28  integer :: neighbor_list_size
29 
30  double precision :: xij(3), dist_sq, cutoff
31 
32  type(threefry_rng_t) :: state(1)
33  integer :: seed_size, clock
34  integer, allocatable :: seed(:)
35 
36  call test% init()
37 
38  call random_seed(size = seed_size)
39  allocate(seed(seed_size))
40  call system_clock(count=clock)
41  seed = clock + 37 * [ (i - 1, i = 1, seed_size) ]
42  call random_seed(put = seed)
43  deallocate(seed)
44 
45  call threefry_rng_init(state, int(clock, c_int64_t))
46 
47  l = [20, 10, 35]
48  n_solvent = l(1)*l(2)*l(3)*rho
49  n_colloids = 20
50 
51  call solvent% init(n_solvent)
52  call colloids% init(n_colloids)
53 
54  call solvent_cells%init(l, 1.d0)
55 
56  solvent% species = 1
57  colloids% species = 1
58  call solvent% random_placement(l*1.d0, state=state(1))
59  call colloids% random_placement(l*1.d0, state=state(1))
60 
61  call solvent% sort(solvent_cells)
62 
63  cutoff = 3.6
64  neighbor_list_size = rho * 6 * int(cutoff**3)
65 
66  call neigh% init(colloids% Nmax, neighbor_list_size)
67 
68  call neigh% make_stencil(solvent_cells, cutoff)
69 
70  call neigh% update_list(colloids, solvent, cutoff*0.8, solvent_cells)
71 
72  do i = 1, colloids% Nmax
73  n_neigh = neigh% n(i)
74  do j = 1, solvent% Nmax
75  xij = rel_pos(colloids% pos(:, i), solvent% pos(:, j), solvent_cells% edges)
76  dist_sq = sum(xij**2)
77  if (dist_sq < cutoff**2) then
78  call test% assert_equal( is_in_list(j, neigh% list(1:n_neigh,i)), .true. )
79  end if
80  end do
81  end do
82 
83  call test% print()
84 
85 contains
86 
87  function is_in_list(idx, list) result(l)
88  integer, intent(in) :: idx
89  integer, intent(in) :: list(:)
90 
91  logical :: l
92 
93  l = ( minval( abs(list - idx) ) == 0 )
94 
95  end function is_in_list
96 
97 end program test_neighbor_list
Derived type and routines for neighbor listing.
logical function is_in_list(idx, list)
Data for particles.
Compute compact Hilbert indices.
Definition: hilbert.f90:9
Utility routines.
Definition: common.f90:12
program test_neighbor_list
pure double precision function, dimension(3), public rel_pos(x, y, L)
Return x-y distance with minimum image convention.
Definition: common.f90:163
Spatial cells.
Definition: cell_system.f90:11