def test_compare_lattice_datasets_equal(self):
        # given
        lattice = make_cubic_lattice('test', 1.0, (2, 3, 4))
        reference = make_cubic_lattice('test', 1.0, (2, 3, 4,))

        data = DataContainer()

        lattice.data = data
        reference.data = data

        # this should pass without problems
        compare_lattice_datasets(lattice, reference, testcase=self)
Exemple #2
0
    def test_compare_lattice_datasets_equal(self):
        # given
        lattice = make_cubic_lattice('test', 1.0, (2, 3, 4))
        reference = make_cubic_lattice('test', 1.0, (
            2,
            3,
            4,
        ))

        data = DataContainer()

        lattice.data = data
        reference.data = data

        # this should pass without problems
        compare_lattice_datasets(lattice, reference, testcase=self)
    def test_source_from_a_cubic_lattice(self):
        cuds = make_cubic_lattice('test', 0.4, (14, 24, 34), (4, 5, 6))
        self._add_velocity(cuds)
        source = SlimCUDSSource(cuds=cuds)
        self.assertEqual(source.data.number_of_points, 14 * 24 * 34)
        assert_array_equal(source.data.origin, (4.0, 5.0, 6.0))

        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)
        vectors = source.data.point_data.vectors.to_array()

        for node in cuds.iter(item_type=CUBA.NODE):
            point_id = source.data.compute_point_id(node.index)
            assert_array_equal(
                cuds.get_coordinate(node.index),
                source.data.get_point(point_id))
            assert_array_equal(vectors[point_id], node.index)

        source.point_vectors_name = ''
        self.assertEqual(source.data.point_data.number_of_arrays, 0)
Exemple #4
0
 def test_make_cubic_lattice(self):
     lattice = make_cubic_lattice('Lattice0', self.a, (14, 4, 5), (4, 5, 6))
     self.assertIsInstance(lattice, Lattice)
     self.assertEqual(lattice.name, 'Lattice0')
     self.assertEqual(lattice.primitive_cell.bravais_lattice,
                      BravaisLattice.CUBIC)
     assert_array_equal(lattice.size, (14, 4, 5))
     assert_array_equal(lattice.origin, (4, 5, 6))
 def test_make_cubic_lattice(self):
     lattice = make_cubic_lattice(
         'Lattice0', self.a, (14, 4, 5), (4, 5, 6))
     self.assertIsInstance(lattice, Lattice)
     self.assertEqual(lattice.name, 'Lattice0')
     self.assertEqual(lattice.primitive_cell.bravais_lattice,
                      BravaisLattice.CUBIC)
     assert_array_equal(lattice.size, (14, 4, 5))
     assert_array_equal(lattice.origin, (4, 5, 6))
def create_example_lattice():
    lattice = make_cubic_lattice('test', 0.1, (5, 10, 12))

    def work_on_nodes(nodes):
        for node in nodes:
            index = array(node.index) + 1.0
            node.data[CUBA.TEMPERATURE] = prod(index)
            yield node

    lattice.update(work_on_nodes(lattice.iter(item_type=CUBA.NODE)))
    return lattice
    def test_lattice_show(self):
        lattice = make_cubic_lattice(
            'test', 0.2, (10, 10, 1), origin=(0.2, -2.4, 0.))

        def function():
            show(lattice)
            return True

        tester = ModalDialogTester(function)
        tester.open_and_run(when_opened=lambda x: x.close(accept=False))
        self.assertTrue(tester.result)
    def test_source_from_a_cubic_lattice(self):
        lattice = make_cubic_lattice('test', 0.4, (14, 24, 34), (4, 5, 6))
        self.add_velocity(lattice)
        source = self.tested_class(cuds=lattice)
        data = source.data
        self.assertEqual(data.number_of_points, 14 * 24 * 34)
        assert_array_equal(data.origin, (4.0, 5.0, 6.0))

        vectors = data.point_data.vectors.to_array()
        for node in lattice.iter(item_type=CUBA.NODE):
            point_id = data.compute_point_id(node.index)
            assert_array_equal(
                lattice.get_coordinate(node.index),
                data.get_point(point_id))
            assert_array_equal(vectors[point_id], node.index)
 def test_closed_file_not_usable(self):
     filename = os.path.join(self.temp_dir, 'test.cuds')
     with closing(H5CUDS.open(filename)) as handle:
         handle.add_dataset(Mesh(name="test_1"))
         handle.add_dataset(Particles(name="test_2"))
         lattice = make_cubic_lattice("test_3", 1.0, (2, 3, 4))
         handle.add_dataset(lattice)
         test_h1 = handle.get_dataset("test_1")
         test_h2 = handle.get_dataset("test_2")
         test_h3 = handle.get_dataset("test_3")
     with self.assertRaises(Exception):
         handle.get_dataset('test_h1')
     with self.assertRaises(Exception):
         test_h1.name = 'foo'
     with self.assertRaises(Exception):
         test_h2.name = 'foo'
     with self.assertRaises(Exception):
         test_h3.name = 'foo'
