def test(self): # Set to true if you need a new # comparison configuration new_configuration = False boxl = 12 sampsteps = 2000 tstep = 0.01 temp = 0.0 S = espressomd.System() if (S.n_nodes > 1): print("NOTE: Ignoring testcase for n_nodes > 1") return S.box_l = [boxl, boxl, boxl] S.skin = 0.1 S.time_step = tstep S.part.add(id=0, pos=[6.0,3.0,2.0], swimming={"mode": "pusher", "v_swim": 0.10, "dipole_length": 1.0, "rotational_friction": 2.0}, quat=[np.sqrt(.5),np.sqrt(.5), 0, 0]) S.part.add(id=1, pos=[2.0,3.0,6.0], swimming={"mode": "pusher", "f_swim": 0.03, "dipole_length": 2.0, "rotational_friction": 20.0}, quat=[np.sqrt(.5), 0,np.sqrt(.5), 0]) S.part.add(id=2, pos=[3.0,2.0,6.0], swimming={"mode": "puller", "v_swim": 0.15, "dipole_length": 0.5, "rotational_friction": 15.0}, quat=[np.sqrt(.5), 0, 0,np.sqrt(.5)]) S.part.add(id=3, pos=[3.0,6.0,2.0], swimming={"mode": "puller", "f_swim": 0.05, "dipole_length": 1.5, "rotational_friction": 6.0}, quat=[ 0, 0,np.sqrt(.5),np.sqrt(.5)]) lbm = lb.LBFluid(agrid=1.0, tau=tstep, fric=0.5, visc=1.0, dens=1.0) S.actors.add(lbm) #thermostat lb $temp integrate.integrate(sampsteps) if new_configuration: lbm.print_vtk_velocity("engine_lb.vtk") self.assertTrue( True ) else: lbm.print_vtk_velocity("engine_lb_tmp.vtk") different, difference = tests_common.calculate_vtk_max_pointwise_difference("engine_lb.vtk", "engine_lb_tmp.vtk",tol=2.0e-7) os.remove("engine_lb_tmp.vtk") print("Maximum deviation to the reference point is: {}".format(difference)) self.assertTrue( different )
class VirtualSitesTracers(ut.TestCase, VirtualSitesTracersCommon): if espressomd.has_features(required_features): box_height = 10. box_lw = 8. system = espressomd.System(box_l=(box_lw, box_lw, box_height)) system.time_step = 0.05 system.cell_system.skin = 0.1 lbf = lb.LBFluid(agrid=1, dens=1, visc=2, tau=system.time_step, fric=1) system.actors.add(lbf) system.thermostat.set_lb(kT=0, act_on_virtual=False) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[0, 0, 1], dist=0.5)) walls[1].set_params( shape=shapes.Wall(normal=[0, 0, -1], dist=-box_height - 0.5)) for wall in walls: system.lbboundaries.add(wall) handle_errors("setup")
def setUp(self): self.params = { 'int_steps': 25, 'int_times': 10, 'time_step': 0.01, 'tau': 0.02, 'agrid': 0.5, 'box_l': 12.0, 'dens': 0.85, 'viscosity': 30.0, 'friction': 2.0, 'temp': 1.5, 'gamma': 1.5, 'skin': 0.2, 'mom_prec': 1.e-11, 'mass_prec_per_node': 4.e-8, 'temp_confidence': 10 } if espressomd.has_features("ROTATION"): self.dof = 6. else: self.dof = 3. self.system.box_l = [ self.params['box_l'], self.params['box_l'], self.params['box_l'] ] self.system.periodicity = [1, 1, 1] self.system.time_step = self.params['time_step'] self.system.cell_system.skin = self.params['skin'] # clear actors that might be left from prev tests for i in self.system.actors: self.system.actors.remove(i) self.system.part.clear() # import particle data self.data = np.genfromtxt(abspath("data/lb_system.data")) for particle in self.data: id = particle[0] typ = particle[1] pos = particle[3:6] f = particle[9:] v = particle[6:9] p = self.system.part.add(id=int(id), pos=pos, v=v, type=int(typ)) if espressomd.has_features("ROTATION"): p.rotation = [1, 1, 1] self.n_col_part = len(self.system.part) self.system.thermostat.set_langevin(kT=self.params['temp'], gamma=self.params['gamma']) self.system.integrator.run(50) # kill particle motion for i in range(self.n_col_part): self.system.part[i].v = [0.0, 0.0, 0.0] self.system.thermostat.turn_off() self.lbf = lb.LBFluid(visc=self.params['viscosity'], dens=self.params['dens'], agrid=self.params['agrid'], tau=self.system.time_step, fric=self.params['friction']) self.system.actors.add(self.lbf) self.system.thermostat.set_lb(kT=self.params['temp']) # give particles a push for i in range(self.n_col_part): self.system.part[i].v = self.system.part[i].v + [0.1, 0.0, 0.0] self.fluidmass = self.params['dens'] self.tot_mom = [0.0, 0.0, 0.0] for i in range(self.n_col_part): self.tot_mom = self.tot_mom + self.system.part[i].v self.system.integrator.run(50) self.max_dmass = 0.0 self.max_dm = [0, 0, 0] self.avg_temp = 0.0 self.avg_fluid_temp = 0.0
kb=kb, kal=kal, kag=kag, kv=kv, kvisc=kvisc, resize=[stretch, stretch, stretch]) # creating the RBC cell = oif.OifCell(cell_type=cellType, particle_type=0, origin=[originX, originY, originZ], rotate=[np.pi / 2.0, 0.0, 0.0], particle_mass=partMass) # fluid lbf = lb.LBFluid(agrid=grid, dens=dens, visc=visc, tau=timeStep) system.actors.add(lbf) system.thermostat.set_lb(LB_fluid=lbf, gamma=friction) # consider taking all nodes that have x coordinate approximately <5% or >95% total rightStretchedParticles = list() leftStretchedParticles = list() for i in cell.mesh.points: posI = (i.get_pos()[0] - cell.get_origin()[0]) / stretch if (posI >= xBoundMinR and posI <= xBoundMaxR): rightStretchedParticles.append(i) if (posI <= -xBoundMinL and posI >= -xBoundMaxL): leftStretchedParticles.append(i) #we need to compute the contact size
def setUp(self): self.tol = 1e-10 self.lbf = lb.LBFluid(**self.LB_params) self.system.actors.add(self.lbf) self.system.thermostat.set_lb(LB_fluid=self.lbf, gamma=self.gamma)
LENGTH = 100 DIAMETER = 20 PADDING = 2 TIME_STEP = 0.01 # Setup the MD parameters BOX_L = np.array( [LENGTH + 2 * PADDING, DIAMETER + 2 * PADDING, DIAMETER + 2 * PADDING]) system = espressomd.System(box_l=BOX_L) system.cell_system.skin = 0.1 system.time_step = TIME_STEP system.min_global_cut = 0.5 # Setup LB fluid lbf = lb.LBFluid(agrid=0.5, dens=1.0, visc=1.0, tau=TIME_STEP) system.actors.add(lbf) ########################################################################## # # Now we set up the three LB boundaries that form the rectifying geometry. # The cylinder boundary/constraint is actually already capped, but we put # in two planes for safety's sake. If you want to create a cylinder of # 'infinite length' using the periodic boundaries, then the cylinder must # extend over the boundary. # ########################################################################## # Setup cylinder cylinder = LBBoundary(shape=espressomd.shapes.Cylinder(center=0.5 * BOX_L,
class ArrayPropertyTest(ut.TestCase): system = espressomd.System(box_l=[1.0, 1.0, 1.0]) system.box_l = [12.0, 12.0, 12.0] system.time_step = 0.01 system.cell_system.skin = 0.01 system.part.add(pos=[0, 0, 0]) lbf = lb.LBFluid(agrid=0.5, dens=1, visc=1, tau=0.01) system.actors.add(lbf) def locked_operators(self, v): with self.assertRaises(ValueError): v[0] = 0 with self.assertRaises(ValueError): v += [1, 1, 1] with self.assertRaises(ValueError): v -= [1, 1, 1] with self.assertRaises(ValueError): v *= [1, 1, 1] with self.assertRaises(ValueError): v /= [1, 1, 1] with self.assertRaises(ValueError): v //= [1, 1, 1] with self.assertRaises(ValueError): v %= [1, 1, 1] with self.assertRaises(ValueError): v **= [1, 1, 1] with self.assertRaises(ValueError): v <<= [1, 1, 1] with self.assertRaises(ValueError): v >>= [1, 1, 1] with self.assertRaises(ValueError): v &= [1, 1, 1] with self.assertRaises(ValueError): v |= [1, 1, 1] with self.assertRaises(ValueError): v ^= [1, 1, 1] def set_copy(self, v): cpy = np.copy(v) self.assertTrue(cpy.flags.writeable) def test_common(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].pos) self.locked_operators(self.system.part[0].v) self.locked_operators(self.system.part[0].f) self.locked_operators(self.system.part[0].pos_folded) # System self.locked_operators(self.system.box_l) # Check (allowed) setter # Particle self.system.part[0].pos = [2, 2, 2] self.assertTrue((self.system.part[0].pos == [2, 2, 2]).all()) self.system.part[0].v = [2, 2, 2] self.assertTrue((self.system.part[0].v == [2, 2, 2]).all()) self.system.part[0].f = [2, 2, 2] self.assertTrue((self.system.part[0].f == [2, 2, 2]).all()) # System self.system.box_l = [2, 2, 2] self.assertTrue((self.system.box_l == [2, 2, 2]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].pos) self.set_copy(self.system.part[0].pos) self.set_copy(self.system.part[0].v) self.set_copy(self.system.part[0].f) self.set_copy(self.system.part[0].pos_folded) # System self.set_copy(self.system.box_l) @utx.skipIfMissingFeatures(["ROTATION"]) def test_rotation(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].omega_lab) self.locked_operators(self.system.part[0].quat) self.locked_operators(self.system.part[0].rotation) self.locked_operators(self.system.part[0].omega_body) self.locked_operators(self.system.part[0].torque_lab) if espressomd.has_features("EXTERNAL_FORCES"): self.locked_operators(self.system.part[0].ext_torque) # Check (allowed) setter # Particle self.system.part[0].quat = [0.5, 0.5, 0.5, 0.5] self.assertTrue((self.system.part[0].quat == [0.5, 0.5, 0.5, 0.5]).all()) self.system.part[0].omega_lab = [2, 2, 2] self.assertTrue((self.system.part[0].omega_lab == [2, 2, 2]).all()) self.system.part[0].rotation = [1, 1, 1] self.assertTrue((self.system.part[0].rotation == [1, 1, 1]).all()) self.system.part[0].omega_body = [2, 2, 2] self.assertTrue((self.system.part[0].omega_body == [2, 2, 2]).all()) self.system.part[0].torque_lab = [2, 2, 2] self.assertTrue((self.system.part[0].torque_lab == [2, 2, 2]).all()) if espressomd.has_features("EXTERNAL_FORCES"): self.system.part[0].ext_torque = [2, 2, 2] self.assertTrue((self.system.part[0].ext_torque == [2, 2, 2]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].omega_lab) self.set_copy(self.system.part[0].quat) self.set_copy(self.system.part[0].rotation) self.set_copy(self.system.part[0].omega_body) self.set_copy(self.system.part[0].torque_lab) if espressomd.has_features("EXTERNAL_FORCES"): self.set_copy(self.system.part[0].ext_torque) @utx.skipIfMissingFeatures(["ROTATIONAL_INERTIA"]) def test_rotational_inertia(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].rinertia) # Check (allowed) setter # Particle self.system.part[0].rinertia = [2, 2, 2] self.assertTrue((self.system.part[0].rinertia == [2, 2, 2]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].rinertia) @utx.skipIfMissingFeatures(["EXTERNAL_FORCES"]) def test_external_forces(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].ext_force) self.locked_operators(self.system.part[0].fix) # Check (allowed) setter # Particle self.system.part[0].ext_force = [2, 2, 2] self.assertTrue((self.system.part[0].ext_force == [2, 2, 2]).all()) self.system.part[0].fix = [1, 1, 1] self.assertTrue((self.system.part[0].fix == [1, 1, 1]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].ext_force) self.set_copy(self.system.part[0].fix) @utx.skipIfMissingFeatures(["ROTATION", "PARTICLE_ANISOTROPY"]) def test_rot_aniso(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].gamma_rot) # Check (allowed) setter # Particle self.system.part[0].gamma_rot = [2, 2, 2] self.assertTrue((self.system.part[0].gamma_rot == [2, 2, 2]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].gamma_rot) def test_lb(self): # Check for exception for various operators # LB self.locked_operators(self.lbf[0, 0, 0].velocity) self.locked_operators(self.lbf[0, 0, 0].stress) self.locked_operators(self.lbf[0, 0, 0].stress_neq) self.locked_operators(self.lbf[0, 0, 0].population) @utx.skipIfMissingFeatures( ["LANGEVIN_PER_PARTICLE", "PARTICLE_ANISOTROPY"]) def test_langevinpp_aniso(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].gamma) # Check (allowed) setter # Particle self.system.part[0].gamma = [2, 2, 2] self.assertTrue((self.system.part[0].gamma == [2, 2, 2]).all()) # Check if copy is settable # Particle self.set_copy(self.system.part[0].gamma) @utx.skipIfMissingFeatures(["DIPOLES"]) def test_dipoles(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].dip) # Check (allowed) setter # Particle self.system.part[0].dip = [2, 2, 2] np.testing.assert_allclose([2, 2, 2], np.copy(self.system.part[0].dip), atol=1E-15) # Check if copy is settable # Particle self.set_copy(self.system.part[0].dip) @utx.skipIfMissingFeatures(["EXCLUSIONS"]) def test_exclusions(self): # Check for exception for various operators # Particle self.locked_operators(self.system.part[0].exclusions) def test_partial_periodic(self): # Check for exception for various operators # System self.locked_operators(self.system.periodicity) # Check (allowed) setter # System self.system.periodicity = [1, 0, 0] self.assertTrue((self.system.periodicity == [1, 0, 0]).all()) # Check if copy is settable # System self.set_copy(self.system.periodicity)
system = espressomd.System() system.time_step = 0.01 system.skin = 0.1 box_l = 50 system.box_l = [box_l, box_l, box_l] system.periodic = [1, 1, 1] system.part.add(id=0, pos=[box_l / 2.0, box_l / 2.0, box_l / 2.0], fix=[1, 1, 1]) # system.part.add(id=0, pos=[box_l/2.0,box_l/2.0,box_l/2.0], ext_force=[0,0,1]) lbf = lb.LBFluid(agrid=1, fric=1, dens=1, visc=1, tau=0.01, ext_force=[0, 0, -1.0 / (box_l**3)]) system.actors.add(lbf) print(system.actors) f_list = [] for i in range(10): f_list.append(system.part[0].f) integrate.integrate(10) print(i) f_list = np.array(f_list) import matplotlib.pyplot as pp
system, LB_draw_boundaries=True, LB_draw_velocity_plane=True, LB_plane_dist=8, LB_plane_axis=1, LB_vel_scale=1e2, LB_plane_ngrid=15, camera_position=[8, 16, 50], velocity_arrows=True, velocity_arrows_type_scale=[20.], velocity_arrows_type_radii=[0.1], velocity_arrows_type_colors=[[0, 1, 0]]) lbf = lb.LBFluid(kT=0, agrid=1.0, dens=1.0, visc=1.0, tau=0.1, ext_force_density=[0, 0.003, 0]) system.actors.add(lbf) system.thermostat.set_lb(LB_fluid=lbf, gamma=1.5) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[1, 0, 0], dist=1.5)) walls[1].set_params(shape=shapes.Wall(normal=[-1, 0, 0], dist=-14.5)) for i in range(100): system.part.add(pos=np.random.random(3) * system.box_l) for wall in walls: system.lbboundaries.add(wall)
## case with bending from addBending import AddBending kb = 1 AddBending(system, kb) #outputDir = "outputBendPara" ## case with bending and volCons from addVolCons import AddVolCons kV = 10 AddVolCons(system, kV) outputDir = "outputVolParaCUDA" # Add LB Fluid lbf = lb.LBFluid(agrid=1, dens=1, visc=1, tau=system.time_step, ext_force_density=[force, 0, 0]) system.actors.add(lbf) system.thermostat.set_lb(LB_fluid=lbf, gamma=1.0, act_on_virtual=False) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[0, 0, 1], dist=0.5)) walls[1].set_params(shape=shapes.Wall(normal=[0, 0, -1], dist=-boxZ + 0.5)) for wall in walls: system.lbboundaries.add(wall) ## make directory
box_width = 64 real_width = box_width+2*agrid box_length = 64 system.box_l = [real_width, real_width, box_length] system.time_step = 0.2 system.cell_system.skin = 0.4 # The temperature is zero. system.thermostat.set_lb(kT=0) # LB Parameters v = [0,0,0.01] # The boundary slip kinematic_visc = 1.0 # Invoke LB fluid lbf = lb.LBFluid(visc=kinematic_visc, dens=1, agrid=agrid, tau=system.time_step, fric=1) system.actors.add(lbf) # Setup walls walls = [None] * 4 walls[0] = lbboundaries.LBBoundary(shape=shapes.Wall(normal=[-1,0,0], dist = -(1+box_width)), velocity=v) walls[1] = lbboundaries.LBBoundary(shape=shapes.Wall(normal=[1,0,0], dist = 1), velocity=v) walls[2] = lbboundaries.LBBoundary(shape=shapes.Wall(normal=[0,-1,0], dist = -(1+box_width)), velocity=v) walls[3] = lbboundaries.LBBoundary(shape=shapes.Wall(normal=[0,1,0], dist = 1), velocity=v) for wall in walls: system.lbboundaries.add(wall)
visualizer = openGLLive(system, LB_draw_boundaries=True, LB_draw_velocity_plane=True, LB_plane_dist=8, LB_plane_axis=1, LB_vel_scale=1e2, LB_plane_ngrid=15, camera_position=[8, 16, 50], velocity_arrows=True, velocity_arrows_type_scale=[20.], velocity_arrows_type_radii=[0.1], velocity_arrows_type_colors=[[0, 1, 0]]) lbf = lb.LBFluid(agrid=1.0, fric=1.0, dens=1.0, visc=1.0, tau=0.1, ext_force=[0, 0.003, 0]) system.actors.add(lbf) system.thermostat.set_lb(kT=0) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[1, 0, 0], dist=1.5)) walls[1].set_params(shape=shapes.Wall(normal=[-1, 0, 0], dist=-14.5)) for i in range(100): system.part.add(pos=np.random.random(3) * system.box_l) for wall in walls: system.lbboundaries.add(wall)