Coverage for examples/poiseuille.py: 100%
47 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1""" Example of a nanoslit pore simulation using tethered LJ particles
3 The particles are tethered with a Hooke spring. The wall particles interact with a relaxation device.
4 All particles are integrated forward in time with the NVE integrator
6 Wall density is set to 1.0 and fluid density to 0.8 - this is achieved by
7 inclusion of a dummy particle type
9 Initial and final configurations are saved in xyz format for easy inspection in vmd
10"""
12import random
13import os
15import numpy as np
17import gamdpy as gp
19# Some system parameters
20nx, ny, nz = 6, 6, 10
21rhoWall = 1.0
22rhoFluid = 0.7
24# Setup a default fcc configuration
25configuration = gp.Configuration(D=3)
26configuration.make_lattice(gp.unit_cells.FCC, cells=[nx, ny, nz], rho=rhoWall)
27configuration['m'] = 1.0
30# Fluid particles have type '0', wall particles '1', dummy particles '2'
31nwall, npart = 0, configuration.N
32hlz = 0.5 * configuration.simbox.get_lengths()[2]
33for n in range(npart):
34 if configuration['r'][n][2] + hlz < 3.0:
35 configuration.ptype[n] = 1
36 nwall = nwall + 1
38nfluid = np.sum(configuration.ptype == 0)
39nfluidWanted = int(nfluid * rhoFluid / rhoWall)
41while nfluid > nfluidWanted:
42 idx = random.randint(0, npart - 1)
43 if configuration.ptype[idx] == 0:
44 configuration.ptype[idx] = 2
45 nfluid = nfluid - 1
47gp.tools.save_configuration(configuration, "initial.xyz")
49# Tether specifications.
50tether = gp.Tether()
51tether.set_anchor_points_from_types(particle_types=[1], spring_constants=[300.0], configuration=configuration)
53# Add gravity force
54grav = gp.Gravity()
55grav.set_gravity_from_types(particle_types=[0], forces=[0.01], configuration=configuration)
57# Temp relaxation for wall particles
58relax = gp.Relaxtemp()
59relax.set_relaxation_from_types(particle_types=[1], temperature=[2.],
60 relax_times=[0.01],configuration=configuration);
62# Set the pair interactions
63pair_func = gp.apply_shifted_potential_cutoff(gp.LJ_12_6_sigma_epsilon)
64sig = [[1.0, 1.0, 0.0], [1.0, 1.0, 0.0], [0.0, 0.0, 0.0]]
65eps = [[1.0, 1.0, 0.0], [1.0, 1.0, 0.0], [0.0, 0.0, 0.0]]
66cut = np.array(sig) * 2.5
67pair_pot = gp.PairPotential(pair_func, params=[sig, eps, cut], max_num_nbs=1000)
69# Temperature
70configuration.randomize_velocities(temperature=2.0)
72# Setup integrator: NVT
73integrator = gp.integrators.NVE(dt=0.005)
75# Compute plan
76compute_plan = gp.get_default_compute_plan(configuration)
78# Setup runtime actions, i.e. actions performed during simulation of timeblocks
79runtime_actions = [gp.TrajectorySaver(),
80 gp.ScalarSaver()]
82# Setup Simulation. Total number of time steps: num_blocks * steps_per_block
83sim = gp.Simulation(configuration, [pair_pot, tether, grav, relax], integrator, runtime_actions,
84 num_timeblocks=100, steps_per_timeblock=64,
85 storage='memory', compute_plan=compute_plan)
87prof = gp.CalculatorHydrodynamicProfile(configuration, 0)
89# Run simulation one block at a time
90for block in sim.run_timeblocks():
91 print(sim.status(per_particle=True))
92 prof.update()
94print(sim.summary())
96prof.read()
98gp.tools.save_configuration(configuration, "final.xyz")