def test_should_pass_when_src_props_exist(self):
        # Given
        f = get_particle_array(name='f')
        f.add_property('V')
        s = get_particle_array(name='s')
        s.add_property('V')

        # When
        eq = TestEquation(dest='f', sources=['f', 's'])

        # Then
        check_equation_array_properties(eq, [f, s])
    def test_should_fail_when_src_props_dont_exist(self):
        # Given
        f = get_particle_array(name='f')
        f.add_property('V')
        s = get_particle_array(name='s')

        # When
        eq = TestEquation(dest='f', sources=['f', 's'])

        # Then
        self.assertRaises(RuntimeError,
                          check_equation_array_properties, eq, [f, s])
 def setUp(self):
     self.dim = 1
     n = 10
     dx = 1.0/(n-1)
     x = np.linspace(0, 1, n)
     m = np.ones_like(x)
     h = np.ones_like(x)*dx
     pa = get_particle_array(name='fluid', x=x, h=h, m=m)
     self.pa = pa
    def test_should_pass_when_properties_exist(self):
        # Given
        f = get_particle_array(name='f')

        # When
        eq = SummationDensity(dest='f', sources=['f'])

        # Then
        check_equation_array_properties(eq, [f])
def bench_uniform_distribution():
    arrays = []
    for numPoints in _numPoints:
        nx = numpy.ceil(numpy.power(numPoints, 1./3))
        dx = 1./nx

        xa, ya, za = numpy.mgrid[0:1:dx, 0:1:dx, 0:1:dx]
        xa = xa.ravel(); ya = ya.ravel(); za = za.ravel()
        ha = numpy.ones_like(xa) * 2.0*dx

        gida = numpy.arange(xa.size).astype(numpy.uint32)

        # create the particle array
        pa = get_particle_array(x=xa, y=ya, z=za, h=ha, gid=gida)
        # create the particle array
        pa = get_particle_array(x=xa, y=ya, z=za, h=ha, gid=gida)
        arrays.append(pa)

    results = bench_nnps(arrays)
    print "###Timing Benchmarks for a Uniform Distribution###\n"
    print results
 def _make_2d_grid(self, name='fluid'):
     n = 11
     x, y = np.mgrid[-1:1:n*1j,-1:1:n*1j]
     dx = 2.0/(n-1)
     z = np.zeros_like(x)
     x, y, z = x.ravel(), y.ravel(), z.ravel()
     m = np.ones_like(x)
     p = np.ones_like(x)*2.0
     h = np.ones_like(x)*2*dx
     u = np.ones_like(x)*0.1
     pa = get_particle_array(name=name, x=x, y=y, z=z, h=h, m=m, p=p, u=u)
     return pa
    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))
 def test_exact_extended_spatial_hash_variable_radius(self):
     print ""
     for key in self.dataset_variable_radius:
         x, y, z, h = self.dataset_variable_radius[key]
         pa = get_particle_array(x=x, y=y, z=z, h=h)
         qid = randint(0,pa.get_number_of_particles()-1)
         nn_bf = brute_force_neighbours(pa, pa.x[qid], pa.y[qid],
                 pa.z[qid], pa.h[qid])
         exp = ExtendedSpatialHash(pa, 3, approximate = False)
         nn_sp = UIntArray()
         exp.nearest_neighbours(qid, nn_sp)
         print " - " + key
         assert equal(nn_bf, nn_sp)
Exemple #9
0
 def test_spatial_hash_variable_radius(self):
     print ""
     for key in self.dataset_variable_radius:
         x, y, z, h = self.dataset_variable_radius[key]
         pa = get_particle_array(x=x, y=y, z=z, h=h)
         qid = randint(0,pa.get_number_of_particles()-1)
         nn_bf = brute_force_neighbours(pa, pa.x[qid], pa.y[qid],
                 pa.z[qid], pa.h[qid])
         sp = SpatialHashNNPS([pa])
         nn_sp = UIntArray()
         sp.set_context(0,0)
         sp.get_nearest_neighbours(0,0,qid,nn_sp)
         print " - " + key
         assert equal(nn_bf, nn_sp)
def create_particles(hcp=False, **kwargs):
    "Initial distribution using Hexagonal close packing of particles"
    # create all particles
    global dx
    if hcp:
        x, y, dx, dy, xmin, xmax, ymin, ymax = uniform_distribution.uniform_distribution_hcp2D(
            dx=dx, xmin=-ghost_extent, xmax=Lx+ghost_extent, 
            ymin=-ghost_extent, ymax=Ly+ghost_extent)
    else:
        x, y, dx, dy, xmin, xmax, ymin, ymax = uniform_distribution.uniform_distribution_cubic2D(
            dx=dx, xmin=-ghost_extent, xmax=Lx+ghost_extent, 
            ymin=-ghost_extent, ymax=Ly+ghost_extent)

    x = x.ravel(); y = y.ravel()
    
    # create the basic particle array
    solid = get_particle_array(name='solid', x=x, y=y)
    
    # now sort out the interior from all particles
    indices = _get_interior(solid.x, solid.y)
    fluid = solid.extract_particles( indices )
    fluid.set_name('fluid')

    solid.remove_particles( indices )

    # sort out the obstacle from the interior
    indices = _get_obstacle(fluid.x, fluid.y)
    obstacle = fluid.extract_particles( indices )
    obstacle.set_name('obstacle')

    fluid.remove_particles(indices)

    print "SPHERIC benchmark 6 :: Re = %d, nfluid = %d, nsolid=%d, nobstacle = %d, dt = %g"%(
        Re, fluid.get_number_of_particles(),
        solid.get_number_of_particles(),
        obstacle.get_number_of_particles(), dt)

    # setup requisite particle properties and initial conditions

    if hcp:
        wij_sum = uniform_distribution.get_number_density_hcp(dx, dy, kernel, h0)
        volume = 1./wij_sum
    else:
        volume = dx*dy

    particles = _setup_particle_properties([fluid, solid, obstacle], volume=volume)

    return particles
def bench_random_distribution():
    arrays = []
    for numPoints in _numPoints:
        dx = numpy.power( 1./numPoints, 1.0/3.0 )
        xa = random.random(numPoints)
        ya = random.random(numPoints)
        za = random.random(numPoints)
        ha = numpy.ones_like(xa) * 2*dx
        gida = numpy.arange(numPoints).astype(numpy.uint32)

        # create the particle array
        pa = get_particle_array(x=xa, y=ya, z=za, h=ha, gid=gida)
        arrays.append(pa)

    results = bench_nnps(arrays)
    print "###Timing Benchmarks for a Random Distribution###\n"
    print results
Exemple #12
0
def load(fname):
    """ Load and return data from an  output (.npz) file dumped by PySPH.

    For output file version 1, the function returns a dictionary with
    the keys:

    solver_data : Solver constants at the time of output like time,
    time step and iteration count.

    arrays : ParticleArrays keyed on names with the ParticleArray
    object as value.

    """
    from pysph.base.utils import get_particle_array
    data = numpy.load(fname)

    ret = {"arrays":{}}

    if not 'version' in data.files:
        msg = "Wrong file type! No version nnumber recorded."
        raise RuntimeError(msg)

    version = data['version']

    if version == 1:

        arrays = data["arrays"]
        arrays.shape = (1,)
        arrays = arrays[0]

        solver_data = data["solver_data"]
        solver_data.shape = (1,)
        solver_data = solver_data[0]

        for array_name in arrays:
            array = get_particle_array(name=array_name,
                                       **arrays[array_name])
            ret["arrays"][array_name] = array

        ret["solver_data"] = solver_data

    else:
        raise RuntimeError("Version not understood!")

    return ret
Exemple #13
0
 def test_spatial_hash_large_num_cells(self):
     '''
     Tests SpatialHashNNPS for large number of cells.
     Fails with a segmentation fault.
     '''
     print ""
     for key in self.dataset_large_domain:
         x, y, z, h = self.dataset_large_domain[key]
         pa = get_particle_array(x=x, y=y, z=z, h=h)
         qid = randint(0,pa.get_number_of_particles()-1)
         nn_bf = brute_force_neighbours(pa, pa.x[qid], pa.y[qid],
                 pa.z[qid], pa.h[qid])
         sp = SpatialHashNNPS([pa])
         nn_sp = UIntArray()
         sp.set_context(0,0)
         sp.get_nearest_neighbours(0,0,qid,nn_sp)
         print " - " + key
         assert equal(nn_bf, nn_sp)
Exemple #14
0
def get_plate_particles():
    x = numpy.arange(plate_start, plate_end+dx, dx)
    y = numpy.zeros_like(x)

    # normals and tangents
    tx = numpy.ones_like(x)
    ty = numpy.zeros_like(x)
    tz = numpy.zeros_like(x)

    ny = numpy.ones_like(x)
    nx = numpy.zeros_like(x)
    nz = numpy.zeros_like(x)

    pa = get_particle_array(name='plate', x=x, y=y, tx=tx, ty=ty, tz=tz,
                            nx=nx, ny=ny, nz=nz)
    pa.m[:] = m0

    return pa
    def _create_particle_array(self, x, y, z):
        xr = x.ravel()
        yr = y.ravel()
        zr = z.ravel()
        self.x, self.y, self.z = x.squeeze(), y.squeeze(), z.squeeze()

        hmax = self._get_max_h_in_arrays()
        h = hmax*np.ones_like(xr)
        prop = np.zeros_like(xr)
        pa = get_particle_array(
            name='interpolate',
            x=xr, y=yr, z=zr, h=h,
            number_density=np.zeros_like(xr),
            prop=prop,
            grad_x=np.zeros_like(xr),
            grad_y=np.zeros_like(xr),
            grad_z=np.zeros_like(xr)
        )
        return pa
Exemple #16
0
 def test_linked_list_nnps_large_num_cells(self):
     '''
     Tests LinkedListNNPS for large number of cells.
     Fails with a malloc error
     '''
     print ""
     for key in self.dataset_large_domain:
         x, y, z, h = self.dataset_large_domain[key]
         pa = get_particle_array(x=x, y=y, z=z, h=h)
         qid = randint(0,pa.get_number_of_particles()-1)
         nn_bf = brute_force_neighbours(pa, pa.x[qid], pa.y[qid],
                 pa.z[qid], pa.h[qid])
         r = 1/1.101
         sp = LinkedListNNPS(dim=3, particles=[pa], radius_scale=r, cache=True)
         nn_sp = UIntArray()
         sp.set_context(0,0)
         sp.get_nearest_particles(0,0,qid,nn_sp)
         print " - " + key
         assert equal(nn_bf, nn_sp)
Exemple #17
0
def get_bar_particles():
    xarr = numpy.arange(-bar_width/2.0, bar_width/2.0 + dx, dx)
    yarr = numpy.arange(4*dx, 0.0254 + 4*dx, dx)

    x,y = numpy.meshgrid( xarr, yarr )
    x, y = x.ravel(), y.ravel()

    print 'Number of bar particles: ', len(x)

    hf = numpy.ones_like(x) * h
    mf = numpy.ones_like(x) * dx * dy * r0
    rhof = numpy.ones_like(x) * r0
    csf = numpy.ones_like(x) * ss
    z = numpy.zeros_like(x)
    pa = get_particle_array(name="bar",
                            x=x, y=y, h=hf, m=mf, rho=rhof, cs=csf,
                            e=z)
    # negative fluid particles
    pa.v[:]=-200
    return pa
