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)
示例#2
0
## A script to simulate planar Poisseuille flow in Espresso
from espressomd import lb, shapes, lbboundaries
import numpy as np



# System setup
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.time_step = 0.01
system.cell_system.skin = 0.2

box_l = 16
system.box_l = [box_l] * 3

lbf = lb.LBFluidGPU(agrid=1, dens=1, visc=1, tau=0.01, ext_force=[0, 0.001, 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 wall in walls:
    system.lbboundaries.add(wall)

## Perform enough iterations until the flow profile
## is static (5000 LB updates):
system.integrator.run(5000)

## Part of the solution