Beispiel #1
0
    def test_compare_particles_datasets_not_equal(self):
        # given
        particles = Particles(name="test")
        reference = Particles(name="test_ref")

        particle_list = create_particles_with_id()
        bond_list = create_bonds()
        data = create_data_container()

        particles.add(particle_list)
        reference.add(particle_list)

        particles.add(bond_list)
        reference.add(bond_list)

        particles.data = data
        reference.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_particles = create_particles_with_id()

        particles = Particles(name=reference.name)
        particles.add(test_particles)
        particles.add(bond_list)
        particles.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_bonds = create_bonds()

        particles = Particles(name=reference.name)
        particles.add(particle_list)
        particles.add(test_bonds)
        particles.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_data = DataContainer()

        particles = Particles(name=reference.name)
        particles.add(particle_list)
        particles.add(bond_list)
        particles.data = test_data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)
    def test_compare_particles_datasets_not_equal(self):
        # given
        particles = Particles(name="test")
        reference = Particles(name="test_ref")

        particle_list = create_particles_with_id()
        bond_list = create_bonds()
        data = create_data_container()

        particles.add_particles(particle_list)
        reference.add_particles(particle_list)

        particles.add_bonds(bond_list)
        reference.add_bonds(bond_list)

        particles.data = data
        reference.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_particles = create_particles_with_id()

        particles = Particles(name=reference.name)
        particles.add_particles(test_particles)
        particles.add_bonds(bond_list)
        particles.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_bonds = create_bonds()

        particles = Particles(name=reference.name)
        particles.add_particles(particle_list)
        particles.add_bonds(test_bonds)
        particles.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)

        # given
        test_data = DataContainer()

        particles = Particles(name=reference.name)
        particles.add_particles(particle_list)
        particles.add_bonds(bond_list)
        particles.data = test_data

        # when/then
        with self.assertRaises(AssertionError):
            compare_particles_datasets(particles, reference, testcase=self)
Beispiel #3
0
    def read_modelpart_as_particles(self, filename):
        """ Reads a Kratos formated modelpart from DEM

        """

        # ModelPart MUST have this name.
        model_part = KRTS.ModelPart("Particles")

        model_part.AddNodalSolutionStepVariable(KRTS.RADIUS)
        model_part.AddNodalSolutionStepVariable(KRTSDEM.PARTICLE_DENSITY)
        model_part.AddNodalSolutionStepVariable(KRTS.VELOCITY)
        model_part.AddNodalSolutionStepVariable(KRTSDEM.SKIN_SPHERE)

        model_part_io_fluid = KRTS.ModelPartIO(filename)
        model_part_io_fluid.ReadModelPart(model_part)

        smp_particles = []
        smp_conditions = []
        smp_materials = []

        dem_pe = api.GranularDynamics()
        dem_pe.data[CUBA.DATA_SET] = []

        for i in xrange(0, model_part.NumberOfMeshes()):

            particles_name = 'particles_' + str(i)

            particles = SParticles(name=particles_name)

            # Export particle data to Simphony
            self.exportKratosParticles(model_part, particles, i)

            properties = model_part.GetProperties(0)[i]

            # Fill the boundary condition for the mesh
            condition = self.convertBc(properties, particles_name)

            # Fill the material for the mesh
            material = self.convertMaterial(properties, particles_name)

            # Save the relations
            particlesData = particles.data
            particlesData[CUBA.CONDITION] = condition.name
            particlesData[CUBA.MATERIAL] = material.name
            particles.data = particlesData

            # Pack the return objects
            smp_particles.append(particles)
            smp_conditions.append(condition)
            smp_materials.append(material)

            dem_pe.data[CUBA.DATA_SET].append(particles.name)

        return {
            'datasets': smp_particles,
            'conditions': smp_conditions,
            'materials': smp_materials,
            'pe': dem_pe,
        }
    def test_compare_particles_datasets_equal(self):
        # given
        particles = Particles(name="test")
        reference = Particles(name="test")

        particle_list = create_particles_with_id()
        bond_list = create_bonds()
        data = DataContainer()

        particles.add_particles(particle_list)
        reference.add_particles(particle_list)

        particles.add_bonds(bond_list)
        reference.add_bonds(bond_list)

        particles.data = data
        reference.data = data

        # this should pass without problems
        compare_particles_datasets(particles, reference, testcase=self)
Beispiel #5
0
    def test_compare_particles_datasets_equal(self):
        # given
        particles = Particles(name="test")
        reference = Particles(name="test")

        particle_list = create_particles_with_id()
        bond_list = create_bonds()
        data = DataContainer()

        particles.add(particle_list)
        reference.add(particle_list)

        particles.add(bond_list)
        reference.add(bond_list)

        particles.data = data
        reference.data = data

        # this should pass without problems
        compare_particles_datasets(particles, reference, testcase=self)
