コード例 #1
0
def get_geometry(dx_s=0.03, dx_f=0.03, hdx=1.3, r_f=100.0, r_s=100.0,
                 wall_l=4.0, wall_h=2.0, fluid_l=1., fluid_h=2., cube_s=0.25):
    wall_y1 = np.arange(dx_s, wall_h, dx_s)
    wall_xlayer = np.ones_like(wall_y1) * 2.0
    wall_x1 = []
    wall_x2 = []
    num_layers = 3
    for i in range(num_layers):
        wall_x1.append(wall_xlayer + i * dx_s)
        wall_x2.append(wall_xlayer - i * dx_s + wall_l / 4.0)
    wall_x1, wall_x2 = np.ravel(wall_x1), np.ravel(wall_x2)
    wall_y1 = np.tile(wall_y1, num_layers)
    wall_y2 = wall_y1
    w_center = np.array([wall_l / 2.0, 0.0])
    wall_x3, wall_y3 = get_2d_wall(dx_s, w_center, wall_l, num_layers, False)
    w_center = np.array([2.5, wall_h + dx_s / 2.0])
    wall_x4, wall_y4 = get_2d_wall(dx_s, w_center, 1.0, num_layers)
    wall_x = np.concatenate([wall_x1, wall_x2, wall_x3, wall_x4])
    wall_y = np.concatenate([wall_y1, wall_y2, wall_y3, wall_y4])
    r1 = np.ones_like(wall_x) * r_s
    m1 = r1 * dx_s * dx_s
    h1 = np.ones_like(wall_x) * dx_s * hdx
    cs1 = np.zeros_like(wall_x)
    rad1 = np.ones_like(wall_x) * dx_s
    wall = get_particle_array(name='wall', x=wall_x, y=wall_y, h=h1, rho=r1,
                              m=m1, cs=cs1, rad_s=rad1)
    f_center = np.array([3.0 * wall_l / 8.0, wall_h / 2.0])
    x2, y2 = get_2d_block(dx_f, fluid_l, fluid_h, f_center)
    r2 = np.ones_like(x2) * r_f
    m2 = r2 * dx_f * dx_f
    h2 = np.ones_like(x2) * dx_f * hdx
    cs2 = np.zeros_like(x2)
    rad2 = np.ones_like(x2) * dx_f
    fluid = get_particle_array(name='fluid', x=x2, y=y2, h=h2, rho=r2, m=m2,
                               cs=cs2, rad_s=rad2)
    center1 = np.array([wall_l / 8.0 + cube_s / 2.0,
                        wall_h / 4.0 + cube_s / 2.0])
    cube1_x, cube1_y = get_2d_block(dx_s, cube_s, cube_s, center1)
    b1 = np.zeros_like(cube1_x, dtype=int)
    center2 = np.array([3.0 * wall_l / 4.0 + cube_s / 2.0 + 3.0 * dx_s,
                        wall_h + cube_s / 2.0 + (num_layers + 1) * dx_s])
    cube2_x, cube2_y = get_2d_block(dx_s, cube_s, cube_s, center2)
    b2 = np.ones_like(cube2_x, dtype=int)
    b = np.concatenate([b1, b2])
    x3 = np.concatenate([cube1_x, cube2_x])
    y3 = np.concatenate([cube1_y, cube2_y])
    r3 = np.ones_like(x3) * r_s * 0.5
    m3 = r3 * dx_s * dx_s
    h3 = np.ones_like(x3) * dx_s * hdx
    cs3 = np.zeros_like(x3)
    rad3 = np.ones_like(x3) * dx_s
    cube = get_particle_array_rigid_body(
        name='cube', x=x3, y=y3, h=h3, cs=cs3, rho=r3, m=m3, rad_s=rad3,
        body_id=b)
    remove_overlap_particles(fluid, wall, dx_s, 2)
    return fluid, wall, cube
コード例 #2
0
ファイル: case4.py プロジェクト: mahgadalla/pysph-1
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
コード例 #3
0
ファイル: rod_adami_pysph.py プロジェクト: vikaskurapati/DDP
    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)
        for i in range(len(fluid.x)):
            if (fluid.x[i]*fluid.x[i] + fluid.y[i]*fluid.y[i]) < 0.04:
                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[:] = nu0

        return [fluid, wall]
