コード例 #1
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
コード例 #2
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
コード例 #3
0
    def create_particles(self):
        spc = 0.3
        x = np.array([0, 0])
        y = np.array([0, 0.2])
        soil = get_particle_array(x=x, y=y, m=1, fx=0, fy=0, rad=spc / 2)

        x, y = get_2d_tank(spc, [0.45, -0.3], 2, 2, 2)
        wall = get_particle_array(x=x, y=y, m=1, rad=spc / 2)

        return [soil, wall]
コード例 #4
0
 def test_get_2d_tank(self):
     dx = 0.05
     length = 5.0
     height = 4.0
     center = np.array([1.4, -0.5])
     num_layers = 4
     x, y = G.get_2d_tank(dx, center, length, height, num_layers)
     x_len = max(x) - min(x)
     y_len = max(y) - min(y)
     assert abs(x_len - length - (2.0 * num_layers - 1) * dx) <= 1.001 * dx
     assert abs(y_len - height - num_layers * dx) <= 1.001 * dx
コード例 #5
0
ファイル: test_geometry.py プロジェクト: drwanghan/pysph
 def test_get_2d_tank(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
     num_layers = np.random.randint(1, 4)
     x, y = get_2d_tank(dx, center, length, height, num_layers)
     x_len = max(x) - min(x)
     y_len = max(y) - min(y)
     assert abs(x_len - length - (2.0 * num_layers - 1) * dx) <= 1.001 * dx
     assert abs(y_len - height - num_layers * dx) <= 1.001 * dx
コード例 #6
0
    def create_particles(self):
        spc = 0.1
        x, y = np.mgrid[0:1:spc, 0:1:spc]
        soil = get_particle_array(x=x, y=y, m=1, fx=0, fy=0, rad=spc / 2)

        x, y = get_2d_tank(spc, [0.45, -0.3], 2, 2, 2)
        wall = get_particle_array(x=x, y=y, m=1, rad=spc / 2)
        # import matplotlib.pyplot as plt
        # plt.scatter(tank.x, tank.y)
        # plt.scatter(soil.x, soil.y)
        # plt.show()

        return [soil, wall]
コード例 #7
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]
コード例 #8
0
    def create_particles(self):
        nx, ny = 10, 10
        dx = 1.0 / (nx - 1)
        x, y = np.mgrid[0:1:nx * 1j, 0:1:ny * 1j]
        x = x.flat
        y = y.flat
        m = np.ones_like(x) * 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 / 2.

        body = get_particle_array(name='body', x=x, y=y, h=h, m=m, rad_s=rad_s)
        body_id = np.zeros(len(x), dtype=int)
        body.add_property('body_id', type='int')
        body.body_id[:] = body_id[:]

        self.scheme.setup_properties([body])

        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] = -3.0
        body.vc[1] = -3.0
        body.omega[2] = 1.0

        # this must run
        set_angular_momentum([body])

        # Create the tank.
        x, y = get_2d_tank(dx,
                           base_center=[1., -2.],
                           length=5.0,
                           height=5.0,
                           num_layers=3)
        m = np.ones_like(x) * 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
        tank = get_particle_array(name='tank', x=x, y=y, h=h, m=m, rad_s=rad_s)
        # tank.total_mass[0] = np.sum(m)

        return [body, tank]
コード例 #9
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]
コード例 #10
0
ファイル: test_geometry.py プロジェクト: yang7857854/pysph
 def test_get_2d_tank(self):
     dx = 0.05
     length = 5.0
     height = 4.0
     center = np.random.randn(2)
     num_layers = 4
     x, y = G.get_2d_tank(dx,
                          center,
                          length,
                          height,
                          num_layers,
                          top=False,
                          staggered=False,
                          outside=True)
     offset = (num_layers - 1) * dx
     xmin, xmax, ymin, ymax = min(x), max(x), min(y), max(y)
     lower_true = center[0] - 0.5 * length, center[1]
     upper_true = center[0] + 0.5 * length, center[1] + height
     assert (xmin + offset, ymin + offset) == pytest.approx((lower_true))
     assert (xmax - offset, ymax - offset) == pytest.approx((upper_true))
コード例 #11
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
コード例 #12
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
コード例 #13
0
    def create_particles(self):
        nx = 10
        dx = 1.0 / (nx - 1)
        x4, y4, b4 = create_four_bodies(dx)
        m = np.ones_like(x4) * dx * dx * self.rho0
        h = np.ones_like(x4) * self.hdx * dx
        # radius of each sphere constituting in cube
        rad_s = np.ones_like(x4) * dx / 2.

        body = get_particle_array(name='body',
                                  x=x4,
                                  y=y4,
                                  h=h,
                                  m=m,
                                  rad_s=rad_s)
        body_id = np.zeros(len(x4), dtype=int)
        body.add_property('body_id', type='int')
        body.body_id[:] = b4[:]

        self.scheme.setup_properties([body])

        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')

        # this must run
        set_angular_momentum([body])

        # Create the tank.
        x, y = get_2d_tank(dx,
                           base_center=[1., -2.],
                           length=14.0,
                           height=5.0,
                           num_layers=3)
        m = np.ones_like(x) * 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 / 2.

        tank = get_particle_array(name='tank', x=x, y=y, h=h, m=m, rad_s=rad_s)

        body.vc[0] = -3.0
        body.vc[1] = -3.0
        body.omega[2] = 1.0

        body.vc[3] = -3.0
        body.vc[4] = -3.0
        body.omega[5] = 1.0

        body.vc[6] = -3.0
        body.vc[7] = -3.0
        body.omega[8] = 1.0

        body.vc[9] = -3.0
        body.vc[10] = -3.0
        body.omega[11] = 1.0

        return [body, tank]