Exemple #18
0
    def test_update_minmax_cl(self):
        backend = 'opencl'
        check_import(backend)
        self.setup()

        # Given
        x = [0.0, -1.0, 2.0, 3.0]
        y = [0.0, 1.0, -2.0, 3.0]
        z = [0.0, 1.0, 2.0, -3.0]
        h = [4.0, 1.0, 2.0, 3.0]

        pa = get_particle_array(x=x, y=y, z=z, h=h)
        h = DeviceHelper(pa, backend=backend)
        pa.set_device_helper(h)

        # When
        h.update_minmax_cl(['x', 'y', 'z', 'h'])

        # Then
        assert h.x.minimum == -1.0
        assert h.x.maximum == 3.0

        assert h.y.minimum == -2.0
        assert h.y.maximum == 3.0

        assert h.z.minimum == -3.0
        assert h.z.maximum == 2.0

        assert h.h.minimum == 1.0
        assert h.h.maximum == 4.0

        # When
        h.x.maximum, h.x.minimum = 100., 100.
        h.y.maximum, h.y.minimum = 100., 100.
        h.z.maximum, h.z.minimum = 100., 100.
        h.h.maximum, h.h.minimum = 100., 100.

        h.update_minmax_cl(['x', 'y', 'z', 'h'], only_min=True)

        # Then
        assert h.x.minimum == -1.0
        assert h.x.maximum == 100.0

        assert h.y.minimum == -2.0
        assert h.y.maximum == 100.0

        assert h.z.minimum == -3.0
        assert h.z.maximum == 100.0

        assert h.h.minimum == 1.0
        assert h.h.maximum == 100.0

        # When
        h.x.maximum, h.x.minimum = 100., 100.
        h.y.maximum, h.y.minimum = 100., 100.
        h.z.maximum, h.z.minimum = 100., 100.
        h.h.maximum, h.h.minimum = 100., 100.

        h.update_minmax_cl(['x', 'y', 'z', 'h'], only_max=True)

        # Then
        assert h.x.minimum == 100.0
        assert h.x.maximum == 3.0

        assert h.y.minimum == 100.0
        assert h.y.maximum == 3.0

        assert h.z.minimum == 100.0
        assert h.z.maximum == 2.0

        assert h.h.minimum == 100.0
        assert h.h.maximum == 4.0
Exemple #19
0
def get_tsunami_geometry(dx_solid=0.01,
                         dx_fluid=0.01,
                         r_solid=100.0,
                         r_fluid=100.0,
                         hdx=1.3,
                         l_wall=9.5,
                         h_wall=4.0,
                         angle=26.565051,
                         h_fluid=3.5,
                         l_obstacle=0.91,
                         flat_l=2.25):
    x1, y1, x2, y2 = get_beach_geometry_2d(dx_solid, l_wall, h_wall, flat_l,
                                           angle, 4)
    wall_x = np.concatenate([x1, x2])
    wall_y = np.concatenate([y1, y2])
    r_wall = np.ones_like(wall_x) * r_solid
    m_wall = r_wall * dx_solid * dx_solid
    h_w = np.ones_like(wall_x) * dx_solid * hdx
    wall = get_particle_array(name='wall',
                              x=wall_x,
                              y=wall_y,
                              h=h_w,
                              rho=r_wall,
                              m=m_wall)
    theta = np.pi * angle / 180.0
    h_obstacle = l_obstacle * np.tan(theta)
    obstacle_x1, obstacle_y1 = get_2d_block(dx_solid, l_obstacle, h_obstacle)
    obstacle_x = []
    obstacle_y = []
    for x, y in zip(obstacle_x1, obstacle_y1):
        if (y >= (-x * np.tan(theta))):
            obstacle_x.append(x)
            obstacle_y.append(y)
    x_translate = (l_wall - flat_l) * 0.8
    y_translate = x_translate * np.tan(theta)
    obstacle_x = np.asarray(obstacle_x) - x_translate
    obstacle_y = np.asarray(obstacle_y) + y_translate + dx_solid
    h_obstacle = np.ones_like(obstacle_x) * dx_solid * hdx
    r_obstacle = np.ones_like(obstacle_x) * r_solid
    m_obstacle = r_obstacle * dx_solid * dx_solid
    obstacle = get_particle_array(name='obstacle',
                                  x=obstacle_x,
                                  y=obstacle_y,
                                  rho=r_obstacle,
                                  m=m_obstacle,
                                  h=h_obstacle)
    fluid_center = np.array([flat_l - l_wall / 2.0, h_fluid / 2.0])
    x_fluid, y_fluid = get_2d_block(dx_fluid, l_wall, h_fluid, fluid_center)
    x3 = []
    y3 = []
    for i, xi in enumerate(x_fluid):
        if y_fluid[i] >= np.tan(-theta) * xi:
            x3.append(xi)
            y3.append(y_fluid[i])
    fluid_x = np.array(x3)
    fluid_y = np.array(y3)
    h_f = np.ones_like(fluid_x) * dx_fluid * hdx
    r_f = np.ones_like(fluid_x) * r_fluid
    m_f = r_f * dx_fluid * dx_fluid
    fluid = get_particle_array(name='fluid',
                               x=fluid_x,
                               y=fluid_y,
                               h=h_f,
                               m=m_f,
                               rho=r_f)
    remove_overlap_particles(fluid, obstacle, dx_solid * 1.1, 2)
    remove_overlap_particles(fluid, wall, dx_solid * 1.1, 2)
    return fluid, wall, obstacle
Exemple #20
0
def get_plate_particles():
    gmsh.initialize()
    gmsh.open('t.msh')
    # Launch the GUI to see the results:
    # if '-nopopup' not in sys.argv:
    #     gmsh.fltk.run()

    nodeTags, nodesCoord, parametricCoord = gmsh.model.mesh.getNodes()
    liquid_x = nodesCoord[1::3]
    liquid_y = nodesCoord[2::3]
    liquid_z = nodesCoord[0::3]
    liquid_y = liquid_y + abs(min(liquid_y))
    liquid_x = liquid_x + abs(min(liquid_x))

    liquid_x = liquid_x[0::5] * 1e-3 - 0.002
    liquid_y = liquid_y[0::5] * 1e-3 - 0.1
    liquid_z = liquid_z[0::5] * 1e-3 - 0.005

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

    hf = numpy.ones_like(liquid_x) * h
    mf = numpy.ones_like(liquid_x) * dx * dy * dz * ro1
    rhof = numpy.ones_like(liquid_x) * ro1
    csf = numpy.ones_like(liquid_x) * cs1
    pa = plate = get_particle_array(name="plate",
                                    x=liquid_x,
                                    y=liquid_y,
                                    z=liquid_z,
                                    h=hf,
                                    m=mf,
                                    rho=rhof,
                                    cs=csf)

    # add requisite properties
    # sound speed etc.
    add_properties(pa, 'e')

    # velocity gradient properties
    add_properties(pa, 'v00', 'v01', 'v02', 'v10', 'v11', 'v12', 'v20', 'v21',
                   'v22')

    # artificial stress properties
    add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

    # deviatoric stress components
    add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

    # deviatoric stress accelerations
    add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

    # deviatoric stress initial values
    add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

    # standard acceleration variables
    add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

    # initial values
    add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

    pa.add_constant('G', G1)
    pa.add_constant('n', 4)

    kernel = Gaussian(dim=3)
    wdeltap = kernel.kernel(rij=dx, h=hdx * dx)
    pa.add_constant('wdeltap', wdeltap)
    # load balancing properties
    pa.set_lb_props(list(pa.properties.keys()))

    # removed S_00 and similar components
    plate.v[:] = 0.0
    return plate
# expression for the particle volume. As far as the summation density
# test is concerned, the value will be uniform but not equal to 1. To
# reproduce a density profile of 1, we need to estimate the kernel sum
# or number density of the distribution based on the kernel
wij_sum_estimate = get_number_density_hcp(dx, dy, k, h0)
volume = 1. / wij_sum_estimate
print('Volume estimates :: dx^2 = %g, Number density = %g' % (dx * dy, volume))

x = x.ravel()
y = y.ravel()
h = numpy.ones_like(x) * h0
m = numpy.ones_like(x) * volume
wij = numpy.zeros_like(x)

# use the helper function get_particle_array to create a ParticleArray
pa = utils.get_particle_array(x=x, y=y, h=h, m=m, wij=wij)

# the simulation domain used to request periodicity
domain = DomainManager(xmin=0.,
                       xmax=1.,
                       ymin=0.,
                       ymax=1.,
                       periodic_in_x=True,
                       periodic_in_y=True)

