Beispiel #1
0
    def setUp(self):
        """ 
        11 particles from 0~1 with dx = 0.1, h = 0.1
        Particle 5 has h = 0.2
                
        x  x  x  x  x  O  x  x  x  x  x    
                       
        With a kernel scale factor of 2, particle 5 should have
        neighbor indices [1,2,3,4,5,6,7,8,9]        

        """

        x = numpy.linspace(0, 1, 11)
        dx = x[1] - x[0]

        self._h = dx + 1e-10

        h = numpy.ones_like(x) * self._h
        h[5] = 2 * self._h

        m = numpy.ones_like(x) * dx
        rho = numpy.ones_like(x)

        pa = base.get_particle_array(type=0,
                                     name="test",
                                     x=x,
                                     h=h,
                                     m=m,
                                     rho=rho)

        self.particles = base.Particles(arrays=[pa],
                                        variable_h=True,
                                        in_parallel=False)
Beispiel #2
0
    def setUp(self):
        """ A Dummy fluid solver is created with the following operations

        (i)  -- Equation of State
        (ii) -- Density Rate
        (iii)-- Momentum Equation Pressure Gradient
        (iv) -- Momentum Equation Viscosity 
        
        """
        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        self.solver = s = solver.Solver(dim=2,
                                        integrator_type=solver.EulerIntegrator)

        s.default_kernel = kernel

        self.particles = base.Particles(arrays=[base.get_particle_array()])

        # Create some replacement operations

        self.visc = solver.SPHIntegration(sph.MorrisViscosity,
                                          on_types=[Fluids],
                                          from_types=[Fluids, Solids],
                                          updates=['u', 'v'],
                                          id='visc')

        self.summation_density = solver.SPHOperation(sph.SPHRho,
                                                     on_types=[Fluids, Solids],
                                                     updates=['rho'],
                                                     id='sd')
Beispiel #3
0
    def setUp(self):
        """
        Setup a default simulation in 2D. The setup consists of four particles
        on a circle of radius 2/pi. The particles are constrained to move
        along the circle with forcing functions defined in 
        pysph/sph/funcs/external_forces.pyx 
        
        With the choice of radius and unit magnitude of velocity, the particles
        move by pi/2 radians in 1 second. 

        """
        self.r = r = 2. / numpy.pi
        self.x = x = numpy.array([1.0, 0.0, -1.0, 0.0])
        self.y = y = numpy.array([0.0, 1.0, 0.0, -1.0])

        x *= r
        y *= r

        p = numpy.zeros_like(x)
        e = numpy.zeros_like(x)
        h = numpy.ones_like(x)

        self.pa = pa = base.get_particle_array(x=x,
                                               y=y,
                                               p=p,
                                               e=e,
                                               h=h,
                                               name='tmp')

        self.particles = particles = base.Particles(arrays=[pa])
        self.kernel = base.CubicSplineKernel(dim=2)

        circlex = solver.SPHIntegration(sph.MoveCircleX,
                                        from_types=[Fluids],
                                        on_types=[Fluids],
                                        updates=['x', 'y'],
                                        id='circlex')

        circley = solver.SPHIntegration(sph.MoveCircleY,
                                        from_types=[Fluids],
                                        on_types=[Fluids],
                                        updates=['x', 'y'],
                                        id='circley')

        self.calcx = circlex.get_calcs(particles, self.kernel)
        self.calcy = circley.get_calcs(particles, self.kernel)

        self.calcs = []
        self.calcs.extend(self.calcx)
        self.calcs.extend(self.calcy)

        self.integrator = Integrator(particles=particles, calcs=self.calcs)

        self.setup()
Beispiel #4
0
def bin_particles(pa):
    """ Bin the particles. 
    
    Parameters:
    -----------
    
    pa -- a newly created particle array from the get_particle_array function
    min_cell_size -- the cell size to use for binning
    
    """
    
    particles = base.Particles([pa,])
    return particles
