예제 #1
0
    def create_particles(self):
        dx_airfoil = 0.002
        dx_wall = 0.002
        wall, wing, fluid = windtunnel_airfoil_model(dx_wall=dx_wall,
                                                     dx_airfoil=dx_airfoil)
        outlet = get_particle_array_wcsph(name='outlet')

        dx = 0.01
        y = np.linspace(-0.49, 0.49, 99)
        x = np.zeros_like(y) - 0.81
        rho = np.ones_like(x) * 100.0
        m = rho * dx * dx
        h = np.ones_like(x) * dx * 1.1

        u = np.ones_like(x) * self.options.speed

        inlet = get_particle_array_wcsph(name='inlet',
                                         x=x,
                                         y=y,
                                         m=m,
                                         h=h,
                                         u=u,
                                         rho=rho)

        return [inlet, fluid, wing, outlet, wall]
예제 #2
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        xf, yf = create_fluid()
        rho = get_density(yf)
        m = rho[:] * self.dx * self.dx
        rho = np.ones_like(xf) * self.ro
        h = np.ones_like(xf) * self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf, y=yf, h=h, m=m, rho=rho,
                                         name="fluid")

        xt, yt = create_boundary()
        m = np.ones_like(xt) * 1000 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        rad_s = np.ones_like(xt) * 2 / 2. * 1e-3
        h = np.ones_like(xt) * self.hdx * self.dx
        tank = get_particle_array_wcsph(x=xt, y=yt, h=h, m=m, rho=rho,
                                        rad_s=rad_s, name="tank")

        dx = 1
        xc, yc = create_sphere(1)
        m = np.ones_like(xc) * self.solid_rho * dx * 1e-3 * dx * 1e-3
        rho = np.ones_like(xc) * self.solid_rho
        h = np.ones_like(xc) * self.hdx * self.dx
        rad_s = np.ones_like(xc) * dx / 2. * 1e-3
        # add cs property to run the simulation
        cs = np.zeros_like(xc)
        cube = get_particle_array_rigid_body(x=xc, y=yc, h=h, m=m, rho=rho,
                                             rad_s=rad_s, cs=cs, name="cube")

        return [fluid, tank, cube]
예제 #3
0
    def create_particles(self):
        nb = 2
        sl = slice(-nb*dx, 1 + nb*dx, (10 + 2*nb)*1j)
        x, y, z = np.mgrid[sl, sl, sl]
        x, y, z = (np.ravel(t) for t in (x, y, z))

        inside = (x > 0) & (x < 1) & (y > 0) & (y < 1) & (z > 0) & (z < 1)
        outside = ~inside

        water = inside & (z < water_height)

        # the fluid.
        h0 = hdx*dx
        m = dx*dx*dx*rho
        one_f = np.ones_like(x[water])
        fluid = get_particle_array_wcsph(
            name='fluid', x=x[water], y=y[water], z=z[water],
            rho=rho*one_f, h=h0*one_f, m=m*one_f
        )

        one_s = np.ones_like(x[outside])
        solid = get_particle_array_wcsph(
            name='solid', x=x[outside], y=y[outside], z=z[outside],
            rho=rho*one_s, h=h0*one_s, m=m*one_s
        )
        return [fluid, solid]