# NNPS object for nearest neighbor queries
nps = LinkedListNNPS(dim=2,
                     particles=[
                         pa,
                     ],
                     radius_scale=k.radius_scale,
    def create_ghost(self, pa_arr, inlet=True):
        """Creates ghosts for the given inlet/outlet particles

        Parameters
        -----------

        pa_arr : Particle array
            particles array for which ghost is required
        inlet : bool
            if True, inlet info will be used for ghost creation
        """
        xref, yref, zref = 0.0, 0.0, 0.0
        xn, yn, zn = 0.0, 0.0, 0.0
        has_ghost = True
        if inlet:
            for info in self.inletinfo:
                if info.pa_name == pa_arr.name:
                    xref = info.refpoint[0]
                    yref = info.refpoint[1]
                    zref = info.refpoint[2]
                    xn = info.normal[0]
                    yn = info.normal[1]
                    zn = info.normal[2]
                    has_ghost = info.has_ghost
                    break

        if not inlet:
            for info in self.outletinfo:
                if info.pa_name == pa_arr.name:
                    xref = info.refpoint[0]
                    yref = info.refpoint[1]
                    zref = info.refpoint[2]
                    xn = info.normal[0]
                    yn = info.normal[1]
                    zn = info.normal[2]
                    has_ghost = info.has_ghost
                    break

        if not has_ghost:
            return None
        x = pa_arr.x
        y = pa_arr.y
        z = pa_arr.z

        xij = x - xref
        yij = y - yref
        zij = z - zref

        disp = xij * xn + yij * yn + zij * zn
        x = x - 2 * disp * xn
        y = y - 2 * disp * yn
        z = z - 2 * disp * zn

        m = pa_arr.m
        h = pa_arr.h
        rho = pa_arr.rho
        u = pa_arr.u
        name = ''
        if inlet:
            name = self.inlet_pairs[pa_arr.name]
        else:
            name = self.outlet_pairs[pa_arr.name]

        ghost_pa = get_particle_array(name=name,
                                      m=m,
                                      x=x,
                                      y=y,
                                      h=h,
                                      u=u,
                                      p=0.0,
                                      rho=rho)

        return ghost_pa
Exemple #23
0
    def create_particles(self):
        ghost_extent = (nghost_layers + 0.5) * dx

        x, y = numpy.mgrid[dxb2:domain_width:dx,
                           -ghost_extent:domain_height + ghost_extent:dy]
        x = x.ravel()
        y = y.ravel()

        m = numpy.ones_like(x) * volume * rho0
        rho = numpy.ones_like(x) * rho0
        p = numpy.ones_like(x) * p0
        h = numpy.ones_like(x) * h0
        cs = numpy.ones_like(x) * c0

        # additional properties required for the fluid.
        additional_props = [
            # volume inverse or number density
            'V',
            'pi00',
            'pi01',
            'pi10',
            'pi11',

            # color and gradients
            'color',
            'scolor',
            'cx',
            'cy',
            'cz',
            'cx2',
            'cy2',
            'cz2',

            # discretized interface normals and dirac delta
            'nx',
            'ny',
            'nz',
            'ddelta',

            # interface curvature
            'kappa',
            'nu',
            'alpha',

            # filtered velocities
            'uf',
            'vf',
            'wf',

            # transport velocities
            'uhat',
            'vhat',
            'what',
            'auhat',
            'avhat',
            'awhat',

            # imposed accelerations on the solid wall
            'ax',
            'ay',
            'az',
            'wij',

            # velocity of magnitude squared
            'vmag2',

            # variable to indicate reliable normals and normalizing
            # constant
            'N',
            'wij_sum',
            'wg',
            'ug',
            'vg'
        ]

        # get the fluid particle array
        fluid = get_particle_array(name='fluid',
                                   x=x,
                                   y=y,
                                   h=h,
                                   m=m,
                                   rho=rho,
                                   cs=cs,
                                   p=p,
                                   additional_props=additional_props)

        # set the fluid velocity with respect to the sinusoidal
        # perturbation
        fluid.u[:] = -U
        fluid.N[:] = 0.0
        fluid.nu[:] = nu
        fluid.alpha[:] = sigma
        mode = 1
        for i in range(len(fluid.x)):
            ang = 2 * numpy.pi * fluid.x[i] / (mode * domain_width)
            if fluid.y[
                    i] >= domain_height / 2 + psi0 * domain_height * numpy.sin(
                        ang):
                fluid.u[i] = U
                fluid.color[i] = 1.0

        # extract the top and bottom boundary particles
        indices = numpy.where(fluid.y > domain_height)[0]
        wall = fluid.extract_particles(indices)
        fluid.remove_particles(indices)

        indices = numpy.where(fluid.y < 0)[0]
        bottom = fluid.extract_particles(indices)
        fluid.remove_particles(indices)

        # concatenate the two boundaries
        wall.append_parray(bottom)
        wall.set_name('wall')

        # set the number density initially for all particles
        fluid.V[:] = 1. / volume
        wall.V[:] = 1. / volume
        for i in range(len(wall.x)):
            if wall.y[i] > 0.5:
                wall.color[i] = 1.0
            else:
                wall.color[i] = 0.0
        # set additional output arrays for the fluid
        fluid.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'p', 'rho', 'au',
            'av'
        ])
        wall.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'p', 'rho', 'au',
            'av'
        ])

        print(
            "2D KHI with %d fluid particles and %d wall particles" %
            (fluid.get_number_of_particles(), wall.get_number_of_particles()))

        return [fluid, wall]
Exemple #24
0
def create_particles(**kwargs):
    ghost_extent = (nghost_layers + 0.5)*dx

    x, y = numpy.mgrid[ dxb2:domain_width:dx, -ghost_extent:domain_height+ghost_extent:dy ]
    x = x.ravel(); y = y.ravel()

    m = numpy.ones_like(x) * volume * rho0
    rho = numpy.ones_like(x) * rho0
    h = numpy.ones_like(x) * h0
    cs = numpy.ones_like(x) * c0

    # additional properties required for the fluid.
    additional_props = [
        # volume inverse or number density
        'V', 

        # color and gradients
        'color', 'scolor', 'cx', 'cy', 'cz', 'cx2', 'cy2', 'cz2',
        
        # discretized interface normals and dirac delta
        'nx', 'ny', 'nz', 'ddelta',

        # interface curvature
        'kappa',
        
        # filtered velocities
        'uf', 'vf', 'wf',
        
        # transport velocities
        'uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 
        
        # imposed accelerations on the solid wall
        'ax', 'ay', 'az', 'wij', 
       
        # velocity of magnitude squared
        'vmag2',

        # variable to indicate reliable normals and normalizing
        # constant
        'N', 'wij_sum',
        
        ]

    # get the fluid particle array
    fluid = get_particle_array(
        name='fluid', x=x, y=y, h=h, m=m, rho=rho, cs=cs, 
        additional_props=additional_props)

    # set the fluid velocity with respect to the sinusoidal
    # perturbation
    fluid.u[:] = -U
    mode = 1
    for i in range(len(fluid.x)):
        if fluid.y[i] > domain_height/2 + psi0*domain_height*numpy.sin(2*numpy.pi*fluid.x[i]/(mode*domain_width)):
            fluid.u[i] = U
            fluid.color[i] = 1
            fluid.rho[i] = rho1
            fluid.m[i] = volume*rho1
        else:
            fluid.rho[i] = rho2
            fluid.m[i] = rho2/rho1*volume*rho2

    # extract the top and bottom boundary particles
    indices = numpy.where( fluid.y > domain_height )[0]
    wall = fluid.extract_particles( indices )
    fluid.remove_particles( indices )

    indices = numpy.where( fluid.y < 0 )[0]
    bottom = fluid.extract_particles( indices )
    fluid.remove_particles( indices )
    
    # concatenate the two boundaries
    wall.append_parray( bottom )
    wall.set_name( 'wall' )

    # set the number density initially for all particles
    fluid.V[:] = 1./volume
    wall.V[:] = 1./volume

    # set additional output arrays for the fluid
    fluid.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta',
                             'kappa', 'N', 'p', 'rho'])
    
    print "2D KHI with %d fluid particles and %d wall particles"%(
            fluid.get_number_of_particles(), wall.get_number_of_particles())

    return [fluid, wall]
Exemple #25
0
def get_plate_particles():
    xarr = numpy.arange(0, 0.002 + dx, dx)
    yarr = numpy.arange(-0.020, 0.02 + dx, dx)
    zarr = numpy.arange(-0.02, 0.02 + dx, dx)

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

    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
    csf = numpy.ones_like(x) * cs1
    pa = plate = get_particle_array(name="plate",
                                    x=x,
                                    y=y,
                                    z=z,
                                    h=hf,
                                    m=mf,
                                    rho=rhof,
                                    cs=csf)

    # add requisite properties
    # sound speed etc.
    add_properties(pa, 'e')

    # velocity gradient properties
    add_properties(pa, 'v00', 'v01', 'v02', 'v10', 'v11', 'v12', 'v20', 'v21',
                   'v22')

    # artificial stress properties
    add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

    # deviatoric stress components
    add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

    # deviatoric stress accelerations
    add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

    # deviatoric stress initial values
    add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

    # standard acceleration variables
    add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

    # initial values
    add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

    pa.add_constant('G', G1)
    pa.add_constant('n', 4)

    kernel = Gaussian(dim=3)
    wdeltap = kernel.kernel(rij=dx, h=hdx * dx)
    pa.add_constant('wdeltap', wdeltap)
    # load balancing properties
    pa.set_lb_props(list(pa.properties.keys()))

    # removed S_00 and similar components
    plate.v[:] = 0.0
    return plate
