28 integer,
parameter :: rho = 10
29 double precision,
parameter :: sigma = 1
30 double precision,
parameter :: sigma_cut = sigma*2**(1.d0/6.d0)
33 double precision :: epsilon
34 double precision :: mass
35 double precision :: so_max, co_max
37 double precision :: e1, e2
38 double precision :: tau, dt
40 integer :: n_extra_sorting
43 type(threefry_rng_t),
allocatable :: state(:)
45 double precision :: skin
50 n_threads = omp_get_max_threads()
51 allocate(state(n_threads))
52 call threefry_rng_init(state, 719287321987291_c_long)
56 call colloids% init_from_file(
'input_data.h5',
'colloids', h5md_linear, 4)
57 write(*, *) colloids% pos
62 n = rho*l(1)*l(2)*l(3) - int(rho*4*3.142/3 * sigma**3*colloids%Nmax)
63 if (n <= 0) error stop
'Not enough volume available for solvent' 67 call solvent_colloid_lj% init( reshape( [ epsilon ], [1, 1] ), &
68 reshape( [ sigma ], [1, 1] ), reshape( [ sigma_cut ], [1, 1] ) )
72 call colloid_lj% init( reshape( [ epsilon ], [1, 1] ), &
73 reshape( [ 2*sigma ], [1, 1] ), reshape( [ 2*sigma_cut ], [1, 1] ) )
75 mass = 3000.d0 / (l(1)*l(2)*l(3)) * sigma**3 * 4 * 3.141/3
79 call random_number(solvent% vel(:, :))
80 solvent% vel = (solvent% vel - 0.5d0)*sqrt(6.d0*2)
81 solvent% vel = solvent% vel - spread(sum(solvent% vel,
dim=2)/solvent% Nmax, 2, solvent% Nmax)
85 call solvent_cells%init(l, 1.d0)
87 call solvent% random_placement(solvent_cells% edges, colloids, solvent_colloid_lj, state=state(1))
89 call solvent% sort(solvent_cells)
91 call neigh% init(colloids% Nmax, 500)
100 call neigh% make_stencil(solvent_cells, sigma_cut+skin)
101 call neigh% update_list(colloids, solvent, sigma_cut+skin, solvent_cells)
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 write(*,*)
' e co so | e co co | kin co | kin so | total | temp |' 112 solvent% pos_old = solvent% pos
113 colloids% pos_old = colloids% pos
115 md_loop:
do j = 1, n_md_steps
117 do k = 1, colloids% Nmax
118 colloids% pos(:,k) = colloids% pos(:,k) + dt * colloids% vel(:,k) + dt**2 * colloids% force(:,k) / (2 * mass)
120 so_max = solvent% maximum_displacement()
121 co_max = colloids% maximum_displacement()
123 if ( (co_max >= skin*0.1) .or. (so_max >= skin*0.9) )
then 124 call apply_pbc(solvent, solvent_cells% edges)
125 call apply_pbc(colloids, solvent_cells% edges)
126 call solvent% sort(solvent_cells)
127 call neigh% update_list(colloids, solvent, sigma_cut+skin, solvent_cells)
128 solvent% pos_old = solvent% pos
129 colloids% pos_old = colloids% pos
130 n_extra_sorting = n_extra_sorting + 1
133 call switch(solvent% force, solvent% force_old)
134 call switch(colloids% force, colloids% force_old)
137 e1 =
compute_force(colloids, solvent, neigh, solvent_cells% edges, solvent_colloid_lj)
141 colloids% vel = colloids% vel + dt * ( colloids% force + colloids% force_old ) / (2 * mass)
143 write(15,*) colloids% pos + colloids% image * spread(solvent_cells% edges,
dim=2, ncopies=colloids% Nmax)
147 call apply_pbc(solvent, solvent_cells% edges)
148 call apply_pbc(colloids, solvent_cells% edges)
149 call solvent% sort(solvent_cells)
150 call neigh% update_list(colloids, solvent, sigma_cut + skin, solvent_cells)
151 solvent% pos_old = solvent% pos
152 colloids% pos_old = colloids% pos
156 if (modulo(i,10)==0) &
157 write(*,
'(6f16.3)') e1, e2, mass*sum(colloids% vel**2)/2, sum(solvent% vel**2)/2, &
158 e1+e2+mass*sum(colloids% vel**2)/2+sum(solvent% vel**2)/2, &
163 write(*,*)
'n extra sorting', n_extra_sorting
165 call h5close_f(error)
Derived type and routines for neighbor listing.
subroutine, public md_vel(particles, dt)
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)
subroutine, public apply_pbc(particles, edges)
double precision function, public compute_force_n2(ps, L, lj_params)
Compute compact Hilbert indices.
subroutine, public md_pos(particles, dt)
program setup_simple_colloids
Routines to perform MPCD dynamics.
Routines to perform Molecular Dynamics integration.
Lennard-Jones potential definition.