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")
示例#2
0
    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")
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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))
示例#8
0
                              valency=1,
                              ext_force_density=[0, 0, 1.])
neg = electrokinetics.Species(density=0.05,
                              D=0.1,
                              valency=-1,
                              ext_force_density=[0, 0, -1.])
ek.add_species(pos)
ek.add_species(neg)
system.actors.add(ek)

print(ek.get_params())
print(pos.get_params())
print(neg.get_params())
print(pos[5, 5, 5].density)

ek_wall_left = electrokinetics.EKBoundary(shape=shapes.Wall(dist=1,
                                                            normal=[1, 0, 0]),
                                          charge_density=-0.01)
ek_wall_right = electrokinetics.EKBoundary(shape=shapes.Wall(dist=-9,
                                                             normal=[-1, 0,
                                                                     0]),
                                           charge_density=0.01)
system.ekboundaries.add(ek_wall_left)
system.ekboundaries.add(ek_wall_right)

for i in range(1000):
    system.integrator.run(100)
    sys.stdout.write("\rIntegrating: %03i" % i)
    sys.stdout.flush()

    pos.print_vtk_density("ek/pos_dens_%i.vtk" % i)
    neg.print_vtk_density("ek/neg_dens_%i.vtk" % i)
示例#9
0
                              valency=1,
                              ext_force_density=[0, 0, 1.])
neg = electrokinetics.Species(density=0.05,
                              D=0.1,
                              valency=-1,
                              ext_force_density=[0, 0, -1.])
ek.add_species(pos)
ek.add_species(neg)
system.actors.add(ek)

print(ek.get_params())
print(pos.get_params())
print(neg.get_params())
print(pos[5, 5, 5].density)

ek_wall_left = ekboundaries.EKBoundary(shape=shapes.Wall(dist=1,
                                                         normal=[1, 0, 0]),
                                       charge_density=-0.01)
ek_wall_right = ekboundaries.EKBoundary(shape=shapes.Wall(dist=-9,
                                                          normal=[-1, 0, 0]),
                                        charge_density=0.01)
system.ekboundaries.add(ek_wall_left)
system.ekboundaries.add(ek_wall_right)

if not os.path.isdir("ek"):
    os.makedirs("ek")

n_int_cycles = 1000
for i in range(n_int_cycles):
    system.integrator.run(100)
    print("\rIntegrating: %03i" % i, end='', flush=True)
示例#10
0
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))
示例#11
0
system.non_bonded_inter[0, 0].wca.set_params(epsilon=1, sigma=1)

num_part = 30
wall_offset = 0.1

# create random positions in the box sufficiently away from the walls
ran_pos = np.random.uniform(low=1 + wall_offset,
                            high=box_l - 1 - wall_offset,
                            size=(num_part, 3))
system.part.add(id=np.arange(num_part),
                pos=ran_pos,
                type=np.zeros(num_part, dtype=int))

# bottom wall, normal pointing in the +z direction, laid at z=0.1
floor = shapes.Wall(normal=[0, 0, 1], dist=wall_offset)
c1 = system.constraints.add(particle_type=0,
                            penetrable=False,
                            only_positive=False,
                            shape=floor)

# top wall, normal pointing in the -z direction, laid at z=49.9, since the
# normal direction points down, dist is -49.9
ceil = shapes.Wall(normal=[0, 0, -1], dist=-(box_l - wall_offset))
c2 = system.constraints.add(particle_type=0,
                            penetrable=False,
                            only_positive=False,
                            shape=ceil)

# create stiff FENE bonds
fene = interactions.FeneBond(k=30, d_r_max=2)
    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)
示例#13
0
system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=1,
                                                       sigma=1,
                                                       cutoff=2**(1. / 6),
                                                       shift="auto")

num_part = 30

# create random positions in the box sufficiently away from the walls
ran_pos = np.random.uniform(low=1, high=49, size=(num_part, 3))
system.part.add(id=np.arange(num_part),
                pos=ran_pos,
                type=np.zeros(num_part, dtype=int))

# bottom wall, normal pointing in the +z direction, laid at z=0.1
floor = shapes.Wall(normal=[0, 0, 1], dist=0.1)
c1 = system.constraints.add(particle_type=0,
                            penetrable=False,
                            only_positive=False,
                            shape=floor)

# top wall, normal pointing in the -z direction, laid at z=49.9, since the normal direction points down, dist is -49.9
ceil = shapes.Wall(normal=[0, 0, -1], dist=-49.9)
c2 = system.constraints.add(particle_type=0,
                            penetrable=False,
                            only_positive=False,
                            shape=ceil)

# create_polymer will avoid violating the contraints

