Ejemplo n.º 1
0
 def create_domain(self):
     return DomainManager(xmin=0,
                          xmax=domain_width,
                          ymin=0,
                          ymax=domain_height,
                          periodic_in_x=True,
                          periodic_in_y=True)
Ejemplo n.º 2
0
    def common_setup(self):
        # create the particle arrays
        L = 1.0
        n = 10
        dx = L / n
        hdx = 1.5
        self.L = L
        _x = np.arange(dx / 2, L, dx)
        self.vol = vol = dx * dx

        # fluid particles
        xx, yy = np.meshgrid(_x, _x)

        x = xx.ravel()
        y = yy.ravel()  # particle positions
        p = self._get_pressure(x, y, 0.0)
        h = np.ones_like(x) * hdx * dx   # smoothing lengths
        m = np.ones_like(x) * vol      # mass
        V = np.zeros_like(x)           # volumes

        fluid = get_particle_array(name='fluid', x=x, y=y, h=h, m=m, V=V, p=p)

        # particles and domain
        self.fluid = fluid
        self.domain = DomainManager(xmin=0, xmax=L, ymin=0, ymax=L,
                                    periodic_in_x=True, periodic_in_y=True,
                                    backend=self.backend
                                    )
        self.kernel = get_compiled_kernel(Gaussian(dim=2))
Ejemplo n.º 3
0
 def create_domain(self):
     return DomainManager(xmin=config.xmin,
                          xmax=config.xmax,
                          ymin=config.ymin,
                          ymax=config.ymax,
                          mirror_in_x=True,
                          mirror_in_y=True)
Ejemplo n.º 4
0
 def create_domain(self):
     return DomainManager(xmin=-0.5 * Lx,
                          xmax=0.5 * Lx,
                          ymin=-0.5 * Ly,
                          ymax=0.5 * Ly,
                          periodic_in_x=True,
                          periodic_in_y=True)
 def create_domain(self):
     return DomainManager(xmin=xmin,
                          xmax=xmax,
                          ymin=ymin,
                          ymax=ymax,
                          periodic_in_x=True,
                          periodic_in_y=True)
Ejemplo n.º 6
0
 def create_domain(self):
     return DomainManager(xmin=0,
                          xmax=L,
                          ymin=0,
                          ymax=L,
                          periodic_in_x=True,
                          periodic_in_y=True)
Ejemplo n.º 7
0
    def setUp(self):
        # create the particle arrays
        L = 1.0
        n = 5
        dx = L / n
        hdx = 1.5
        self.L = L
        self.vol = vol = dx * dx * dx

        # fluid particles
        xx, yy, zz = np.mgrid[dx / 2:L:dx, dx / 2:L:dx, dx / 2:L:dx]

        x = xx.ravel()
        y = yy.ravel()
        z = zz.ravel()  # particle positions
        p = self._get_pressure(x, y, z)
        h = np.ones_like(x) * hdx * dx  # smoothing lengths
        m = np.ones_like(x) * vol  # mass
        V = np.zeros_like(x)  # volumes

        fluid = get_particle_array(name='fluid',
                                   x=x,
                                   y=y,
                                   z=z,
                                   h=h,
                                   m=m,
                                   V=V,
                                   p=p)

        # particles and domain
        self.fluid = fluid
        self.domain = DomainManager(xmin=0,
                                    xmax=L,
                                    ymin=0,
                                    ymax=L,
                                    zmin=0,
                                    zmax=L,
                                    periodic_in_x=True,
                                    periodic_in_y=True,
                                    periodic_in_z=True)
        self.kernel = get_compiled_kernel(Gaussian(dim=3))

        self.orig_n = self.fluid.get_number_of_particles()
        self.nnps = LinkedListNNPS(dim=3,
                                   particles=[self.fluid],
                                   domain=self.domain,
                                   radius_scale=self.kernel.radius_scale)