Exemple #26
0
def create_particles(**kwargs):
    _x = np.arange( dx/2, Lx, dx )

    # create the fluid particles
    _y = np.arange( dx/2, Ly, dx )

    x, y = np.meshgrid(_x, _y); fx = x.ravel(); fy = y.ravel()

    # create the channel particles at the top
    _y = np.arange(Ly+dx/2, Ly+dx/2+ghost_extent, dx)
    x, y = np.meshgrid(_x, _y); tx = x.ravel(); ty = y.ravel()

    # create the channel particles at the bottom
    _y = np.arange(-dx/2, -dx/2-ghost_extent, -dx)
    x, y = np.meshgrid(_x, _y); bx = x.ravel(); by = y.ravel()

    # concatenate the top and bottom arrays
    cx = np.concatenate( (tx, bx) )
    cy = np.concatenate( (ty, by) )

    # create the arrays
    channel = get_particle_array(name='channel', x=cx, y=cy)
    fluid = get_particle_array(name='fluid', x=fx, y=fy)

    print "Poiseuille flow :: Re = %g, nfluid = %d, nchannel=%d, dt = %g"%(
        Re, fluid.get_number_of_particles(),
        channel.get_number_of_particles(), dt)

    # add requisite properties to the arrays:
    # particle volume
    fluid.add_property('V')
    channel.add_property('V' )

    # advection velocities and accelerations
    for name in ('uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 'au', 'av', 'aw'):
        fluid.add_property(name)

    # kernel summation correction for the channel
    channel.add_property('wij')

    # imposed accelerations on the solid
    channel.add_property('ax')
    channel.add_property('ay')
    channel.add_property('az')

    # Shepard filtered velocities for the fluid
    for name in ['uf', 'vf', 'wf']:
        fluid.add_property(name)

    # magnitude of velocity
    fluid.add_property('vmag2')

    # setup the particle properties
    volume = dx * dx

    # mass is set to get the reference density of rho0
    fluid.m[:] = volume * rho0
    channel.m[:] = volume * rho0

    # volume is set as dx^2
    fluid.V[:] = 1./volume
    channel.V[:] = 1./volume

    # smoothing lengths
    fluid.h[:] = hdx * dx
    channel.h[:] = hdx * dx

    # load balancing props
    fluid.set_lb_props( fluid.properties.keys() )
    channel.set_lb_props( channel.properties.keys() )

    # return the particle list
    return [fluid, channel]
Exemple #27
0
    def create_particles(self):
        # create the particles
        dx = self.dx
        _x = np.arange(dx / 2, L, dx)
        x, y = np.meshgrid(_x, _x)
        if self.options.init is not None:
            fname = self.options.init
            from pysph.solver.utils import load
            data = load(fname)
            _f = data['arrays']['fluid']
            x, y = _f.x.copy(), _f.y.copy()

        if self.options.perturb > 0:
            np.random.seed(1)
            factor = dx * self.options.perturb
            x += np.random.random(x.shape) * factor
            y += np.random.random(x.shape) * factor

        # Initialize
        m = self.volume * rho0
        h = self.hdx * dx
        re = self.options.re
        b = -8.0 * pi * pi / re
        u0, v0, p0 = exact_solution(U=U, b=b, t=0, x=x, y=y)
        color0 = cos(2 * pi * x) * cos(4 * pi * y)

        # create the arrays
        fluid = get_particle_array(name='fluid',
                                   x=x,
                                   y=y,
                                   m=m,
                                   h=h,
                                   u=u0,
                                   v=v0,
                                   rho=rho0,
                                   p=p0,
                                   color=color0)

        self.scheme.setup_properties([fluid])

        print("Taylor green vortex problem :: nfluid = %d, dt = %g" %
              (fluid.get_number_of_particles(), self.dt))

        # volume is set as dx^2
        if self.options.scheme == 'tvf':
            fluid.V[:] = 1. / self.volume
        if self.options.scheme == 'iisph':
            # These are needed to update the ghost particle properties.
            nfp = fluid.get_number_of_particles()
            fluid.orig_idx[:] = np.arange(nfp)
            fluid.add_output_arrays(['orig_idx'])

        corr = self.kernel_correction
        if corr in ['mixed', 'crksph']:
            fluid.add_property('cwij')
        if corr == 'mixed' or corr == 'gradient':
            fluid.add_property('m_mat', stride=9)
            fluid.add_property('dw_gamma', stride=3)
        elif corr == 'crksph':
            fluid.add_property('ai')
            fluid.add_property('gradbi', stride=4)
            for prop in ['gradai', 'bi']:
                fluid.add_property(prop, stride=2)

        return [fluid]
Exemple #28
0
def get_wavespaddle_geometry(hdx=1.5,
                             dx_f=0.1,
                             dx_s=0.05,
                             r_f=100.,
                             r_s=100.,
                             length=3.75,
                             height=0.3,
                             flat_l=1.,
                             angle=4.2364,
                             h_fluid=0.2,
                             obstacle_side=0.06):
    x1, y1, x2, y2 = get_beach_geometry_2d(dx_s, length, height, flat_l, angle,
                                           3)
    r1 = np.ones_like(x1) * r_s
    m1 = r1 * dx_s * dx_s
    h1 = np.ones_like(x1) * hdx * dx_s
    cs1 = np.zeros_like(x1)
    rad1 = np.ones_like(x1) * dx_s
    wall = get_particle_array(name='wall',
                              x=x1,
                              y=y1,
                              rho=r1,
                              m=m1,
                              h=h1,
                              cs=cs1,
                              rad_s=rad1)
    r2 = np.ones_like(x2) * r_s
    m2 = r2 * dx_s * dx_s
    h2 = np.ones_like(x2) * hdx * dx_s
    paddle = get_particle_array(name='paddle', x=x2, y=y2, rho=r2, m=m2, h=h2)
    fluid_center = np.array([flat_l - length / 2.0, h_fluid / 2.0])
    x_fluid, y_fluid = get_2d_block(dx_f, length, h_fluid, fluid_center)
    x3 = []
    y3 = []
    theta = np.pi * angle / 180.0
    for i, xi in enumerate(x_fluid):
        if y_fluid[i] >= np.tan(-theta) * xi:
            x3.append(xi)
            y3.append(y_fluid[i])
    x3 = np.array(x3)
    y3 = np.array(y3)
    r3 = np.ones_like(x3) * r_f
    m3 = r3 * dx_f * dx_f
    h3 = np.ones_like(x3) * hdx * dx_f
    cs3 = np.zeros_like(x3)
    rad3 = np.ones_like(x3) * dx_f
    fluid = get_particle_array(name='fluid', x=x3, y=y3, rho=r3, m=m3, h=h3)
    square_center = np.array([-0.38, 0.16])
    x4, y4 = get_2d_block(dx_s, obstacle_side, obstacle_side, square_center)
    b1 = np.zeros_like(x4, dtype=int)
    square_center = np.array([-0.7, 0.16])
    x5, y5 = get_2d_block(dx_s, obstacle_side, obstacle_side, square_center)
    b2 = np.ones_like(x5, dtype=int)
    square_center = np.array([-1.56, 0.22])
    x6, y6 = get_2d_block(dx_s, obstacle_side, obstacle_side, square_center)
    b3 = np.ones_like(x5, dtype=int) * 2
    b = np.concatenate([b1, b2, b3])
    x4 = np.concatenate([x4, x5, x6])
    y4 = np.concatenate([y4, y5, y6])
    r4 = np.ones_like(x4) * r_s * 0.5
    m4 = r4 * dx_s * dx_s
    h4 = np.ones_like(x4) * hdx * dx_s
    cs4 = np.zeros_like(x4)
    rad4 = np.ones_like(x4) * dx_s
    obstacle = get_particle_array_rigid_body(name='obstacle',
                                             x=x4,
                                             y=y4,
                                             h=h4,
                                             rho=r4,
                                             m=m4,
                                             cs=cs4,
                                             rad_s=rad4,
                                             body_id=b)
    remove_overlap_particles(fluid, wall, dx_s, 2)
    remove_overlap_particles(fluid, paddle, dx_s, 2)
    remove_overlap_particles(fluid, obstacle, dx_s, 2)
    return fluid, wall, paddle, obstacle
Exemple #29
0
    def create_particles(self):
        hdx = self.hdx
        dx = self.dx
        ghost_extent = 5 * dx
        # create all the particles
        _x = np.arange(-ghost_extent - dx / 2, L + ghost_extent + dx / 2, dx)
        x, y = np.meshgrid(_x, _x)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < L)):
                if ((y[i] > 0.0) and (y[i] < L)):
                    indices.append(i)

        # create the arrays
        solid = get_particle_array(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(indices)
        fluid.set_name('fluid')
        solid.remove_particles(indices)
        
        # add requisite properties to the arrays:
        self.scheme.setup_properties([fluid, solid])

        disp_vals = (self.re, self.dt, self.dx)
        print("Lid driven cavity :: Re = %d, dt = %g, dx = %g" % disp_vals)
        temp = self.Umax*self.h0/self.nu
        print('Check Factor = ', temp)

        # setup the particle properties
        volume = dx * dx

        # mass is set to get the reference density of rho0
        fluid.m[:] = volume * rho0
        solid.m[:] = volume * rho0
        # Set a reference rho also, some schemes will overwrite this with a
        # summation density.
        fluid.rho[:] = rho0
        solid.rho[:] = rho0

        # smoothing lengths
        fluid.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        # imposed horizontal velocity on the lid
        solid.u[:] = 0.0
        solid.v[:] = 0.0

        for i in range(solid.get_number_of_particles()):
            if solid.y[i] > L:
                solid.u[i] = Umax

        # volume is set as dx^2
        fluid.V[:] = 1. / volume
        solid.V[:] = 1. / volume

        fluid.lmda[:] = 1.0
        return [fluid, solid]
Exemple #30
0
            update_nstlist = True
        else:
            update_nstlist = False
        
        # update_dyn has the priority over update_nstlist
        update = False
        if update_dyn:
            update = True
        else:
            update = update_nstlist

        if update:
            
            print "Neighbor search",nl_updates
            
            pa = get_particle_array(name='prot', x=rx, y=ry, z=rz, h=1.0) #h=1.0 must not be changed as it affects radius_scale in nnps.LinkedListNNPS
            
            nps = nnps.LinkedListNNPS(dim=3, particles=[pa], radius_scale=rcut2)  
            #nps = nnps.SpatialHashNNPS(dim=3, particles=[pa], radius_scale=rcut2)  
            
            src_index = 0
            dst_index = 0
            neighbors = []
            tot = 0

            for i in range(nca):
                nbrs = UIntArray()
                nps.get_nearest_particles(src_index, dst_index, i, nbrs)
                tmp = nbrs.get_npy_array().tolist()
                
                # patch
def create_particles(empty=False, **kwargs):
    # create all the particles
    _x = np.arange( -ghost_extent - dx/2, Lx + ghost_extent + dx/2, dx )
    _y = np.arange( -ghost_extent - dx/2, Ly + ghost_extent + dx/2, dx )
    x, y = np.meshgrid(_x, _y); x = x.ravel(); y = y.ravel()

    # sort out the fluid and the solid
    indices = []
    for i in range(x.size):
        if ( (x[i] > 0.0) and (x[i] < Lx) ):
            if ( (y[i] > 0.0)  and (y[i] < Ly) ):
                indices.append(i)

    # create the arrays
    solid = get_particle_array(name='solid', x=x, y=y)

    # remove the fluid particles from the solid
    fluid = solid.extract_particles(indices); fluid.set_name('fluid')
    solid.remove_particles(indices)

    # sort out the two fluid phases
    indices = []
    for i in range(fluid.get_number_of_particles()):
        if fluid.y[i] > 1 - 0.15*np.sin(2*np.pi*fluid.x[i]):
            indices.append(i)

    fluid1 = fluid.extract_particles(indices); fluid1.set_name('fluid1')
    fluid2 = fluid
    fluid2.set_name('fluid2')
    fluid2.remove_particles(indices)

    fluid1.rho[:] = rho1
    fluid2.rho[:] = rho2

    print "Rayleigh Taylor Instability problem :: Re = %d, nfluid = %d, nsolid=%d, dt = %g"%(
        Re, fluid1.get_number_of_particles() + fluid2.get_number_of_particles(),
        solid.get_number_of_particles(), dt)

    # add requisite properties to the arrays:
    # particle volume
    fluid1.add_property('V')
    fluid2.add_property('V')
    solid.add_property('V' )

    # advection velocities and accelerations
    for name in ('uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 'au', 'av', 'aw'):
        fluid1.add_property(name)
        fluid2.add_property(name)

    # kernel summation correction for the solid
    solid.add_property('wij')

    # imposed accelerations on the solid
    solid.add_property('ax')
    solid.add_property('ay')
    solid.add_property('az')

    # Shepard filtered velocities for the fluid
    for name in ['uf', 'vf', 'wf']:
        fluid1.add_property(name)
        fluid2.add_property(name)

    # magnitude of velocity
    fluid1.add_property('vmag2')
    fluid2.add_property('vmag2')

    # setup the particle properties
    volume = dx * dx

    # mass is set to get the reference density of each phase
    fluid1.m[:] = volume * rho1
    fluid2.m[:] = volume * rho2

    # volume is set as dx^2
    fluid1.V[:] = 1./volume
    fluid2.V[:] = 1./volume
    solid.V[:] = 1./volume

    # smoothing lengths
    fluid1.h[:] = hdx * dx
    fluid2.h[:] = hdx * dx
    solid.h[:] = hdx * dx

    # load balancing props
    fluid1.set_lb_props( fluid1.properties.keys() )
    fluid2.set_lb_props( fluid2.properties.keys() )
    solid.set_lb_props( solid.properties.keys() )

    # return the arrays
    return [fluid1, fluid2, solid]
Exemple #32
0
def create_particles(**kwargs):
    #x,y = numpy.mgrid[-1.05:1.05+1e-4:dx, -0.105:0.105+1e-4:dx]
    spacing = 0.041 # spacing = 2*5cm

    x,y = numpy.mgrid[-ro:ro:dx, -ro:ro:dx]
    x = x.ravel()
    y = y.ravel()

    d = (x*x+y*y)
    keep = numpy.flatnonzero((ri*ri<=d) * (d<ro*ro))
    x = x[keep]
    y = y[keep]

    x = numpy.concatenate([x-spacing,x+spacing])
    y = numpy.concatenate([y,y])

    print 'Ellastic Collision with %d particles'%(x.size)
    print "Shear modulus G = %g, Young's modulus = %g, Poisson's ratio =%g"%(G,E,nu)

    #print bdry, numpy.flatnonzero(bdry)
    m = numpy.ones_like(x)*dx*dx
    h = numpy.ones_like(x)*hdx*dx
    rho = numpy.ones_like(x)
    z = numpy.zeros_like(x)

    p = 0.5*1.0*100*100*(1 - (x**2 + y**2))

    cs = numpy.ones_like(x) * 10000.0

    # u is set later
    v = z
    u_f = 0.059

    p *= 0
    h *= 1

    # create the particle array
    pa = get_particle_array(
        name="solid", x=x+spacing, y=y, m=m, rho=rho, h=h,
        p=p, cs=cs, u=z, v=v)

    pa.cs[:] = c0
    pa.u = pa.cs*u_f*(2*(x<0)-1)

    # add requisite properties

    # sound speed etc.
    add_properties(pa, 'cs', 'e' )

    # velocity gradient properties
    add_properties(pa, 'v00', 'v01', 'v10', 'v11')

    # artificial stress properties
    add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

    # deviatoric stress components
    add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

    # deviatoric stress accelerations
    add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

    # deviatoric stress initial values
    add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

    # standard acceleration variables
    add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

    # initial values
    add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

    # load balancing properties
    pa.set_lb_props( pa.properties.keys() )

    return [pa,]
Exemple #33
0
 def create_particles(self):
     fluid_x, fluid_y = get_2d_block(
         dx=dx, length=Lx, height=Ly, center=np.array([0., 0.]))
     rho_fluid = np.ones_like(fluid_x) * rho2
     m_fluid = rho_fluid * volume
     h_fluid = np.ones_like(fluid_x) * h0
     cs_fluid = np.ones_like(fluid_x) * c0
     circle_x, circle_y = get_2d_circle(dx=dx, r=0.2,
                                        center=np.array([0.0, 0.0]))
     rho_circle = np.ones_like(circle_x) * rho1
     m_circle = rho_circle * volume
     h_circle = np.ones_like(circle_x) * h0
     cs_circle = np.ones_like(circle_x) * c0
     wall_x, wall_y = get_2d_block(dx=dx, length=Lx+6*dx, height=Ly+6*dx,
                                   center=np.array([0., 0.]))
     rho_wall = np.ones_like(wall_x) * rho2
     m_wall = rho_wall * volume
     h_wall = np.ones_like(wall_x) * h0
     cs_wall = np.ones_like(wall_x) * c0
     additional_props = ['V', 'color', 'scolor', 'cx', 'cy', 'cz',
                         'cx2', 'cy2', 'cz2', 'nx', 'ny', 'nz', 'ddelta',
                         'uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat',
                         'ax', 'ay', 'az', 'wij', 'vmag2', 'N', 'wij_sum',
                         'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0',
                         'kappa', 'arho', 'nu', 'wg', 'ug', 'vg',
                         'pi00', 'pi01', 'pi02', 'pi10', 'pi11', 'pi12',
                         'pi20', 'pi21', 'pi22']
     gas = get_particle_array(
         name='gas', x=fluid_x, y=fluid_y, h=h_fluid, m=m_fluid,
         rho=rho_fluid, cs=cs_fluid, additional_props=additional_props)
     gas.nu[:] = nu2
     gas.color[:] = 0.0
     liquid = get_particle_array(
         name='liquid', x=circle_x, y=circle_y, h=h_circle, m=m_circle,
         rho=rho_circle, cs=cs_circle, additional_props=additional_props)
     liquid.nu[:] = nu1
     liquid.color[:] = 1.0
     wall = get_particle_array(
         name='wall', x=wall_x, y=wall_y, h=h_wall, m=m_wall,
         rho=rho_wall, cs=cs_wall, additional_props=additional_props)
     wall.color[:] = 0.0
     remove_overlap_particles(wall, liquid, dx_solid=dx, dim=2)
     remove_overlap_particles(wall, gas, dx_solid=dx, dim=2)
     remove_overlap_particles(gas, liquid, dx_solid=dx, dim=2)
     gas.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta',
                            'kappa', 'N', 'scolor', 'p'])
     liquid.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny',
                               'ddelta', 'kappa', 'N', 'scolor', 'p'])
     wall.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny',
                             'ddelta', 'kappa', 'N', 'scolor', 'p'])
     for i in range(len(gas.x)):
         R = sqrt(r(gas.x[i], gas.y[i]) + 0.0001*gas.h[i]*gas.h[i])
         f = np.exp(-R/r0)
         gas.u[i] = v0*gas.x[i]*(1.0-(gas.y[i]*gas.y[i])/(r0*R))*f/r0
         gas.v[i] = -v0*gas.y[i]*(1.0-(gas.x[i]*gas.x[i])/(r0*R))*f/r0
     for i in range(len(liquid.x)):
         R = sqrt(r(liquid.x[i], liquid.y[i]) +
                  0.0001*liquid.h[i]*liquid.h[i])
         liquid.u[i] = v0*liquid.x[i] * \
             (1.0 - (liquid.y[i]*liquid.y[i])/(r0*R))*f/r0
         liquid.v[i] = -v0*liquid.y[i] * \
             (1.0 - (liquid.x[i]*liquid.x[i])/(r0*R))*f/r0
     return [liquid, gas, wall]