Beispiel #6
0
def generate_particles(smp_particles, smp_conditions, smp_materials, smp_pe):
    # Define the particle containers.
    particles = SParticles(name='particles')

    # Fill the data ( particle )
    data = DataContainer()
    data[CUBA.RADIUS] = 5e-5

    particles.add([
        SParticle(
            coordinates=(0.002, 0.004, 0.004),
            data=DataContainer(data),
        )
    ])

    material = api.Material(name='material_' + particles.name)
    materialData = material.data

    materialData[CUBA.DENSITY] = 950.0
    materialData[CUBA.YOUNG_MODULUS] = 35e9
    materialData[CUBA.POISSON_RATIO] = 0.20
    materialData[CUBA.FRICTION_COEFFICIENT] = 0.5773502691896257
    # materialData[CUBA.PARTICLE_COHESION] = 0.0
    materialData[CUBA.RESTITUTION_COEFFICIENT] = 0.02
    materialData[CUBA.ROLLING_FRICTION] = 0.01
    # materialData[CUBA.DEM_CONTINUUM_CONSTITUTIVE_LAW_NAME] = \
    # "DEM_KDEMFabric"
    # materialData[CUBA.DEM_DISCONTINUUM_CONSTITUTIVE_LAW_NAME] = \
    # "DEM_D_Hertz_viscous_Coulomb"
    # materialData[CUBA.CONTACT_TAU_ZERO] = 25
    # materialData[CUBA.CONTACT_SIGMA_MIN] = 5
    # materialData[CUBA.CONTACT_INTERNAL_FRICC] = 1

    material.data = materialData

    particlesData = particles.data
    particlesData[CUBA.MATERIAL] = material.name
    particles.data = particlesData

    # Pack the return objects
    smp_particles.append(particles)
    smp_materials.append(material)

    # Add the datasets that will be used by the wrapper
    smp_pe.data[CUBA.DATA_SET].append(particles.name)

    return {
        'datasets': smp_particles,
        'conditions': smp_conditions,
        'materials': smp_materials,
        'pe': smp_pe,
    }
    def test_add_get_particle_container_data(self):
        filename = os.path.join(self.temp_dir, 'test.cuds')
        original_pc = Particles(name="test")
        # Change data
        data = original_pc.data
        data[CUBA.NAME] = 'somename'
        original_pc.data = data

        # Store particle container along with its data
        with closing(H5CUDS.open(filename)) as handle:
            handle.add_dataset(original_pc)

        # Reopen the file and check the data if it is still there
        with closing(H5CUDS.open(filename, 'r')) as handle:
            pc = handle.get_dataset('test')
            self.assertIn(CUBA.NAME, pc.data)
            self.assertEqual(pc.data[CUBA.NAME], 'somename')
    def get_empty_particles(self, name):
        """ Get an empty particle container

        The returned data set is configured accordingly.

        Parameters
        ----------
        name : str
            name of particle container

        Returns
        -------
        pc : Particles
            dataset with no particles but properly configured

        """
        pc = Particles(name=name)
        pc.data = {CUBA.VECTOR: self._box_vectors,
                   CUBA.ORIGIN: self._box_origin}
        return pc
    def _handle_new_particles(self, uname, particles):
        """Add new particle container to this manager.


        Parameters
        ----------
        uname : string
            non-changing unique name of particles
        particles : ABCParticles
            particle container to be added

        """
        # create stand-alone particle container to use
        # as a cache of for input/output to LAMMPS
        pc = Particles(name="_")
        pc.data = DataContainer(particles.data)

        for p in particles.iter(item_type=CUBA.PARTICLE):
            pc.add([p])

        for b in particles.iter(item_type=CUBA.BOND):
            pc.add([b])

        self._pc_cache[uname] = pc