コード例 #4
0
ファイル: st_bouscasse.py プロジェクト: yang7857854/pysph
    def create_particles(self):
        dx = self.dx
        h0 = self.h0
        volume = dx * dx
        m = rho * volume

        xt, yt = get_2d_tank(dx=dx,
                             length=L,
                             height=0.2 * L,
                             num_layers=n_layers,
                             base_center=[L / 2, -dx])

        xf, yf = get_2d_block(dx=dx,
                              length=L - 2 * dx,
                              height=h,
                              center=[L / 2, h / 2])

        fluid = get_particle_array(name='fluid',
                                   x=xf,
                                   y=yf,
                                   h=h0,
                                   m=m,
                                   rho=rho)
        solid = get_particle_array(name='solid',
                                   x=xt,
                                   y=yt,
                                   h=h0,
                                   m=m,
                                   rho=rho)

        fluid.u = -amp * omega * np.ones_like(xf)

        self.scheme.setup_properties([fluid, solid])
        particles = [fluid, solid]
        return particles
コード例 #5
0
    def setUp(self):
        self.l = l = 1.0
        n = 20
        dx = l / n
        hdx = 1.5

        x, y, z = G.get_3d_block(dx, l, l, l)
        h = np.ones_like(x) * hdx * dx
        m = np.ones_like(x) * dx * dx * dx
        V = np.zeros_like(x)
        fluid = get_particle_array(name='fluid', x=x, y=y, z=z, h=h, m=m, V=V)

        x, y = G.get_2d_block(dx, l, l)
        z = np.ones_like(x) * (l + 5 * dx) / 2.0
        z = np.concatenate([z, -z])
        x = np.tile(x, 2)
        y = np.tile(y, 2)
        m = np.ones_like(x) * dx * dx * dx
        h = np.ones_like(x) * hdx * dx
        V = np.zeros_like(x)
        channel = get_particle_array(name='channel',
                                     x=x,
                                     y=y,
                                     z=z,
                                     h=h,
                                     m=m,
                                     V=V)

        self.particles = [fluid, channel]
        self.kernel = get_compiled_kernel(Gaussian(dim=3))
コード例 #6
0
    def create_particles(self):
        dx = self.dx
        h0 = self.hdx * self.dx
        m = rho * dx * dx

        xt, yt = get_2d_tank(dx=dx,
                             length=length,
                             height=h_tank,
                             num_layers=n_layers,
                             base_center=[0.0, -dx])

        xf, yf = get_2d_block(dx=dx,
                              length=length - 2 * dx,
                              height=h_liquid,
                              center=[0.0, h_liquid * 0.5])

        fluid = get_particle_array(name='fluid',
                                   x=xf,
                                   y=yf,
                                   h=h0,
                                   m=m,
                                   rho=rho)
        solid = get_particle_array(name='solid',
                                   x=xt,
                                   y=yt,
                                   h=h0,
                                   m=m,
                                   rho=rho)

        self.scheme.setup_properties([fluid, solid])
        particles = [fluid, solid]
        return particles
