RMPCDMD
test_cell_system_0.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 
5 program try_all
6  use cell_system
7  use hilbert
8  use tester
9  implicit none
10 
11  type(cell_system_t) :: solvent_cells
12  type(tester_t) :: test
13 
14  integer, parameter :: N = 1000000
15  double precision, target, allocatable :: pos1(:, :), pos2(:, :)
16  double precision, pointer :: pos(:,:), pos_old(:,:), pos_pointer(:,:)
17 
18  integer :: i, L(3), seed_size, clock
19  integer, allocatable :: seed(:)
20  integer :: h, c1(3), c2(3)
21 
22  allocate(pos1(3, n))
23  allocate(pos2(3, n))
24 
25  call test% init()
26 
27  call random_seed(size = seed_size)
28  allocate(seed(seed_size))
29  call system_clock(count=clock)
30  seed = clock + 37 * [ (i - 1, i = 1, seed_size) ]
31  call random_seed(put = seed)
32  deallocate(seed)
33 
34  pos => pos1
35  pos_old => pos2
36 
37  l = [120, 30, 30]
38 
39  call random_number(pos)
40  do i = 1, 3
41  pos(i, :) = pos(i, :)*l(i)
42  end do
43 
44  call solvent_cells%init(l, 1.d0)
45 
46  call solvent_cells%count_particles(pos)
47 
48  call solvent_cells%sort_particles(pos, pos_old)
49 
50  pos_pointer => pos
51  pos => pos_old
52  pos_old => pos_pointer
53 
54  call solvent_cells%count_particles(pos)
55 
56  call test% assert_equal(solvent_cells%cell_start(1), 1)
57  call test% assert_equal(solvent_cells%cell_start(solvent_cells%N), n+1)
58  call test% assert_equal(sum(solvent_cells%cell_count), n)
59 
60  h = 1
61  do i = 1, n
62  if (i .ge. solvent_cells% cell_start(h) + solvent_cells% cell_count(h)) h = h + 1
63  do while (solvent_cells% cell_count(h) .eq. 0)
64  h = h+1
65  end do
66  c1 = solvent_cells%cartesian_indices(pos(:,i))
67  c2 = compact_h_to_p(h-1, solvent_cells% M)
68  call test% assert_equal(c1, c2)
69  end do
70 
71  call test% print()
72 
73  deallocate(pos1)
74  deallocate(pos2)
75 
76 end program try_all
pure integer function, dimension(dim), public compact_h_to_p(h, m)
Definition: hilbert.f90:274
Compute compact Hilbert indices.
Definition: hilbert.f90:9
Spatial cells.
Definition: cell_system.f90:11
program try_all