fene = interactions.FeneBond(k=30, d_r_max=2)
示例#14
0
# the force density on the fluid nodes
force_density = 0.001

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)
示例#15
0
                                     prefactor=bjerrum_length)

# Set up the charged and neutral species
density_counterions = -2.0 * sigma / width
counterions = electrokinetics.Species(
    density=density_counterions,
    D=D,
    valency=valency,
    ext_force_density=[ext_force_density, 0, 0])

ek.add_species(counterions)

# Set up the walls confining the fluid
ek_wall_left = espressomd.ekboundaries.EKBoundary(charge_density=sigma / agrid,
                                                  shape=shapes.Wall(
                                                      normal=[0, 0, 1],
                                                      dist=padding))
ek_wall_right = espressomd.ekboundaries.EKBoundary(
    charge_density=sigma / agrid,
    shape=shapes.Wall(normal=[0, 0, -1], dist=-(padding + width)))

system.ekboundaries.add(ek_wall_left)
system.ekboundaries.add(ek_wall_right)

system.actors.add(ek)

# Integrate the system
for i in range(100):
    system.integrator.run(integration_length)
    sys.stdout.write("\rintegration: %i%%" % (i + 1))
    sys.stdout.flush()
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
from os import mkdir
mkdir(outputDir)

## Perform integration
from writeVTK import WriteVTK
WriteVTK(system, str(outputDir + "/cell_" + str(0) + ".vtk"))

stepSize = 1000
numSteps = 20
    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(self):
        system = self.es

        pi = math.pi
        box_x = 6
        box_y = 6
        width = 50

        padding = 6
        box_z = width + 2 * padding

        # Set the electrokinetic parameters
        agrid = 1.0
        dt = 1.0 / 7.
        force = 0.13
        sigma = -0.05
        viscosity_kinematic = 2.3
        friction = 4.3
        temperature = 2.9
        bjerrum_length = 0.47

        temperature_LB = agrid * agrid / (3.0 * dt * dt)
        kB_LB = 1.0
        cs_squared = (1.0 / 3.0) * (agrid * agrid / (dt * dt))

        system.box_l = [box_x, box_y, box_z]

        # Set the simulation parameters

        system.time_step = dt
        system.cell_system.skin = 0.1
        system.thermostat.turn_off()
        integration_length = 10000

        # Output density, velocity, and pressure tensor profiles

        output_profiles = 1

        # Set up the charged and neutral species

        density_water = 26.15
        density_counterions = -2.0 * float(sigma) / float(width)
        valency = 1.0

        # Set up the (LB) electrokinetics fluid

        ek = electrokinetics.Electrokinetics(agrid=agrid,
                                             lb_density=density_water,
                                             viscosity=viscosity_kinematic,
                                             friction=friction,
                                             T=temperature,
                                             prefactor=bjerrum_length *
                                             temperature,
                                             stencil="nonlinear")

        counterions = electrokinetics.Species(density=density_counterions,
                                              D=0.3,
                                              valency=valency,
                                              ext_force=[force, 0, 0])
        ek.add_species(counterions)

        # Set up the walls confining the fluid and carrying charge

        ek_wall1 = electrokinetics.EKBoundary(
            charge_density=sigma / (agrid * padding),
            shape=shapes.Wall(normal=[0, 0, 1], dist=padding))
        system.ekboundaries.add(ek_wall1)
        ek_wall2 = electrokinetics.EKBoundary(
            charge_density=sigma / (agrid * padding),
            shape=shapes.Wall(normal=[0, 0, -1], dist=-(padding + width)))
        system.ekboundaries.add(ek_wall2)

        system.actors.add(ek)

        # Integrate the system

        system.integrator.run(integration_length)

        # compare the various quantities to the analytic results

        total_velocity_difference = 0.0
        total_density_difference = 0.0
        total_pressure_difference_xx = 0.0
        total_pressure_difference_yy = 0.0
        total_pressure_difference_zz = 0.0
        total_pressure_difference_xy = 0.0
        total_pressure_difference_yz = 0.0
        total_pressure_difference_xz = 0.0

        # initial parameters for bisection scheme
        size = pi / (2.0 * width)

        pnt0 = 0.0
        pntm = pnt0 + size
        pnt1 = pnt0 + 1.9 * size

        # the bisection scheme

        tol = 1.0e-08
        while (size > tol):

            val0 = solve(pnt0, width, bjerrum_length, sigma, valency)
            val1 = solve(pnt1, width, bjerrum_length, sigma, valency)
            valm = solve(pntm, width, bjerrum_length, sigma, valency)

            if (val0 < 0.0 and val1 > 0.0):
                if (valm < 0.0):
                    pnt0 = pntm
                    size = size / 2.0
                    pntm = pnt0 + size
                else:
                    pnt1 = pntm
                    size = size / 2.0
                    pntm = pnt1 - size
            elif (val0 > 0.0 and val1 < 0.0):
                if (valm < 0.0):
                    pnt1 = pntm
                    size = size / 2.0
                    pntm = pnt1 - size
                else:
                    pnt0 = pntm
                    size = size / 2.0
                    pntm = pnt0 + size
            else:
                sys.exit(
                    "Bisection method fails:\nTuning of domain boundaries may be required."
                )