Ejemplo n.º 8
0
 def create_domain(self):
     """Create periodic boundary conditions in x-direction."""
     return DomainManager(xmin=0,
                          xmax=self.Lx,
                          zmin=0,
                          zmax=self.Ly,
                          periodic_in_x=True,
                          periodic_in_z=True)
Ejemplo n.º 9
0
 def create_domain(self):
     """Create the domain as periodic domain in x and z."""
     return DomainManager(xmin=-self.L / 2,
                          xmax=self.L / 2,
                          zmin=-self.L / 4,
                          zmax=self.L / 4,
                          periodic_in_x=True,
                          periodic_in_z=True)
Ejemplo n.º 10
0
 def create_domain(self):
     # domain for periodicity
     domain = DomainManager(xmin=0,
                            xmax=L,
                            ymin=0,
                            ymax=H,
                            periodic_in_x=True,
                            periodic_in_y=True)
     return domain
Ejemplo n.º 11
0
 def create_domain(self):
     i_ghost = n_inlet * dx
     o_ghost = n_outlet * dx
     domain = DomainManager(xmin=-i_ghost,
                            xmax=l_tunnel + o_ghost,
                            ymin=0,
                            ymax=w_tunnel,
                            periodic_in_y=True)
     return domain
Ejemplo n.º 12
0
 def create_domain(self):
     '''
     Set-up periodic boundary
     '''
     L = self.L
     return DomainManager(
         xmin=0, xmax=L, ymin=0, ymax=L, 
         periodic_in_x=True, periodic_in_y=True
     )
Ejemplo n.º 13
0
 def setUp(self):
     TestPeriodicChannel3D.setUp(self)
     l = self.l
     self.domain = DomainManager(zmin=-l / 2.0,
                                 zmax=l / 2.0,
                                 periodic_in_z=True)
     self.nnps = LinkedListNNPS(dim=3,
                                particles=self.particles,
                                domain=self.domain,
                                radius_scale=self.kernel.radius_scale)
Ejemplo n.º 14
0
    def setUp(self):
        # create the particle arrays
        L = 1.0
        n = 100
        dx = L / n
        hdx = 1.5
        _x = np.arange(dx / 2, L, dx)
        self.vol = vol = dx * dx

        # fluid particles
        xx, yy = np.meshgrid(_x, _x)

        x = xx.ravel()
        y = yy.ravel()  # particle positions
        h = np.ones_like(x) * hdx * dx  # smoothing lengths
        m = np.ones_like(x) * vol  # mass
        V = np.zeros_like(x)  # volumes

        fluid = get_particle_array(name='fluid', x=x, y=y, h=h, m=m, V=V)

        # channel particles
        _y = np.arange(L + dx / 2, L + dx / 2 + 10 * dx, dx)
        xx, yy = np.meshgrid(_x, _y)

        xtop = xx.ravel()
        ytop = yy.ravel()

        _y = np.arange(-dx / 2, -dx / 2 - 10 * dx, -dx)
        xx, yy = np.meshgrid(_x, _y)

        xbot = xx.ravel()
        ybot = yy.ravel()

        x = np.concatenate((xtop, xbot))
        y = np.concatenate((ytop, ybot))

        h = np.ones_like(x) * hdx * dx
        m = np.ones_like(x) * vol
        V = np.zeros_like(x)

        channel = get_particle_array(name='channel', x=x, y=y, h=h, m=m, V=V)

        # particles and domain
        self.particles = particles = [fluid, channel]
        self.domain = domain = DomainManager(xmin=0,
                                             xmax=L,
                                             periodic_in_x=True)
        self.kernel = get_compiled_kernel(Gaussian(dim=2))
