示例#1
0
 def setUp(self):
     lg = RectangleGenerator(kernel=CubicSplineKernel(2))
     self.pas = [lg.get_particles()]
     self.pas[0].x += 0.1
     self.pas[0].y += 0.2
     self.cell_size = 0.1
     self.dim = 2
示例#2
0
    def test_get_particles(self):
        """
        Tests the get_particles function.
        """
        lg = LineGenerator(particle_spacing=0.5, kernel=CubicSplineKernel(3))

        particle_array = lg.get_particles()
        self.assertEqual(particle_array.get_number_of_particles(), 3)

        self.assertEqual(check_array(particle_array.x, [0, 0, 0]), True)
        self.assertEqual(check_array(particle_array.y, [0, 0, 0]), True)
        self.assertEqual(check_array(particle_array.z, [0, 0.5, 1.0]), True)
        self.assertEqual(check_array(particle_array.h, [0.1, 0.1, 0.1]), True)
        self.assertEqual(
            check_array(particle_array.rho, [1000., 1000., 1000.]), True)
        self.assertEqual(
            check_array(particle_array.m, [1000. / 318.30988618379064] * 3),
            True)

        lg.particle_spacing = 0.1
        particle_array = lg.get_particles()
        m = particle_array.m[0]
        # just make sure the mass returned is less than the previous case.
        # exact computation not done currently.
        self.assertEqual(m < 1000 / 318.30988618379064, True)
示例#3
0
 def setUp(self):
     lg = LineGenerator(kernel=CubicSplineKernel(1))
     lg.end_point.x = 1.0
     lg.end_point.z = 0.0
     self.pas = [lg.get_particles()]
     self.pas[0].x += 0.1
     self.cell_size = 0.1
     self.dim = 1
示例#4
0
 def setUp(self):
     lg = CuboidGenerator(kernel=CubicSplineKernel(3))
     self.pas = [lg.get_particles()]
     # to shift the origin
     self.pas[0].x += 0.1
     self.pas[0].y += 0.2
     self.pas[0].z += 0.3
     self.cell_size = 0.1
     self.dim = 3
示例#5
0
    def test_get_particles(self):
        """
        Tests the get_particles function.
        """
        pg = ParticleGenerator()
        self.assertEqual(pg.validate_setup(), False)

        pg.kernel = CubicSplineKernel()
        self.assertRaises(NotImplementedError, pg.get_particles)
        self.assertRaises(NotImplementedError, pg.get_coords)
        self.assertRaises(NotImplementedError, pg.generate_func)
示例#6
0
 def test_get_particles(self):
     """
     Tests the get_particles function.
     """
     rg = RectangleGenerator(particle_spacing_x1=0.5,
                             particle_spacing_x2=0.5,
                             kernel=CubicSplineKernel(3))
     p = rg.get_particles()
     self.assertEqual(p.get_number_of_particles(), 9)
     self.assertEqual(
         check_array(p.x, [0, 0.0, 0.0, 0.5, 0.5, 0.5, 1.0, 1.0, 1.0]),
         True)
     self.assertEqual(
         check_array(p.y, [0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0]),
         True)
     self.assertEqual(check_array(p.z, [0, 0, 0, 0, 0, 0, 0, 0, 0]), True)
     self.assertEqual(check_array(p.h, [0.1] * 9), True)
     self.assertEqual(check_array(p.rho, [1000.] * 9), True)
     self.assertEqual(check_array(p.m, [1000. / 318.30988618379064] * 9),
                      True)
