RMPCDMD
setup_simple_fluid.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 setup_fluid
6  use common
7  use cell_system
9  use hilbert
10  use interaction
11  use hdf5
12  use h5md_module
13  use mpcd
14  use threefry_module
15  use iso_c_binding
16  use omp_lib
17  implicit none
18 
19  type(threefry_rng_t), target, allocatable :: state(:)
20 
21  type(cell_system_t) :: solvent_cells
22  type(particle_system_t) :: solvent
23 
24  type(profile_t) :: tz
25 
26  type(h5md_file_t) :: datafile
27  type(h5md_element_t) :: elem
28  type(h5md_element_t) :: e_solvent, e_solvent_v, e_solvent_spec, e_solvent_id
29  type(h5md_element_t) :: e_solvent_image
30  integer(HID_T) :: box_group, solvent_group
31 
32  integer, parameter :: N = 10240
33 
34  integer :: i, L(3), error, clock, n_threads
35 
36  double precision, parameter :: tau=0.1d0
37  double precision, parameter :: T = 1
38  double precision :: v_com(3), wall_v(3,2)
39 
40  n_threads = omp_get_max_threads()
41  allocate(state(n_threads))
42  call threefry_rng_init(state, 2985348049158689438_c_int64_t)
43 
44  call h5open_f(error)
45 
46  l = [8, 8, 16]
47 
48  call solvent% init(n)
49 
50  do i=1, solvent% Nmax
51  solvent% vel(1,i) = threefry_normal(state(1))*sqrt(t)
52  solvent% vel(2,i) = threefry_normal(state(1))*sqrt(t)
53  solvent% vel(3,i) = threefry_normal(state(1))*sqrt(t)
54  end do
55  v_com = sum(solvent% vel, dim=2) / size(solvent% vel, dim=2)
56  solvent% vel = solvent% vel - spread(v_com, dim=2, ncopies=size(solvent% vel, dim=2))
57 
58  solvent% force = 0
59  solvent% species = 1
60  call solvent% random_placement(l*1.d0, state=state(1))
61 
62  call solvent_cells%init(l, 1.d0)
63 
64  call solvent_cells%count_particles(solvent% pos)
65 
66  call datafile% create('data_setup_simple_fluid.h5', 'RMPCDMD:setup_simple_fluid', '0.0 dev', 'Pierre de Buyl')
67 
68  call tz% init(0.d0, solvent_cells% edges(3), l(3))
69 
70  call h5gcreate_f(datafile% particles, 'solvent', solvent_group, error)
71  call h5gcreate_f(solvent_group, 'box', box_group, error)
72  call h5md_write_attribute(box_group, 'dimension', 3)
73  call h5md_write_attribute(box_group, 'boundary', ['periodic', 'periodic', 'periodic'])
74  call elem% create_fixed(box_group, 'edges', l*1.d0)
75  call h5gclose_f(box_group, error)
76 
77  call e_solvent% create_time(solvent_group, 'position', solvent% pos, ior(h5md_time, h5md_store_time))
78  call e_solvent_v% create_time(solvent_group, 'velocity', solvent% vel, ior(h5md_time, h5md_store_time))
79  call e_solvent_spec% create_time(solvent_group, 'species', solvent% species, ior(h5md_time, h5md_store_time))
80  call e_solvent_id% create_time(solvent_group, 'id', solvent% id, ior(h5md_time, h5md_store_time))
81  call e_solvent_image% create_time(solvent_group, 'image', solvent% image, ior(h5md_time, h5md_store_time))
82 
83  call solvent% sort(solvent_cells)
84  call solvent_cells%count_particles(solvent% pos)
85  solvent_cells% origin(1) = threefry_double(state(1)) - 1
86  solvent_cells% origin(2) = threefry_double(state(1)) - 1
87  solvent_cells% origin(3) = threefry_double(state(1)) - 1
88 
89  wall_v = 0
90  do i = 1, 200
91  call simple_mpcd_step(solvent, solvent_cells, state)
92  call mpcd_stream_periodic(solvent, solvent_cells, tau)
93  solvent_cells% origin(1) = threefry_double(state(1)) - 1
94  solvent_cells% origin(2) = threefry_double(state(1)) - 1
95  solvent_cells% origin(3) = threefry_double(state(1)) - 1
96  call solvent% sort(solvent_cells)
97  call solvent_cells%count_particles(solvent% pos)
98  end do
99  do i = 1,solvent% Nmax
100  if (solvent% pos(3,i) <= solvent_cells% edges(3)/2) then
101  solvent% species(i) = 1
102  else
103  solvent% species(i) = 2
104  end if
105  end do
106 
107  solvent% image = 0
108 
109  do i = 1, 200
110  !call simple_mpcd_step(solvent, solvent_cells, state)
111  call wall_mpcd_step(solvent, solvent_cells, state)
112  v_com = sum(solvent% vel, dim=2) / size(solvent% vel, dim=2)
113 
114  call mpcd_stream_periodic(solvent, solvent_cells, tau)
115 
116  solvent_cells% origin(1) = threefry_double(state(1)) - 1
117  solvent_cells% origin(2) = threefry_double(state(1)) - 1
118  solvent_cells% origin(3) = threefry_double(state(1)) - 1
119  call solvent% sort(solvent_cells)
120  call solvent_cells%count_particles(solvent% pos)
121  call e_solvent% append(solvent% pos, i, i*tau)
122  call e_solvent_image% append(solvent% image, i, i*tau)
123  call e_solvent_v% append(solvent% vel, i, i*tau)
124  call e_solvent_spec% append(solvent% species, i, i*tau)
125  call e_solvent_id% append(solvent% id, i, i*tau)
126 
127  end do
128 
129  clock = 0
130  do i = 1 , solvent_cells% N
131  if ( solvent_cells% cell_count(i) > 0 ) clock = clock + 1
132  end do
133  write(*,*) clock, 'filled cells'
134  write(*,*) l(1)*l(2)*l(3), 'actual cells'
135 
136  call e_solvent% close()
137  call e_solvent_v% close()
138 
139  call h5gclose_f(solvent_group, error)
140 
141  call tz% norm()
142  call elem% create_fixed(datafile% observables, 'tz', tz% data)
143  call elem% create_fixed(datafile% observables, 'tz_count', tz% count)
144 
145  call h5gclose_f(datafile% observables, error)
146 
147  call datafile% close()
148 
149  call h5close_f(error)
150 
151 end program setup_fluid
subroutine, public wall_mpcd_step(particles, cells, state, wall_temperature, wall_v, wall_n, thermostat, bulk_temperature, alpha, keep_cell_v)
Collisions in partially filled cells at the walls use the rule of Lamura et al (2001) ...
Definition: mpcd.f90:195
subroutine, public mpcd_stream_periodic(particles, cells, dt)
Stream MPCD particles in a periodic system.
Definition: mpcd.f90:441
Data for particles.
subroutine, public simple_mpcd_step(particles, cells, state, alpha, thermostat, T, hydro)
Perform a collision.
Definition: mpcd.f90:72
program setup_fluid
Compute compact Hilbert indices.
Definition: hilbert.f90:9
Utility routines.
Definition: common.f90:12
Container for a profile, e.g. v(x)
Definition: common.f90:66
integer, parameter dim
Definition: hilbert.f90:15
Routines to perform MPCD dynamics.
Definition: mpcd.f90:18
Spatial cells.
Definition: cell_system.f90:11
Lennard-Jones potential definition.
Definition: interaction.f90:10