예제 #4
0
    def create_particles(self, nboundary_layers=2, nfluid_offset=2,
                         hdx=1.5, **kwargs):
        nfluid = self.nfluid
        xf, yf = self.get_fluid(nfluid_offset)
        fluid = get_particle_array_wcsph(name='fluid', x=xf, y=yf)

        fluid.gid[:] = range(fluid.get_number_of_particles())

        np = nfluid

        xb, yb = self.get_wall(nboundary_layers)
        boundary = get_particle_array_wcsph(name='boundary', x=xb, y=yb)

        np += boundary.get_number_of_particles()

        dx, dy, ro = self.dx, self.dy, self.ro

        # smoothing length, mass and density
        fluid.h[:] = numpy.ones_like(xf) * hdx * dx
        fluid.m[:] = dx * dy * 0.5 * ro
        fluid.rho[:] = ro
        fluid.rho0[:] = ro

        boundary.h[:] = numpy.ones_like(xb) * hdx * dx
        boundary.m[:] = dx * dy * 0.5 * ro
        boundary.rho[:] = ro
        boundary.rho0[:] = ro

        # create the particles list
        particles = [fluid, boundary]

        if self.with_obstacle:
            xo, yo = create_obstacle( x1=2.5, x2=2.5+dx, height=0.25, dx=dx )
            gido = numpy.array( range(xo.size), dtype=numpy.uint32 )
            
            obstacle = get_particle_array_wcsph(name='obstacle',x=xo, y=yo)
            
            obstacle.h[:] = numpy.ones_like(xo) * hdx * dx
            obstacle.m[:] = dx * dy * 0.5 * ro
            obstacle.rho[:] = ro
            obstacle.rho0[:] = ro
            
            # add the obstacle to the boundary particles
            boundary.append_parray( obstacle )

            np += obstacle.get_number_of_particles()

        # set the gid for the boundary particles
        boundary.gid[:] = range( boundary.get_number_of_particles() )

        # boundary particles can do with a reduced list of properties
        # to be saved to disk since they are fixed
        boundary.set_output_arrays( ['x', 'y', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'] )

        print "2D dam break with %d fluid, %d boundary particles"%(
            fluid.get_number_of_particles(),
            boundary.get_number_of_particles())

        return particles
예제 #5
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        xf, yf = create_fluid()
        m = self.ro * self.dx * self.dx
        rho = self.ro
        h = self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf,
                                         y=yf,
                                         h=h,
                                         m=m,
                                         rho=rho,
                                         name="fluid")

        dx = 2
        xt, yt = create_boundary()
        m = 1000 * self.dx * self.dx
        rho = 1000
        rad_s = 2 / 2. * 1e-3
        h = self.hdx * self.dx
        V = dx * dx * 1e-6
        tank = get_particle_array_wcsph(x=xt,
                                        y=yt,
                                        h=h,
                                        m=m,
                                        rho=rho,
                                        rad_s=rad_s,
                                        V=V,
                                        name="tank")
        for name in ['fx', 'fy', 'fz']:
            tank.add_property(name)

        dx = 1
        xc, yc = create_three_spheres()
        b_id, rho = properties_of_three_spheres()
        m = rho * dx * 1e-3 * dx * 1e-3
        h = self.hdx * self.dx
        rad_s = dx / 2. * 1e-3
        V = dx * dx * 1e-6
        cs = 0.0
        cube = get_particle_array_rigid_body(x=xc,
                                             y=yc,
                                             h=h,
                                             m=m,
                                             rho=rho,
                                             rad_s=rad_s,
                                             V=V,
                                             cs=cs,
                                             body_id=b_id,
                                             name="cube")

        return [fluid, tank, cube]
예제 #6
0
    def create_particles(self):
        dx = self.dx
        hdx = self.hdx
        xmin, xmax = 0.0, 1.0
        ymin, ymax = 0.0, 1.0
        zmin, zmax = 0.0, 1.0
        x, y, z = numpy.mgrid[xmin:xmax:dx, ymin:ymax:dx, zmin:zmax:dx]
        x = x.ravel()
        y = y.ravel()
        z = z.ravel()

        # set up particle properties
        h0 = hdx * dx

        volume = dx**3
        m0 = rho0 * volume

        fluid = get_particle_array_wcsph(name='fluid', x=x, y=y, z=z)
        fluid.m[:] = m0
        fluid.h[:] = h0

        fluid.rho[:] = rho0
        #nnps = LinkedListNNPS(dim=3, particles=[fluid])
        #nnps.spatially_order_particles(0)

        print("Number of particles:", x.size)
        fluid.set_lb_props(list(fluid.properties.keys()))
        return [fluid]
예제 #7
0
def create_particles(**kwargs):
    # create the particles
    _x = np.arange(dx / 2, L, dx)
    x, y = np.meshgrid(_x, _x)
    x = x.ravel()
    y = y.ravel()
    h = np.ones_like(x) * dx

    # create the arrays
    fluid = get_particle_array_wcsph(name='fluid', x=x, y=y, h=h)

    # add the requisite arrays
    for prop in ('color', 'ax', 'ay', 'az', 'u0', 'v0'):
        fluid.add_property(name=prop)

    print("Advection mixing problem :: nfluid = %d" %
          (fluid.get_number_of_particles()))

    # setup the particle properties
    pi = np.pi
    cos = np.cos
    sin = np.sin

    # color
    fluid.color[:] = cos(2 * pi * x) * cos(4 * pi * y)

    # velocities
    fluid.u0[:] = +sin(pi * x) * sin(pi * x) * sin(2 * pi * y)
    fluid.v0[:] = -sin(pi * y) * sin(pi * y) * sin(2 * pi * x)

    # return the particle list
    return [
        fluid,
    ]
예제 #8
0
def create_particles(**kwargs):
    # create the particles
    _x = np.arange( dx/2, L, dx )
    x, y = np.meshgrid(_x, _x); x = x.ravel(); y = y.ravel()
    h = np.ones_like(x) * dx

    # create the arrays
    fluid = get_particle_array_wcsph(name='fluid', x=x, y=y, h=h)

    # add the requisite arrays
    for prop in ('color', 'ax', 'ay', 'az', 'u0', 'v0'):
        fluid.add_property(name=prop)

    print "Advection mixing problem :: nfluid = %d"%(
        fluid.get_number_of_particles())

    # setup the particle properties
    pi = np.pi; cos = np.cos; sin=np.sin

    # color
    fluid.color[:] = cos(2*pi*x) * cos(4*pi*y)

    # velocities
    fluid.u0[:] = +sin(pi*x)*sin(pi*x) * sin(2*pi*y)
    fluid.v0[:] = -sin(pi*y)*sin(pi*y) * sin(2*pi*x)

    # return the particle list
    return [fluid,]
예제 #9
0
 def test_dump_and_load_with_constants(self):
     x = np.linspace(0, 1.0, 10)
     y = x * 2.0
     pa = get_particle_array_wcsph(name='fluid',
                                   x=x,
                                   y=y,
                                   constants={
                                       'c1': 1.0,
                                       'c2': [2.0, 3.0]
                                   })
     pa.add_property('A', data=2.0, stride=2)
     pa.set_output_arrays(['x', 'y', 'A'])
     fname = self._get_filename('simple')
     dump(fname, [pa], solver_data={})
     data = load(fname)
     arrays = data['arrays']
     pa1 = arrays['fluid']
     self.assertListEqual(list(sorted(pa.properties.keys())),
                          list(sorted(pa1.properties.keys())))
     self.assertListEqual(list(sorted(pa.constants.keys())),
                          list(sorted(pa1.constants.keys())))
     self.assertTrue(np.allclose(pa.x, pa1.x, atol=1e-14))
     self.assertTrue(np.allclose(pa.y, pa1.y, atol=1e-14))
     self.assertTrue(np.allclose(pa.A, pa1.A, atol=1e-14))
     self.assertTrue(np.allclose(pa.c1, pa1.c1, atol=1e-14))
     self.assertTrue(np.allclose(pa.c2, pa1.c2, atol=1e-14))
예제 #10
0
파일: geometry.py 프로젝트: mpcsdspa/pysph
def remove_overlap_particles(fluid_parray, solid_parray, dx_solid, dim=3):
    """
    This function will take 2 particle arrays as input and will remove all
    the particles of the first particle array which are in the vicinity of
    the particles from second particle array. The function will remove all
    the particles within the dx_solid vicinity so some particles are removed
    at the outer surface of the particles from the second particle array.
    This uses a pysph nearest neighbour particles search which will output
    the particles within some range for every given particle.

    Parameters
    ----------
    fluid_parray : a pysph particle array object
    solid_parray : a pysph particle array object
    dx_solid : a number which is the dx of the second particle array
    dim : dimensionality of the problem

    The particle arrays should atleast contain x, y and h values for a 2d case
    and atleast x, y, z and h values for a 3d case

    Returns
    -------
    particle_array : pysph wcsph_particle_array with x, y, z and h values
    """

    x = fluid_parray.x
    x1 = solid_parray.x
    y = fluid_parray.y
    y1 = solid_parray.y
    z = fluid_parray.z
    z1 = solid_parray.z
    h = fluid_parray.h
    if dim == 2:
        z = np.zeros_like(x)
        z1 = np.zeros_like(x1)
    modified_points = []
    h_new = []
    ll_nnps = LinkedListNNPS(dim, [fluid_parray, solid_parray])
    for i in range(len(x)):
        nbrs = UIntArray()
        ll_nnps.get_nearest_particles(1, 0, i, nbrs)
        point_i = np.array([x[i], y[i], z[i]])
        near_points = nbrs.get_npy_array()
        distances = []
        for ind in near_points:
            dest = [x1[ind], y1[ind], z1[ind]]
            distances.append(distance(point_i, dest))
        if len(distances) == 0:
            modified_points.append(point_i)
            h_new.append(h[i])
        elif min(distances) >= (dx_solid * (1.0 - 1.0e-07)):
            modified_points.append(point_i)
            h_new.append(h[i])
    modified_points = np.array(modified_points)
    x_new = modified_points[:, 0]
    y_new = modified_points[:, 1]
    z_new = modified_points[:, 2]
    p_array = get_particle_array_wcsph(x=x_new, y=y_new, z=z_new, h=h_new)
    return p_array
예제 #11
0
def Geometry():
    """ Create particles """
    plt.close('all')
    dx = 0.05
    x, y = np.mgrid[-5.0:5.0:dx * .75, -5.0:5.0:dx * .75]
    xw = x.ravel()
    yw = y.ravel()
    plt.axis('equal')
    #plt.scatter(x,y)
    #plt.show()
    indices = []
    for i in range(len(xw)):
        if (xw[i] > -4.9) & (xw[i] < 4.9):
            if (yw[i] > -4.9):
                indices.append(i)
    ro = 1000
    hdx = 1.2
    m = ones_like(xw) * dx * dx * ro
    h = ones_like(xw) * hdx * dx
    rho = ones_like(xw) * ro

    wall = get_particle_array_wcsph(x=xw, y=yw, m=m, rho=rho, h=h, name='wall')
    wall.remove_particles(indices)

    print("Number of Solid particles are %d" % wall.get_number_of_particles())

    x, y = np.mgrid[-4.8:-2.9:dx, -4.8:-0.9:dx]
    xf = x.ravel()
    yf = y.ravel()

    m = ones_like(xf) * dx * dx * ro
    h = ones_like(xf) * hdx * dx
    rho = ones_like(xf) * ro

    fluid = get_particle_array_wcsph(x=xf,
                                     y=yf,
                                     m=m,
                                     rho=rho,
                                     h=h,
                                     name='fluid')
    print("Number of fluid particles are %d" % fluid.get_number_of_particles())
    # plt.scatter(wall.x,wall.y)
    # plt.scatter(fluid.x,fluid.y)
    # plt.show()
    return [wall, fluid]
예제 #12
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        # xf, yf = create_fluid_with_solid_cube()
        xf, yf = create_fluid()
        uf = np.zeros_like(xf)
        vf = np.zeros_like(xf)
        m = initialize_mass(xf, yf)
        rho = initialize_density_fluid(xf, yf)
        h = np.ones_like(xf) * self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf, y=yf, h=h, m=m, rho=rho, u=uf,
                                         v=vf, name="fluid")

        xt, yt = create_boundary(self.dx / 2.)
        ut = np.zeros_like(xt)
        vt = np.zeros_like(xt)
        m = np.ones_like(xt) * 1500 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        h = np.ones_like(xt) * self.hdx * self.dx / 2.
        tank = get_particle_array_wcsph(x=xt, y=yt, h=h, m=m, rho=rho, u=ut,
                                        v=vt, name="tank")

        xc, yc, indices = create_cube()
        _m = 2120 * self.dx * self.dx / 2.
        m = np.ones_like(xc) * _m
        h = np.ones_like(xc) * self.hdx * self.dx / 2.
        rho = np.ones_like(xc) * 2120
        cube = get_particle_array_rigid_body(name="cube", x=xc, y=yc, m=m, h=h,
                                             rho=rho)
        add_properties(cube, 'indices')
        cube.indices[:] = indices[:]
        add_properties(cube, 'rad_s')
        cube.rad_s[:] = 0.5 * 1e-3
        add_properties(
            cube,
            'tang_disp_x',
            'tang_disp_y',
            'tang_disp_z',
            'tang_disp_x0',
            'tang_disp_y0',
            'tang_disp_z0',
            'tang_velocity_x',
            'tang_velocity_y',
            'tang_velocity_z', )

        return [fluid, tank, cube]