コード例 #7
0
ファイル: case7.py プロジェクト: mahgadalla/pysph-1
def get_wavespaddle_geometry(hdx=1.,
                             dx_f=0.02,
                             dx_s=0.02,
                             r_f=100.,
                             r_s=100.,
                             length=13.,
                             height=0.8,
                             flat_l=1.48,
                             h_fluid=0.43,
                             angle=2.8624):
    x1, y1, x2, y2 = get_beach_geometry_2d(dx_s, length, height, flat_l, angle,
                                           3)
    theta = np.pi * angle / 180.0
    p1x = flat_l - 9.605
    p1y = 0.40625
    p2x = flat_l - 10.065
    p2y = 0.6085
    theta1 = np.arctan((p2y - p1y) / (p2x - p1x))
    p3x = flat_l - 10.28
    p3y = 0.6085
    theta2 = np.arctan((p3y - p2y) / (p3x - p2x))
    p4x = flat_l - 10.62
    p4y = 0.457
    theta3 = np.arctan((p4y - p3y) / (p4x - p3x))
    obs_x1 = np.arange(p2x, p1x, dx_s / 2.0)
    obs_y1 = p1y + (obs_x1 - p1x) * np.tan(theta1)
    obs_x2 = np.arange(p3x, p2x, dx_s / 2.0)
    obs_y2 = p2y + (obs_x2 - p2x) * np.tan(-theta2)
    obs_x3 = np.arange(p4x, p3x, dx_s / 2.0)
    obs_y3 = p3y + (obs_x3 - p3x) * np.tan(theta3)
    x1 = np.concatenate([x1, obs_x1, obs_x2, obs_x3])
    y1 = np.concatenate([y1, obs_y1, obs_y2, obs_y3])
    r1 = np.ones_like(x1) * r_s
    m1 = r1 * dx_s * dx_s
    h1 = np.ones_like(x1) * hdx * dx_s
    wall = get_particle_array(name='wall', x=x1, y=y1, rho=r1, m=m1, h=h1)
    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 = []
    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
    fluid = get_particle_array(name='fluid', x=x3, y=y3, rho=r3, m=m3, h=h3)
    remove_overlap_particles(fluid, wall, dx_s, 2)
    remove_overlap_particles(fluid, paddle, dx_s, 2)
    return fluid, wall, paddle
コード例 #8
0
ファイル: case2.py プロジェクト: drwanghan/pysph
def get_dam_geometry(dx_tank=0.03,
                     dx_fluid=0.03,
                     r_tank=100.0,
                     h_f=2.0,
                     l_f=1.0,
                     r_fluid=100.0,
                     hdx=1.5,
                     l_tank=4.0,
                     h_tank=4.0,
                     h_f2=1.0):
    tank_x, tank_y = get_2d_tank(dx_tank,
                                 length=l_tank,
                                 height=h_tank,
                                 num_layers=4)
    rho_tank = np.ones_like(tank_x) * r_tank
    m_tank = rho_tank * dx_tank * dx_tank
    h_t = np.ones_like(tank_x) * dx_tank * hdx
    tank = get_particle_array(name='dam',
                              x=tank_x,
                              y=tank_y,
                              h=h_t,
                              rho=rho_tank,
                              m=m_tank)
    center = np.array([(l_f - l_tank) / 2.0, h_f / 2.0])
    fluid_x1, fluid_y1 = get_2d_block(dx_fluid, l_f, h_f, center)
    center = np.array([l_f / 2.0, h_f2 / 2.0])
    fluid_x2, fluid_y2 = get_2d_block(dx_fluid, l_tank - l_f - 2.0 * dx_fluid,
                                      h_f2, center)
    fluid_x = np.concatenate([fluid_x1, fluid_x2])
    fluid_y = np.concatenate([fluid_y1, fluid_y2])
    h_fluid = 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_fluid,
                               rho=r_f,
                               m=m_f)
    remove_overlap_particles(fluid, tank, dx_tank, 2)
    return fluid, tank
コード例 #9
0
ファイル: test_geometry.py プロジェクト: drwanghan/pysph
 def test_get_2d_block(self):
     dx = (10.0)**(np.random.uniform(-2, -1))
     center = np.random.random_sample(2)
     length = np.random.randint(50, 200) * dx
     height = np.random.randint(50, 200) * dx
     x, y = get_2d_block(dx, length, height, center)
     len_x = max(x) - min(x)
     len_y = max(y) - min(y)
     new_center = np.array([(max(x) + min(x)) / 2.0,
                            (max(y) + min(y)) / 2.0])
     self.assertAlmostEqual(len_x, length)
     self.assertAlmostEqual(len_y, height)
     assert np.allclose(new_center, center)
コード例 #10
0
ファイル: test_geometry.py プロジェクト: yang7857854/pysph
 def test_get_2d_block(self):
     dx = 0.05
     length = 5.0
     height = 4.0
     center = np.array([0.4, 10.3])
     x, y = G.get_2d_block(dx, length, height, center)
     len_x = max(x) - min(x)
     len_y = max(y) - min(y)
     new_center = np.array([(max(x) + min(x)) / 2.0,
                            (max(y) + min(y)) / 2.0])
     assert len_x == pytest.approx(length)
     assert len_y == pytest.approx(height)
     assert np.allclose(new_center, center)