Exemple #10
0
    def test_compare_lattice_datasets_not_equal(self):
        # given
        lattice = make_cubic_lattice('test', 1.0, (2, 3, 4))
        reference = make_cubic_lattice('test_ref', 1.0, (
            2,
            3,
            4,
        ))

        data = create_data_container()

        lattice.data = data
        reference.data = data

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

        # given
        test_data = DataContainer()

        lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4))
        lattice.data = test_data

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

        # given
        lattice = make_cubic_lattice('test', 2.0, (2, 3, 4))
        lattice.data = data

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

        # given
        lattice = make_cubic_lattice('test_ref', 1.0, (4, 6, 8))
        lattice.data = data

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

        # given
        lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4),
                                     (2.0, 2.0, 2.0))
        lattice.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_lattice_datasets(lattice, reference, testcase=self)
    def test_compare_lattice_datasets_not_equal(self):
        # given
        lattice = make_cubic_lattice('test', 1.0, (2, 3, 4))
        reference = make_cubic_lattice('test_ref', 1.0, (2, 3, 4,))

        data = create_data_container()

        lattice.data = data
        reference.data = data

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

        # given
        test_data = DataContainer()

        lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4))
        lattice.data = test_data

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

        # given
        lattice = make_cubic_lattice('test', 2.0, (2, 3, 4))
        lattice.data = data

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

        # given
        lattice = make_cubic_lattice('test_ref', 1.0, (4, 6, 8))
        lattice.data = data

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

        # given
        lattice = make_cubic_lattice('test_ref', 1.0, (2, 3, 4),
                                     (2.0, 2.0, 2.0))
        lattice.data = data

        # when/then
        with self.assertRaises(AssertionError):
            compare_lattice_datasets(lattice, reference, testcase=self)
    def test_source_from_a_cubic_lattice(self):
        # given
        lattice = make_cubic_lattice('test', 0.4, (14, 24, 34), (4, 5, 6))
        self.add_velocity(lattice)

        # when
        data_set = cuds2vtk(cuds=lattice)

        # then
        self.assertEqual(data_set.GetNumberOfPoints(), 14 * 24 * 34)
        assert_array_equal(data_set.GetOrigin(), (4.0, 5.0, 6.0))

        point_data = data_set.GetPointData()
        arrays = {
            point_data.GetArray(index).GetName():
            vtk_to_numpy(point_data.GetArray(index))
            for index in range(point_data.GetNumberOfArrays())}
        for node in lattice.iter(item_type=CUBA.NODE):
            point_id = data_set.ComputePointId(node.index)
            assert_array_equal(
                lattice.get_coordinate(node.index),
                data_set.GetPoint(point_id))
            for key, value in node.data.iteritems():
                assert_array_equal(arrays[key.name][point_id], value)
Exemple #13
0
 def dummy_lattice():
     return make_cubic_lattice('Lattice0', 0.2, (5, 5, 5))
 def test_lattice_snapshot(self):
     filename = self.filename
     lattice = make_cubic_lattice(
         'test', 0.2, (10, 10, 1), origin=(0.2, -2.4, 0.))
     snapshot(lattice, filename)
     self.assertImageSavedWithContent(filename)
    def create_dataset(self, name):
        """ Create and return a cuds object

        """
        return make_cubic_lattice(name, 1.0, (2, 3, 4))
import numpy

from simphony.cuds.lattice import make_cubic_lattice
from simphony.core.cuba import CUBA

lattice = make_cubic_lattice('test', 0.1, (50, 10, 120))


def set_temperature(nodes):
    for node in nodes:
        index = numpy.array(node.index) + 1.0
        node.data[CUBA.TEMPERATURE] = numpy.prod(index)
        yield node

lattice.update_nodes(set_temperature(lattice.iter_nodes()))


if __name__ == '__main__':
    from simphony.visualisation import paraview_tools

    # Visualise the Lattice object
    paraview_tools.show(lattice, select=(CUBA.TEMPERATURE, 'nodes'))
import numpy

from mayavi.scripts import mayavi2
from simphony.cuds.lattice import make_cubic_lattice
from simphony.core.cuba import CUBA

cubic = make_cubic_lattice("cubic", 0.1, (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)

add_temperature(cubic)


# Now view the data.
@mayavi2.standalone
def view(lattice):
    from mayavi.modules.glyph import Glyph
    from simphony_mayavi.sources.api import CUDSSource
    mayavi.new_scene()  # noqa
    src = CUDSSource(cuds=lattice)
    mayavi.add_source(src)  # noqa
    g = Glyph()
    gs = g.glyph.glyph_source
    gs.glyph_source = gs.glyph_dict['sphere_source']