예제 #13
0
    def create_particles(self):
        # get the geometry
        xt, yt, xf, yf = get_fluid_and_dam_geometry(
            self.dam_length, self.dam_height, self.fluid_length,
            self.fluid_height, self.dam_layers, self.dam_spacing,
            self.fluid_spacing, [3 * self.dam_spacing, 3 * self.dam_spacing])

        # create fluid particle array
        m = self.fluid_rho * self.fluid_spacing * self.fluid_spacing
        rho = self.fluid_rho
        h = self.hdx * self.fluid_spacing
        fluid = get_particle_array_wcsph(x=xf, y=yf, h=h, m=m, rho=rho,
                                         name="fluid")

        # create tank particle array
        m = self.fluid_rho * self.dam_spacing * self.dam_spacing
        rho = 1000
        rad_s = self.dam_spacing / 2.
        h = self.hdx * self.dam_spacing
        V = self.dam_spacing**2
        tank = get_particle_array_wcsph(x=xt, y=yt, h=h, m=m, rho=rho,
                                        rad_s=rad_s, V=V, name="tank")
        for name in ['fx', 'fy', 'fz']:
            tank.add_property(name)

        xc, yc = create_ten_circles(radius=self.sphere_radius,
                                    spacing=self.sphere_spacing,
                                    fluid_height=self.fluid_height)

        # get density of each sphere
        rho = get_rho_of_each_sphere(xc, yc, radius=self.sphere_radius,
                                     spacing=self.sphere_spacing)
        # get bodyid for each sphere
        body_id = get_body_id_of_each_sphere(xc, yc, radius=self.sphere_radius,
                                             spacing=self.sphere_spacing)
        m = rho * self.sphere_spacing**2
        h = self.hdx * self.sphere_spacing
        rad_s = self.sphere_spacing / 2.
        V = self.sphere_spacing**2
        cs = 0.0
        cube = get_particle_array_rigid_body(x=xc, y=yc, h=h, m=m, rho=rho,
                                             rad_s=rad_s, V=V, cs=cs,
                                             body_id=body_id, name="cube")
        return [fluid, tank, cube]
예제 #14
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        # xf, yf = create_fluid_with_solid_cube()
        xf, yf = create_fluid()
        rho = get_density(yf)
        m = rho[:] * self.dx * self.dx
        rho = np.ones_like(xf) * self.ro
        h = np.ones_like(xf) * self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf,
                                         y=yf,
                                         h=h,
                                         m=m,
                                         rho=rho,
                                         name="fluid")

        xt, yt = create_boundary()
        m = np.ones_like(xt) * 1000 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        h = np.ones_like(xt) * self.hdx * self.dx
        rad_s = np.ones_like(xt) * 2 / 2. * 1e-3
        tank = get_particle_array_wcsph(x=xt,
                                        y=yt,
                                        h=h,
                                        m=m,
                                        rho=rho,
                                        name="tank",
                                        rad_s=rad_s)

        dx = 1
        xc, yc = create_cube(1)
        m = np.ones_like(xc) * 2120 * dx * 1e-3 * dx * 1e-3
        rho = np.ones_like(xc) * 2120
        h = np.ones_like(xc) * self.hdx * self.dx
        rad_s = np.ones_like(xc) * dx / 2. * 1e-3
        cube = get_particle_array_rigid_body(x=xc,
                                             y=yc,
                                             h=h,
                                             m=m,
                                             rho=rho,
                                             rad_s=rad_s,
                                             name="cube")
        return [fluid, tank, cube]
 def setup_properties(self, particles, clean=True):
     from pysph.base.utils import get_particle_array_wcsph
     dummy = get_particle_array_wcsph(name='junk')
     props = list(dummy.properties.keys())
     output_props = [
         'x', 'y', 'z', 'u', 'v', 'w', 'rho', 'm', 'h', 'pid', 'gid', 'tag',
         'p'
     ]
     for pa in particles:
         self._ensure_properties(pa, props, clean)
         pa.set_output_arrays(output_props)
    def create_particles(self):
        """Create the circular patch of fluid."""
        # xf, yf = create_fluid_with_solid_cube()
        xf, yf = create_fluid()
        uf = np.zeros_like(xf)
        vf = np.zeros_like(xf)
        m = initialize_mass(xf, yf)
        rho = initialize_density_fluid(xf, yf)
        h = np.ones_like(xf) * self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf, y=yf, h=h, m=m, rho=rho, u=uf,
                                         v=vf, name="fluid")

        xt, yt = create_boundary(self.dx / 2.)
        ut = np.zeros_like(xt)
        vt = np.zeros_like(xt)
        m = np.ones_like(xt) * 1500 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        h = np.ones_like(xt) * self.hdx * self.dx / 2.
        tank = get_particle_array_wcsph(x=xt, y=yt, h=h, m=m, rho=rho, u=ut,
                                        v=vt, name="tank")

        return [fluid, tank]
예제 #17
0
 def test_dump_and_load_with_partial_data_dump(self):
     x = np.linspace(0, 1.0, 10)
     y = x*2.0
     pa = get_particle_array_wcsph(name='fluid', x=x, y=y)
     pa.set_output_arrays(['x', 'y'])
     fname = self._get_filename('simple')
     dump(fname, [pa], solver_data={})
     data = load(fname)
     arrays = data['arrays']
     pa1 = arrays['fluid']
     self.assertListEqual(list(sorted(pa.properties.keys())),
                          list(sorted(pa1.properties.keys())))
     self.assertTrue(np.allclose(pa.x, pa1.x, atol=1e-14))
     self.assertTrue(np.allclose(pa.y, pa1.y, atol=1e-14))
    def create_particles(self):
        """Create the circular patch of fluid."""
        dx = self.dx
        hdx = self.hdx
        co = self.co
        ro = self.ro
        name = 'fluid'
        x, y = mgrid[-1.05:1.05+1e-4:dx, -1.05:1.05+1e-4:dx]
        x = x.ravel()
        y = y.ravel()

        m = ones_like(x)*dx*dx*ro
        h = ones_like(x)*hdx*dx
        rho = ones_like(x) * ro
        u = -100*x
        v = 100*y

        # remove particles outside the circle
        indices = []
        for i in range(len(x)):
            if sqrt(x[i]*x[i] + y[i]*y[i]) - 1 > 1e-10:
                indices.append(i)

        pa = get_particle_array_wcsph(x=x, y=y, m=m, rho=rho, h=h, u=u, v=v,
                                name=name)
        pa.remove_particles(indices)

        print("Elliptical drop :: %d particles"
              % (pa.get_number_of_particles()))
        print("Effective viscosity: rho*alpha*h*c/8 = %s" % self.mu)
        
        pa.add_property('m_mat', stride=9)
        pa.add_property('gradrho', stride=3)
        pa.add_property('gradlmda', stride=3)
        
        add_props = [
            'lmda', 'delta_s', 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 
            'ax', 'ay', 'az', 'DRh', 'DY', 'DX', 'DZ', 'vmax'
        ]
        for i in add_props:
            pa.add_property(i)

        pa.set_output_arrays([
            'x', 'y', 'z', 'u', 'v', 'w', 'rho', 'm', 'h', 'pid', 'gid', 'tag', 
            'p', 'lmda', 'delta_s', 'DRh', 'vmax'
        ])
        return [pa]
예제 #19
0
def create_particles(**kwargs):
    # create the particles
    _x = np.arange(a, b + 1e-3, dx)
    x, y = np.meshgrid(_x, _x)
    x = x.ravel()
    y = y.ravel()
    h = np.ones_like(x) * dx

    cx = cy = 0.5
    indices = []
    for i in range(x.size):
        xi = x[i]
        yi = y[i]
        if ((xi - cx)**2 + (yi - cy)**2 > 0.25**2):
            indices.append(i)

    # create the arrays
    fluid = get_particle_array_wcsph(name='fluid', x=x, y=y, h=h)

    # remove particles outside the circular patch
    fluid.remove_particles(indices)

    # add the requisite arrays
    for prop in ('color', 'ax', 'ay', 'az'):
        fluid.add_property(name=prop)

    print("Advection test :: nfluid = %d" % (fluid.get_number_of_particles()))

    # setup the particle properties
    pi = np.pi
    cos = np.cos
    sin = np.sin

    # color
    fluid.color[:] = cos(2 * pi * fluid.x) * cos(2 * pi * fluid.y)
    fluid.u[:] = 1.0
    fluid.v[:] = 1.0

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

    # return the particle list
    return [
        fluid,
    ]
예제 #20
0
 def create_particles(self):
     dx = 0.025
     x, y = np.mgrid[-1.05:1.05:dx, -1.05:1.05:dx]
     mask = x * x + y * y < 1
     x = x[mask]
     y = y[mask]
     rho = 1.0
     h = 1.3 * dx
     m = rho * dx * dx
     pa = get_particle_array_wcsph(name='fluid',
                                   x=x,
                                   y=y,
                                   u=-100 * x,
                                   v=100 * y,
                                   rho=rho,
                                   m=m,
                                   h=h)
     return [pa]
