Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
# local imports
from pysph.base.particle_array import ParticleArray
from pysph.parallel.parallel_cell import ParallelCellManager
from pysph.solver.basic_generators import LineGenerator
from pysph.base.cell import INT_INF
from pysph.base.point import *


pcm = ParallelCellManager(initialize=False, dimension=1)


parray = ParticleArray(name="parray")

if rank == 0:
    lg = LineGenerator(start_point=Point(0, 0, 0), end_point=Point(1.0, 0, 0), particle_spacing=0.01)
    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.01
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)
Beispiel #4
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]
Beispiel #5
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]
Beispiel #6
0
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 LineGenerator
from pysph.base.cell import INT_INF
from pysph.base.point import *

pcm = ParallelCellManager(initialize=False, dimension=1)

parray = ParticleArray(name='parray')

if rank == 0:
    lg = LineGenerator(start_point=Point(0, 0, 0),
                       end_point=Point(1.0, 0, 0),
                       particle_spacing=0.01)
    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.01
else:
    parray.add_property({'name': 'x'})
    parray.add_property({'name': 'y'})
    parray.add_property({'name': 'z'})
    parray.add_property({'name': 'h'})
Beispiel #7
0
def test():
    pcm = ParallelCellManager(initialize=False)

    # create 2 particles, one with proc 0 another with proc 1

    lg = LineGenerator(particle_spacing=0.5)

    lg.start_point.x = 0.0
    lg.end_point.x = 10.0
    lg.start_point.y = lg.start_point.z = 0.0
    lg.end_point.y = lg.end_point.z = 0.0

    x, y, z = lg.get_coords()
    num_particles = len(x)

    logger.info('Num particles : %d'%(len(x)))

    parray = ParticleArray(name='p1',
                       x={'data':x},
                       y={'data':y},
                       z={'data':z},
                       h={'data':None, 'default':0.5})


    # add parray to the cell manager
    parray.add_property({'name':'u'})
    parray.add_property({'name':'v'})
    parray.add_property({'name':'w'})
    parray.add_property({'name':'rho'})
    parray.add_property({'name':'p'})
    
    parray = LoadBalancer.distribute_particles(parray, num_procs, 1.0)[rank]
    pcm.add_array_to_bin(parray)
    
    np = pcm.arrays_to_bin[0].num_real_particles
    nptot = comm.bcast(comm.reduce(np))
    assert nptot == num_particles

    pcm.initialize()

    np = pcm.arrays_to_bin[0].num_real_particles
    nptot = comm.bcast(comm.reduce(np))
    assert nptot == num_particles
    
    pcm.set_jump_tolerance(INT_INF())

    logger.debug('%d: num_cells=%d'%(rank,len(pcm.cells_dict)))
    logger.debug('%d:'%rank + ('\n%d '%rank).join([str(c) for c  in pcm.cells_dict.values()]))

    # on processor 0 move all particles from one of its cell to the next cell
    if rank == 0:
        cell = pcm.cells_dict.get(list(pcm.proc_map.cell_map.values()[0])[0])
        logger.debug('Cell is %s'%(cell))
        indices = []
        cell.get_particle_ids(indices)
        indices = indices[0]
        logger.debug('Num particles in Cell is %d'%(indices.length))
        parr = cell.arrays_to_bin[0]
        x, y, z = parr.get('x', 'y', 'z', only_real_particles=False)
        logger.debug(str(len(x)) + str(x))
        logger.debug(str(indices.length) + str(indices.get_npy_array()))
        for i in range(indices.length):
            x[indices[i]] += cell.cell_size

        parr.set_dirty(True)

        pcm.update_status()
        logger.debug('Calling cell manager update')
        logger.debug('Is dirty %s'%(pcm.is_dirty))
        pcm.update()

        np = pcm.arrays_to_bin[0].num_real_particles
        nptot = comm.bcast(comm.reduce(np))
        assert nptot == num_particles

        #logger.debug('hierarchy :%s'%(pcm.hierarchy_list))
        logger.debug('cells : %s'%(pcm.cells_dict))
        logger.debug('num particles : %d'%(parray.get_number_of_particles()))
        logger.debug('real particles : %d'%(parray.num_real_particles))
Beispiel #8
0
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 LineGenerator
from pysph.base.cell import INT_INF
from pysph.base.point import *

from pysph.parallel.load_balancer import LoadBalancer

pcm = ParallelCellManager(initialize=False)

# create 2 particles, one with proc 0 another with proc 1

lg = LineGenerator(particle_spacing=0.5)

lg.start_point.x = 0.0
lg.end_point.x = 10.0
lg.start_point.y = lg.start_point.z = 0.0
lg.end_point.y = lg.end_point.z = 0.0

x, y, z = lg.get_coords()
num_particles = len(x)

logger.info('Num particles : %d' % (len(x)))

parray = ParticleArray(name='p1',
                       x={'data': x},
                       y={'data': y},
                       z={'data': z},