Exemple #34
0
    def create_particles(self):
        # create all the particles
        _x = np.arange(-ghost_extent - dx / 2, Lx + ghost_extent + dx / 2, dx)
        _y = np.arange(-ghost_extent - dx / 2, Ly + ghost_extent + dx / 2, dx)
        x, y = np.meshgrid(_x, _y)
        x = x.ravel()
        y = y.ravel()

        # sort out the fluid and the solid
        indices = []
        for i in range(x.size):
            if ((x[i] > 0.0) and (x[i] < Lx)):
                if ((y[i] > 0.0) and (y[i] < Ly)):
                    indices.append(i)

        # create the arrays
        solid = get_particle_array(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(indices)
        fluid.set_name('fluid')
        solid.remove_particles(indices)

        # sort out the two fluid phases
        indices = []
        for i in range(fluid.get_number_of_particles()):
            if fluid.y[i] > 1 - 0.15 * np.sin(2 * np.pi * fluid.x[i]):
                indices.append(i)

        fluid1 = fluid.extract_particles(indices)
        fluid1.set_name('fluid1')
        fluid2 = fluid
        fluid2.set_name('fluid2')
        fluid2.remove_particles(indices)

        fluid1.rho[:] = rho1
        fluid2.rho[:] = rho2

        print(
            "Rayleigh Taylor Instability problem :: Re = %d, nfluid = %d, nsolid=%d, dt = %g"
            % (Re, fluid1.get_number_of_particles() +
               fluid2.get_number_of_particles(),
               solid.get_number_of_particles(), dt))

        # add requisite properties to the arrays:
        self.scheme.setup_properties([fluid1, fluid2, solid])

        # setup the particle properties
        volume = dx * dx

        # mass is set to get the reference density of each phase
        fluid1.m[:] = volume * rho1
        fluid2.m[:] = volume * rho2

        # volume is set as dx^2
        fluid1.V[:] = 1. / volume
        fluid2.V[:] = 1. / volume
        solid.V[:] = 1. / volume

        # smoothing lengths
        fluid1.h[:] = hdx * dx
        fluid2.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        # return the arrays
        return [fluid1, fluid2, solid]
Exemple #35
0
def get_projectile_particles():

    x, y = numpy.mgrid[-r:r:dx, -r:r:dx]
    x = x.ravel()
    y = y.ravel()

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

    x = x - (r + 2 * dx)
    print('%d Projectile particles' % len(x))

    hf = numpy.ones_like(x) * h
    mf = numpy.ones_like(x) * dx * dy * ro2
    rhof = numpy.ones_like(x) * ro2
    csf = numpy.ones_like(x) * cs2
    z = numpy.zeros_like(x)

    u = numpy.ones_like(x) * v_s

    pa = projectile = get_particle_array(name="projectile",
                                         x=x,
                                         y=y,
                                         h=hf,
                                         m=mf,
                                         rho=rhof,
                                         cs=csf,
                                         u=u)

    # add requisite properties
    # sound speed etc.
    add_properties(pa, 'e')

    # velocity gradient properties
    add_properties(pa, 'v00', 'v01', 'v02', 'v10', 'v11', 'v12', 'v20', 'v21',
                   'v22')

    # artificial stress properties
    add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

    # deviatoric stress components
    add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

    # deviatoric stress accelerations
    add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

    # deviatoric stress initial values
    add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

    # standard acceleration variables
    add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

    # initial values
    add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

    # load balancing properties
    pa.set_lb_props(list(pa.properties.keys()))

    return projectile
    def create_particles(self):
        # create all the particles
        _x = np.arange( -ghost_extent - dx/2, Lx + ghost_extent + dx/2, dx )
        _y = np.arange( -ghost_extent - dx/2, Ly + ghost_extent + dx/2, dx )
        x, y = np.meshgrid(_x, _y); x = x.ravel(); y = y.ravel()

        # sort out the fluid and the solid
        indices = []
        for i in range(x.size):
            if ( (x[i] > 0.0) and (x[i] < Lx) ):
                if ( (y[i] > 0.0)  and (y[i] < Ly) ):
                    indices.append(i)

        # create the arrays
        solid = get_particle_array(name='solid', x=x, y=y)

        # remove the fluid particles from the solid
        fluid = solid.extract_particles(indices); fluid.set_name('fluid')
        solid.remove_particles(indices)

        # sort out the two fluid phases
        indices = []
        for i in range(fluid.get_number_of_particles()):
            if fluid.y[i] > 1 - 0.15*np.sin(2*np.pi*fluid.x[i]):
                indices.append(i)

        fluid1 = fluid.extract_particles(indices); 
        fluid1.set_name('fluid1')
        fluid2 = fluid
        fluid2.set_name('fluid2')
        fluid2.remove_particles(indices)

        # add requisite properties to the arrays:
        # self.scheme.setup_properties([solid])

        materials = MixtureParticle(baseProperties={'V': 0, 'auhat': 0, 'avhat': 0, 'awhat': 0, 'what': 0, 'uhat': 0, 'vhat': 0, 'rho0': rho1, 'vmag2':0, 'p0': p1, 't0': 270, 't': 270})

        print('props', materials.generateFullParticleProperties())

        

        for propertyName in materials.generateFullParticleProperties():
            solid.add_property(propertyName, type='double', default=materials.getPropertyValue(propertyName))
            fluid1.add_property(propertyName, type='double', default=materials.getPropertyValue(propertyName))
            fluid2.add_property(propertyName, type='double', default=materials.getPropertyValue(propertyName))

        for prop in ['wg', 'wf', 'vf', 'vg', 'ug', 'uf', 'wij']:
            solid.add_property(prop)

        fluid1.rho[:] = rho1
        fluid1.rho0[:] = rho1
        fluid1.p[:] = p1
        fluid1.p0[:] = p1
        fluid2.rho[:] = rho2
        fluid2.rho0[:] = rho2
        fluid2.p[:] = p2
        fluid2.p0[:] = p2

        print("Rayleigh Taylor Instability problem :: Re = %d, nfluid = %d, nsolid=%d, dt = %g"%(
            Re, fluid1.get_number_of_particles() + fluid2.get_number_of_particles(),
            solid.get_number_of_particles(), dt))

        

        # setup the particle properties
        volume = dx * dx

        # mass is set to get the reference density of each phase
        fluid1.m[:] = volume * rho1
        fluid2.m[:] = volume * rho2

        # volume is set as dx^2
        fluid1.V[:] = 1./volume
        fluid2.V[:] = 1./volume
        solid.V[:] = 1./volume

        # smoothing lengths
        fluid1.h[:] = hdx * dx
        fluid2.h[:] = hdx * dx
        solid.h[:] = hdx * dx

        both_fluids = fluid1
        both_fluids.append_parray(fluid2)
        both_fluids.set_name('fluid')

        # return the arrays
        return [both_fluids, solid]
Exemple #37
0
    def setUp(self):
        """Default set-up used by all the tests

        Particles with the following coordinates (x, y, z) are placed in a box

        0 : -1.5 , 0.25 , 0.5
        1 : 0.33 , -0.25, 0.25
        2 : 1.25 , -1.25, 1.25
        3 : 0.05 , 1.25 , -0.5
        4 : -0.5 , 0.5  , -1.25
        5 : -0.75, 0.75 , -1.25
        6 : -1.25, 0.5  , 0.5
        7 : 0.5  , 1.5  , -0.5
        8 : 0.5  , -0.5 , 0.5
        9 : 0.5  , 1.75 , -0.75

        The cell size is set to 1. Valid cell indices and the
        particles they contain are given below:

        (-2, 0, 0) : particle 0, 6
        (0, -1, 0) : particle 1, 8
        (1, -2, 1) : particle 2
        (0, 1, -1) : particle 3, 7, 9
        (-1, 0, -2): particle 4, 5

        """
        x = numpy.array(
            [-1.5, 0.33, 1.25, 0.05, -0.5, -0.75, -1.25, 0.5, 0.5, 0.5])

        y = numpy.array(
            [0.25, -0.25, -1.25, 1.25, 0.5, 0.75, 0.5, 1.5, -0.5, 1.75])

        z = numpy.array(
            [0.5, 0.25, 1.25, -0.5, -1.25, -1.25, 0.5, -0.5, 0.5, -0.75])

        # using a degenrate (h=0) array will set cell size to 1 for NNPS
        h = numpy.zeros_like(x)

        pa = get_particle_array(x=x, y=y, z=z, h=h)

        self.dict_box_sort_nnps = nnps.DictBoxSortNNPS(dim=3,
                                                       particles=[pa],
                                                       radius_scale=1.0)

        self.box_sort_nnps = nnps.BoxSortNNPS(dim=3,
                                              particles=[pa],
                                              radius_scale=1.0)

        self.ll_nnps = nnps.LinkedListNNPS(dim=3,
                                           particles=[pa],
                                           radius_scale=1.0)

        self.sp_hash_nnps = nnps.SpatialHashNNPS(dim=3,
                                                 particles=[pa],
                                                 radius_scale=1.0)

        self.ext_sp_hash_nnps = nnps.ExtendedSpatialHashNNPS(dim=3,
                                                             particles=[pa],
                                                             radius_scale=1.0)

        self.strat_radius_nnps = nnps.StratifiedHashNNPS(dim=3,
                                                         particles=[pa],
                                                         radius_scale=1.0)

        # these are the expected cells
        self.expected_cells = {
            IntPoint(-2, 0, 0): [0, 6],
            IntPoint(0, -1, 0): [1, 8],
            IntPoint(1, -2, 1): [2],
            IntPoint(0, 1, -1): [3, 7, 9],
            IntPoint(-1, 0, -2): [4, 5]
        }
Exemple #38
0
    def create_particles(self):
        x, y = np.mgrid[dx:l_tunnel + dx / 4:dx, dx / 2:w_tunnel - dx / 4:dx]
        x, y = (np.ravel(t) for t in (x, y))
        one = np.ones_like(x)
        volume = dx * dx * one
        m = volume * rho
        fluid = get_particle_array(name='fluid',
                                   m=m,
                                   x=x,
                                   y=y,
                                   h=h0 * one,
                                   V=1.0 / volume,
                                   u=umax * one)

        xc, yc = center
        cond = (x - xc)**2 + (y - yc)**2 < 1.0
        one = np.ones_like(x[cond])
        volume = dx * dx * one
        solid = get_particle_array(name='solid',
                                   x=x[cond].ravel(),
                                   y=y[cond].ravel(),
                                   m=volume * rho,
                                   rho=one * rho,
                                   h=h0 * one,
                                   V=1.0 / volume)
        G.remove_overlap_particles(fluid, solid, dx, dim=2)

        x, y = np.mgrid[dx:n_outlet * dx:dx, dx / 2:w_tunnel - dx / 4:dx]
        x, y = (np.ravel(t) for t in (x, y))
        x += l_tunnel
        one = np.ones_like(x)
        volume = dx * dx * one
        m = volume * rho
        outlet = get_particle_array(name='outlet',
                                    x=x,
                                    y=y,
                                    m=m,
                                    h=h0 * one,
                                    V=1.0 / volume,
                                    u=umax * one)

        # Setup the inlet particle array with just the particles we need at the
        # exit plane which is replicated by the inlet.
        y = np.arange(dx / 2, w_tunnel - dx / 4.0, dx)
        x = np.zeros_like(y)
        one = np.ones_like(x)
        volume = one * dx * dx

        inlet = get_particle_array(name='inlet',
                                   x=x,
                                   y=y,
                                   m=volume * rho,
                                   h=h0 * one,
                                   u=umax * one,
                                   rho=rho * one,
                                   V=1.0 / volume)
        self.scheme.setup_properties([fluid, inlet, outlet, solid])
        for p in fluid.properties:
            if p not in outlet.properties:
                outlet.add_property(p)

        return [fluid, solid, inlet, outlet]
Exemple #39
0
    def create_particles(self):
        # create the particles
        dx = self.dx
        _x = np.arange(dx / 2, L, dx)
        x, y = np.meshgrid(_x, _x)
        x = x.ravel()
        y = y.ravel()
        if self.options.init is not None:
            fname = self.options.init
            from pysph.solver.utils import load
            data = load(fname)
            _f = data['arrays']['fluid']
            x, y = _f.x.copy(), _f.y.copy()

        if self.options.perturb > 0:
            np.random.seed(1)
            factor = dx * self.options.perturb
            x += np.random.random(x.shape) * factor
            y += np.random.random(x.shape) * factor
        h = np.ones_like(x) * dx

        # create the arrays

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

        self.scheme.setup_properties([fluid])

        # add the requisite arrays
        fluid.add_property('color')
        fluid.add_output_arrays(['color'])

        print("Taylor green vortex problem :: nfluid = %d, dt = %g" % (
            fluid.get_number_of_particles(), self.dt))

        # 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.u[:] = -U * cos(2 * pi * x) * sin(2 * pi * y)
        fluid.v[:] = +U * sin(2 * pi * x) * cos(2 * pi * y)
        fluid.p[:] = -U * U * (np.cos(4 * np.pi * x) +
                               np.cos(4 * np.pi * y)) * 0.25

        # mass is set to get the reference density of each phase
        fluid.rho[:] = rho0
        fluid.m[:] = self.volume * fluid.rho

        # volume is set as dx^2
        if self.options.scheme == 'tvf':
            fluid.V[:] = 1. / self.volume
        if self.options.scheme == 'iisph':
            # These are needed to update the ghost particle properties.
            nfp = fluid.get_number_of_particles()
            fluid.orig_idx[:] = np.arange(nfp)
            fluid.add_output_arrays(['orig_idx'])

        # smoothing lengths
        fluid.h[:] = self.hdx * dx

        corr = self.kernel_correction
        if corr in ['mixed', 'crksph']:
            fluid.add_property('cwij')
        if corr == 'mixed' or corr == 'gradient':
            fluid.add_property('m_mat', stride=9)
            fluid.add_property('dw_gamma', stride=3)
        elif corr == 'crksph':
            fluid.add_property('ai')
            fluid.add_property('gradbi', stride=4)
            for prop in ['gradai', 'bi']:
                fluid.add_property(prop, stride=2)

        # return the particle list
        return [fluid]
Exemple #40
0
    def create_particles(self):
        x, y = numpy.mgrid[dxb2:domain_width:dx, dyb2:domain_height:dy]
        x = x.ravel()
        y = y.ravel()

        m = numpy.ones_like(x) * volume * rho0
        rho = numpy.ones_like(x) * rho0
        h = numpy.ones_like(x) * h0
        cs = numpy.ones_like(x) * c0

        # additional properties required for the fluid.
        additional_props = [
            # volume inverse or number density
            'V',

            # color and gradients
            'color',
            'scolor',
            'cx',
            'cy',
            'cz',
            'cx2',
            'cy2',
            'cz2',

            # discretized interface normals and dirac delta
            'nx',
            'ny',
            'nz',
            'ddelta',

            # interface curvature
            'kappa',

            # transport velocities
            'uhat',
            'vhat',
            'what',
            'auhat',
            'avhat',
            'awhat',

            # imposed accelerations on the solid wall
            'ax',
            'ay',
            'az',
            'wij',

            # velocity of magnitude squared
            'vmag2',

            # variable to indicate reliable normals and normalizing
            # constant
            'N',
            'wij_sum',
        ]

        # get the fluid particle array
        fluid = get_particle_array(name='fluid',
                                   x=x,
                                   y=y,
                                   h=h,
                                   m=m,
                                   rho=rho,
                                   cs=cs,
                                   additional_props=additional_props)

        # set the color of the inner square
        for i in range(x.size):
            if ((fluid.x[i] > 0.35) and (fluid.x[i] < 0.65)):
                if ((fluid.y[i] > 0.35) and (fluid.y[i] < 0.65)):
                    fluid.color[i] = 1.0

        # particle volume
        fluid.V[:] = 1. / volume

        # set additional output arrays for the fluid
        fluid.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])

        print("2D Square droplet deformation with %d fluid particles" %
              (fluid.get_number_of_particles()))

        return [
            fluid,
        ]