# obtain the desired xi value

        xi = pntm

        if (output_profiles):
            fp = open("ek_eof_profile.dat", "w")

        for i in range(int(box_z / agrid)):

            if (i * agrid >= padding and i * agrid < box_z - padding):
                xvalue = i * agrid - padding
                position = i * agrid - padding - width / 2.0 + agrid / 2.0

                # density
                measured_density = counterions[int(box_x / (2 * agrid)),
                                               int(box_y / (2 * agrid)),
                                               i].density
                calculated_density = density(position, xi, bjerrum_length)
                density_difference = abs(measured_density - calculated_density)
                total_density_difference = total_density_difference + density_difference

                # velocity
                measured_velocity = ek[int(box_x / (2 * agrid)),
                                       int(box_y / (2 * agrid)), i].velocity[0]
                calculated_velocity = velocity(position, xi, width,
                                               bjerrum_length, force,
                                               viscosity_kinematic,
                                               density_water)
                velocity_difference = abs(measured_velocity -
                                          calculated_velocity)
                total_velocity_difference = total_velocity_difference + velocity_difference

                # diagonal pressure tensor

                measured_pressure_xx = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(0, 0)]
                calculated_pressure_xx = hydrostatic_pressure_non_lin(
                    ek, position, xi, bjerrum_length, (0, 0), box_x, box_y,
                    box_z, agrid, temperature)
                measured_pressure_yy = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(1, 1)]
                calculated_pressure_yy = hydrostatic_pressure_non_lin(
                    ek, position, xi, bjerrum_length, (1, 1), box_x, box_y,
                    box_z, agrid, temperature)
                measured_pressure_zz = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(2, 2)]
                calculated_pressure_zz = hydrostatic_pressure_non_lin(
                    ek, position, xi, bjerrum_length, (2, 2), box_x, box_y,
                    box_z, agrid, temperature)

                pressure_difference_xx = abs(measured_pressure_xx -
                                             calculated_pressure_xx)
                pressure_difference_yy = abs(measured_pressure_yy -
                                             calculated_pressure_yy)
                pressure_difference_zz = abs(measured_pressure_zz -
                                             calculated_pressure_zz)

                total_pressure_difference_xx = total_pressure_difference_xx + pressure_difference_xx
                total_pressure_difference_yy = total_pressure_difference_yy + pressure_difference_yy
                total_pressure_difference_zz = total_pressure_difference_zz + pressure_difference_zz

                # xy component pressure tensor
                measured_pressure_xy = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(0, 1)]
                calculated_pressure_xy = 0.0
                pressure_difference_xy = abs(measured_pressure_xy -
                                             calculated_pressure_xy)
                total_pressure_difference_xy = total_pressure_difference_xy + pressure_difference_xy

                # yz component pressure tensor
                measured_pressure_yz = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(1, 2)]
                calculated_pressure_yz = 0.0
                pressure_difference_yz = abs(measured_pressure_yz -
                                             calculated_pressure_yz)
                total_pressure_difference_yz = total_pressure_difference_yz + pressure_difference_yz

                # xz component pressure tensor
                measured_pressure_xz = ek[int(box_x / (2 * agrid)),
                                          int(box_y / (2 * agrid)),
                                          i].pressure[(0, 2)]
                calculated_pressure_xz = pressure_tensor_offdiagonal(
                    position, xi, bjerrum_length, force)
                pressure_difference_xz = abs(measured_pressure_xz -
                                             calculated_pressure_xz)
                total_pressure_difference_xz = total_pressure_difference_xz + pressure_difference_xz

                if (output_profiles):
                    fp.write(
                        "{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}\n".
                        format(position, measured_density, calculated_density,
                               measured_velocity, calculated_velocity,
                               measured_pressure_xy, calculated_pressure_xy,
                               measured_pressure_yz, calculated_pressure_yz,
                               measured_pressure_xz, calculated_pressure_xz,
                               measured_pressure_xx, calculated_pressure_xx,
                               measured_pressure_yy, calculated_pressure_yy,
                               measured_pressure_zz, calculated_pressure_zz))

        if (output_profiles):
            fp.close

        total_density_difference = agrid * total_density_difference / width
        total_velocity_difference = agrid * total_velocity_difference / width
        total_pressure_difference_xx = agrid * total_pressure_difference_xx / width
        total_pressure_difference_yy = agrid * total_pressure_difference_yy / width
        total_pressure_difference_zz = agrid * total_pressure_difference_zz / width
        total_pressure_difference_xy = agrid * total_pressure_difference_xy / width
        total_pressure_difference_yz = agrid * total_pressure_difference_yz / width
        total_pressure_difference_xz = agrid * total_pressure_difference_xz / width

        print("Density deviation: {}".format(total_density_difference))
        print("Velocity deviation: {}".format(total_velocity_difference))
        print("Pressure deviation xx component: {}".format(
            total_pressure_difference_xx))
        print("Pressure deviation yy component: {}".format(
            total_pressure_difference_yy))
        print("Pressure deviation zz component: {}".format(
            total_pressure_difference_zz))
        print("Pressure deviation xy component: {}".format(
            total_pressure_difference_xy))
        print("Pressure deviation yz component: {}".format(
            total_pressure_difference_yz))
        print("Pressure deviation xz component: {}".format(
            total_pressure_difference_xz))

        self.assertLess(total_density_difference, 8.0e-06,
                        "Density accuracy not achieved")
        self.assertLess(total_velocity_difference, 3.0e-06,
                        "Velocity accuracy not achieved")
        self.assertLess(total_pressure_difference_xx, 6.0e-05,
                        "Pressure accuracy xx component not achieved")
        self.assertLess(total_pressure_difference_yy, 8.0e-05,
                        "Pressure accuracy yy component not achieved")
        self.assertLess(total_pressure_difference_zz, 8.0e-05,
                        "Pressure accuracy zz component not achieved")
        self.assertLess(total_pressure_difference_xy, 1.0e-10,
                        "Pressure accuracy xy component not achieved")
        self.assertLess(total_pressure_difference_yz, 1.0e-10,
                        "Pressure accuracy yz component not achieved")
        self.assertLess(total_pressure_difference_xz, 2.0e-05,
                        "Pressure accuracy xz component not achieved")