コード例 #11
0
ファイル: dam_break_2d.py プロジェクト: magicknight/pysph
    def create_particles(self):
        if self.options.staggered_grid:
            nboundary_layers = 2
            nfluid_offset = 2
            wall_hex_pack = True
        else:
            nboundary_layers = 4
            nfluid_offset = 1
            wall_hex_pack = False
        xt, yt = get_2d_tank(dx=self.dx, length=container_width,
                             height=container_height, base_center=[2, 0],
                             num_layers=nboundary_layers)
        xf, yf = get_2d_block(dx=self.dx, length=fluid_column_width,
                              height=fluid_column_height, center=[0.5, 1])

        xf += self.dx
        yf += self.dx

        fluid = get_particle_array(name='fluid', x=xf, y=yf, h=h, m=m, rho=ro)
        boundary = get_particle_array(name='boundary', x=xt, y=yt, h=h, m=m,
                                      rho=ro)

        self.scheme.setup_properties([fluid, boundary])
        if self.options.scheme == 'iisph':
            # the default position tends to cause the particles to be pushed
            # away from the wall, so displacing it by a tiny amount helps.
            fluid.x += self.dx / 4

        # Adding extra properties for kernel correction
        corr = self.kernel_corr
        if corr == 'kernel-corr' or corr == 'mixed-corr':
            fluid.add_property('cwij')
            boundary.add_property('cwij')
        if corr == 'mixed-corr' or corr == 'grad-corr':
            fluid.add_property('m_mat', stride=9)
            boundary.add_property('m_mat', stride=9)
        elif corr == 'crksph':
            fluid.add_property('ai')
            boundary.add_property('ai')
            fluid.add_property('gradbi', stride=9)
            boundary.add_property('gradbi', stride=9)
            for prop in ['gradai', 'bi']:
                fluid.add_property(prop, stride=3)
                boundary.add_property(prop, stride=3)

        return [fluid, boundary]
コード例 #12
0
    def create_particles(self):
        if self.options.staggered_grid:
            nboundary_layers = 2
            nfluid_offset = 2
            wall_hex_pack = True
        else:
            nboundary_layers = 4
            nfluid_offset = 1
            wall_hex_pack = False

        xt, yt = get_2d_tank(dx=self.dx,
                             length=container_width,
                             height=container_height,
                             base_center=[container_width / 2, 0],
                             num_layers=nboundary_layers)

        xf, yf = get_2d_block(
            dx=self.dx,
            length=fluid_column_width,
            height=fluid_column_height,
            center=[fluid_column_width / 2, fluid_column_height / 2])

        xf += self.dx
        yf += self.dx

        fluid = get_particle_array(name='fluid', x=xf, y=yf, h=h, m=m, rho=ro)
        boundary = get_particle_array(name='boundary',
                                      x=xt,
                                      y=yt,
                                      h=h,
                                      m=m,
                                      rho=ro)

        self.scheme.setup_properties([fluid, boundary])
        if self.options.scheme == 'iisph':
            # the default position tends to cause the particles to be pushed
            # away from the wall, so displacing it by a tiny amount helps.
            fluid.x += self.dx / 4

        self.kernel_corrections(fluid, boundary)

        return [fluid, boundary]
コード例 #13
0
 def create_particles(self):
     fluid_x, fluid_y = get_2d_block(dx=dx,
                                     length=Lx - dx,
                                     height=Ly - dx,
                                     center=np.array([0., 0.5 * Ly]))
     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
     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',
         'pi00', 'pi01', 'pi02', 'pi10', 'pi11', 'pi12', 'pi20', 'pi21',
         'pi22'
     ]
     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)
     for i in range(len(fluid.x)):
         if fluid.y[i] > 0.25 and fluid.y[i] < 0.75:
             fluid.color[i] = 1.0
         else:
             fluid.color[i] = 0.0
     fluid.V[:] = 1. / volume
     fluid.add_output_arrays([
         'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
         'scolor', 'p'
     ])
     angles = np.random.random_sample((len(fluid.x), )) * 2 * np.pi
     vel = np.sqrt(2 * KE / fluid.m)
     fluid.u = vel
     fluid.v = vel
     fluid.nu[:] = 0.0
     return [fluid]