Ejemplo n.º 15
0
    def test_evaluation_with_domain_manager(self):
        # Given
        xd = [0.0]
        hd = self.src.h[:1]
        dest = get_particle_array(name='dest', x=xd, h=hd)
        dx = self.dx
        dm = DomainManager(xmin=-dx / 2, xmax=1.0 + dx / 2, periodic_in_x=True)
        sph_eval = SPHEvaluator(arrays=[dest, self.src],
                                equations=self.equations,
                                dim=1,
                                domain_manager=dm)

        # When.
        sph_eval.evaluate()

        # Then.
        self.assertAlmostEqual(dest.rho[0], 9.0, places=2)
Ejemplo n.º 16
0
    def create_domain(self):
        """Create a DomainManager with Lees-Edwards BCs.

        Both directions are set as periodic and the value gamma_yx ist set to the
        shear rate to shift particles crossing the x-boundary. As the BC has to keep
        track of time, the time step is passed as well.
        """
        return DomainManager(
            xmin=0,
            xmax=Lx,
            periodic_in_x=True,
            ymin=0,
            ymax=Ly,
            periodic_in_y=True,
            gamma_yx=gamma,
            n_layers=1,
            dt=dt,
        )
Ejemplo n.º 17
0
    def create_domain(self):
        """Create periodic boundary conditions in all directions.

        Additionally, gamma values are set to enforce Lee-Edwards BCs.
        """
        return DomainManager(
            xmin=0,
            xmax=self.C,
            periodic_in_x=True,
            ymin=0,
            ymax=self.C,
            periodic_in_y=True,
            zmin=0,
            zmax=self.C,
            periodic_in_z=True,
            gamma_yx=self.options.G,
            n_layers=1,
            dt=self.solver.dt,
            calls_per_step=2,
        )
Ejemplo n.º 18
0
 def create_domain(self):
     return DomainManager(xmin=self.xmin,
                          xmax=self.xmax,
                          periodic_in_x=True)
Ejemplo n.º 19
0
    fluid.u[:] = 1.0
    fluid.v[:] = 1.0

    # mass
    fluid.m[:] = dx**2 * 1.0

    # return the particle list
    return [
        fluid,
    ]


# domain for periodicity
domain = DomainManager(xmin=0,
                       xmax=1.0,
                       ymin=0,
                       ymax=1.0,
                       periodic_in_x=True,
                       periodic_in_y=True)

# Create the application.
app = Application(domain=domain)

# Create the kernel
kernel = WendlandQuintic(dim=2)

# Create the integrator.
integrator = EulerIntegrator(fluid=EulerStep())

# Create a solver.
solver = Solver(kernel=kernel, dim=2, integrator=integrator)
Ejemplo n.º 20
0
 def create_domain(self):
     return DomainManager(xmin=self.xmin, xmax=self.xmax, mirror_in_x=True)
Ejemplo n.º 21
0
 def create_domain(self):
     return DomainManager(xmin=0.0, xmax=4.0, periodic_in_x=True)