예제 #21
0
    def test_detect_missing_arrays_for_many_particle_arrays(self):
        # Given.
        x = np.asarray([1.0])
        u = np.asarray([0.0])
        h = np.ones_like(x)
        fluid = get_particle_array_wcsph(name='fluid', x=x, u=u, h=h, m=h)
        solid = get_particle_array(name='solid', x=x, u=u, h=h, m=h)
        arrays = [fluid, solid]

        # When
        integrator = PECIntegrator(fluid=TwoStageRigidBodyStep(),
                                   solid=TwoStageRigidBodyStep())
        equations = [SHM(dest="fluid", sources=None)]
        kernel = CubicSpline(dim=1)
        a_eval = AccelerationEval(particle_arrays=arrays,
                                  equations=equations,
                                  kernel=kernel)
        comp = SPHCompiler(a_eval, integrator=integrator)

        # Then
        self.assertRaises(RuntimeError, comp.compile)
예제 #22
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        dx = self.dx
        hdx = self.hdx
        ro = self.ro
        name = 'fluid'
        x, y = mgrid[-1.05:1.05 + 1e-4:dx, -1.05:1.05 + 1e-4:dx]
        # Get the particles inside the circle.
        condition = ~((x * x + y * y - 1.0) > 1e-10)
        x = x[condition].ravel()
        y = y[condition].ravel()

        m = ones_like(x) * dx * dx * ro
        h = ones_like(x) * hdx * dx
        rho = ones_like(x) * ro
        u = -100 * x
        v = 100 * y

        pa = get_particle_array_wcsph(x=x,
                                      y=y,
                                      m=m,
                                      rho=rho,
                                      h=h,
                                      u=u,
                                      v=v,
                                      name=name)

        print("Elliptical drop :: %d particles" %
              (pa.get_number_of_particles()))

        # add requisite variables needed for this formulation
        for name in ('arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'rho0', 'u0',
                     'v0', 'w0', 'x0', 'y0', 'z0'):
            pa.add_property(name)

        # set the output property arrays
        pa.set_output_arrays(
            ['x', 'y', 'u', 'v', 'rho', 'm', 'h', 'p', 'pid', 'tag', 'gid'])

        return [pa]
예제 #23
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        name = 'fluid'
        dx = self.dx
        hdx = self.hdx
        ro = self.ro

        x, y = mgrid[-1.05:1.05 + 1e-4:dx, -1.05:1.05 + 1e-4:dx]
        x = x.ravel()
        y = y.ravel()

        m = ones_like(x) * dx * dx * ro
        h = ones_like(x) * hdx * dx
        rho = ones_like(x) * ro
        u = -100 * x
        v = 100 * y

        # remove particles outside the circle
        indices = []
        for i in range(len(x)):
            if sqrt(x[i] * x[i] + y[i] * y[i]) - 1 > 1e-10:
                indices.append(i)

        pa = get_particle_array_wcsph(x=x,
                                      y=y,
                                      m=m,
                                      rho=rho,
                                      h=h,
                                      u=u,
                                      v=v,
                                      name=name)
        pa.remove_particles(indices)

        print("Elliptical drop :: %d particles" %
              (pa.get_number_of_particles()))

        pa.set_output_arrays(
            ['x', 'y', 'u', 'v', 'rho', 'h', 'p', 'pid', 'tag', 'gid'])
        return [pa]
예제 #24
0
def create_particles(**kwargs):
    # create the particles
    _x = np.arange( a, b+1e-3, dx )
    x, y = np.meshgrid(_x, _x); x = x.ravel(); y = y.ravel()
    h = np.ones_like(x) * dx

    cx = cy = 0.5
    indices = []
    for i in range(x.size):
        xi = x[i]; yi = y[i]
        if ( (xi - cx)**2 + (yi - cy)**2 > 0.25**2 ):
            indices.append(i)

    # create the arrays
    fluid = get_particle_array_wcsph(name='fluid', x=x, y=y, h=h)

    # remove particles outside the circular patch
    fluid.remove_particles(indices)

    # add the requisite arrays
    for prop in ('color', 'ax', 'ay', 'az'):
        fluid.add_property(name=prop)

    print "Advection test :: nfluid = %d"%(
        fluid.get_number_of_particles())

    # setup the particle properties
    pi = np.pi; cos = np.cos; sin=np.sin

    # color
    fluid.color[:] = cos(2*pi*fluid.x) * cos(2*pi*fluid.y)
    fluid.u[:] = 1.0; fluid.v[:] = 1.0

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

    # return the particle list
    return [fluid,]
예제 #25
0
def get_outer_core_particles():

    x, y, z = numpy.mgrid[-r1:r1:dx, -r1:r1:dx, -0.002:0.002:dx]
    x = x.ravel()
    y = y.ravel()
    z = z.ravel()

    d = (x * x + y * y + z * z)
    keep = numpy.flatnonzero((d < r1 * r1) * (r * r < d))
    x = x[keep]
    y = y[keep]
    z = z[keep]

    print('%d Target particles' % len(x))

    hf = numpy.ones_like(x) * h
    mf = numpy.ones_like(x) * dx * dy * dz * ro1
    #rhof = numpy.ones_like(x) * ro1
    rhof = numpy.ones_like(x) * 1000
    csf = numpy.ones_like(x) * cs1
    u = numpy.ones_like(x) * 0
    v = numpy.ones_like(x) * 1000
    w = numpy.ones_like(x) * 0

    outer_core = get_particle_array_wcsph(name="outer_core",
                                          x=x,
                                          y=y,
                                          z=z,
                                          h=hf,
                                          m=mf,
                                          rho0=rhof,
                                          uo=u,
                                          v0=v,
                                          w0=w,
                                          cs=csf)

    return outer_core
예제 #26
0
    def create_particles(self, **kwargs):
        fluid_column_height=self.fluid_column_height
        fluid_column_width=self.fluid_column_width
        fluid_column_length=self.fluid_column_length

        container_height = self.container_height
        container_length = self.container_length
        container_width = self.container_width

        obstacle_height = self.obstacle_height
        obstacle_length = self.obstacle_length
        obstacle_width = self.obstacle_width

        obstacle_center_x = self.obstacle_center_x
        obstacle_center_y = self.obstacle_center_y

        nboundary_layers = self.nboundary_layers
        dx = self.dx

        # get the domain limits
        ghostlims = nboundary_layers * dx

        xmin, xmax = 0.0 -ghostlims, container_length + ghostlims
        zmin, zmax = 0.0 - ghostlims, container_height + ghostlims

        cw2 = 0.5 * container_width
        ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims
            
        # create all particles
        eps = 0.1 * dx
        xx, yy, zz = numpy.mgrid[xmin:xmax+eps:dx,
                                 ymin:ymax+eps:dx,
                                 zmin:zmax+eps:dx]

        x = xx.ravel(); y = yy.ravel(); z = zz.ravel()

        # create a dummy particle array from which we'll sort
        pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z)

        # get the individual arrays
        indices = []
        findices = []
        oindices = []

        obw2 = 0.5 * obstacle_width
        obl2 = 0.5 * obstacle_length
        obh = obstacle_height
        ocx = obstacle_center_x
        ocy = obstacle_center_y

        for i in range(x.size):
            xi = x[i]; yi = y[i]; zi = z[i]

            # fluid
            if ( (0 < xi <= fluid_column_length) and \
                     (-cw2 < yi < cw2) and \
                     (0 < zi <= fluid_column_height) ):

                findices.append(i)

            # obstacle
            if ( (ocx-obl2 <= xi <= ocx+obl2) and \
                     (ocy-obw2 <= yi <= ocy+obw2) and \
                     (0 < zi <= obh) ):

                oindices.append(i)

        # extract the individual arrays
        fa = LongArray(len(findices)); fa.set_data(numpy.array(findices))
        fluid = pa.extract_particles(fa)
        fluid.set_name('fluid')

        oa = LongArray(len(oindices)); oa.set_data(numpy.array(oindices))
        obstacle = pa.extract_particles(oa)
        obstacle.set_name('obstacle')

        indices = concatenate( (where( y <= -cw2 )[0],
                                where( y >= cw2 )[0],
                                where( x >= container_length )[0],
                                where( x <= 0 )[0],
                                where( z <= 0 )[0]) )

        # remove duplicates
        indices = array(list(set(indices)))

        wa = LongArray(indices.size); wa.set_data(indices)
        boundary = pa.extract_particles(wa)
        boundary.set_name('boundary')

        # create the particles
        particles = [fluid, boundary, obstacle]

        # set up particle properties
        h0 = self.hdx * dx

        volume = dx**3
        m0 = self.rho0 * volume

        for pa in particles:
            pa.m[:] = m0
            pa.h[:] = h0

            pa.rho[:] = self.rho0

        nf = fluid.num_real_particles
        nb = boundary.num_real_particles
        no = obstacle.num_real_particles

        print "3D dam break with %d fluid, %d boundary, %d obstacle particles"%(nf, nb, no)

        # load balancing props for the arrays
        #fluid.set_lb_props(['x', 'y', 'z', 'u', 'v', 'w', 'rho', 'h', 'm', 'gid',
        #                    'x0', 'y0', 'z0', 'u0', 'v0', 'w0', 'rho0'])
        fluid.set_lb_props( fluid.properties.keys() )

        #boundary.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        #obstacle.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        boundary.set_lb_props( boundary.properties.keys() )
        obstacle.set_lb_props( obstacle.properties.keys() )

        # boundary and obstacle particles can do with a reduced list of properties
        # to be saved to disk since they are fixed
        boundary.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'] )
        obstacle.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'] )

        return particles