コード例 #14
0
 def create_particles(self):
     fluid_x, fluid_y = get_2d_block(dx=dx,
                                     length=Lx - dx,
                                     height=Ly - dx,
                                     center=np.array([0., 0.]))
     rho_fluid = np.ones_like(fluid_x) * rho1
     m_fluid = rho_fluid * volume
     h_fluid = np.ones_like(fluid_x) * h0
     cs_fluid = np.ones_like(fluid_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'
     ]
     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.0625:
             fluid.color[i] = 1.0
         else:
             fluid.color[i] = 0.0
     fluid.V[:] = 1. / volume
     fluid.add_output_arrays([
         'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
         'scolor', 'p'
     ])
     # angles = np.random.random_sample((len(fluid.x),))*2*np.pi
     # vel = np.sqrt(2 * KE / fluid.m)
     # fluid.u = vel*2.0*np.cos(angles)
     # fluid.v = vel*2.0*np.sin(angles)
     fluid.nu[:] = nu0
     return [fluid]
コード例 #15
0
ファイル: equilibrium_rod.py プロジェクト: yang7857854/pysph
    def create_particles(self):
        fluid_x, fluid_y = get_2d_block(dx=dx,
                                        length=Lx - dx,
                                        height=Ly - dx,
                                        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
        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',
            'pi00', 'pi01', 'pi02', 'pi10', 'pi11', 'pi12', 'pi20', 'pi21',
            'pi22', 'alpha'
        ]

        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)
        fluid.alpha[:] = sigma
        for i in range(len(fluid.x)):
            if (fluid.x[i] * fluid.x[i] + fluid.y[i] * fluid.y[i]) < 0.0625:
                fluid.color[i] = 1.0
            else:
                fluid.color[i] = 0.0
        fluid.V[:] = 1. / volume
        fluid.add_output_arrays([
            'V', 'color', 'cx', 'cy', 'nx', 'ny', 'ddelta', 'kappa', 'N',
            'scolor', 'p'
        ])
        fluid.nu[:] = nu
        return [fluid]
コード例 #16
0
ファイル: case3.py プロジェクト: drwanghan/pysph
def get_wavespaddle_geometry(hdx=1.5,
                             dx_f=0.1,
                             dx_s=0.1,
                             r_f=100.,
                             r_s=100.,
                             length=3.75,
                             height=0.3,
                             flat_l=1.,
                             angle=4.2364,
                             h_fluid=0.2):
    x1, y1, x2, y2 = get_beach_geometry_2d(dx_s, length, height, flat_l, angle,
                                           5)
    r1 = np.ones_like(x1) * r_s
    m1 = r1 * dx_s * dx_s
    h1 = np.ones_like(x1) * hdx * dx_s
    wall = get_particle_array(name='wall', x=x1, y=y1, rho=r1, m=m1, h=h1)
    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
    fluid = get_particle_array(name='fluid', x=x3, y=y3, rho=r3, m=m3, h=h3)
    remove_overlap_particles(fluid, wall, dx_s, 2)
    remove_overlap_particles(fluid, paddle, dx_s, 2)
    return fluid, wall, paddle
コード例 #17
0
ファイル: test_geometry.py プロジェクト: yang7857854/pysph
 def test_remove_overlap_particles(self):
     dx_1 = 0.1
     dx_2 = 0.15
     length = 4.5
     height = 3.0
     radius = 2.0
     x1, y1 = G.get_2d_block(dx_1, length, height)
     x2, y2 = G.get_2d_circle(dx_2, radius)
     r1 = np.ones_like(x1) * 100.0
     m1 = r1 * dx_1 * dx_1
     h1 = np.ones_like(x1) * dx_1 * 1.5
     fluid = get_particle_array(name='fluid',
                                x=x1,
                                y=y1,
                                h=h1,
                                rho=r1,
                                m=m1)
     r2 = np.ones_like(x2) * 100.0
     m2 = r2 * dx_2 * dx_2
     h2 = np.ones_like(x2) * dx_2 * 1.5
     solid = get_particle_array(name='solid',
                                x=x2,
                                y=y2,
                                h=h2,
                                rho=r2,
                                m=m2)
     G.remove_overlap_particles(fluid, solid, dx_2, 2)
     x1 = fluid.x
     y1 = fluid.y
     count = 0
     for i in range(len(x1)):
         point = np.array([x1[i], y1[i]])
         dist = G.distance_2d(point)
         if dist <= radius:
             count += 1
     assert count == 0