Ejemplo n.º 22
0
    def __init__(self,
                 all_particles,
                 scheme,
                 domain=None,
                 innerloop=True,
                 updates=True,
                 parallel=False,
                 steps=None,
                 D=0):
        """The second integrator is a simple Euler-Integrator (accurate
        enough due to very small time steps; very fast) using EBGSteps.
        EBGSteps are basically the same as EulerSteps, exept for the fact
        that they work with an intermediate ebg velocity [eu, ev, ew].
        This velocity does not interfere with the actual velocity, which
        is neseccery to not disturb the real velocity through artificial
        damping in this step. The ebg velocity is initialized for each
        inner loop again and reset in the outer loop."""
        from math import ceil
        from pysph.base.kernels import CubicSpline
        from pysph.sph.integrator_step import EBGStep
        from compyle.config import get_config
        from pysph.sph.integrator import EulerIntegrator
        from pysph.sph.scheme import BeadChainScheme
        from pysph.sph.equation import Group
        from pysph.sph.fiber.utils import (HoldPoints, Contact,
                                           ComputeDistance)
        from pysph.sph.fiber.beadchain import (Tension, Bending,
                                               ArtificialDamping)
        from pysph.base.nnps import DomainManager, LinkedListNNPS
        from pysph.sph.acceleration_eval import AccelerationEval
        from pysph.sph.sph_compiler import SPHCompiler

        if not isinstance(scheme, BeadChainScheme):
            raise TypeError("Scheme must be BeadChainScheme")

        self.innerloop = innerloop
        self.dt = scheme.dt
        self.fiber_dt = scheme.fiber_dt
        self.domain_updates = updates
        self.steps = steps
        self.D = D
        self.eta0 = scheme.rho0 * scheme.nu

        # if there are more than 1 particles involved, elastic equations are
        # iterated in an inner loop.
        if self.innerloop:
            # second integrator
            # self.fiber_integrator = EulerIntegrator(fiber=EBGStep())
            steppers = {}
            for f in scheme.fibers:
                steppers[f] = EBGStep()
            self.fiber_integrator = EulerIntegrator(**steppers)
            # The type of spline has no influence here. It must be large enough
            # to contain the next particle though.
            kernel = CubicSpline(dim=scheme.dim)
            equations = []
            g1 = []
            for fiber in scheme.fibers:
                g1.append(ComputeDistance(dest=fiber, sources=[fiber]))
            equations.append(Group(equations=g1))

            g2 = []
            for fiber in scheme.fibers:
                g2.append(
                    Tension(dest=fiber, sources=None, ea=scheme.E * scheme.A))
                g2.append(
                    Bending(dest=fiber, sources=None, ei=scheme.E * scheme.Ip))
                g2.append(
                    Contact(dest=fiber,
                            sources=scheme.fibers,
                            E=scheme.E,
                            d=scheme.dx,
                            dim=scheme.dim,
                            k=scheme.k,
                            lim=scheme.lim,
                            eta0=self.eta0))
                g2.append(ArtificialDamping(dest=fiber, sources=None,
                                            d=self.D))
            equations.append(Group(equations=g2))

            g3 = []
            for fiber in scheme.fibers:
                g3.append(HoldPoints(dest=fiber, sources=None, tag=100))
            equations.append(Group(equations=g3))

            # These equations are applied to fiber particles only - that's the
            # reason for computational speed up.
            particles = [p for p in all_particles if p.name in scheme.fibers]
            # A seperate DomainManager is needed to ensure that particles don't
            # leave the domain.
            if domain:
                xmin = domain.manager.xmin
                ymin = domain.manager.ymin
                zmin = domain.manager.zmin
                xmax = domain.manager.xmax
                ymax = domain.manager.ymax
                zmax = domain.manager.zmax
                periodic_in_x = domain.manager.periodic_in_x
                periodic_in_y = domain.manager.periodic_in_y
                periodic_in_z = domain.manager.periodic_in_z
                gamma_yx = domain.manager.gamma_yx
                gamma_zx = domain.manager.gamma_zx
                gamma_zy = domain.manager.gamma_zy
                n_layers = domain.manager.n_layers
                N = self.steps or int(ceil(self.dt / self.fiber_dt))
                # dt = self.dt/N
                self.domain = DomainManager(xmin=xmin,
                                            xmax=xmax,
                                            ymin=ymin,
                                            ymax=ymax,
                                            zmin=zmin,
                                            zmax=zmax,
                                            periodic_in_x=periodic_in_x,
                                            periodic_in_y=periodic_in_y,
                                            periodic_in_z=periodic_in_z,
                                            gamma_yx=gamma_yx,
                                            gamma_zx=gamma_zx,
                                            gamma_zy=gamma_zy,
                                            n_layers=n_layers,
                                            dt=self.dt,
                                            calls_per_step=N)
            else:
                self.domain = None
            # A seperate list for the nearest neighbourhood search is
            # benefitial since it is much smaller than the original one.
            nnps = LinkedListNNPS(dim=scheme.dim,
                                  particles=particles,
                                  radius_scale=kernel.radius_scale,
                                  domain=self.domain,
                                  fixed_h=False,
                                  cache=False,
                                  sort_gids=False)
            # The acceleration evaluator needs to be set up in order to compile
            # it together with the integrator.
            if parallel:
                self.acceleration_eval = AccelerationEval(
                    particle_arrays=particles,
                    equations=equations,
                    kernel=kernel)
            else:
                self.acceleration_eval = AccelerationEval(
                    particle_arrays=particles,
                    equations=equations,
                    kernel=kernel,
                    mode='serial')
            # Compilation of the integrator not using openmp, because the
            # overhead is too large for those few fiber particles.
            comp = SPHCompiler(self.acceleration_eval, self.fiber_integrator)
            if parallel:
                comp.compile()
            else:
                config = get_config()
                config.use_openmp = False
                comp.compile()
                config.use_openmp = True
            self.acceleration_eval.set_nnps(nnps)

            # Connecting neighbourhood list to integrator.
            self.fiber_integrator.set_nnps(nnps)
