def test_source_from_a_xy_plane_hexagonal_lattice(self):
        xspace = 0.1
        yspace = 0.1*numpy.sqrt(3.)/2.
        lattice = make_hexagonal_lattice('test', xspace, 0.2, (5, 4, 1))
        self.add_velocity(lattice)
        source = self.tested_class(cuds=lattice)
        data = source.data
        self.assertEqual(data.number_of_points, 5 * 4 * 1)

        for index, point in enumerate(data.points):
            # The lattice has 4 rows (y axis) and 5 columns (x axis).
            # Thus the correct size to unravel is (4, 5) instead of
            # (5, 4).
            row, column = numpy.unravel_index(index,  (4, 5))
            assert_array_equal(
                point, (
                    xspace * column + 0.5 * xspace * row,
                    yspace * row,
                    0.0))

        vectors = data.point_data.vectors.to_array()
        for node in lattice.iter(item_type=CUBA.NODE):
            position = (
                node.index[0] * xspace + 0.5 * xspace * node.index[1],
                node.index[1] * yspace,
                0.0)
            point_id = data.find_point(position)
            assert_array_equal(vectors[point_id], node.index)
示例#2
0
 def test_make_hexagonal_lattice(self):
     lattice = make_hexagonal_lattice('Lattice6', self.a, self.c, (5, 5, 5))
     self.assertIsInstance(lattice, Lattice)
     self.assertEqual(lattice.name, 'Lattice6')
     self.assertEqual(lattice.primitive_cell.bravais_lattice,
                      BravaisLattice.HEXAGONAL)
     assert_array_equal(lattice.size, (5, 5, 5))
     assert_array_equal(lattice.origin, (0, 0, 0))
示例#3
0
 def test_make_hexagonal_lattice(self):
     lattice = make_hexagonal_lattice(
         'Lattice6', self.a, self.c, (5, 5, 5))
     self.assertIsInstance(lattice, Lattice)
     self.assertEqual(lattice.name, 'Lattice6')
     self.assertEqual(lattice.primitive_cell.bravais_lattice,
                      BravaisLattice.HEXAGONAL)
     assert_array_equal(lattice.size, (5, 5, 5))
     assert_array_equal(lattice.origin, (0, 0, 0))
    def test_source_from_a_xy_plane_hexagonal_lattice(self):
        # given
        lattice = make_hexagonal_lattice('test', 0.1, 0.2, (5, 4, 1))
        self.add_velocity(lattice)

        # when
        data_set = cuds2vtk(cuds=lattice)

        # then
        self.assertEqual(data_set.GetNumberOfPoints(), 5 * 4)

        points = vtk_to_numpy(data_set.GetPoints().GetData())
        for node in lattice.iter(item_type=CUBA.NODE):
            position = lattice.get_coordinate(node.index)
            point_id = data_set.FindPoint(position)
            assert_array_equal(
                points[point_id], numpy.asarray(position, dtype=points.dtype))
    def test_source_from_a_xy_plane_hexagonal_lattice(self):
        xspace = 0.1
        yspace = 0.1*numpy.sqrt(3.)/2.
        cuds = make_hexagonal_lattice('test', xspace, 0.2, (5, 4, 1))
        self._add_velocity(cuds)
        source = SlimCUDSSource(cuds=cuds)
        self.assertEqual(source.data.number_of_points, 5 * 4 * 1)
        self.assertEqual(source.data.point_data.number_of_arrays, 1)
        self.assertEqual(len(source._point_vectors_list), 2)
        self.assertEqual(source._point_vectors_list, ['VELOCITY', ''])
        self.assertEqual(source.point_vectors_name, 'VELOCITY')

        source.point_vectors_name = ''
        self.assertEqual(source.data.point_data.number_of_arrays, 0)

        source.point_vectors_name = 'VELOCITY'
        self.assertEqual(source.data.point_data.number_of_arrays, 1)

        for index, point in enumerate(source.data.points):
            # The lattice has 4 rows (y axis) and 5 columns (x axis).
            # Thus the correct size to unravel is (4, 5) instead of
            # (5, 4).
            row, column = numpy.unravel_index(index,  (4, 5))
            assert_array_equal(
                point, (
                    xspace * column + 0.5 * xspace * row,
                    yspace * row,
                    0.0))

        vectors = source.data.point_data.vectors.to_array()
        for node in cuds.iter(item_type=CUBA.NODE):
            position = (
                node.index[0] * xspace + 0.5 * xspace * node.index[1],
                node.index[1] * yspace,
                0.0)
            point_id = source.data.find_point(position)
            assert_array_equal(vectors[point_id], node.index)
# particles container
particles = Particles('particles_example')

# add particles
particle_iter = (Particle(coordinates=point,
                          data=DataContainer(TEMPERATURE=temperature[index]))
                 for index, point in enumerate(points))
uids = particles.add(particle_iter)

# add bonds
bond_iter = (Bond(particles=[uids[index] for index in indices])
             for indices in bonds)
particles.add(bond_iter)


hexagonal = make_hexagonal_lattice(
    'hexagonal', 0.1, 0.1, (5, 5, 5), (5, 4, 0))
orthorhombic = make_orthorhombic_lattice(
    'orthorhombic', (0.1, 0.2, 0.3), (5, 5, 5), (5, 4, 0))
body_centered = make_body_centered_orthorhombic_lattice(
    'body_centered', (0.1, 0.2, 0.3), (5, 5, 5), (5, 10, 12))


def add_temperature(lattice):
    new_nodes = []
    for node in lattice.iter(item_type=CUBA.NODE):
        index = numpy.array(node.index) + 1.0
        node.data[CUBA.TEMPERATURE] = numpy.prod(index)
        new_nodes.append(node)
    lattice.update(new_nodes)