Example #1
0
def load(fname):
    """ Load and return data from an  output (.npz) file dumped by PySPH.

    For output file version 1, the function returns a dictionary with
    the keys:

    solver_data : Solver constants at the time of output like time,
    time step and iteration count.

    arrays : ParticleArrays keyed on names with the ParticleArray
    object as value.

    """
    from pysph.base.particle_array import get_particle_array
    data = numpy.load(fname)

    ret = {"arrays":{}}

    if not 'version' in data.files:
        msg = "Wrong file type! No version nnumber recorded."
        raise RuntimeError(msg)
    
    version = data['version']

    if version == 1:

        arrays = data["arrays"]
        arrays.shape = (1,)
        arrays = arrays[0]

        solver_data = data["solver_data"]
        solver_data.shape = (1,)
        solver_data = solver_data[0]

        for array_name in arrays:
            array = get_particle_array(name=array_name,
                                       cl_precision="single",
                                       **arrays[array_name])
            
            ret["arrays"][array_name] = array
            
        ret["solver_data"] = solver_data

    else:
        raise RuntimeError("Version not understood!")

    return ret
Example #2
0
    def setUp(self):

        self.np = np = 4

        x = numpy.array([0, 1, 1, 0])
        y = numpy.array([0, 0, 1, 1])
        h = numpy.ones_like(x) * 0.3

        pa = get_particle_array(name="test", cl_precision="single",
                                x=x, y=y, h=h)

        self.scale_fac = 2.0
        
        self.particles = particles = CLParticles(
            [pa,], OpenCLNeighborLocatorType.LinkedListSPHNeighborLocator,
            DomainManagerType.LinkedListManager)

        self.ctx = create_some_context()
        block_20,
        block_30,
        block_40,
        block_50,
        block_21,
        block_31,
        block_41,
        block_51,
        block_22,
        block_32,
        block_42,
        block_52,
    ]


pa = get_particle_array(name="test" + str(rank), x=x, y=y, h=h)
particles = Particles(arrays=[pa])

# create the block manager
pm = pm = SimpleBlockManager(block_scale_factor=2.0)
pm.initialize(particles)

cm = pm.cm

assert abs(pm.block_size - 0.3) < 1e-15
assert pm.block_size == cm.cell_size


cells_dict = cm.cells_dict
pmap = pm.processor_map