コード例 #18
0
ファイル: case1.py プロジェクト: mahgadalla/pysph-1
def get_dam_geometry(dx_tank=0.03,
                     dx_fluid=0.03,
                     r_tank=100.0,
                     h_f=2.0,
                     l_f=1.0,
                     r_fluid=100.0,
                     hdx=1.5,
                     l_tank=4.0,
                     h_tank=4.0):
    tank_x, tank_y = get_2d_tank(dx_tank,
                                 length=l_tank,
                                 height=h_tank,
                                 num_layers=5)
    rho_tank = np.ones_like(tank_x) * r_tank
    m_tank = rho_tank * dx_tank * dx_tank
    h_t = np.ones_like(tank_x) * dx_tank * hdx
    tank = get_particle_array(name='dam',
                              x=tank_x,
                              y=tank_y,
                              h=h_t,
                              rho=rho_tank,
                              m=m_tank)
    center = np.array([(l_f - l_tank) / 2.0, h_f / 2.0])
    fluid_x, fluid_y = get_2d_block(dx_fluid, l_f, h_f, center)
    fluid_x += dx_tank
    fluid_y += dx_tank
    h_fluid = 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_fluid,
                               rho=r_f,
                               m=m_f)
    return fluid, tank
コード例 #19
0
ファイル: test_geometry.py プロジェクト: drwanghan/pysph
 def test_remove_overlap_particles(self):
     dx_1 = (10)**(np.random.randint(-2, -1))
     dx_2 = (10)**(np.random.randint(-2, -1))
     length = np.random.randint(20, 40) * dx_1
     height = np.random.randint(20, 40) * dx_1
     radius = np.random.randint(20, 40) * dx_2
     x1, y1 = get_2d_block(dx_1, length, height)
     x2, y2 = get_2d_circle(dx_2, radius)
     r1 = np.ones_like(x1) * 100.0
     m1 = r1 * dx_1 * dx_1
     h1 = np.ones_like(x1) * dx_1 * 1.5
     fluid = get_particle_array(name='fluid',
                                x=x1,
                                y=y1,
                                h=h1,
                                rho=r1,
                                m=m1)
     r2 = np.ones_like(x2) * 100.0
     m2 = r2 * dx_2 * dx_2
     h2 = np.ones_like(x2) * dx_2 * 1.5
     solid = get_particle_array(name='solid',
                                x=x2,
                                y=y2,
                                h=h2,
                                rho=r2,
                                m=m2)
     remove_overlap_particles(fluid, solid, dx_2, 2)
     x1 = fluid.x
     y1 = fluid.y
     count = 0
     for i in range(len(x1)):
         point = np.array([x1[i], y1[i]])
         dist = distance_2d(point)
         if dist <= radius:
             count += 1
     assert count == 0