示例#7
0
def create_particles(options):
    if options.type == "square":
        # create the square block of particles.
        start_point = Point(0, 0, 0)
        end_point = Point(options.square_width, options.square_width, 0)

        parray = ParticleArray()
        if rank == 0:
            rg = RectangleGenerator(
                start_point=start_point,
                end_point=end_point,
                particle_spacing_x1=options.particle_spacing,
                particle_spacing_x2=options.particle_spacing,
                density_computation_mode=Dcm.Set_Constant,
                particle_density=1000.0,
                mass_computation_mode=Mcm.Compute_From_Density,
                particle_h=options.particle_radius,
                kernel=CubicSplineKernel(2),
                filled=True)
            tmp = rg.get_particles()
            parray.append_parray(tmp)

        if rank != 0:
            # add some necessary properties to the particle array.
            parray.add_property({'name': 'x'})
            parray.add_property({'name': 'y'})
            parray.add_property({'name': 'z'})
            parray.add_property({
                'name': 'h',
                'default': options.particle_radius
            })
            parray.add_property({'name': 'rho', 'default': 1000.})
            parray.add_property({'name': 'pid'})
            parray.add_property({'name': '_tmp', 'default': 0.0})
            parray.add_property({'name': 'm'})
        else:
            parray.add_property({'name': '_tmp'})
            parray.add_property({'name': 'pid', 'default': 0.0})

        return [parray]

    elif options.type == "dam_break":

        dam_wall = ParticleArray()
        dam_fluid = ParticleArray()

        if rank == 0:

            radius = 0.2
            dam_width = 10.0
            dam_height = 7.0
            solid_particle_h = radius
            dam_particle_spacing = radius / 9.
            solid_particle_mass = 1.0
            origin_x = origin_y = 0.0

            fluid_particle_h = radius
            fluid_density = 1000.
            fluid_column_height = 3.0
            fluid_column_width = 2.0
            fluid_particle_spacing = radius

            # generate the left wall - a line
            lg = LineGenerator(particle_mass=solid_particle_mass,
                               mass_computation_mode=Mcm.Set_Constant,
                               density_computation_mode=Dcm.Ignore,
                               particle_h=solid_particle_h,
                               start_point=Point(0, 0, 0),
                               end_point=Point(0, dam_height, 0),
                               particle_spacing=dam_particle_spacing)
            tmp = lg.get_particles()
            dam_wall.append_parray(tmp)

            # generate one half of the base
            lg.start_point = Point(dam_particle_spacing, 0, 0)
            lg.end_point = Point(dam_width / 2, 0, 0)
            tmp = lg.get_particles()
            dam_wall.append_parray(tmp)

            # generate particles for the left column of fluid.
            rg = RectangleGenerator(
                start_point=Point(origin_x + 2.0 * solid_particle_h,
                                  origin_y + 2.0 * solid_particle_h, 0.0),
                end_point=Point(
                    origin_x + 2.0 * solid_particle_h + fluid_column_width,
                    origin_y + 2.0 * solid_particle_h + fluid_column_height,
                    0.0),
                particle_spacing_x1=fluid_particle_spacing,
                particle_spacing_x2=fluid_particle_spacing,
                density_computation_mode=Dcm.Set_Constant,
                mass_computation_mode=Mcm.Compute_From_Density,
                particle_density=1000.,
                particle_h=fluid_particle_h,
                kernel=CubicSplineKernel(2),
                filled=True)
            dam_fluid = rg.get_particles()

            # generate the right wall - a line
            lg = LineGenerator(particle_mass=solid_particle_mass,
                               mass_computation_mode=Mcm.Set_Constant,
                               density_computation_mode=Dcm.Ignore,
                               particle_h=solid_particle_h,
                               start_point=Point(dam_width, 0, 0),
                               end_point=Point(dam_width, dam_height, 0),
                               particle_spacing=dam_particle_spacing)

            tmp = lg.get_particles()
            dam_wall.append_parray(tmp)

            # generate the right half of the base
            lg.start_point = Point(dam_width / 2. + dam_particle_spacing, 0, 0)
            lg.end_point = Point(dam_width, 0, 0)
            tmp = lg.get_particles()
            dam_wall.append_parray(tmp)

        for parray in [dam_fluid, dam_wall]:

            if rank != 0:
                # add some necessary properties to the particle array.
                parray.add_property({'name': 'x'})
                parray.add_property({'name': 'y'})
                parray.add_property({'name': 'z'})
                parray.add_property({
                    'name': 'h',
                    'default': options.particle_radius
                })
                parray.add_property({'name': 'rho', 'default': 1000.})
                parray.add_property({'name': 'pid'})
                parray.add_property({'name': '_tmp', 'default': 0.0})
                parray.add_property({'name': 'm'})
            else:
                parray.add_property({'name': '_tmp'})
                parray.add_property({'name': 'pid', 'default': 0.0})

        return [dam_fluid, dam_wall]
    x = numpy.linspace(0, 1, 11)
    h = numpy.ones_like(x) * 0.2
    m = numpy.ones_like(x) * 0.1
    rho = numpy.ones_like(x)
    fval = x * x

#create the particles on processor 1
if rank == 1:
    x = numpy.linspace(1.1, 2, 10)
    h = numpy.ones_like(x) * 0.2
    m = numpy.ones_like(x) * 0.1
    rho = numpy.ones_like(x)
    fval = x * x

#create the particles in parallel without load balancing
kernel = CubicSplineKernel(dim=1)
pa = get_particle_array(x=x, h=h, m=m, fval=fval, rho=rho)
particles = Particles([pa], in_parallel=True, load_balancing=False)

#make sure the particles need updating
particles.update()

#choose the function and the sph calc
func = sph.SPHRho(pa, pa)
calc = sph.SPHCalc(particles=particles,
                   kernel=kernel,
                   func=func,
                   updates=['rho'],
                   integrates=False)

tmpx = pa.get('tmpx', only_real_particles=False)