예제 #27
0
def main():
    comm = mpi.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    if size != 4:
        if rank == 0:
            raise RuntimeError("Run this test with 4 processors")

    # create the initial distribution
    if rank == 0:
        numPoints = 12
        x = np.array(
            [0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0])

        y = np.array(
            [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0])

        gid = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype=np.uint32)

        exportLocalids = np.array([2, 3, 4, 7, 8, 9], dtype=np.uint32)
        exportProcs = np.array([2, 2, 2, 2, 2, 2], dtype=np.int32)
        numExport = 6

        parts = np.ones(shape=numPoints, dtype=np.int32) * rank

    if rank == 1:
        numPoints = 6
        x = np.array([2.0, 3.0, 4.0, 0.0, 1.0, 2.0])

        y = np.array([2.0, 2.0, 2.0, 3.0, 3.0, 3.0])

        gid = np.array([12, 13, 14, 15, 16, 17], dtype=np.uint32)

        exportLocalids = np.array([0, 1, 2], dtype=np.uint32)
        exportProcs = np.array([0, 3, 3], dtype=np.int32)
        numExport = 3

        parts = np.ones(shape=numPoints, dtype=np.int32) * rank

    if rank == 2:
        numPoints = 3
        x = np.array([4.0, 5.0, 0.0])
        y = np.array([3.0, 3.0, 4.0])
        gid = np.array([18, 19, 20], dtype=np.uint32)

        exportLocalids = np.array([0, 1, 2], dtype=np.uint32)
        exportProcs = np.array([3, 3, 1], dtype=np.int32)
        numExport = 3

        parts = np.ones(shape=numPoints, dtype=np.int32) * rank

    if rank == 3:
        numPoints = 4
        x = np.array([1.0, 2.0, 3.0, 4.0])
        y = np.array([4.0, 4.0, 4.0, 4.0])
        gid = np.array([21, 22, 23, 24], dtype=np.uint32)

        exportLocalids = np.array([0, 1], dtype=np.uint32)
        exportProcs = np.array([1, 1], dtype=np.int32)
        numExport = 2

        parts = np.ones(shape=numPoints, dtype=np.int32) * rank

    # Gather the Global data on root
    X = np.zeros(shape=25, dtype=np.float64)
    Y = np.zeros(shape=25, dtype=np.float64)
    GID = np.zeros(shape=25, dtype=np.uint32)

    displacements = np.array([12, 6, 3, 4], dtype=np.int32)

    comm.Gatherv(sendbuf=[x, mpi.DOUBLE],
                 recvbuf=[X, (displacements, None)],
                 root=0)
    comm.Gatherv(sendbuf=[y, mpi.DOUBLE],
                 recvbuf=[Y, (displacements, None)],
                 root=0)
    comm.Gatherv(sendbuf=[gid, mpi.UNSIGNED_INT],
                 recvbuf=[GID, (displacements, None)],
                 root=0)

    # broadcast global X, Y and GID to everyone
    comm.Bcast(buf=X, root=0)
    comm.Bcast(buf=Y, root=0)
    comm.Bcast(buf=GID, root=0)

    # create the local particle arrays and exchange objects
    u = np.ones_like(x)
    pa = get_particle_array_wcsph(name='test', x=x, y=y, u=u, gid=gid)
    # Squeeze the arrays so that they are forced to resize when doing
    # the lb exchange.
    for arr in pa.properties.values():
        arr.squeeze()
    pa.set_lb_props(['x', 'y', 'u', 'gid'])

    pae = ParticleArrayExchange(pa_index=0, pa=pa, comm=comm)

    # set the export indices for each array
    pae.reset_lists()
    pae.numParticleExport = numExport
    pae.exportParticleLocalids.resize(numExport)
    pae.exportParticleLocalids.set_data(exportLocalids)

    pae.exportParticleProcs.resize(numExport)
    pae.exportParticleProcs.set_data(exportProcs)

    # call lb_balance with these lists
    pae.lb_exchange_data()

    # All arrays must be local after lb_exchange_data
    assert (pa.num_real_particles == pa.get_number_of_particles())
    assert (np.allclose(pa.tag, 0))

    # now check the data on each array
    numParticles = 6
    if rank == 0:
        numParticles = 7

    assert (pa.num_real_particles == numParticles)

    for i in range(numParticles):
        assert (abs(X[pa.gid[i]] - pa.x[i]) < 1e-15)
        assert (abs(Y[pa.gid[i]] - pa.y[i]) < 1e-15)
        assert (GID[pa.gid[i]] == pa.gid[i])

    # Check that all non-load balanced props are not garbage values
    for prop in ('z', 'v', 'w', 'p'):
        np.testing.assert_array_almost_equal(pa.get(prop), 0.0)
    np.testing.assert_array_almost_equal(pa.u, 1.0)
예제 #28
0
X = np.array( [0,1,2,3,4,
               0,1,2,3,4,
               0,1,2,3,4,
               0,1,2,3,4,
               0,1,2,3,4,], dtype=np.float64 )

Y = np.array( [0,0,0,0,0,
               1,1,1,1,1,
               2,2,2,2,2,
               3,3,3,3,3,
               4,4,4,4,4], dtype=np.float64 )

GID = np.array( range(25), dtype=np.uint32 )

# create the local particle arrays and exchange objects
pa = get_particle_array_wcsph(name='test', x=x, y=y, gid=gid)

pae = ParticleArrayExchange(pa_index=0, pa=pa, comm=comm)

# set the export indices for each array
pae.reset_lists()
pae.numParticleExport = numExport
pae.exportParticleLocalids.resize(numExport)
pae.exportParticleLocalids.set_data( exportLocalids )

pae.exportParticleProcs.resize( numExport )
pae.exportParticleProcs.set_data( exportProcs )