def create_particles(staggered=True, **kwargs):
    if staggered:
        x1, y1 = numpy.mgrid[ dxb2:domain_width:dx, dyb2:domain_height:dy ]
        x2, y2 = numpy.mgrid[ dx:domain_width:dx, dy:domain_height:dy ]

        x1 = x1.ravel(); y1 = y1.ravel()
        x2 = x2.ravel(); y2 = y2.ravel()
        
        x = numpy.concatenate( [x1, x2] )
        y = numpy.concatenate( [y1, y2] )
        volume = dx*dx/2
    else:
        x, y = numpy.mgrid[ dxb2:domain_width:dx, dyb2:domain_height:dy ]
        x = x.ravel(); y = y.ravel()
        volume = dx*dx

    m = numpy.ones_like(x) * volume * rho0
    rho = numpy.ones_like(x) * rho0
    h = numpy.ones_like(x) * h0
    cs = numpy.ones_like(x) * c0

    # additional properties required for the fluid.
    additional_props = [
        # volume inverse or number density
        'V', 

        # color and gradients
        'color', 'scolor', 'cx', 'cy', 'cz', 'cx2', 'cy2', 'cz2',
        
        # discretized interface normals and dirac delta
        'nx', 'ny', 'nz', 'ddelta',

        # interface curvature
        'kappa',
        
        # filtered velocities
        'uf', 'vf', 'wf',
        
        # transport velocities
        'uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 
        
        # imposed accelerations on the solid wall
        'ax', 'ay', 'az', 'wij', 
       
        # velocity of magnitude squared needed for TVF
        'vmag2',

        # variable to indicate reliable normals and normalizing
        # constant
        'N', 'wij_sum'        
        
        ]

    # get the fluid particle array
    fluid = get_particle_array(
        name='fluid', x=x, y=y, h=h, m=m, rho=rho, cs=cs, 
        additional_props=additional_props)

    # set the color of the inner circle
    for i in range(x.size):
        if ( ((fluid.x[i]-0.5)**2 + (fluid.y[i]-0.5)**2) <= 0.25**2 ):
            fluid.color[i] = 1.0
                
    # particle volume
    fluid.V[:] = 1./volume

    # set additional output arrays for the fluid
    fluid.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'p', 
                             'kappa', 'N', 'scolor'])
    
    print "2D Circular droplet deformation with %d fluid particles"%(
            fluid.get_number_of_particles())

    return [fluid,]