Beispiel #5
0
def test_sph_calc():

    x = numpy.array([
        0,
    ])
    y = numpy.array([
        0,
    ])
    z = numpy.array([
        0,
    ])
    h = numpy.ones_like(x)

    pa = base.get_particle_array(name="test",
                                 x=x,
                                 y=y,
                                 z=z,
                                 h=h,
                                 _tmpx=z,
                                 _tmpy=z,
                                 _tmpz=z)
    particles = base.Particles(arrays=[
        pa,
    ])
    kernel = base.CubicSplineKernel(dim=1)

    vector_force1 = sph.VectorForce.withargs(force=base.Point(1, 1, 1))
    vector_force2 = sph.VectorForce.withargs(force=base.Point(1, 1, 1))

    func1 = vector_force1.get_func(pa, pa)
    func2 = vector_force2.get_func(pa, pa)

    calc = sph.SPHCalc(particles=particles,
                       sources=[pa, pa],
                       dest=pa,
                       kernel=kernel,
                       funcs=[func1, func2],
                       updates=['u', 'v', 'w'],
                       integrates=True)

    # evaluate the calc. Accelerations are stored in _tmpx, _tmpy and _tmpz

    calc.sph('_tmpx', '_tmpy', '_tmpz')

    tmpx, tmpy, tmpz = pa.get('_tmpx', '_tmpy', '_tmpz')

    # the acceleration should be 2 in each direction

    assert (abs(tmpx[0] - 2.0) < 1e-16)
    assert (abs(tmpy[0] - 2.0) < 1e-16)
    assert (abs(tmpz[0] - 2.0) < 1e-16)
Beispiel #6
0
    def setUp(self):

        parrays = []

        for i in range(np):
            x = numpy.array([x0[i]])
            y = numpy.array([y0[i]])
            z = numpy.array([z0[i]])
            h = numpy.array([h0[i]])

            mi = numpy.array([m[i]])

            name = 'array' + str(i)
            pa = base.get_particle_array(name=name, x=x, y=y, z=z, h=h, m=mi)

            parrays.append(pa)

        self.parrays = parrays

        self.particles = base.Particles(arrays=parrays)

        kernel = base.CubicSplineKernel(dim=3)

        self.solver = s = solver.Solver(dim=3,
                                        integrator_type=solver.EulerIntegrator)

        # NBodyForce operation

        s.add_operation(
            solver.SPHIntegration(sph.NBodyForce.withargs(eps=eps),
                                  on_types=[Fluids],
                                  from_types=[Fluids],
                                  updates=['u', 'v', 'w'],
                                  id='nbody_force'))

        # position stepping

        s.add_operation_step([Fluids])

        # time step and final time

        s.set_final_time(tf)
        s.set_time_step(dt)

        # setup the integrator

        s.setup_integrator(self.particles)
Beispiel #7
0
    def setUp(self):
        """ Setup for SPHOperationTestCase

        Setup:
        ------
        Create two particle arrays, one Fluid and one Solid.
        Instantiate the class with a default function `SPHRho` with 
        various combinations of the from and on types and check for the 
        filtering of the arrays.

        """

        x = numpy.linspace(0, 1, 11)
        h = numpy.ones_like(x) * 2 * (x[1] - x[0])

        #create the fluid particle array

        self.fluid = base.get_particle_array(name='fluid',
                                             type=Fluid,
                                             x=x,
                                             h=h)

        #create the solid particle array

        self.solid = base.get_particle_array(name="solid",
                                             type=Solid,
                                             x=x,
                                             h=h)

        #create the particles

        self.particles = particles = base.Particles(
            arrays=[self.fluid, self.solid])

        #set the kernel

        self.kernel = base.CubicSplineKernel()
Beispiel #8
0
vf = numpy.array([0.0])
cf = numpy.array([25.0])
rhof = numpy.array([1.0])

fluid = base.get_particle_array(name="fluid", type=Fluid, x=xf, y=yf,
                                h=hf, m=mf, rho=rhof, v=vf, cs=cf)

#generate the boundary
l = base.Line(base.Point(-.5), 1.0, 0)
g = base.Geometry('line', [l], False)
g.mesh_geometry(dx)
boundary = g.get_particle_array(re_orient=True)

boundary.m[:] = 1.0

particles = base.Particles(arrays=[fluid, boundary])
app.particles = particles


kernel = base.HarmonicKernel(dim=2, n=3)

