def test_stokes(self): self.system.actors.clear() self.system.lbboundaries.clear() self.system.actors.add(self.lbf) # The temperature is zero. self.system.thermostat.set_lb(kT=0) # 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: self.system.lbboundaries.add(wall) # setup sphere without slip in the middle sphere = lbboundaries.LBBoundary(shape=shapes.Sphere( radius=radius, center=[real_width / 2] * 2 + [box_length / 2], direction=1)) self.system.lbboundaries.add(sphere) def size(vector): tmp = 0 for k in vector: tmp += k * k return np.sqrt(tmp) self.system.integrator.run(800) stokes_force = 6 * np.pi * KVISC * radius * size(v) print("Stokes' Law says: f=%f" % stokes_force) # get force that is exerted on the sphere for i in range(4): self.system.integrator.run(200) force = sphere.get_force() print("Measured force: f=%f" % size(force)) self.assertLess(abs(1.0 - size(force) / stokes_force), 0.06)
def test(self): self.system.actors.clear() self.system.lbboundaries.clear() self.system.actors.add(self.lbf) # Setup walls for i in range(3): n = np.zeros(3) n[i] = 1 self.system.lbboundaries.add( lbboundaries.LBBoundary(shape=shapes.Wall( normal=-n, dist=-(self.system.box_l[i] - AGRID)))) self.system.lbboundaries.add(lbboundaries.LBBoundary( shape=shapes.Wall( normal=n, dist=AGRID))) # setup sphere without slip in the middle sphere = lbboundaries.LBBoundary(shape=shapes.Sphere( radius=RADIUS, center=self.system.box_l / 2, direction=1)) self.system.lbboundaries.add(sphere) sphere_volume = 4. / 3. * np.pi * RADIUS**3 # Equilibration last_force = -999999 self.system.integrator.run(100) while True: self.system.integrator.run(10) force = np.linalg.norm(sphere.get_force()) if np.linalg.norm(force - last_force) < 0.01: break last_force = force # Check force balance boundary_force = np.zeros(3) for b in self.system.lbboundaries: boundary_force += b.get_force() fluid_nodes = count_fluid_nodes(self.lbf) fluid_volume = fluid_nodes * AGRID**3 applied_force = fluid_volume * np.array(LB_PARAMS['ext_force_density']) np.testing.assert_allclose( boundary_force, applied_force, atol=0.08 * np.linalg.norm(applied_force)) # Check buoyancy force on the sphere expected_force = np.array( [0, -sphere_volume * DENS * G, 0]) np.testing.assert_allclose( np.copy(sphere.get_force()), expected_force, atol=np.linalg.norm(expected_force) * 0.02)
def test_stokes(self): self.system.actors.clear() self.system.lbboundaries.clear() self.system.actors.add(self.lbf) self.system.thermostat.set_lb(LB_fluid=self.lbf, gamma=1.0) # 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: self.system.lbboundaries.add(wall) # setup sphere without slip in the middle sphere = lbboundaries.LBBoundary( shape=shapes.Sphere(radius=radius, center=[real_width / 2] * 2 + [box_length / 2], direction=1)) self.system.lbboundaries.add(sphere) def size(vector): tmp = 0 for k in vector: tmp += k * k return np.sqrt(tmp) last_force = -1000. dynamic_viscosity = self.lbf.viscosity * self.lbf.density stokes_force = 6 * np.pi * dynamic_viscosity * radius * size(v) self.system.integrator.run(35) while True: self.system.integrator.run(5) force = np.linalg.norm(sphere.get_force()) if np.abs(last_force - force) < 0.01 * stokes_force: break last_force = force force = np.copy(sphere.get_force()) np.testing.assert_allclose(force, [0, 0, stokes_force], rtol=0.03, atol=stokes_force * 0.03)
def reset_lb(self, ext_force_density=(0, 0, 0)): box_height = 10 box_lw = 8 self.system.actors.clear() self.system.lbboundaries.clear() self.lbf = self.LBClass(kT=0.0, agrid=1, dens=1, visc=1.8, tau=self.system.time_step, ext_force_density=ext_force_density) self.system.actors.add(self.lbf) self.system.thermostat.set_lb(LB_fluid=self.lbf, act_on_virtual=False, gamma=1) # 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: self.system.lbboundaries.add(wall) handle_errors("setup")
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.LBFluidGPU(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 test_particle_torques(self): """setup shear flow and check if resulting torques match the formulae in the core """ bottom = shapes.Wall(normal=[0, 0, 1], dist=self.LB_params['agrid']) top = shapes.Wall(normal=[0, 0, -1], dist=-self.system.box_l[2] + self.LB_params['agrid']) self.system.lbboundaries.add(lbboundaries.LBBoundary(shape=bottom)) self.system.lbboundaries.add( lbboundaries.LBBoundary(shape=top, velocity=[1e-3, 1e-3, 0])) self.system.integrator.run(100) #fix the particles so inaccuracies from position updates #before torque calculation don't matter self.add_all_types_of_swimmers(fix=True, rotation=True, put_in_corners=False) self.system.integrator.run(20) for swimmer in self.system.part: director = swimmer.director dip_len = swimmer.swimming["dipole_length"] mode_fac = 1. if swimmer.swimming["mode"] == "puller" else -1. source_pos = swimmer.pos + mode_fac * dip_len * director v_center = self.lbf.get_interpolated_velocity(swimmer.pos) v_source = self.lbf.get_interpolated_velocity(source_pos) diff = v_center - v_source cross = np.cross(diff, director) #half-step omega with isotropic rinertia omega_part = swimmer.omega_lab + 0.5 * self.system.time_step * \ swimmer.torque_lab / swimmer.rinertia[0] omega_swim = cross / np.linalg.norm(cross) * \ np.linalg.norm(diff) / dip_len torque = swimmer.swimming["rotational_friction"] * \ (omega_swim - omega_part) self.system.integrator.run(1, reuse_forces=True) np.testing.assert_allclose( swimmer.torque_lab, torque, atol=self.tol)
def test_advection(self): # System setup system = self.s system.virtual_sites = VirtualSitesInertialessTracers() system.time_step = 0.02 system.cell_system.skin = 0.1 box_height = 16. box_lw = 16 system.box_l = box_lw, box_lw, box_height lbf = lb.LBFluidGPU(agrid=1, dens=1, visc=2, tau=system.time_step, fric=1) 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=[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) # Establish steady state flow field system.part.add(id=0, pos=(0, 5.5, 5.5), virtual=0, ext_force=(10, 0, 0)) for i in range(100): last_t = system.time last_x = system.part[0].pos system.integrator.run(500) print(system.part[0].v, (system.part[0].pos - last_x) / (system.time - last_t))
'visc': viscosity, 'tau': time_step, 'ext_force_density': [fluid_force, 0.0, 0.0] } lbf = espressomd.lb.LBFluid(**lb_params) system.actors.add(lbf) system.thermostat.set_lb(LB_fluid=lbf, gamma=friction) print("fluid was added") sim_info = open(directory + "/sim_info.dat", "a") sim_info.write("fluid was added: " + str(datetime.datetime.now()) + "\n") sim_info.close() #LOAD FLUID BOUDARIES for boundary in boundaries: system.lbboundaries.add(lbboundaries.LBBoundary(shape=boundary)) print("fluid boundaries were added:") sim_info = open(directory + "/sim_info.dat", "a") sim_info.write("fluid boundaries were added: " + str(datetime.datetime.now()) + "\n") sim_info.close() #VTK OF INITIAL CELLS POSITIONS for id, rbc in enumerate(rbcs): rbc.output_vtk_pos_folded(vtk_directory + "/rbc" + str(id) + ".vtk") print("initial vtk files were created:") #OUTPUT FILES FOR EACH CELL CREATED # for id, rbc in enumerate(rbcs): # out_file_rbc = open(directory + "/rbc" + str(id) + "_sim" + str(sim_name) + ".dat", "w+") # out_file_rbc.write("")
def calc(var): # AVB: Create an output directory for this to store the output files outdir = "./Noelle/r01.5kBT4Ads/1000=3.2" if not os.path.exists(outdir): os.makedirs(outdir) # Setup constant time_step = 0.01 loops = 30 step_per_loop = 100 # AVB: the parameters (that I usually use) a = 0.05 r0 = 2.0 * a kBT = 4.0e-6 vwf_type = 0 collagen_type = 1 monomer_mass = 0.01 box_l = 32.0 #print("Shear velocity:") #shear_velocity = float(input()) #vy = box_l*shear_velocity vy = var print(vy) v = [0, vy, 0] # System setup system = 0 system = System(box_l=[box_l, box_l, box_l]) system.set_random_state_PRNG() np.random.seed(seed=system.seed) system.cell_system.skin = 0.4 mpc = 20 # The number of monomers has been set to be 20 as default # Change this value for further simulations # Fene interaction fene = interactions.FeneBond(k=0.04, d_r_max=0.3) system.bonded_inter.add(fene) # Setup polymer of part_id 0 with fene bond # AVB: Notice the mode, max_tries and shield parameters for pruned self-avoiding random walk algorithm polymer.create_polymer(N_P=1, MPC=mpc, bond=fene, bond_length=r0, start_pos=[29.8, 16.0, 16.0], mode=2, max_tries=100, shield=0.6 * r0) # AVB: setting the type of particles and changing mass of each monomer to 0.01 system.part[:].type = vwf_type system.part[:].mass = monomer_mass # AVB: I suggest to add Lennard-Jones interaction between the monomers # AVB: to reproduce hydrophobicity # AVB: parameters for the potential (amplitude and cut-off redius) amplVwfVwf = 4.0 * kBT # sometimes we change this to 2.0*kBT rcutVwfVwf = 1.5 * r0 # AVB: the potential system.non_bonded_inter[vwf_type, vwf_type].lennard_jones.set_params( epsilon=amplVwfVwf, sigma=r0 / 1.122, shift="auto", cutoff=rcutVwfVwf, min=r0 * 0.6) print("Warming up the polymer chain.") ## For longer chains (>100) an extensive ## warmup is neccessary ... system.time_step = 0.002 system.thermostat.set_langevin(kT=4.0e-6, gamma=1.0) # AVB: Here the Langevin thermostat is needed, because we have not yet initialized the LB-fluid. # AVB: And somehow it is necessary so that the polymer adopts the equilibrium conformation of the globule. # AVB: you may skip this step for i in range(100): system.force_cap = float(i) + 1 system.integrator.run(100) print("Warmup finished.") system.force_cap = 0 system.integrator.run(100) system.time_step = time_step system.integrator.run(500) # AVB: the following command turns the Langevin thermostat on in line 49 system.thermostat.turn_off() # AVB: This command sets the velocities of all particles to zero system.part[:].v = [0, 0, 0] # AVB: The density was too small here. I have set 1.0 for now. # AVB: It would be necessary to recalculate, but the density of the liquid should not affect the movements of the polymer (this is how our physical model works). lbf = espressomd.lb.LBFluid(agrid=1, dens=1.0, visc=1.0e2, tau=time_step, fric=0.01) system.actors.add(lbf) system.thermostat.set_lb(kT=4.0e-6) # Setup boundaries walls = [lbboundaries.LBBoundary() for k in range(2)] walls[0].set_params(shape=shapes.Wall(normal=[1, 0, 0], dist=1.5), velocity=v) walls[1].set_params(shape=shapes.Wall(normal=[-1, 0, 0], dist=-30.5)) for wall in walls: system.lbboundaries.add(wall) print("Warming up the system with LB fluid.") system.integrator.run(5000) print("LB fluid warming finished.") # AVB: after this you should have a completely collapsed polymer globule # AVB: If you want to watch the process of globule formation in Paraview, just change 5000 to 0 in line 100 N = 25 x_coord = np.array([30] * N) y_coord = np.arange(14, 24, 5 / N) z_coord = np.arange(14, 24, 5 / N) for i in range(N): for j in range(N): system.part.add(id=i * N + j + 100, pos=np.array([x_coord[i], y_coord[j], z_coord[i]]), v=np.array([0, 0, 0]), type=i * N + j + 100) all_collagen = range(100, (N - 1) * N + (N - 1) + 100) system.comfixed.types = all_collagen for i in range(100, (N - 1) * N + (N - 1) + 100): system.non_bonded_inter[vwf_type, i].lennard_jones.set_params(epsilon=amplVwfVwf, sigma=r0 / 1.122, shift="auto", cutoff=rcutVwfVwf, min=r0 * 0.6) # configure correlators com_pos = ComPosition(ids=(0, )) c = Correlator(obs1=com_pos, tau_lin=16, tau_max=loops * step_per_loop, delta_N=1, corr_operation="square_distance_componentwise", compress1="discard1") system.auto_update_accumulators.add(c) print("Sampling started.") print("lenth after warmup") print( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) lengths = [] ylengths = [] for i in range(loops): system.integrator.run(step_per_loop) system.analysis.append() lengths.append( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) lbf.print_vtk_velocity(outdir + "/" + str(vy) + "%04i.vtk" % i) system.part.writevtk(outdir + "/" + str(vy) + "vwf_all%04i.vtk" % i, types=all_collagen) system.part.writevtk(outdir + "/" + str(vy) + "vwf_poly%04i.vtk" % i, types=[0]) cor = list(system.part[:].pos) y = [] for l in cor: y.append(l[1]) ylengths.append(max(y) - min(y)) sys.stdout.write("\rSampling: %05i" % i) sys.stdout.flush() 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=-30.5)) for i in range(100): system.integrator.run(step_per_loop) lengths.append( system.analysis.calc_re(chain_start=0, number_of_chains=1, chain_length=mpc - 1)[0]) system.part.writevtk(outdir + "/" + str(vy) + "vwf_all[r0=2,kBT=4]intheEND.vtk") with open(outdir + "/lengths" + str(vy) + ".dat", "a") as datafile: datafile.write("\n".join(map(str, lengths))) with open(outdir + "/lengthsY" + str(vy) + ".dat", "a") as datafile: datafile.write("\n".join(map(str, ylengths))) mean_vy = [(vy * 10000) / 32, sum(ylengths) / len(ylengths)] print("mean_vy") print(mean_vy) with open(outdir + "/mean_vy" + "2kBT_2r0" + ".dat", "a") as datafile: datafile.write(" ".join(map(str, mean_vy))) c.finalize() corrdata = c.result() corr = zeros((corrdata.shape[0], 2)) corr[:, 0] = corrdata[:, 0] corr[:, 1] = (corrdata[:, 2] + corrdata[:, 3] + corrdata[:, 4]) / 3 savetxt(outdir + "/msd_nom" + str(mpc) + ".dat", corr) with open(outdir + "/rh_out.dat", "a") as datafile: rh = system.analysis.calc_rh(chain_start=0, number_of_chains=1, chain_length=mpc - 1) datafile.write(str(mpc) + " " + str(rh[0]) + "\n")
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) visualizer.run(1)
def test_stokes(self): # System setup agrid = 1 radius = 5.5 box_width = 54 real_width = box_width + 2 * agrid box_length = 54 system = espressomd.System(box_l=[real_width, real_width, box_length]) system.box_l = [real_width, real_width, box_length] system.time_step = 0.4 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 = 5.0 # Invoke LB fluid lbf = lb.LBFluidGPU(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) # setup sphere without slip in the middle sphere = lbboundaries.LBBoundary( shape=shapes.Sphere(radius=radius, center=[real_width / 2] * 2 + [box_length / 2], direction=1)) system.lbboundaries.add(sphere) def size(vector): tmp = 0 for k in vector: tmp += k * k return np.sqrt(tmp) system.integrator.run(800) stokes_force = 6 * np.pi * kinematic_visc * radius * size(v) print("Stokes' Law says: f=%f" % stokes_force) # get force that is exerted on the sphere for i in range(5): system.integrator.run(200) force = sphere.get_force() print("Measured force: f=%f" % size(force)) self.assertLess(abs(1.0 - size(force) / stokes_force), 0.06)
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) # setup sphere without slip in the middle sphere = lbboundaries.LBBoundary(shape=shapes.Sphere(radius=radius, center = [real_width/2] * 2 + [box_length/2], direction = 1))
lbf = lb.LBFluid_GPU(agrid=1, dens=1, visc=1, tau=0.01, ext_force=[force_density, 0, 0]) system.actors.add(lbf) system.thermostat.set_lb(kT=0) # create the boundary "shape" upper_wall = shapes.Wall(normal=[0, 1, 0], dist=1.5) lower_wall = shapes.Wall(normal=[0, -1, 0], dist=-(box_l - 1.5)) # from these shapes, define the LB boundary upper_bound = lbboundaries.LBBoundary(shape=upper_wall) lower_bound = lbboundaries.LBBoundary(shape=lower_wall) system.lbboundaries.add(upper_bound) system.lbboundaries.add(lower_bound) # save the center x-velocity in this file center_output = open("center_velocity.dat", "w") max_time = 1000 for i in range(max_time): system.integrator.run(500) print("Running simulation, step: {}/{}\r".format(i, max_time)) vx = (lbf[box_l / 2, box_l / 2, box_l / 2].velocity[0]) center_output.write("{}\n".format(vx))