Exemple #42
0
def get_plate_particles():
    x, y, z = numpy.mgrid[0:0.002 + dx:dx, -0.02:0.02 + dx:dx,
                          -0.02:0.02 + dx:dx]
    x = x.ravel()
    y = y.ravel()
    z = z.ravel()

    d = (z * z + y * y)
    keep = numpy.flatnonzero(d <= 0.02 * 0.02)

    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
    csf = numpy.ones_like(x) * cs1
    pa = plate = get_particle_array(name="plate",
                                    x=x,
                                    y=y,
                                    z=z,
                                    h=hf,
                                    m=mf,
                                    rho=rhof,
                                    cs=csf)

    # add requisite properties
    # sound speed etc.
    add_properties(pa, 'e')

    # velocity gradient properties
    add_properties(pa, 'v00', 'v01', 'v02', 'v10', 'v11', 'v12', 'v20', 'v21',
                   'v22')

    # artificial stress properties
    add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

    # deviatoric stress components
    add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

    # deviatoric stress accelerations
    add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

    # deviatoric stress initial values
    add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

    # standard acceleration variables
    add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

    # initial values
    add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

    # load balancing properties
    pa.set_lb_props(list(pa.properties.keys()))

    # removed S_00 and similar components
    plate.v[:] = 0.0
    return plate
def create_particles(**kwargs):
    x, y = numpy.mgrid[ dxb2:domain_width:dx, dyb2:domain_height:dy ]
    x = x.ravel(); y = y.ravel()

    m = numpy.ones_like(x) * volume * rho0
    rho = numpy.ones_like(x) * rho0
    h = numpy.ones_like(x) * h0
    cs = numpy.ones_like(x) * c0

    # additional properties required for the fluid.
    additional_props = [
        # volume inverse or number density
        'V', 

        # color and gradients
        'color', 'scolor', 'cx', 'cy', 'cz', 'cx2', 'cy2', 'cz2',
        
        # discretized interface normals and dirac delta
        'nx', 'ny', 'nz', 'ddelta',

        # interface curvature
        'kappa',
        
        # filtered velocities
        'uf', 'vf', 'wf',
        
        # transport velocities
        'uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 
        
        # imposed accelerations on the solid wall
        'ax', 'ay', 'az', 'wij', 
       
        # velocity of magnitude squared
        'vmag2',

        # variable to indicate reliable normals and normalizing
        # constant
        'N', 'wij_sum',
        
        ]

    # get the fluid particle array
    fluid = get_particle_array(
        name='fluid', x=x, y=y, h=h, m=m, rho=rho, cs=cs, 
        additional_props=additional_props)

    # set the color of the inner square
    for i in range(x.size):
        if ( (fluid.x[i] > 0.35) and (fluid.x[i] < 0.65) ):
            if ( (fluid.y[i] > 0.35) and (fluid.y[i] < 0.65) ):
                fluid.color[i] = 1.0
                
    # particle volume
    fluid.V[:] = 1./volume

    # set additional output arrays for the fluid
    fluid.add_output_arrays(['V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta',
                             'kappa', 'N', 'scolor', 'p'])
    
    print "2D Square droplet deformation with %d fluid particles"%(
            fluid.get_number_of_particles())

    return [fluid,]
Exemple #44
0
 def setup(self):
     self.pa = get_particle_array(name='f', x=[0.0, 1.0], m=1.0, rho=2.0)
Exemple #45
0
    def create_particles(self):
        #x,y = numpy.mgrid[-1.05:1.05+1e-4:dx, -0.105:0.105+1e-4:dx]
        spacing = 0.041  # spacing = 2*5cm

        x, y = numpy.mgrid[-ro:ro:dx, -ro:ro:dx]
        x = x.ravel()
        y = y.ravel()

        d = (x * x + y * y)
        keep = numpy.flatnonzero((ri * ri <= d) * (d < ro * ro))
        x = x[keep]
        y = y[keep]

        x = numpy.concatenate([x - spacing, x + spacing])
        y = numpy.concatenate([y, y])

        print('Ellastic Collision with %d particles' % (x.size))
        print(
            "Shear modulus G = %g, Young's modulus = %g, Poisson's ratio =%g" %
            (G, E, nu))

        #print bdry, numpy.flatnonzero(bdry)
        m = numpy.ones_like(x) * dx * dx
        h = numpy.ones_like(x) * hdx * dx
        rho = numpy.ones_like(x)
        z = numpy.zeros_like(x)

        p = 0.5 * 1.0 * 100 * 100 * (1 - (x**2 + y**2))

        cs = numpy.ones_like(x) * 10000.0

        # u is set later
        v = z
        u_f = 0.059

        p *= 0
        h *= 1

        # create the particle array
        pa = get_particle_array(name="solid",
                                x=x + spacing,
                                y=y,
                                m=m,
                                rho=rho,
                                h=h,
                                p=p,
                                cs=cs,
                                u=z,
                                v=v)

        pa.cs[:] = c0
        pa.u = pa.cs * u_f * (2 * (x < 0) - 1)

        # add requisite properties

        # sound speed etc.
        add_properties(pa, 'cs', 'e')

        # velocity gradient properties
        add_properties(pa, 'v00', 'v01', 'v02', 'v10', 'v11', 'v12', 'v20',
                       'v21', 'v22')

        # artificial stress properties
        add_properties(pa, 'r00', 'r01', 'r02', 'r11', 'r12', 'r22')

        # deviatoric stress components
        add_properties(pa, 's00', 's01', 's02', 's11', 's12', 's22')

        # deviatoric stress accelerations
        add_properties(pa, 'as00', 'as01', 'as02', 'as11', 'as12', 'as22')

        # deviatoric stress initial values
        add_properties(pa, 's000', 's010', 's020', 's110', 's120', 's220')

        # standard acceleration variables
        add_properties(pa, 'arho', 'au', 'av', 'aw', 'ax', 'ay', 'az', 'ae')

        # initial values
        add_properties(pa, 'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'e0')

        # load balancing properties
        pa.set_lb_props(list(pa.properties.keys()))

        return [
            pa,
        ]
Exemple #46
0
    def create_particles(self):
        fluid_x, fluid_y = get_2d_block(dx=dx,
                                        length=Lx,
                                        height=Ly,
                                        center=np.array([0., 0.]))
        rho_fluid = np.ones_like(fluid_x) * rho0
        m_fluid = rho_fluid * volume
        h_fluid = np.ones_like(fluid_x) * h0
        cs_fluid = np.ones_like(fluid_x) * c0
        wall_x, wall_y = get_2d_block(dx=dx,
                                      length=Lx + 6 * dx,
                                      height=Ly + 6 * dx,
                                      center=np.array([0., 0.]))
        rho_wall = np.ones_like(wall_x) * rho0
        m_wall = rho_wall * volume
        h_wall = np.ones_like(wall_x) * h0
        cs_wall = np.ones_like(wall_x) * c0
        additional_props = [
            'V', 'color', 'scolor', 'cx', 'cy', 'cz', 'cx2', 'cy2', 'cz2',
            'nx', 'ny', 'nz', 'ddelta', 'uhat', 'vhat', 'what', 'auhat',
            'avhat', 'awhat', 'ax', 'ay', 'az', 'wij', 'vmag2', 'N', 'wij_sum',
            'rho0', 'u0', 'v0', 'w0', 'x0', 'y0', 'z0', 'kappa', 'arho', 'nu',
            'wg', 'ug', 'vg', 'pi00', 'pi01', 'pi10', 'pi11', 'alpha'
        ]
        consts = {'max_ddelta': np.zeros(1, dtype=float)}

        fluid = get_particle_array(name='fluid',
                                   x=fluid_x,
                                   y=fluid_y,
                                   h=h_fluid,
                                   m=m_fluid,
                                   rho=rho_fluid,
                                   cs=cs_fluid,
                                   additional_props=additional_props,
                                   constants=consts)
        for i in range(len(fluid.x)):
            if (fluid.x[i] * fluid.x[i] +
                    fluid.y[i] * fluid.y[i]) < 0.1875 * 0.1875:
                fluid.color[i] = 1.0
            else:
                fluid.color[i] = 0.0
        fluid.alpha[:] = sigma
        wall = get_particle_array(name='wall',
                                  x=wall_x,
                                  y=wall_y,
                                  h=h_wall,
                                  m=m_wall,
                                  rho=rho_wall,
                                  cs=cs_wall,
                                  additional_props=additional_props)
        wall.color[:] = 0.0
        remove_overlap_particles(wall, fluid, dx_solid=dx, dim=2)
        fluid.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])
        wall.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])
        for i in range(len(fluid.x)):
            R = sqrt(
                r(fluid.x[i], fluid.y[i]) + 0.0001 * fluid.h[i] * fluid.h[i])
            fluid.u[i] = v0 * fluid.x[i] * (1.0 - (fluid.y[i] * fluid.y[i]) /
                                            (r0 * R)) * np.exp(-R / r0) / r0
            fluid.v[i] = -v0 * fluid.y[i] * (1.0 - (fluid.x[i] * fluid.x[i]) /
                                             (r0 * R)) * np.exp(-R / r0) / r0
        fluid.nu[:] = nu

        return [fluid, wall]