s = solver.Solver(dim=2, integrator_type=solver.PredictorCorrectorIntegrator)

# set the kernel as the default for the solver

s.default_kernel = kernel

#Tait equation
s.add_operation(solver.SPHOperation(
        
        sph.TaitEquation.withargs(co=25.0, ro=1.0), 
Beispiel #9
0
                                y=yf,
                                h=hf,
                                m=mf,
                                rho=rhof,
                                v=vf,
                                cf=cf)

boundary = base.get_particle_array(name="boundary",
                                   type=1,
                                   x=xb,
                                   y=yb,
                                   h=hb,
                                   m=mb,
                                   rho=rhob)

particles = base.Particles(arrays=[boundary, fluid])
app.particles = particles

s = solver.Solver(dim=2, integrator_type=solver.EulerIntegrator)

#Equation of state
s.add_operation(
    solver.SPHOperation(sph.TaitEquation.withargs(co=25.0, ro=1.0),
                        on_types=[Fluid, Solid],
                        updates=['p', 'cs'],
                        id='eos'))

#Continuity equation
s.add_operation(
    solver.SPHIntegration(sph.SPHDensityRate.withargs(),
                          from_types=[Fluid, Solid],
Beispiel #10
0
    def setUp(self):
        """ The setup consists of four particles placed at the
        vertices of a unit square. 
        
        """

        self.precision = "single"

        self.np = 4

        x = numpy.array([0, 0, 1, 1], numpy.float64)
        y = numpy.array([0, 1, 1, 0], numpy.float64)

        z = numpy.zeros_like(x)
        m = numpy.ones_like(x)

        u = numpy.array([1, 0, 0, -1], numpy.float64)
        p = numpy.array([0, 0, 1, 1], numpy.float64)

        self.pa = pa = base.get_particle_array(name="test",
                                               x=x,
                                               y=y,
                                               z=z,
                                               m=m,
                                               u=u,
                                               p=p,
                                               cl_precision=self.precision)

        self.particles = particles = base.Particles([
            pa,
        ])

        sphrho_func = sph.SPHRho.withargs()
        density_rate_func = sph.SPHDensityRate.withargs()

        self.sphrho_func = sphrho_func.get_func(pa, pa)
        self.density_rate_func = density_rate_func.get_func(pa, pa)

        self.sphrho_func.kernel = base.CubicSplineKernel(dim=2)
        self.density_rate_func.kernel = base.CubicSplineKernel(dim=2)

        self.rho_calc = sph.SPHCalc(particles, [
            pa,
        ],
                                    pa,
                                    base.CubicSplineKernel(dim=2), [
                                        self.sphrho_func,
                                    ],
                                    updates=['rho'])

        self.rho_calc_cl = sph.CLCalc(particles, [
            pa,
        ],
                                      pa,
                                      base.CubicSplineKernel(dim=2), [
                                          self.sphrho_func,
                                      ],
                                      updates=['rho'])

        if solver.HAS_CL:
            self.ctx = ctx = cl.create_some_context()
            self.q = q = cl.CommandQueue(ctx)
            self.rho_calc_cl.setup_cl(ctx)
Beispiel #11
0
    def setUp(self):
        """ The setup consists of two fluid particle arrays, each
        having one particle. The fluids are acted upon by an external
        vector force and gravity.

        Comparison is made with the PySPH integration of the system.
        
        """

        x1 = numpy.array([
            -0.5,
        ])
        y1 = numpy.array([
            1.0,
        ])

        x2 = numpy.array([
            0.5,
        ])
        y2 = numpy.array([
            1.0,
        ])

        tmpx1 = numpy.ones_like(x1)
        tmpx2 = numpy.ones_like(x2)

        self.f1 = base.get_particle_array(name="fluid1",
                                          x=x1,
                                          y=y1,
                                          tmpx=tmpx1)
        self.f2 = base.get_particle_array(name="fluid2",
                                          x=x2,
                                          y=y2,
                                          tmpx=tmpx2)

        self.particles = base.Particles(arrays=[self.f1, self.f2])
        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        gravity = solver.SPHIntegration(sph.GravityForce.withargs(gy=-10.0),
                                        on_types=[Fluid],
                                        updates=['u', 'v'],
                                        id='gravity')

        force = solver.SPHIntegration(sph.GravityForce.withargs(gx=-10.0),
                                      on_types=[Fluid],
                                      updates=['u', 'v'],
                                      id='force')

        position = solver.SPHIntegration(
            sph.PositionStepping,
            on_types=[Fluid],
            updates=['x', 'y'],
            id='step',
        )

        gravity.calc_type = sph.CLCalc
        force.calc_type = sph.CLCalc
        position.calc_type = sph.CLCalc

        gravity_calcs = gravity.get_calcs(self.particles, kernel)
        force_calcs = force.get_calcs(self.particles, kernel)
        position_calcs = position.get_calcs(self.particles, kernel)

        self.calcs = calcs = []
        calcs.extend(gravity_calcs)
        calcs.extend(force_calcs)
        calcs.extend(position_calcs)

        self.integrator = CLIntegrator(self.particles, calcs)

        self.ctx = ctx = cl.create_some_context()
        self.integrator.setup_integrator(ctx)
        self.queue = calcs[0].queue

        self.dt = 0.1
        self.nsteps = 10
Beispiel #12
0
            precision_types.append('double')

        for prec in precision_types:

            print "\n========================================================"
            print "Summation Density Comparison using %s precision" % (prec)

            pa = base.get_particle_array(cl_precision=prec,
                                         name="test",
                                         x=x,
                                         h=h,
                                         m=m,
                                         rho=rho)

            particles = base.Particles(arrays=[
                pa,
            ],
                                       locator_type=NSquareNeighborLocator)

            kernel = base.CubicSplineKernel(dim=1)

            # create the function
            func = sph.SPHRho.get_func(pa, pa)

            # create the CLCalc object
            cl_calc = sph.CLCalc(particles=particles,
                                 sources=[
                                     pa,
                                 ],
                                 dest=pa,
                                 kernel=kernel,
                                 funcs=[
Beispiel #13
0
    def setUp(self):
        """ A simple simulation in 2D with boundary particles spaced with a
        distance dp. The fluid particles are in a row just above as shown
        in the fgure. 

                   dx
                  o   o   o   o   o
            x x x x x x x x x x x x x x x  

        Y
        |  Z
        | /
        |/___ X
            

        Expected Behavior:
        -------------------
        The Monaghan Boundary force is defned such that a particle moving 
        parallel to the wall experiences a constant force.
        Each fluid particle can be thought of successive instances of a 
        moving particle and hence each of them should experience the same
        force.

        """

        #fluid particle spacing
        self.dx = dx = 0.1

        #solid particle spacing
        self.dp = dp = 0.05

        #the fluid properties
        xf = numpy.array([-.2, -.1, 0.0, 0.1, 0.2])
        yf = numpy.array([dp, dp, dp, dp, dp])
        hf = numpy.ones_like(xf) * 2 * dx
        mf = numpy.ones_like(xf) * dx
        cs = numpy.ones_like(xf)
        rhof = numpy.ones_like(xf)

        self.fluid = base.get_particle_array(x=xf,
                                             y=yf,
                                             h=hf,
                                             m=mf,
                                             rho=rhof,
                                             cs=cs,
                                             ax=mf,
                                             ay=mf,
                                             az=mf,
                                             name='fluid',
                                             type=Fluid)

        l = base.Line(base.Point(-0.35), 0.70, 0.0)
        g = base.Geometry('line', lines=[l], is_closed=False)
        g.mesh_geometry(dp)
        self.solid = g.get_particle_array(re_orient=True)

        self.particles = particles = base.Particles(
            arrays=[self.fluid, self.solid])

        self.kernel = kernel = base.CubicSplineKernel(dim=2)

        self.solver = solver.Solver(kernel.dim, solver.EulerIntegrator)

        self.solver.add_operation(
            solver.SPHIntegration(sph.MonaghanBoundaryForce.withargs(delp=dp),
                                  from_types=[Solid],
                                  on_types=[Fluid],
                                  updates=['u', 'v', 'w'],
                                  id='boundary'))

        self.solver.setup_integrator(particles)

        self.integrator = self.solver.integrator