# call remote_exchange data with these lists
pae.remote_exchange_data()
예제 #29
0
def main():
    comm = mpi.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    if size != 4:
        if rank == 0:
            raise RuntimeError("Run this test with 4 processors")

    # create the data
    gid0 = np.array([0, 1, 5, 6, 10, 11, 12], dtype=np.uint32)
    gid1 = np.array([15, 16, 17, 20, 21, 22], dtype=np.uint32)
    gid2 = np.array([2, 3, 4, 7, 8, 9], dtype=np.uint32)
    gid3 = np.array([13, 14, 18, 19, 23, 24], dtype=np.uint32)

    if rank == 0:
        numPoints = 7
        x = np.array([0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 2.0])

        y = np.array([0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 2.0])

        gid = gid0

        exportLocalids = np.array([1, 3, 4, 5, 6, 6, 6], dtype=np.uint32)
        exportProcs = np.array([2, 2, 1, 1, 1, 2, 3], dtype=np.int32)

        numExport = 7
        numRemote = 6

    elif rank == 1:
        numPoints = 6
        x = np.array([0.0, 1.0, 2.0, 0.0, 1.0, 2.0])

        y = np.array([3.0, 3.0, 3.0, 4.0, 4.0, 4.0])

        gid = gid1

        exportLocalids = np.array([0, 1, 2, 2, 5], dtype=np.uint32)
        exportProcs = np.array([0, 0, 0, 3, 3], dtype=np.int32)

        numExport = 5
        numRemote = 5

    elif rank == 2:
        numPoints = 6
        x = np.array([2.0, 3.0, 4.0, 2.0, 3.0, 4.0])
        y = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0])
        gid = gid2

        exportLocalids = np.array([0, 3, 4, 5], dtype=np.uint32)
        exportProcs = np.array([0, 0, 3, 3], dtype=np.int32)

        numExport = 4
        numRemote = 5

    elif rank == 3:
        numPoints = 6
        x = np.array([3.0, 4.0, 3.0, 4.0, 3.0, 4.0])
        y = np.array([2.0, 2.0, 3.0, 3.0, 4.0, 4.0])
        gid = gid3

        exportLocalids = np.array([0, 0, 1, 2, 4], dtype=np.uint32)
        exportProcs = np.array([0, 2, 2, 1, 1], dtype=np.int32)

        numExport = 5
        numRemote = 5

    stride = 2
    a = np.ones(x.shape[0] * stride) * rank

    # Global data
    X = np.array([
        0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3,
        4
    ],
                 dtype=np.float64)

    Y = np.array([
        0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4,
        4
    ],
                 dtype=np.float64)

    A = np.ones(X.shape[0] * stride)
    A[::stride][gid0] = 0
    A[1::stride][gid0] = 0
    A[::stride][gid1] = 1
    A[1::stride][gid1] = 1
    A[::stride][gid2] = 2
    A[1::stride][gid2] = 2
    A[::stride][gid3] = 3
    A[1::stride][gid3] = 3

    GID = np.array(range(25), dtype=np.uint32)

    # create the local particle arrays and exchange objects
    pa = get_particle_array_wcsph(name='test', x=x, y=y, gid=gid)
    pa.add_property('a', data=a, stride=stride)

    pae = ParticleArrayExchange(pa_index=0, pa=pa, comm=comm)

    # set the export indices for each array
    pae.reset_lists()
    pae.numParticleExport = numExport
    pae.exportParticleLocalids.resize(numExport)
    pae.exportParticleLocalids.set_data(exportLocalids)

    pae.exportParticleProcs.resize(numExport)
    pae.exportParticleProcs.set_data(exportProcs)

    # call remote_exchange data with these lists
    pae.remote_exchange_data()

    # the added particles should be remote
    tag = pa.get('tag', only_real_particles=False)
    assert (pa.num_real_particles == numPoints)
    assert (pa.get_number_of_particles() == numPoints + numRemote)

    assert (np.allclose(tag[numPoints:], 1))

    # now check the data on each array
    numParticles = numPoints + numRemote

    x, y, a, gid = pa.get('x', 'y', 'a', 'gid', only_real_particles=False)
    np.testing.assert_array_almost_equal(X[gid], x)
    np.testing.assert_array_almost_equal(Y[gid], y)
    np.testing.assert_array_equal(GID[gid], gid)
    np.testing.assert_array_almost_equal(A[::stride][gid], a[::2])
    np.testing.assert_array_almost_equal(A[1::stride][gid], a[1::2])
예제 #30
0
import numpy as np
from pysph.base.utils import get_particle_array_wcsph
x, y = np.mgrid[-1:1:50j, -1:1:50j]
mask = x * x + y * y < 1.0
pa = get_particle_array_wcsph(name='fluid', x=x[mask], y=y[mask])
plt.scatter(pa.x, pa.y, marker='.')
예제 #31
0
    1,
    2,
    3,
    4,
],
             dtype=np.float64)

Y = np.array([
    0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
],
             dtype=np.float64)

GID = np.array(range(25), dtype=np.uint32)

# create the local particle arrays and exchange objects
pa = get_particle_array_wcsph(name='test', x=x, y=y, gid=gid)

pae = ParticleArrayExchange(pa_index=0, pa=pa, comm=comm)

# set the export indices for each array
pae.reset_lists()
pae.numParticleExport = numExport
pae.exportParticleLocalids.resize(numExport)
pae.exportParticleLocalids.set_data(exportLocalids)

pae.exportParticleProcs.resize(numExport)
pae.exportParticleProcs.set_data(exportProcs)