示例#19
0
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")
示例#20
0
pos = electrokinetics.Species(
    density=0.05, D=0.1, valency=1, ext_force_density=[0, 0, 1.])
neg = electrokinetics.Species(
    density=0.05, D=0.1, valency=-1, ext_force_density=[0, 0, -1.])
ek.add_species(pos)
ek.add_species(neg)
system.actors.add(ek)

print(ek.get_params())
print(pos.get_params())
print(neg.get_params())
print(pos[5, 5, 5].density)


ek_wall_left = ekboundaries.EKBoundary(
    shape=shapes.Wall(dist=1, normal=[1, 0, 0]), charge_density=-0.01)
ek_wall_right = ekboundaries.EKBoundary(
    shape=shapes.Wall(dist=-9, normal=[-1, 0, 0]), charge_density=0.01)
system.ekboundaries.add(ek_wall_left)
system.ekboundaries.add(ek_wall_right)


if not os.path.isdir("ek"):
    os.makedirs("ek")


n_int_cycles = 1000
for i in range(n_int_cycles):
    system.integrator.run(100)
    print("\rIntegrating: %03i" % i, end='', flush=True)
示例#21
0
# Particle types
#===========================
type_counter = 0
type_mono = type_counter
type_counter+=1
type_wall = type_counter

system.non_bonded_inter[type_mono, type_mono].lennard_jones.set_params( epsilon=1.0, sigma=1.0, cutoff=2.**(1.0 / 6.0), shift="auto")
system.non_bonded_inter[type_mono, type_wall].lennard_jones.set_params( epsilon=1.0, sigma=1.0, cutoff=2.**(1.0 / 6.0), shift="auto")
    

#===========================
# define the particle constraints (two walls)
#===========================

left_constr=system.constraints.add(particle_type=type_wall, penetrable=1, only_positive=0, shape=shapes.Wall(normal=[1,0,0], dist=1.12))
right_constr=system.constraints.add(particle_type=type_wall, penetrable=1, only_positive=0, shape=shapes.Wall(normal=[-1,0,0], dist=-(box_l-0.5)))


for p in range(0,n_mono):
    system.part.add(id=p, pos=(np.random.random(3) * system.box_l*0.5)+(box_l*0.25,0,0), type=type_mono )

cap=1
system.non_bonded_inter.set_force_cap(cap)
print( "Warming up... ",)
dist=system.analysis.mindist(p1=[type_mono], p2=[type_mono])
for t in range(4000):
    print( "Warming step: {} min_dist={} cap={}\r".format(t, dist, cap))
    system.integrator.run(200)
    dist=system.analysis.mindist(p1=[type_mono], p2=[type_mono])
    cap = cap + 1.