def test(self): c = ShapeBasedConstraint() w = Wall(normal=[-1, 0, 0]) c.shape = w # Does the shape parameter return the correct lcass self.assertEqual(c.shape.__class__, Wall) # Do the sciprt object match self.assertEqual(c.shape, w) # Different shape c.shape = Sphere(radius=1) # Test class self.assertEqual(c.shape.__class__, Sphere) # Test parameter retrieval self.assertAlmostEqual(c.shape.radius, 1, places=8) with self.assertRaises(RuntimeError): c.shape = Wall(thisparameterdoesnotexist=0)
class LBBoundariesBase(object): system = espressomd.System(box_l=[10.0, 10.0, 10.0]) wall_shape1 = Wall(normal=[1., 0., 0.], dist=2.5) wall_shape2 = Wall(normal=[-1., 0., 0.], dist=-7.5) def test_add(self): boundary = espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1) self.system.lbboundaries.add(boundary) self.assertEqual(boundary, self.system.lbboundaries[0]) def test_remove(self): lbb = self.system.lbboundaries b1 = lbb.add( espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) b2 = lbb.add( espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) lbb.remove(b1) self.assertFalse(b1 in lbb) self.assertTrue(b2 in lbb) def test_size(self): lbb = self.system.lbboundaries self.assertEqual(lbb.size(), 0) lbb.add(espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) self.assertEqual(lbb.size(), 1) lbb.add(espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) self.assertEqual(lbb.size(), 2) def test_empty(self): lbb = self.system.lbboundaries self.assertTrue(lbb.empty()) lbb.add(espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) self.assertFalse(lbb.empty()) def test_clear(self): lbb = self.system.lbboundaries b1 = lbb.add( espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) b2 = lbb.add( espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) lbb.clear() self.assertTrue(lbb.empty()) def test_boundary_flags(self): lbb = self.system.lbboundaries lbb.add(espressomd.lbboundaries.LBBoundary(shape=self.wall_shape1)) lbb.add(espressomd.lbboundaries.LBBoundary(shape=self.wall_shape2)) rng = range(20) lbf = self.lbf for i in product(range(0, 5), rng, rng): self.assertEqual(lbf[i].boundary, 1) for i in product(range(5, 15), rng, rng): self.assertEqual(lbf[i].boundary, 0) for i in product(range(15, 20), rng, rng): self.assertEqual(lbf[i].boundary, 2) lbb.clear() for i in product(rng, rng, rng): self.assertEqual(lbf[i].boundary, 0)
system.cell_system.skin = 0.3 system.thermostat.set_langevin(kT=temp, gamma=gamma, seed=42) # Visualizer visualizer = visualization_opengl.openGLLive( system, camera_position=[-3 * box_l, box_l * 0.5, box_l * 0.5], camera_right=[0, 0, 1], drag_force=5 * 298, background_color=[1, 1, 1], light_pos=[30, 30, 30], ext_force_arrows_type_scale=[0.0001], ext_force_arrows=False) # Walls system.constraints.add(shape=Wall(dist=0, normal=[0, 0, 1]), particle_type=types["Electrode"]) system.constraints.add(shape=Wall(dist=-box_z, normal=[0, 0, -1]), particle_type=types["Electrode"]) # Place particles for i in range(int(n_ionpairs)): p = numpy.random.random(3) * box_l p[2] += lj_sigmas["Electrode"] system.part.add(id=len(system.part), type=types["Cl"], pos=p, q=charges["Cl"], mass=masses["Cl"]) for i in range(int(n_ionpairs)): p = numpy.random.random(3) * box_l
os.remove(os.path.join(checkpoint.checkpoint_dir, filepath)) LB_implementation = None if 'LB.CPU' in modes: LB_implementation = espressomd.lb.LBFluid elif 'LB.GPU' in modes and espressomd.gpu_available(): LB_implementation = espressomd.lb.LBFluidGPU if LB_implementation: lbf = LB_implementation(agrid=0.5, visc=1.3, dens=1.5, tau=0.01) system.actors.add(lbf) if 'THERM.LB' in modes: system.thermostat.set_lb(LB_fluid=lbf, seed=23, gamma=2.0) if any(has_features(i) for i in ["LB_BOUNDARIES", "LB_BOUNDARIES_GPU"]): if 'EK.GPU' not in modes: system.lbboundaries.add( LBBoundary(shape=Wall(normal=(0, 0, 1), dist=0.5), velocity=(1e-4, 1e-4, 0))) EK_implementation = None if 'EK.GPU' in modes and espressomd.gpu_available( ) and espressomd.has_features('ELECTROKINETICS'): EK_implementation = espressomd.electrokinetics ek = EK_implementation.Electrokinetics(agrid=0.5, lb_density=26.15, viscosity=1.7, friction=0.0, T=1.1, prefactor=0.88, stencil="linkcentered") ek_species = EK_implementation.Species( density=0.4,
checkpoint_id=idx, checkpoint_path="@CMAKE_CURRENT_BINARY_DIR@") LB_implementation = None if 'LB.CPU' in modes: LB_implementation = espressomd.lb.LBFluid elif 'LB.GPU' in modes and espressomd.gpu_available(): LB_implementation = espressomd.lb.LBFluidGPU if LB_implementation: lbf = LB_implementation(agrid=0.5, visc=1.3, dens=1.5, tau=0.01) system.actors.add(lbf) if 'LBTHERM' in modes: system.thermostat.set_lb(LB_fluid=lbf, seed=23, gamma=2.0) if espressomd.has_features("LB_BOUNDARIES") or espressomd.has_features("LB_BOUNDARIES_GPU"): if not 'EK.GPU' in modes: system.lbboundaries.add( LBBoundary(shape=Wall(normal=(0, 0, 1), dist=0.5), velocity=(1e-4, 1e-4, 0))) EK_implementation = None if 'EK.GPU' in modes and espressomd.gpu_available() and espressomd.has_features('ELECTROKINETICS'): EK_implementation = espressomd.electrokinetics ek = EK_implementation.Electrokinetics( agrid=0.5, lb_density=26.15, viscosity=1.7, friction=0.0, T=1.1, prefactor=0.88, stencil="linkcentered") ek_species = EK_implementation.Species( density=0.4, D=0.02,
# Here we use exactly the same parameters for the geometry of the constraints # that was used for the LB boundaries. This can be done, since the distance # function used for the constraints is the same as the one used for the # LB boundaries. # ########################################################################## cylinder = Cylinder(center=0.5 * BOX_L, axis=[1, 0, 0], radius=DIAMETER / 2.0, length=LENGTH, direction=-1) system.constraints.add(shape=cylinder, particle_type=1) # Setup walls wall = Wall(dist=PADDING, normal=[1, 0, 0]) system.constraints.add(shape=wall, particle_type=1) wall = Wall(dist=-(LENGTH + PADDING), normal=[-1, 0, 0]) system.constraints.add(shape=wall, particle_type=1) # Setup cone IRAD = 4.0 ANGLE = pi / 4.0 ORAD = (DIAMETER - IRAD) / sin(ANGLE) SHIFT = 0.25 * ORAD * cos(ANGLE) hollow_cone = HollowCone( center=[BOX_L[0] / 2.0 + SHIFT, BOX_L[1] / 2.0, BOX_L[2] / 2.0], axis=[-1, 0, 0], outer_radius=ORAD,
box_l = (n_ionpairs * sum(masses.values()) / density)**(1. / 3.) box_z = box_l + 2.0 * (lj_sigmas["Electrode"]) box_volume = box_l * box_l * box_z elc_gap = box_z * 0.15 system.box_l = [box_l, box_l, box_z + elc_gap] system.periodicity = [1, 1, 1] system.time_step = time_step system.cell_system.skin = 0.3 system.thermostat.set_langevin(kT=temp, gamma=gamma) # Visualizer visualizer = openGLLive(system, camera_position=[-3 * box_l, box_l * 0.5, box_l * 0.5], camera_right=[ 0, 0, 1], drag_force=5 * 298, background_color=[1, 1, 1], light_pos=[30, 30, 30], ext_force_arrows_scale=[0.0001], ext_force_arrows=False) # Walls system.constraints.add(shape=Wall( dist=0, normal=[0, 0, 1]), particle_type=types["Electrode"]) system.constraints.add(shape=Wall( dist=-box_z, normal=[0, 0, -1]), particle_type=types["Electrode"]) # Place particles for i in range(int(n_ionpairs)): p = numpy.random.random(3) * box_l p[2] += lj_sigmas["Electrode"] system.part.add(id=len(system.part), type=types["Cl"], pos=p, q=charges["Cl"], mass=masses["Cl"]) for i in range(int(n_ionpairs)): p = numpy.random.random(3) * box_l p[2] += lj_sigmas["Electrode"] system.part.add(id=len(system.part), type=types["Na"], pos=p, q=charges["Na"], mass=masses["Na"])
# 'infinite length' using the periodic boundaries, then the cylinder must # extend over the boundary. # ########################################################################## # Setup cylinder cylinder = LBBoundary( shape=Cylinder( center=[length / 2.0, (diameter + 4) / 2.0, (diameter + 4) / 2.0], axis=[1, 0, 0], radius=diameter / 2.0, length=length, direction=-1)) system.lbboundaries.add(cylinder) # Setup walls wall = LBBoundary(shape=Wall(dist=2, normal=[1, 0, 0])) system.lbboundaries.add(wall) wall = LBBoundary(shape=Wall(dist=-(length - 2), normal=[-1, 0, 0])) system.lbboundaries.add(wall) # Setup cone irad = 4.0 angle = pi / 4.0 orad = (diameter - irad) / sin(angle) shift = 0.25 * orad * cos(angle) hollow_cone = LBBoundary( shape=HollowCone( center=[length / 2.0 + shift,
# function used for the constraints is the same as the one used for the # LB boundaries. # ########################################################################## ## Exercise 2 ## # Complete the geometry from the LB-based # script. You need to add types to the walls # and cone as well. cylinder = Cylinder(...) system.constraints.add(shape=cylinder, particle_type=1) # Setup walls wall = Wall(...) system.constraints.add(shape=wall, particle_type=1) wall = Wall(...) system.constraints.add(shape=wall, particle_type=1) # Setup cone ... hollow_cone = HollowCone(...) system.constraints.add(shape=hollow_cone, particle_type=1) ########################################################################## # # We set up a WCA (almost-hard) interaction between the particles and the
# function used for the constraints is the same as the one used for the # LB boundaries. # ########################################################################## cylinder = Cylinder( center=[length / 2.0, (diameter + 4) / 2.0, (diameter + 4) / 2.0], axis=[1, 0, 0], radius=diameter / 2.0, length=length, direction=-1) system.constraints.add(shape=cylinder, particle_type=1) # Setup walls wall = Wall(dist=2, normal=[1, 0, 0]) system.constraints.add(shape=wall, particle_type=2) wall = Wall(dist=-(length - 2), normal=[-1, 0, 0]) system.constraints.add(shape=wall, particle_type=3) # Setup cone irad = 4.0 angle = pi / 4.0 orad = (diameter - irad) / sin(angle) shift = 0.25 * orad * cos(angle) hollow_cone = HollowCone( center=[length / 2.0 + shift, (diameter + 4) / 2.0, (diameter + 4) / 2.0], axis=[-1, 0, 0],
# extend over the boundary. # ########################################################################## # Setup cylinder cylinder = LBBoundary(shape=Cylinder(center=0.5 * BOX_L, axis=[1, 0, 0], radius=DIAMETER / 2.0, length=LENGTH, direction=-1)) system.lbboundaries.add(cylinder) # Setup walls wall = LBBoundary(shape=Wall(dist=PADDING, normal=[1, 0, 0])) system.lbboundaries.add(wall) wall = LBBoundary(shape=Wall(dist=-(LENGTH + PADDING), normal=[-1, 0, 0])) system.lbboundaries.add(wall) # Setup cone IRAD = 4.0 ANGLE = pi / 4.0 ORAD = (DIAMETER - IRAD) / sin(ANGLE) SHIFT = 0.25 * ORAD * cos(ANGLE) hollow_cone = LBBoundary(shape=espressomd.shapes.HollowConicalFrustum( center=[BOX_L[0] / 2.0 - 1.3 * SHIFT, BOX_L[1] / 2.0, BOX_L[2] / 2.0], axis=[-1, 0, 0],