コード例 #20
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
コード例 #21
0
def windtunnel_airfoil_model(dx_wall=0.01,
                             dx_airfoil=0.01,
                             dx_fluid=0.01,
                             r_solid=100.0,
                             r_fluid=100.0,
                             airfoil='2412',
                             hdx=1.1,
                             chord=1.0,
                             h_tunnel=1.0,
                             l_tunnel=10.0):
    """
    Generates a geometry which can be used for wind tunnel like simulations.

    Parameters
    ----------
    dx_wall : a number which is the dx of the wind tunnel wall
    dx_airfoil : a number which is the dx of the airfoil used
    dx_fluid : a number which is the dx of the fluid used
    r_solid : a number which is the initial density of the solid particles
    r_fluid : a number which is the initial density of the fluid particles
    airfoil : 4 or 5 digit string which is the airfoil name
    hdx : a number which is the hdx for the particle arrays
    chord : a number which is the chord of the airfoil
    h_tunnel : a number which is the height of the wind tunnel
    l_tunnel : a number which is the length of the wind tunnel

    Returns
    -------
    wall : pysph wcsph particle array for the wind tunnel walls
    wing : pysph wcsph particle array for the airfoil
    fluid : pysph wcsph particle array for the fluid
    """

    wall_center_1 = np.array([0.0, h_tunnel / 2.])
    wall_center_2 = np.array([0.0, -h_tunnel / 2.])
    x_wall_1, y_wall_1 = get_2d_wall(dx_wall, wall_center_1, l_tunnel)
    x_wall_2, y_wall_2 = get_2d_wall(dx_wall, wall_center_2, l_tunnel)
    x_wall = np.concatenate([x_wall_1, x_wall_2])
    y_wall = np.concatenate([y_wall_1, y_wall_2])
    y_wall_1 = y_wall_1 + dx_wall
    y_wall_2 = y_wall_2 - dx_wall
    y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2])
    y_wall_1 = y_wall_1 + dx_wall
    y_wall_2 = y_wall_2 - dx_wall
    y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2])
    y_wall_1 = y_wall_1 + dx_wall
    y_wall_2 = y_wall_2 - dx_wall
    x_wall = np.concatenate([x_wall, x_wall, x_wall, x_wall])
    y_wall = np.concatenate([y_wall, y_wall_1, y_wall_2])
    h_wall = np.ones_like(x_wall) * dx_wall * hdx
    rho_wall = np.ones_like(x_wall) * r_solid
    mass_wall = rho_wall * dx_wall * dx_wall
    wall = get_particle_array_wcsph(name='wall',
                                    x=x_wall,
                                    y=y_wall,
                                    h=h_wall,
                                    rho=rho_wall,
                                    m=mass_wall)
    if len(airfoil) == 4:
        x_airfoil, y_airfoil = get_4digit_naca_airfoil(dx_airfoil, airfoil,
                                                       chord)
    else:
        x_airfoil, y_airfoil = get_5digit_naca_airfoil(dx_airfoil, airfoil,
                                                       chord)
    x_airfoil = x_airfoil - 0.5
    h_airfoil = np.ones_like(x_airfoil) * dx_airfoil * hdx
    rho_airfoil = np.ones_like(x_airfoil) * r_solid
    mass_airfoil = rho_airfoil * dx_airfoil * dx_airfoil
    wing = get_particle_array_wcsph(name='wing',
                                    x=x_airfoil,
                                    y=y_airfoil,
                                    h=h_airfoil,
                                    rho=rho_airfoil,
                                    m=mass_airfoil)
    x_fluid, y_fluid = get_2d_block(dx_fluid, 1.6, h_tunnel)
    h_fluid = np.ones_like(x_fluid) * dx_fluid * hdx
    rho_fluid = np.ones_like(x_fluid) * r_fluid
    mass_fluid = rho_fluid * dx_fluid * dx_fluid
    fluid = get_particle_array_wcsph(name='fluid',
                                     x=x_fluid,
                                     y=y_fluid,
                                     h=h_fluid,
                                     rho=rho_fluid,
                                     m=mass_fluid)
    remove_overlap_particles(fluid, wall, dx_wall, 2)
    remove_overlap_particles(fluid, wing, dx_airfoil, 2)
    return wall, wing, fluid
コード例 #22
0
ファイル: adami_2.py プロジェクト: vikaskurapati/DDP
    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', 'pi10', 'pi11'
        ]
        consts = {'max_ddelta': np.zeros(1, dtype=float)}
        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,
                                 constants=consts)
        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,
                                    constants=consts)
        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])
            gas.u[i] = v0 * gas.x[i] * (1.0 - (gas.y[i] * gas.y[i]) /
                                        (r0 * R)) * np.exp(-R / r0) / r0
            gas.v[i] = -v0 * gas.y[i] * (1.0 - (gas.x[i] * gas.x[i]) /
                                         (r0 * R)) * np.exp(-R / r0) / 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))*np.exp(-R/r0)/r0
            liquid.v[i] = -v0*liquid.y[i] * \
                (1.0 - (liquid.x[i]*liquid.x[i])/(r0*R))*np.exp(-R/r0)/r0
        return [liquid, gas, wall]