Ejemplo n.º 23
0
class PeriodicBox3DTestCase(PeriodicBox2DTestCase):
    """Test the periodicity algorithms in the Domain Manager.

    We create a 3D box with periodicity along x, y and z.  We check if this
    produces a constant density with summation density.

    """

    def setUp(self):
        # create the particle arrays
        L = 1.0
        n = 5
        dx = L / n
        hdx = 1.5
        self.L = L
        self.vol = vol = dx * dx * dx

        # fluid particles
        xx, yy, zz = np.mgrid[dx / 2:L:dx, dx / 2:L:dx, dx / 2:L:dx]

        x = xx.ravel()
        y = yy.ravel()
        z = zz.ravel()  # particle positions
        p = self._get_pressure(x, y, z)
        h = np.ones_like(x) * hdx * dx   # smoothing lengths
        m = np.ones_like(x) * vol      # mass
        V = np.zeros_like(x)           # volumes

        fluid = get_particle_array(name='fluid', x=x, y=y, z=z,
                                   h=h, m=m, V=V, p=p
                                   )

        # particles and domain
        self.fluid = fluid
        self.domain = DomainManager(
            xmin=0, xmax=L, ymin=0, ymax=L, zmin=0, zmax=L,
            periodic_in_x=True, periodic_in_y=True, periodic_in_z=True
        )
        self.kernel = get_compiled_kernel(Gaussian(dim=3))

        self.orig_n = self.fluid.get_number_of_particles()
        self.nnps = LinkedListNNPS(
            dim=3, particles=[self.fluid],
            domain=self.domain,
            radius_scale=self.kernel.radius_scale)

    def test_summation_density(self):
        self._check_summation_density()

    def test_box_wrapping(self):
        # Given
        fluid = self.fluid
        fluid.x += 0.35
        fluid.y += 0.35
        fluid.z += 0.35
        self._check_summation_density()

    def test_periodicity(self):
        # Given.
        fluid = self.fluid

        # When
        self.domain.update()

        # Then.
        x, y, z, p = fluid.get('x', 'y', 'z', 'p', only_real_particles=False)
        xmin, xmax, ymin, ymax = x.min(), x.max(), y.min(), y.max()
        zmin, zmax = z.min(), z.max()
        new_n = fluid.get_number_of_particles()
        self.assertTrue(new_n > self.orig_n)
        self.assertTrue(xmin < 0.0)
        self.assertTrue(xmax > self.L)
        self.assertTrue(ymin < 0.0)
        self.assertTrue(ymax > self.L)
        self.assertTrue(zmin < 0.0)
        self.assertTrue(zmax > self.L)

        p_expect = self._get_pressure(x, y, z)
        diff = np.abs(p - p_expect).max()
        message = "Pressure not equal, max diff: %s" % diff
        self.assertTrue(np.allclose(p, p_expect, atol=1e-14), message)