Beispiel #10
0
def generate_fibers(smp_particles, smp_conditions, smp_materials, smp_pe):
    # Define the particle containers.
    fibers = SParticles(name='fibers')

    # Fill the data ( fiber )
    data = DataContainer()
    data[CUBA.RADIUS] = 1e-5

    fiberCoords = [
        (0.1166666666666666685, 0.5083333333333333037, 0.5166666666666666075),
        (0.1499999999999999944, 0.5250000000000000222, 0.5500000000000000444),
        (0.1833333333333333481, 0.5416666666666667407, 0.5833333333333332593),
        (0.2166666666666666741, 0.5583333333333333481, 0.6166666666666666963),
        (0.2500000000000000000, 0.5749999999999999556, 0.6499999999999999112),
        (0.2833333333333333259, 0.5916666666666665630, 0.6833333333333333481)
    ]

    fibers.add([
        SParticle(
            coordinates=fiberCoords[0],
            data=DataContainer(data),
        ),
        SParticle(
            coordinates=fiberCoords[1],
            data=DataContainer(data),
        ),
        SParticle(
            coordinates=fiberCoords[2],
            data=DataContainer(data),
        ),
        SParticle(
            coordinates=fiberCoords[3],
            data=DataContainer(data),
        ),
        SParticle(
            coordinates=fiberCoords[4],
            data=DataContainer(data),
        ),
        SParticle(
            coordinates=fiberCoords[5],
            data=DataContainer(data),
        )
    ])

    material = api.Material(name='material_' + fibers.name)
    materialData = material.data

    materialData[CUBA.DENSITY] = 1050.0
    materialData[CUBA.YOUNG_MODULUS] = 1.0e9
    materialData[CUBA.POISSON_RATIO] = 0.20
    materialData[CUBA.FRICTION_COEFFICIENT] = 0.9999999999999999
    # materialData[CUBA.PARTICLE_COHESION] = 0.0
    materialData[CUBA.RESTITUTION_COEFFICIENT] = 0.02
    materialData[CUBA.ROLLING_FRICTION] = 0.01
    # materialData[CUBA.FABRIC_COEFFICIENT] = 0.1
    # materialData[CUBA.DEM_CONTINUUM_CONSTITUTIVE_LAW_NAME] = \
    # "DEM_KDEMFabric"
    # materialData[CUBA.DEM_DISCONTINUUM_CONSTITUTIVE_LAW_NAME] = \
    # "DEM_D_Hertz_viscous_Coulomb"
    # materialData[CUBA.CONTACT_TAU_ZERO] = 25
    # materialData[CUBA.CONTACT_SIGMA_MIN] = 5
    # materialData[CUBA.CONTACT_INTERNAL_FRICC] = 1

    material.data = materialData

    fibersData = fibers.data
    fibersData[CUBA.MATERIAL] = material.name
    fibers.data = fibersData

    # Pack the return objects
    smp_particles.append(fibers)
    smp_materials.append(material)

    # Add the datasets that will be used by the wrapper
    smp_pe.data[CUBA.DATA_SET].append(fibers.name)

    return {
        'datasets': smp_particles,
        'conditions': smp_conditions,
        'materials': smp_materials,
        'pe': smp_pe,
    }
def read_data_file(filename, atom_style=None, name=None):
    """ Reads LAMMPS data file and create CUDS objects

    Reads LAMMPS data file and create a Particles and CUDS. The CUDS
    will contain a material for each atom type (e.g. CUBA.MATERIAL_TYPE).

    The attributes for each particle are based upon what atom-style
    the file contains (i.e. "sphere" means that particles in addition to having
    CUBA.VELOCITY will also have a CUBA.RADIUS and CUBA.MASS). See
    'atom_style' for more details.

    Parameters
    ----------
    filename : str
        filename of lammps data file
    atom_style : AtomStyle, optional
        type of atoms in the file.  If None, then an attempt of
        interpreting the atom-style in the file is performed.
    name : str, optional
        name to be given to returned Particles.  If None, then filename is
        used.

    Returns
    -------
    particles : Particles
        particles
    SD : CUDS
        SD containing materials

    """
    handler = LammpsSimpleDataHandler()
    parser = LammpsDataFileParser(handler=handler)

    parser.parse(filename)

    if atom_style is None:
        atom_style = (
            get_atom_style(handler.get_atom_type())
            if handler.get_atom_type()
            else AtomStyle.ATOMIC)

    types = (atom_t for atom_t in
             range(1, handler.get_number_atom_types() + 1))
    atoms = handler.get_atoms()
    velocities = handler.get_velocities()
    masses = handler.get_masses()

    box_origin = handler.get_box_origin()
    box_vectors = handler.get_box_vectors()

    type_to_material_map = {}

    statedata = CUDS()

    # set up a Material for each different type
    for atom_type in types:
        material = Material()
        description = "Material for lammps atom type (originally '{}')".format(
            atom_type
        )
        material.description = description
        type_to_material_map[atom_type] = material.uid
        statedata.add([material])

    # add masses to materials
    for atom_type, mass in masses.iteritems():
        material = statedata.get(type_to_material_map[atom_type])
        material.data[CUBA.MASS] = mass
        statedata.update([material])

    def convert_atom_type_to_material(atom_type):
        return type_to_material_map[atom_type]

    interpreter = LammpsDataLineInterpreter(atom_style,
                                            convert_atom_type_to_material)

    # create particles
    particles = Particles(name=name if name else filename)
    data = particles.data
    data.update({CUBA.ORIGIN: box_origin,
                 CUBA.VECTOR: box_vectors})
    particles.data = data

    # add each particle
    for lammps_id, values in atoms.iteritems():
        coordinates, data = interpreter.convert_atom_values(values)
        data.update(interpreter.convert_velocity_values(velocities[lammps_id]))

        p = Particle(coordinates=coordinates, data=data)
        particles.add([p])

    return particles, statedata