Exemple #47
0
    def create_particles(self):
        _x = np.arange(dx / 2, Lx, dx)

        # create the fluid particles
        _y = np.arange(dx / 2, Ly, dx)

        x, y = np.meshgrid(_x, _y)
        fx = x.ravel()
        fy = y.ravel()

        # create the channel particles at the top
        _y = np.arange(Ly + dx / 2, Ly + dx / 2 + ghost_extent, dx)
        x, y = np.meshgrid(_x, _y)
        tx = x.ravel()
        ty = y.ravel()

        # create the channel particles at the bottom
        _y = np.arange(-dx / 2, -dx / 2 - ghost_extent, -dx)
        x, y = np.meshgrid(_x, _y)
        bx = x.ravel()
        by = y.ravel()

        # concatenate the top and bottom arrays
        cx = np.concatenate((tx, bx))
        cy = np.concatenate((ty, by))

        # create the arrays
        channel = get_particle_array(name="channel",
                                     x=cx,
                                     y=cy,
                                     rho=rho0 * np.ones_like(cx))
        fluid = get_particle_array(name="fluid",
                                   x=fx,
                                   y=fy,
                                   rho=rho0 * np.ones_like(fx))

        print("Couette flow :: Re = %g, nfluid = %d, nchannel=%d, dt = %g" % (
            Re,
            fluid.get_number_of_particles(),
            channel.get_number_of_particles(),
            dt,
        ))

        self.scheme.setup_properties([fluid, channel])

        # setup the particle properties
        volume = dx * dx

        # mass is set to get the reference density of rho0
        fluid.m[:] = volume * rho0
        channel.m[:] = volume * rho0

        # volume is set as dx^2
        fluid.V[:] = 1.0 / volume
        channel.V[:] = 1.0 / volume

        # smoothing lengths
        fluid.h[:] = hdx * dx
        channel.h[:] = hdx * dx

        # channel velocity on upper portion
        indices = np.where(channel.y > d)[0]
        channel.u[indices] = Vmax

        # return the particle list
        return [fluid, channel]
Exemple #48
0
if __name__ == '__main__':
    all_functions = inspect.getmembers(dataset, inspect.isfunction)
    i = 0
    for name, test in all_functions:
        print i, name
        i+=1
    choices = raw_input("Choose tests: ")
    N_s = raw_input("Enter N in that order: ")
    choices = [int(i) for i in choices.split()]
    N_s = [int(i) for i in N_s.split()]
    pa_list = []
    H = float(sys.argv[1])
    for test, N in zip(choices, N_s):
        x, y, z, h = make_testcase(all_functions[test][1], N)
        pa = get_particle_array(x=x, y=y, z=z, h=h)
        pa_list.append(pa)
    columns = [all_functions[i][0] for i in choices]
    index = ["LinkedListNNPS", "SpatialHashNNPS", "ExtendedSpatialHash(approx)",
            "ExtendedSpatialHash(exact)"]
    value = [[],[],[],[]]
    nbrs = UIntArray()
    for i,pa in enumerate(pa_list):
        value[0].append(time_pysph_nnps(pa, nbrs, pa.get_number_of_particles()))
        value[1].append(time_spatial_hash_nnps(pa, nbrs, pa.get_number_of_particles()))
        value[2].append(time_extended_spatial_hash(pa,nbrs,H,True,pa.get_number_of_particles()))
        value[3].append(time_extended_spatial_hash(pa,nbrs,H,False,pa.get_number_of_particles()))
    if len(value[0]) == 1:
        value = [value[0], value[1], value[2], value[3]]
    print pd.DataFrame(value, index, columns)
def create_particles(**kwargs):
    # create all the particles
    _x = np.arange( dx/2, L, dx )
    _y = np.arange( dx/2, H, dx)
    x, y = np.meshgrid(_x, _y); x = x.ravel(); y = y.ravel()

    # sort out the fluid and the solid
    indices = []
    cx = 0.5 * L; cy = 0.5 * H
    for i in range(x.size):
        xi = x[i]; yi = y[i]
        if ( np.sqrt( (xi-cx)**2 + (yi-cy)**2 ) > a ):
                #if ( (yi > 0) and (yi < H) ):
            indices.append(i)

    # create the arrays
    solid = get_particle_array(name='solid', x=x, y=y)

    # remove the fluid particles from the solid
    fluid = solid.extract_particles(indices); fluid.set_name('fluid')
    solid.remove_particles(indices)

    print "Periodic cylinders :: Re = %g, nfluid = %d, nsolid=%d, dt = %g"%(
        Re, fluid.get_number_of_particles(),
        solid.get_number_of_particles(), dt)

    # add requisite properties to the arrays:
    # particle volume
    fluid.add_property('V')
    solid.add_property('V' )

    # advection velocities and accelerations
    for name in ('uhat', 'vhat', 'what', 'auhat', 'avhat', 'awhat', 'au', 'av', 'aw'):
        fluid.add_property(name)

    # kernel summation correction for the solid
    solid.add_property('wij')

    # imposed accelerations on the solid
    solid.add_property('ax')
    solid.add_property('ay')
    solid.add_property('az')

    # Shepard filtered velocities for the fluid
    for name in ['uf', 'vf', 'wf']:
        fluid.add_property(name)

    # magnitude of velocity
    fluid.add_property('vmag')

    # density acceleration
    fluid.add_property('arho')

    # setup the particle properties
    volume = dx * dx

    # mass is set to get the reference density of rho0
    fluid.m[:] = volume * rho0
    solid.m[:] = volume * rho0
    solid.rho[:] = rho0

    # reference pressures and densities
    fluid.rho[:] = rho0

    # volume is set as dx^2
    fluid.V[:] = 1./volume
    solid.V[:] = 1./volume

    # smoothing lengths
    fluid.h[:] = hdx * dx
    solid.h[:] = hdx * dx

    # return the particle list
    return [fluid, solid]
Exemple #50
0
    def create_particles(self):
        '''
        Set up particle arrays
        '''
        dx = self.dx
        L = self.L
        _x = np.arange(dx / 2, L, dx)
        x, y = np.meshgrid(_x, _x)

        if self.options.perturb > 0:
            np.random.seed(1)
            factor = dx * self.options.perturb
            x += np.random.random(x.shape) * factor
            y += np.random.random(x.shape) * factor

        m = self.volume * self.rho0
        h = self.hdx * dx
        re = self.options.re
        b = -8.0 * pi * pi / re
        u0, v0, p0 = exact_solution(U=self.U, b=b, t=0, x=x, y=y)
        color0 = cos(2 * pi * x) * cos(4 * pi * y)

        # create the arrays
        fluid = get_particle_array(name='fluid',
                                   x=x,
                                   y=y,
                                   m=m,
                                   h=h,
                                   u=u0,
                                   v=v0,
                                   rho=self.rho0,
                                   p=p0,
                                   color=color0)

        fluid.add_property('m_mat', stride=9)
        fluid.add_property('gradrho', stride=3)
        fluid.add_property('gradlmda', stride=3)

        add_props = [
            'lmda',
            'rho0',
            'u0',
            'v0',
            'w0',
            'x0',
            'y0',
            'z0',
            'ax',
            'ay',
            'az',
            'DRh',
            'DY',
            'DX',
            'DZ',
            'uhat',
            'vhat',
            'what',
            'auhat',
            'avhat',
            'awhat',
            'vmag2',
            'V',
            'arho',
            'vmag',
        ]
        for i in add_props:
            fluid.add_property(i)
        rk4_props = [
            'rho',
            'ax',
            'ay',
            'au',
            'av',
            'arho',
            'x0',
            'y0',
            'u0',
            'v0',
            'rho0',
            'xstar',
            'ystar',
            'ustar',
            'vstar',
            'rhostar',
            'vmag',
            'vmag2',
        ]
        for i in rk4_props:
            fluid.add_property(i)

        fluid.set_output_arrays([
            'x', 'y', 'z', 'u', 'v', 'w', 'rho', 'p', 'h', 'm', 'vmag',
            'vmag2', 'pid', 'gid', 'tag', 'DRh', 'lmda'
        ])

        # setup the particle properties
        volume = dx * dx

        # mass is set to get the reference density of rho0
        fluid.V[:] = 1. / volume
        fluid.lmda[:] = 1.0

        return [fluid]
# for the hexagonal particle spacing, dx*dy is only an approximate
# expression for the particle volume. As far as the summation density
# test is concerned, the value will be uniform but not equal to 1. To
# reproduce a density profile of 1, we need to estimate the kernel sum
# or number density of the distribution based on the kernel
wij_sum_estimate = get_number_density_hcp(dx, dy, k, h0)
volume = 1./wij_sum_estimate
print 'Volume estimates :: dx^2 = %g, Number density = %g'%(dx*dy, volume)

x = x.ravel(); y = y.ravel()
h = numpy.ones_like(x) * h0
m = numpy.ones_like(x) * volume
wij = numpy.zeros_like(x)

# use the helper function get_particle_array to create a ParticleArray
pa = utils.get_particle_array(x=x,y=y,h=h,m=m,wij=wij)

# the simulation domain used to request periodicity
domain = DomainManager(
    xmin=min, xmax=max, ymin=min, ymax=max,periodic_in_x=False, periodic_in_y=False)

print "NumPa:", pa.num_real_particles

# NNPS object for nearest neighbor queries
nps = BoxSortNNPS(dim=2, particles=[pa,], radius_scale=k.radius_scale, domain=domain)
#nps.bin()
DMP = DeviceMemoryPool()
"""
cells = nps.cells

max_cell_pop = 0
    def create_particles(self):
        nx, ny, nz = 10, 10, 10
        dx = self.dx
        # x, y, z = create_an_unsymmetric_body(self.dx * 2., 0.5, 0.5, 1.)

        x, y, z = np.mgrid[0:1:nx * 1j, 0:1:ny * 1j, 0:1:nz * 1j]
        x = x.flat
        y = y.flat
        z = z.flat

        m = np.ones_like(x) * dx * dx * dx * self.rho0
        h = np.ones_like(x) * self.hdx * dx
        # radius of each sphere constituting in cube
        rad_s = np.ones_like(x) * dx / 4.

        body = get_particle_array(name='body', x=x, y=y, z=z, h=h, m=m)

        body_id = np.zeros(len(x), dtype=int)
        body.add_property('body_id', type='int')
        body.body_id[:] = body_id[:]

        setup_rigid_body_unconstrained_dynamics(body, principal_moi=False)

        setup_rigid_body_collision_dynamics(body, rad_s)

        add_properties(body, 'tang_velocity_z', 'tang_disp_y',
                       'tang_velocity_x', 'tang_disp_x', 'tang_velocity_y',
                       'tang_disp_z')

        # body.vc[0] = 0.5
        # body.vc[1] = 0.5
        body.omega[1] = 5.

        # this must run
        set_angular_momentum([body])

        # create child body
        x, y, z = np.mgrid[-2. * dx:1 + 2. * dx:nx * 1j,
                           -2. * dx:1 + 2. * dx:ny * 1j,
                           -2. * dx:1 + 2. * dx:nz * 1j]
        x = x.flat
        y = y.flat
        z = z.flat

        rad_s = np.ones_like(x) * dx / 4.
        child_body = get_particle_array(name='child_body',
                                        x=x,
                                        y=y,
                                        z=z,
                                        h=h,
                                        m=m)
        body_id = np.zeros(len(x), dtype=int)
        child_body.add_property('body_id', type='int')
        child_body.body_id[:] = body_id[:]
        setup_child_body(child_body, body)

        setup_rigid_body_collision_dynamics(child_body, rad_s)

        add_properties(child_body, 'tang_velocity_z', 'tang_disp_y',
                       'tang_velocity_x', 'tang_disp_x', 'tang_velocity_y',
                       'tang_disp_z')

        # from IPython import embed; embed()

        return [body, child_body]