# call remote_exchange data with these lists
pae.remote_exchange_data()
예제 #32
0
def main():
    # Initialize MPI and find out number of local particles
    comm = mpi.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    # number of particles per array
    numMyPoints = 1 << 10
    numGlobalPoints = size * numMyPoints

    avg_vol = 1.0 / numGlobalPoints
    dx = numpy.power(avg_vol, 1.0 / dim)
    mass = avg_vol
    hdx = 1.3

    if numGlobalPoints % size != 0:
        raise RuntimeError("Run with 2^n num procs!")

    # everybody creates two particle arrays with numMyPoints
    x1 = random.random(numMyPoints)
    y1 = random.random(numMyPoints)
    z1 = random.random(numMyPoints)
    h1 = numpy.ones_like(x1) * hdx * dx
    rho1 = numpy.zeros_like(x1)

    x2 = random.random(numMyPoints)
    y2 = random.random(numMyPoints)
    z2 = random.random(numMyPoints)
    h2 = numpy.ones_like(x2) * hdx * dx
    rho2 = numpy.zeros_like(x2)

    # z1[:] = 1.0
    # z2[:] = 0.5

    # local particle arrays
    pa1 = get_particle_array_wcsph(x=x1, y=y1, h=h1, rho=rho1, z=z1)
    pa2 = get_particle_array_wcsph(x=x2, y=y2, h=h2, rho=rho2, z=z2)

    # gather the data on root
    X1 = numpy.zeros(numGlobalPoints)
    Y1 = numpy.zeros(numGlobalPoints)
    Z1 = numpy.zeros(numGlobalPoints)
    H1 = numpy.ones_like(X1) * hdx * dx
    RHO1 = numpy.zeros_like(X1)

    gathers = (numpy.ones(size) * numMyPoints, None)

    comm.Gatherv(sendbuf=[x1, mpi.DOUBLE], recvbuf=[X1, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[y1, mpi.DOUBLE], recvbuf=[Y1, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[z1, mpi.DOUBLE], recvbuf=[Z1, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[rho1, mpi.DOUBLE],
                 recvbuf=[RHO1, gathers, mpi.DOUBLE])

    X2 = numpy.zeros(numGlobalPoints)
    Y2 = numpy.zeros(numGlobalPoints)
    Z2 = numpy.zeros(numGlobalPoints)
    H2 = numpy.ones_like(X2) * hdx * dx
    RHO2 = numpy.zeros_like(X2)

    comm.Gatherv(sendbuf=[x2, mpi.DOUBLE], recvbuf=[X2, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[y2, mpi.DOUBLE], recvbuf=[Y2, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[z2, mpi.DOUBLE], recvbuf=[Z2, gathers, mpi.DOUBLE])
    comm.Gatherv(sendbuf=[rho2, mpi.DOUBLE],
                 recvbuf=[RHO2, gathers, mpi.DOUBLE])

    # create the particle arrays and PM
    PA1 = get_particle_array_wcsph(x=X1, y=Y1, z=Z1, h=H1, rho=RHO1)
    PA2 = get_particle_array_wcsph(x=X2, y=Y2, z=Z2, h=H2, rho=RHO2)

    # create the parallel manager
    PARTICLES = [PA1, PA2]
    PM = ZoltanParallelManagerGeometric(dim=dim,
                                        particles=PARTICLES,
                                        comm=comm)

    # create the local NNPS object with all the particles
    Nnps = BoxSortNNPS(dim=dim, particles=PARTICLES)
    Nnps.update()

    # only root computes summation density
    if rank == 0:
        assert numpy.allclose(PA1.rho, 0)
        sd_evaluate(Nnps, PM, mass, src_index=1, dst_index=0)
        sd_evaluate(Nnps, PM, mass, src_index=0, dst_index=0)
        RHO1 = PA1.rho

        assert numpy.allclose(PA2.rho, 0)
        sd_evaluate(Nnps, PM, mass, src_index=0, dst_index=1)
        sd_evaluate(Nnps, PM, mass, src_index=1, dst_index=1)
        RHO2 = PA2.rho

    # wait for the root...
    comm.barrier()

    # create the local particle arrays
    particles = [pa1, pa2]

    # create the local nnps object and parallel manager
    pm = ZoltanParallelManagerGeometric(dim=dim,
                                        comm=comm,
                                        particles=particles)
    nnps = BoxSortNNPS(dim=dim, particles=particles)

    # set the Zoltan parameters (Optional)
    pz = pm.pz
    pz.set_lb_method("RCB")
    pz.Zoltan_Set_Param("DEBUG_LEVEL", "0")

    # Update the parallel manager (distribute particles)
    pm.update()

    # update the local nnps
    nnps.update()

    # Compute summation density individually on each processor
    sd_evaluate(nnps, pm, mass, src_index=0, dst_index=1)
    sd_evaluate(nnps, pm, mass, src_index=1, dst_index=1)

    sd_evaluate(nnps, pm, mass, src_index=0, dst_index=0)
    sd_evaluate(nnps, pm, mass, src_index=1, dst_index=0)

    # gather the density and global ids
    rho1 = pa1.rho
    tmp = comm.gather(rho1)
    if rank == 0:
        global_rho1 = numpy.concatenate(tmp)
        assert (global_rho1.size == numGlobalPoints)

    rho2 = pa2.rho
    tmp = comm.gather(rho2)
    if rank == 0:
        global_rho2 = numpy.concatenate(tmp)
        assert (global_rho2.size == numGlobalPoints)

    # gather global x1 and y1
    x1 = pa1.x
    tmp = comm.gather(x1)
    if rank == 0:
        global_x1 = numpy.concatenate(tmp)
        assert (global_x1.size == numGlobalPoints)

    y1 = pa1.y
    tmp = comm.gather(y1)
    if rank == 0:
        global_y1 = numpy.concatenate(tmp)
        assert (global_y1.size == numGlobalPoints)

    z1 = pa1.z
    tmp = comm.gather(z1)
    if rank == 0:
        global_z1 = numpy.concatenate(tmp)
        assert (global_z1.size == numGlobalPoints)

    # gather global x2 and y2
    x2 = pa2.x
    tmp = comm.gather(x2)
    if rank == 0:
        global_x2 = numpy.concatenate(tmp)
        assert (global_x2.size == numGlobalPoints)

    y2 = pa2.y
    tmp = comm.gather(y2)
    if rank == 0:
        global_y2 = numpy.concatenate(tmp)
        assert (global_y2.size == numGlobalPoints)

    z2 = pa2.z
    tmp = comm.gather(z2)
    if rank == 0:
        global_z2 = numpy.concatenate(tmp)
        assert (global_z2.size == numGlobalPoints)

    # gather global indices
    gid1 = pa1.gid
    tmp = comm.gather(gid1)
    if rank == 0:
        global_gid1 = numpy.concatenate(tmp)
        assert (global_gid1.size == numGlobalPoints)

    gid2 = pa2.gid
    tmp = comm.gather(gid2)
    if rank == 0:
        global_gid2 = numpy.concatenate(tmp)
        assert (global_gid2.size == numGlobalPoints)

    # check rho1
    if rank == 0:
        # make sure the arrays are of the same size
        assert (global_x1.size == X1.size)
        assert (global_y1.size == Y1.size)
        assert (global_z1.size == Z1.size)

        for i in range(numGlobalPoints):

            # make sure we're chacking the right point
            assert abs(global_x1[i] - X1[global_gid1[i]]) < 1e-14
            assert abs(global_y1[i] - Y1[global_gid1[i]]) < 1e-14
            assert abs(global_z1[i] - Z1[global_gid1[i]]) < 1e-14

            diff = abs(global_rho1[i] - RHO1[global_gid1[i]])
            condition = diff < 1e-14
            assert condition, "diff = %g" % (diff)

    # check rho2
    if rank == 0:
        # make sure the arrays are of the same size
        assert (global_x2.size == X2.size)
        assert (global_y2.size == Y2.size)
        assert (global_z2.size == Z2.size)

        for i in range(numGlobalPoints):

            # make sure we're chacking the right point
            assert abs(global_x2[i] - X2[global_gid2[i]]) < 1e-14
            assert abs(global_y2[i] - Y2[global_gid2[i]]) < 1e-14
            assert abs(global_z2[i] - Z2[global_gid2[i]]) < 1e-14

            diff = abs(global_rho2[i] - RHO2[global_gid2[i]])
            condition = diff < 1e-14
            assert condition, "diff = %g" % (diff)

    if rank == 0:
        print("Summation density test: OK")
예제 #33
0
    def create_particles(self, **kwargs):
        fluid_column_height=self.fluid_column_height
        fluid_column_width=self.fluid_column_width
        fluid_column_length=self.fluid_column_length

        container_height = self.container_height
        container_length = self.container_length
        container_width = self.container_width

        obstacle_height = self.obstacle_height
        obstacle_length = self.obstacle_length
        obstacle_width = self.obstacle_width

        obstacle_center_x = self.obstacle_center_x
        obstacle_center_y = self.obstacle_center_y

        nboundary_layers = self.nboundary_layers
        dx = self.dx

        # get the domain limits
        ghostlims = nboundary_layers * dx

        xmin, xmax = 0.0 -ghostlims, container_length + ghostlims
        ymin, ymax = 0.0 - ghostlims, container_width + ghostlims
        zmin, zmax = 0.0 - ghostlims, container_height + ghostlims
        
        cw2 = 0.5 * container_width
        #ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims

        # create all particles
        #import matplotlib.pyplot as plt

        #from mpl_toolkits.mplot3d import Axes3D
        #import matplotlib.pyplot as plt 

        #ig = plt.figure()
        #ax = Axes3D(fig)
        eps = 0.1 * dx
        xx, yy, zz = numpy.mgrid[xmin:xmax+eps:dx,
                                 ymin:ymax+eps:dx,
                                 zmin:zmax+eps:dx]

        x = xx.ravel(); y = yy.ravel(); z = zz.ravel()

        
        geom=GetGeo()
        gem=geom.get_data(xn=len(xx),yn=len(xx[0]))
        gem=np.transpose(gem)
        ges=np.ones_like(xx)
        
        for itr in range(len(xx[0,0])):
            ges[:,:,itr]=ges[:,:,itr]*gem
        ge=ges.ravel()
        
        ge=ge-np.min(ge)-0.1
        ge=ge/np.max(ge)*0.8
        #import matplotlib.pyplot as plt

        #from mpl_toolkits.mplot3d import Axes3D
        #import matplotlib.pyplot as plt 

        #ig = plt.figure()
        #ax = Axes3D(fig)

        # create a dummy particle array from which we'll sort
        pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z)
        #pa.
        # get the individual arrays
        indices = []
        findices = []
        oindices = []

        obw2 = 0.5 * obstacle_width
        obl2 = 0.5 * obstacle_length
        obh = obstacle_height
        ocx = obstacle_center_x
        ocy = obstacle_center_y

        print(obw2,obl2,obh)
        #ax.scatter3D(x,y,z,alpha=0.05)
        gggx=xmax-xmin
        gggy=ymax-ymin
        for i in range(x.size):
            xi = x[i]; yi = y[i]; zi = ge[i]-z[i]

            # fluid
            if ( (xmin+gggx*0.4< xi <= xmin+gggx*0.6) and \
                     (ymin+gggy*0.4< yi < ymin+gggy*0.6) and \
                     (0 < -zi <= 0.3) ):
                #ax.scatter3D(xi,yi,zi,alpha=0.5)
                findices.append(i)

            # obstacle
            if ( (ocx-obl2 <= xi <= ocx+obl2) and \
                     (ocy-obw2 <= yi <= ocy+obw2) and \
                     (0 < -zi <= obh) ):
                #ax.scatter3D(xi,yi,zi,alpha=0.5)
                findices.append(i)
                oindices.append(i)
        #plt.show()
        # extract the individual arrays
        fa = LongArray(len(findices)); fa.set_data(numpy.array(findices))
        fluid = pa.extract_particles(fa)
        fluid.set_name('fluid')

        if self.with_obstacle:
            oa = LongArray(len(oindices)); oa.set_data(numpy.array(oindices))
            obstacle = pa.extract_particles(oa)
            obstacle.set_name('obstacle')
        """
        indices = concatenate( (where( y <= -cw2 )[0],
                                where( y >= cw2 )[0],
                                where( x >= container_length )[0],
                                where( x <= 0 )[0],
                                where( z <= 0 )[0]) )
        """
        # remove duplicates
        #        indices = array(list(set(indices)))
        indices=np.where(ge>z)[0]
        print(len(indices))
        wa = LongArray(indices.size); wa.set_data(indices)
        boundary = pa.extract_particles(wa)
        boundary.set_name('boundary')

        # create the particles
        if self.with_obstacle:
            particles = [fluid, boundary, obstacle]
        else:
            particles = [fluid, boundary]

        # set up particle properties
        h0 = self.hdx * dx

        volume = dx**3
        m0 = self.rho0 * volume

        for pa in particles:
            pa.m[:] = m0
            pa.h[:] = h0

            pa.rho[:] = self.rho0

        nf = fluid.num_real_particles
        nb = boundary.num_real_particles
    
        
        if self.with_obstacle:
            no = obstacle.num_real_particles
            print("3D dam break with %d fluid, %d boundary, %d obstacle particles"%(nf, nb, no))
        else:
            print("3D dam break with %d fluid, %d boundary particles"%(nf, nb))


        # load balancing props for the arrays
        #fluid.set_lb_props(['x', 'y', 'z', 'u', 'v', 'w', 'rho', 'h', 'm', 'gid',
        #                    'x0', 'y0', 'z0', 'u0', 'v0', 'w0', 'rho0'])
        fluid.set_lb_props( list(fluid.properties.keys()) )

        #boundary.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        #obstacle.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        boundary.set_lb_props( list(boundary.properties.keys()) )

        # boundary and obstacle particles can do with a reduced list of properties
        # to be saved to disk since they are fixed
        boundary.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'] )

        if self.with_obstacle:
            obstacle.set_lb_props( list(obstacle.properties.keys()) )
            obstacle.set_output_arrays( ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'] )

        return particles
예제 #34
0
    def create_particles(self):
        """Create the circular patch of fluid."""
        # xf, yf = create_fluid_with_solid_cube()
        xf, yf = create_fluid()
        rho = get_density(yf)
        m = rho[:] * self.dx * self.dx
        rho = np.ones_like(xf) * self.ro
        h = np.ones_like(xf) * self.hdx * self.dx
        fluid = get_particle_array_wcsph(x=xf,
                                         y=yf,
                                         h=h,
                                         m=m,
                                         rho=rho,
                                         name="fluid")

        xt, yt = create_big_boundary()
        m = np.ones_like(xt) * 1000 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        rad_s = np.ones_like(xt) * 2 / 2. * 1e-3
        h = np.ones_like(xt) * self.hdx * self.dx
        big_tank = get_particle_array_wcsph(x=xt,
                                            y=yt,
                                            h=h,
                                            m=m,
                                            rho=rho,
                                            rad_s=rad_s,
                                            name="big_tank")

        dx = 1
        xc, yc = create_inside_cube()
        m = np.ones_like(xc) * self.solid_rho * dx * 1e-3 * dx * 1e-3
        rho = np.ones_like(xc) * self.solid_rho
        h = np.ones_like(xc) * self.hdx * self.dx
        rad_s = np.ones_like(xc) * dx / 2. * 1e-3
        # add cs property to run the simulation
        cs = np.zeros_like(xc)
        cube = get_particle_array_rigid_body(x=xc,
                                             y=yc,
                                             h=h,
                                             m=m,
                                             rho=rho,
                                             rad_s=rad_s,
                                             cs=cs,
                                             name="cube")

        dx = 1
        xc, yc = create_outside_cube()
        yc = yc + 0.04
        xc = xc + 0.02
        m = np.ones_like(xc) * self.wood_rho * dx * 1e-3 * dx * 1e-3
        rho = np.ones_like(xc) * self.wood_rho
        h = np.ones_like(xc) * self.hdx * self.dx
        rad_s = np.ones_like(xc) * dx / 2. * 1e-3
        # add cs property to run the simulation
        cs = np.zeros_like(xc)
        wood = get_particle_array_rigid_body(x=xc,
                                             y=yc,
                                             h=h,
                                             m=m,
                                             rho=rho,
                                             rad_s=rad_s,
                                             cs=cs,
                                             name="wood")

        xt, yt = create_small_boundary()
        m = np.ones_like(xt) * 1000 * self.dx * self.dx
        rho = np.ones_like(xt) * 1000
        rad_s = np.ones_like(xt) * 2 / 2. * 1e-3
        h = np.ones_like(xt) * self.hdx * self.dx
        cs = np.zeros_like(xt)
        small_tank = get_particle_array_rigid_body(x=xt,
                                                   y=yt,
                                                   h=h,
                                                   m=m,
                                                   rho=rho,
                                                   rad_s=rad_s,
                                                   cs=cs,
                                                   name="small_tank")

        xc, yc = create_outside_cube()
        yc = yc + 0.15
        m = np.ones_like(xc) * self.wood_rho * dx * 1e-3 * dx * 1e-3
        rho = np.ones_like(xc) * self.wood_rho
        h = np.ones_like(xc) * self.hdx * self.dx
        rad_s = np.ones_like(xc) * dx / 2. * 1e-3
        # add cs property to run the simulation
        cs = np.zeros_like(xc)
        outside = get_particle_array_rigid_body(x=xc,
                                                y=yc,
                                                h=h,
                                                m=m,
                                                rho=rho,
                                                rad_s=rad_s,
                                                cs=cs,
                                                name="outside")
        return [fluid, big_tank, small_tank, cube, wood, outside]
예제 #35
0
    def create_particles(self, **kwargs):
        fluid_column_height = self.fluid_column_height
        fluid_column_width = self.fluid_column_width
        fluid_column_length = self.fluid_column_length

        container_height = self.container_height
        container_length = self.container_length
        container_width = self.container_width

        obstacle_height = self.obstacle_height
        obstacle_length = self.obstacle_length
        obstacle_width = self.obstacle_width

        obstacle_center_x = self.obstacle_center_x
        obstacle_center_y = self.obstacle_center_y

        nboundary_layers = self.nboundary_layers
        dx = self.dx

        # get the domain limits
        ghostlims = nboundary_layers * dx

        xmin, xmax = 0.0 - ghostlims, container_length + ghostlims
        zmin, zmax = 0.0 - ghostlims, container_height + ghostlims

        cw2 = 0.5 * container_width
        ymin, ymax = -cw2 - ghostlims, cw2 + ghostlims

        # create all particles
        eps = 0.1 * dx
        xx, yy, zz = numpy.mgrid[xmin:xmax + eps:dx,
                                 ymin:ymax + eps:dx,
                                 zmin:zmax + eps:dx]

        x = xx.ravel()
        y = yy.ravel()
        z = zz.ravel()

        # create a dummy particle array from which we'll sort
        pa = get_particle_array_wcsph(name='block', x=x, y=y, z=z)

        # get the individual arrays
        indices = []
        findices = []
        oindices = []

        obw2 = 0.5 * obstacle_width
        obl2 = 0.5 * obstacle_length
        obh = obstacle_height
        ocx = obstacle_center_x
        ocy = obstacle_center_y

        for i in range(x.size):
            xi = x[i]
            yi = y[i]
            zi = z[i]

            # fluid
            if ((0 < xi <= fluid_column_length) and
                (-cw2 < yi < cw2) and
                    (0 < zi <= fluid_column_height)):

                findices.append(i)

            # obstacle
            if ((ocx - obl2 <= xi <= ocx + obl2) and
                (ocy - obw2 <= yi <= ocy + obw2) and
                    (0 < zi <= obh)):

                oindices.append(i)

        # extract the individual arrays
        fa = LongArray(len(findices))
        fa.set_data(numpy.array(findices))
        fluid = pa.extract_particles(fa)
        fluid.set_name('fluid')

        if self.with_obstacle:
            oa = LongArray(len(oindices))
            oa.set_data(numpy.array(oindices))
            obstacle = pa.extract_particles(oa)
            obstacle.set_name('obstacle')

        indices = concatenate((where(y <= -cw2)[0],
                               where(y >= cw2)[0],
                               where(x >= container_length)[0],
                               where(x <= 0)[0],
                               where(z <= 0)[0]))

        # remove duplicates
        indices = array(list(set(indices)))

        wa = LongArray(indices.size)
        wa.set_data(indices)
        boundary = pa.extract_particles(wa)
        boundary.set_name('boundary')

        # create the particles
        if self.with_obstacle:
            particles = [fluid, boundary, obstacle]
        else:
            particles = [fluid, boundary]

        # set up particle properties
        h0 = self.hdx * dx

        volume = dx**3
        m0 = self.rho0 * volume

        for pa in particles:
            pa.m[:] = m0
            pa.h[:] = h0

            pa.rho[:] = self.rho0

        nf = fluid.num_real_particles
        nb = boundary.num_real_particles

        if self.with_obstacle:
            no = obstacle.num_real_particles
            print(
                "3D dam break with %d fluid, %d boundary, %d obstacle particles" %
                (nf, nb, no))
        else:
            print(
                "3D dam break with %d fluid, %d boundary particles" %
                (nf, nb))

        # load balancing props for the arrays
        # fluid.set_lb_props(['x', 'y', 'z', 'u', 'v', 'w', 'rho', 'h', 'm', 'gid',
        #                    'x0', 'y0', 'z0', 'u0', 'v0', 'w0', 'rho0'])
        fluid.set_lb_props(list(fluid.properties.keys()))

        #boundary.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        #obstacle.set_lb_props(['x', 'y', 'z', 'rho', 'h', 'm', 'gid', 'rho0'])
        boundary.set_lb_props(list(boundary.properties.keys()))

        # boundary and obstacle particles can do with a reduced list of properties
        # to be saved to disk since they are fixed
        boundary.set_output_arrays(
            ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'])

        if self.with_obstacle:
            obstacle.set_lb_props(list(obstacle.properties.keys()))
            obstacle.set_output_arrays(
                ['x', 'y', 'z', 'rho', 'm', 'h', 'p', 'tag', 'pid', 'gid'])

        return particles