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
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]
logger.addHandler(logging.StreamHandler()) # local imports from pysph.base.particle_array import ParticleArray from pysph.parallel.parallel_cell import ParallelCellManager from pysph.solver.basic_generators import RectangleGenerator from pysph.base.cell import INT_INF from pysph.base.point import * pcm = ParallelCellManager(initialize=False, dimension=2) parray = ParticleArray(name='parray') if rank == 0: lg = RectangleGenerator(particle_spacing_x1=0.1, particle_spacing_x2=0.1) x, y, z = lg.get_coords() parray.add_property({'name':'x', 'data':x}) parray.add_property({'name':'y', 'data':y}) parray.add_property({'name':'z', 'data':z}) parray.add_property({'name':'h'}) parray.align_particles() parray.h[:] = 0.1 else: parray.add_property({'name':'x'}) parray.add_property({'name':'y'}) parray.add_property({'name':'z'}) parray.add_property({'name':'h'}) pcm.add_array_to_bin(parray)
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]
logging.basicConfig(level=logging.DEBUG, filename=log_file_name, filemode='w') logger.addHandler(logging.StreamHandler()) # local imports from pysph.base.particle_array import ParticleArray from pysph.parallel.parallel_cell import ParallelCellManager from pysph.solver.basic_generators import RectangleGenerator from pysph.base.cell import INT_INF from pysph.base.point import * pcm = ParallelCellManager(initialize=False, dimension=2) parray = ParticleArray(name='parray') if rank == 0: lg = RectangleGenerator(particle_spacing_x1=0.1, particle_spacing_x2=0.1) x, y, z = lg.get_coords() parray.add_property({'name': 'x', 'data': x}) parray.add_property({'name': 'y', 'data': y}) parray.add_property({'name': 'z', 'data': z}) parray.add_property({'name': 'h'}) parray.align_particles() parray.h[:] = 0.1 else: parray.add_property({'name': 'x'}) parray.add_property({'name': 'y'}) parray.add_property({'name': 'z'}) parray.add_property({'name': 'h'}) pcm.add_array_to_bin(parray)