27 integer,
parameter :: rho = 10
31 double precision :: epsilon, sigma, sigma_cut
32 double precision :: mass
33 double precision :: so_max, co_max
35 double precision :: e1, e2
36 double precision :: tau, dt
42 type(threefry_rng_t),
allocatable :: state(:)
45 n_threads = omp_get_max_threads()
46 allocate(state(n_threads))
47 call threefry_rng_init(state, 4811119176716995551_c_int64_t)
52 n = rho *l(1)*l(2)*l(3)
56 sigma_cut = sigma*2**(1.d0/6.d0)
58 call solvent_colloid_lj% init( reshape( [ epsilon ], [1, 1] ), &
59 reshape( [ sigma ], [1, 1] ), reshape( [ sigma_cut ], [1, 1] ) )
63 sigma_cut = sigma*2**(1.d0/6.d0)
65 call colloid_lj% init( reshape( [ epsilon ], [1, 1] ), &
66 reshape( [ sigma ], [1, 1] ), reshape( [ sigma_cut ], [1, 1] ) )
68 mass = rho * sigma**3 * 4 * 3.141/3
69 write(*,*)
'mass =', mass
73 call colloids% init(1)
75 open(15,file =
'data56.txt')
77 write(*, *) colloids% pos
81 call random_number(solvent% vel(:, :))
82 solvent% vel = (solvent% vel - 0.5d0)*sqrt(6.d0*2)
83 solvent% vel = solvent% vel - spread(sum(solvent% vel,
dim=2)/solvent% Nmax, 2, solvent% Nmax)
87 call solvent_cells%init(l, 1.d0)
88 colloids% pos(:,1) = solvent_cells% edges/2.0
90 call solvent% random_placement(solvent_cells% edges, colloids, solvent_colloid_lj, state(1))
92 call solvent% sort(solvent_cells)
94 call neigh% init(colloids% Nmax, 300)
95 call neigh% make_stencil(solvent_cells, 1.5d0)
97 call neigh% update_list(colloids, solvent, 1.5d0, solvent_cells)
101 dt = tau / n_md_steps
103 e1 =
compute_force(colloids, solvent, neigh, solvent_cells% edges, solvent_colloid_lj)
105 solvent% force_old = solvent% force
106 colloids% force_old = colloids% force
109 md_equil:
do j = 1, n_md_steps
110 solvent% pos_old = solvent% pos + dt * solvent% vel + dt**2 * solvent% force / 2
112 do k = 1, solvent% Nmax
113 solvent% pos(:,k) = modulo(solvent% pos_old(:,k), solvent_cells% edges)
115 colloids% pos_old = colloids% pos + dt * colloids% vel + dt**2 * colloids% force / (2 * mass)
116 do k = 1, colloids% Nmax
117 jump = floor(colloids% pos_old(:,k) / solvent_cells% edges)
118 colloids% image(:,k) = colloids% image(:,k) + jump
119 colloids% pos(:,k) = colloids% pos_old(:,k) - jump*solvent_cells% edges
122 call switch(solvent% force, solvent% force_old)
123 call switch(colloids% force, colloids% force_old)
126 e1 =
compute_force(colloids, solvent, neigh, solvent_cells% edges, solvent_colloid_lj)
130 do k = 1, solvent% Nmax
131 solvent% vel(:,k) = solvent% vel(:,k) + dt * ( solvent% force(:,k) + solvent% force_old(:,k) ) / 2
133 colloids% vel = colloids% vel + dt * ( colloids% force + colloids% force_old ) / (2 * mass)
137 call solvent% sort(solvent_cells)
138 call neigh% update_list(colloids, solvent, 1.5d0, solvent_cells)
144 write(*,*)
' e co so | e co co | kin co | kin so | total | temp |' 150 md:
do j = 1, n_md_steps
151 solvent% pos_old = solvent% pos + dt * solvent% vel + dt**2 * solvent% force / 2
153 do k = 1, solvent% Nmax
154 solvent% pos(:,k) = modulo(solvent% pos_old(:,k), solvent_cells% edges)
156 colloids% pos_old = colloids% pos + dt * colloids% vel + dt**2 * colloids% force / (2 * mass)
157 do k = 1, colloids% Nmax
158 jump = floor(colloids% pos_old(:,k) / solvent_cells% edges)
159 colloids% image(:,k) = colloids% image(:,k) + jump
160 colloids% pos(:,k) = colloids% pos_old(:,k) - jump*solvent_cells% edges
162 so_max = max(maxval(sqrt(sum((solvent% pos - solvent% pos_old)**2,
dim=1))), so_max)
163 co_max = max(maxval(sqrt(sum((colloids% pos - colloids% pos_old)**2,
dim=1))), co_max)
165 call switch(solvent% force, solvent% force_old)
166 call switch(colloids% force, colloids% force_old)
169 e1 =
compute_force(colloids, solvent, neigh, solvent_cells% edges, solvent_colloid_lj)
173 do k = 1, solvent% Nmax
174 solvent% vel(:,k) = solvent% vel(:,k) + dt * ( solvent% force(:,k) + solvent% force_old(:,k) ) / 2
176 colloids% vel = colloids% vel + dt * ( colloids% force + colloids% force_old ) / (2 * mass)
180 write(15,*) colloids% pos + colloids% image * spread(solvent_cells% edges,
dim=2, ncopies=colloids% Nmax)
182 call solvent% sort(solvent_cells)
183 call neigh% update_list(colloids, solvent, 1.5d0, solvent_cells)
187 write(*,
'(6f16.3)') e1, e2, mass*sum(colloids% vel**2)/2, sum(solvent% vel**2)/2, &
188 e1+e2+mass*sum(colloids% vel**2)/2+sum(solvent% vel**2)/2, &
194 call h5close_f(error)
Derived type and routines for neighbor listing.
double precision function, public compute_temperature(particles, cells, tz)
Compute the temperature of a mpcd solvent.
subroutine, public simple_mpcd_step(particles, cells, state, alpha, thermostat, T, hydro)
Perform a collision.
double precision function, public compute_force(ps1, ps2, n_list, L, lj_params)
double precision function, public compute_force_n2(ps, L, lj_params)
Compute compact Hilbert indices.
Routines to perform MPCD dynamics.
Routines to perform Molecular Dynamics integration.
program setup_simple_colloid
Lennard-Jones potential definition.