예제 #1
0
 def test11(self):
     grid1 = datamodel.new_regular_grid((4, 4), [1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((4, 4), [1.0, 1.0] | units.m,
                                        offset=[-0.5, -0.5] | units.m)
     self.assertTrue(grid1.overlaps(grid2))
     overlap = grid1.get_overlap_with(grid2)
     self.assertEquals(overlap.position, grid1[0:3, 0:3].position)
예제 #2
0
 def test12(self):
     grid1 = datamodel.new_regular_grid((4, 4), [1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((4, 4), [1.0, 1.0] | units.m,
                                        offset=[-0.5, -0.5] | units.m)
     self.assertTrue(grid1.overlaps(grid2))
     overlap = grid1.get_overlap_with(grid2,
                                      eps=grid2.cellsize()[0] * 1.e-6)
     self.assertEquals(overlap.position, grid1[0:2, 0:2].position)
예제 #3
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test2(self):
     grid = datamodel.new_rectilinear_grid((10,), (1.0 * numpy.arange(11),))
     self.assertEqual(grid._axes_cell_boundaries, 1.0 * numpy.arange(11))
     grid = datamodel.new_regular_grid((10,), [10.0])
     self.assertEqual(grid._lengths, [10.0])
     grid = datamodel.new_cartesian_grid((10,), 1.0)
     self.assertEqual(grid._cellsize, 1.0)
     grid = datamodel.new_regular_grid((10, 20), [10.0, 15.0])
     self.assertEquals(grid._lengths, [10.0, 15.0])
예제 #4
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test3(self):
     grid1 = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid1.mass = grid1.x.value_in(units.m) | units.kg
     grid2 = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid2.position += (10.0, 0, 0) | units.m
     grid2.mass = grid2.x.value_in(units.m) | units.kg
     samples = SamplePointsOnMultipleGrids((grid1, grid2), [[3.0, 3.0, 3.0], [4.0, 3.0, 3.0], [13, 3, 3]] | units.m)
     self.assertEquals(len(samples), 3)
     self.assertEquals(samples.mass, [3.0, 4.0, 13.0] | units.kg)
예제 #5
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test10(self):
     grid1 = datamodel.new_regular_grid((5, 4), [1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4), [0.1, 0.1] | units.m)
     grid3 = datamodel.new_regular_grid((5, 4), [0.1, 0.1] | units.m, offset=[0.5, 0.6] | units.m)
     self.assertTrue(grid1.overlaps(grid2))
     self.assertTrue(grid1.overlaps(grid3))
     self.assertFalse(grid2.overlaps(grid3))
     self.assertTrue(grid2.overlaps(grid1))
     self.assertTrue(grid3.overlaps(grid1))
     self.assertFalse(grid3.overlaps(grid2))
예제 #6
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test22(self):
     grid1 = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     slice1 = grid1[1:3, :, :].copy()
     slice2 = grid2[1:3, :, :]
     slice1.x = -10 | units.m
     channel = slice1.new_channel_to(slice2)
     channel.copy()
     self.assertEquals(grid2.x[1:3], -10 | units.m)
     self.assertEquals(grid2.x[4], grid1.x[4])
예제 #7
0
 def test10(self):
     grid1 = datamodel.new_regular_grid((5, 4), [1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4), [.1, .1] | units.m)
     grid3 = datamodel.new_regular_grid((5, 4), [.1, .1] | units.m,
                                        offset=[0.5, 0.6] | units.m)
     self.assertTrue(grid1.overlaps(grid2))
     self.assertTrue(grid1.overlaps(grid3))
     self.assertFalse(grid2.overlaps(grid3))
     self.assertTrue(grid2.overlaps(grid1))
     self.assertTrue(grid3.overlaps(grid1))
     self.assertFalse(grid3.overlaps(grid2))
예제 #8
0
 def test22(self):
     grid1 = datamodel.new_regular_grid((5, 4, 2),
                                        [1.0, 1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4, 2),
                                        [1.0, 1.0, 1.0] | units.m)
     slice1 = grid1[1:3, :, :].copy()
     slice2 = grid2[1:3, :, :]
     slice1.x = -10 | units.m
     channel = slice1.new_channel_to(slice2)
     channel.copy()
     self.assertEquals(grid2.x[1:3], -10 | units.m)
     self.assertEquals(grid2.x[4], grid1.x[4])
예제 #9
0
    def test46(self):
        grid = datamodel.new_regular_grid((6, ), [1.0], axes_names="abcd")
        subgrid = grid[::2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])

        grid = datamodel.new_regular_grid((7, ), [1.0], axes_names="abcd")
        subgrid = grid[::2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])

        grid = datamodel.new_regular_grid((7, ), [1.0], axes_names="abcd")
        subgrid = grid[6:0:-2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])
예제 #10
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test46(self):
        grid = datamodel.new_regular_grid((6,), [1.0], axes_names="abcd")
        subgrid = grid[::2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])

        grid = datamodel.new_regular_grid((7,), [1.0], axes_names="abcd")
        subgrid = grid[::2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])

        grid = datamodel.new_regular_grid((7,), [1.0], axes_names="abcd")
        subgrid = grid[6:0:-2]
        self.assertEquals(subgrid[-2].a, subgrid.a[-2])
예제 #11
0
 def test3(self):
     grid1 = datamodel.new_regular_grid((5, 5, 5),
                                        [10.0, 10.0, 10.0] | units.m)
     grid1.mass = grid1.x.value_in(units.m) | units.kg
     grid2 = datamodel.new_regular_grid((5, 5, 5),
                                        [10.0, 10.0, 10.0] | units.m)
     grid2.position += (10.0, 0, 0) | units.m
     grid2.mass = grid2.x.value_in(units.m) | units.kg
     samples = SamplePointsOnMultipleGrids(
         (grid1, grid2),
         [[3.0, 3.0, 3.0], [4.0, 3.0, 3.0], [13, 3, 3]] | units.m)
     self.assertEquals(len(samples), 3)
     self.assertEquals(samples.mass, [3.0, 4.0, 13.0] | units.kg)
예제 #12
0
 def test2(self):
     grid = datamodel.new_rectilinear_grid((10, ),
                                           (1. * numpy.arange(11), ))
     self.assertEqual(grid._axes_cell_boundaries, 1. * numpy.arange(11))
     grid = datamodel.new_regular_grid((10, ), [10.])
     self.assertEqual(grid._lengths, [10.])
     grid = datamodel.new_cartesian_grid((10, ), 1.)
     self.assertEqual(grid._cellsize, 1.)
     grid = datamodel.new_regular_grid((
         10,
         20,
     ), [10., 15.])
     self.assertEquals(grid._lengths, [10., 15.])
예제 #13
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test40(self):
     grid1 = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     grid1.m1 = 1
     grid1.m2 = 2
     channel = grid1.new_channel_to(grid2)
     channel.transform(["m3"], lambda x, y: (x,), ["m1", "m2"])
     self.assertEquals(grid2.m3, 1)
     channel.transform(["m3"], lambda x, y: (y,), ["m1", "m2"])
     self.assertEquals(grid2.m3, 2)
     channel.transform(["m3"], lambda x, y: (x + y,), ["m1", "m2"])
     self.assertEquals(grid2.m3, 3)
     channel.transform(["m3", "m4"], lambda x, y: (x + y, 2 * x - y), ["m1", "m2"])
     self.assertEquals(grid2.m3, 3)
     self.assertEquals(grid2.m4, 0)
예제 #14
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test40b(self):
     grid = datamodel.new_regular_grid((50,), [1.0] | units.m)
     for index in [[0], [0, 3, 4], [1, 2, 2], [[2, 3]], [[0, 1], [2, 3]], range(50)]:
         i = numpy.array(index)
         self.assertEquals(grid[i].x, grid.x[i])
         self.assertEquals(grid[i][1:].x, grid.x[i][1:])
         self.assertEquals(grid[i][1::2].x, grid.x[i][1::2])
예제 #15
0
    def test2(self):
        grid = datamodel.new_regular_grid([2, 2, 2], [1, 1, 1]
                                          | generic_unit_system.length)
        grid.rho = grid.x * (
            0.1 | generic_unit_system.mass / generic_unit_system.length**4)
        data_file = StringIO()
        instance = vtk.VtkUnstructuredGrid("test.vtu", data_file, grid)
        instance.store()
        contents = data_file.getvalue()

        self.assertTrue(
            contents.find('<Piece NumberOfPoints="27" NumberOfCells="8"') > 0)
        self.assertTrue(
            contents.find(
                'DataArray type="Int32" NumberOfComponents="1" Name="connectivity">'
            ) > 0)
        self.assertTrue(
            contents.find(
                'DataArray type="Int32" NumberOfComponents="1" Name="offsets">'
            ) > 0)
        self.assertTrue(contents.find('11 11 11') > 0)
        self.assertTrue(contents.find('56 64') > 0)
        self.assertTrue(
            contents.find(
                'DataArray type="Float64" NumberOfComponents="3" Name="points">'
            ) > 0)
        self.assertTrue(
            contents.find(
                '<DataArray type="Float64" NumberOfComponents="1" Name="rho">')
            > 0)
예제 #16
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test4(self):
     grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[0].position, [3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[1].position, [5.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[-1].position, [5.0, 5.0, 5.0] | units.m)
예제 #17
0
    def test6(self):
        grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
        points = grid.points().reshape([6 * 5 * 3, 3])
        connectivity = grid.connectivity()

        self.assertEquals(connectivity.shape, (5, 4, 2, 8))
        cell = connectivity[1][1][1]
        self.assertAlmostRelativeEquals(points[cell[0]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.0, 0.0, 0.0] | units.m))
        self.assertAlmostRelativeEquals(points[cell[1]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.2, 0, 0.0] | units.m))
        self.assertAlmostRelativeEquals(points[cell[2]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0, 0.25, 0.0] | units.m))
        self.assertAlmostRelativeEquals(points[cell[3]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.2, 0.25, 0.0] | units.m))
        self.assertAlmostRelativeEquals(points[cell[4]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.0, 0.0, 0.5] | units.m))
        self.assertAlmostRelativeEquals(points[cell[5]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.2, 0.0, 0.5] | units.m))
        self.assertAlmostRelativeEquals(points[cell[6]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.0, 0.25, 0.5] | units.m))
        self.assertAlmostRelativeEquals(points[cell[7]],
                                        ([0.2, 0.25, 0.5] | units.m) +
                                        ([0.2, 0.25, 0.5] | units.m))

        self.assertEquals(connectivity[0][0][0], [0, 15, 3, 18, 1, 16, 4, 19])
예제 #18
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test1(self):
        grid1 = datamodel.new_cartesian_grid((4, 5), 1.0 | units.m)
        grid2 = datamodel.new_regular_grid((4, 5), [4.0, 5.0] | units.m)
        grid3 = datamodel.new_rectilinear_grid((4, 5), [numpy.arange(5.0) | units.m, numpy.arange(6.0) | units.m])

        self.assertEqual(grid1.position, grid2.position)
        self.assertEqual(grid2.position, grid3.position)
예제 #19
0
    def test2(self):
        grid = datamodel.new_regular_grid((5, 5, 5),
                                          [10.0, 10.0, 10.0] | units.m)
        grid.mass = grid.x.value_in(units.m) | units.kg
        sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        sample = grid.samplePoint([2.5, 2.5, 2.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [0, 0, 0])
        sample = grid.samplePoint([3.5, 3.5, 3.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        sample = grid.samplePoint([4.5, 4.5, 4.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        self.assertEquals(sample.index, [2, 2, 2])

        for x in range(0, 100):

            sample = grid.samplePoint(
                [0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 +
                 (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [-1, 1, 2])
        for x in range(100, 300):

            sample = grid.samplePoint(
                [0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 +
                 (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [0, 2, 3])

        for x in range(300, 400):
            sample = grid.samplePoint(
                [0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 +
                 (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [1, 3, 4])
예제 #20
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test2(self):
        grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
        grid.mass = grid.x.value_in(units.m) | units.kg
        sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        sample = grid.samplePoint([2.5, 2.5, 2.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [0, 0, 0])
        sample = grid.samplePoint([3.5, 3.5, 3.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        sample = grid.samplePoint([4.5, 4.5, 4.5] | units.m)
        self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
        self.assertEquals(sample.index, [2, 2, 2])

        for x in range(0, 100):

            sample = grid.samplePoint([0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 + (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [-1, 1, 2])
        for x in range(100, 300):

            sample = grid.samplePoint([0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 + (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [0, 2, 3])

        for x in range(300, 400):
            sample = grid.samplePoint([0.0 + (x / 100.0), 4.0 + (x / 100.0), 6.0 + (x / 100.0)] | units.m)
            self.assertEquals(sample.index_for_000_cell, [1, 3, 4])
예제 #21
0
    def test5(self):
        grid = datamodel.new_regular_grid((5, 5, 5),
                                          [10.0, 10.0, 10.0] | units.m)
        grid.mass = grid.x.value_in(units.m) | units.kg
        sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
        masses = sample.get_values_of_attribute("mass")
        self.assertEquals(masses[0], 3.0 | units.kg)
        self.assertEquals(masses[1], 5.0 | units.kg)
        self.assertEquals(masses[2], 3.0 | units.kg)
        self.assertEquals(masses[3], 3.0 | units.kg)
        self.assertEquals(masses[4], 5.0 | units.kg)
        self.assertEquals(masses[5], 3.0 | units.kg)
        self.assertEquals(masses[6], 5.0 | units.kg)
        self.assertEquals(masses[7], 5.0 | units.kg)
        factors = sample.weighing_factors
        self.assertEquals(factors[0], 1.0 | units.none)
        self.assertEquals(factors[1], 0.0 | units.none)
        self.assertEquals(factors[2], 0.0 | units.none)
        self.assertEquals(factors[3], 0.0 | units.none)
        self.assertEquals(factors[4], 0.0 | units.none)
        self.assertEquals(factors[5], 0.0 | units.none)
        self.assertEquals(factors[6], 0.0 | units.none)
        self.assertEquals(factors[7], 0.0 | units.none)

        self.assertAlmostRelativeEquals(sample.mass, 3.0 | units.kg)
예제 #22
0
    def test6(self):
        grid = datamodel.new_regular_grid((5, 5, 5),
                                          [10.0, 10.0, 10.0] | units.m)
        grid.mass = grid.x.value_in(units.m) | units.kg
        for xpos in numpy.arange(3.0, 5.0, 0.1):
            sample = grid.samplePoint([xpos, 3.0, 3.0] | units.m)
            self.assertAlmostRelativeEquals(
                sample.mass,
                (3.0 | units.kg) + ((2.0 * (xpos - 3.0) / 2.0) | units.kg))

            sample = grid.samplePoint([xpos, 3.0, 3.0] | units.m)
            self.assertAlmostRelativeEquals(
                sample.mass,
                (3.0 | units.kg) + ((2.0 * (xpos - 3.0) / 2.0) | units.kg))

            sample = grid.samplePoint([xpos, 5.0, 3.0] | units.m)
            self.assertAlmostRelativeEquals(
                sample.mass,
                (3.0 | units.kg) + ((2.0 * (xpos - 3.0) / 2.0) | units.kg))

            sample = grid.samplePoint([xpos, 3.0, 5.0] | units.m)
            self.assertAlmostRelativeEquals(
                sample.mass,
                (3.0 | units.kg) + ((2.0 * (xpos - 3.0) / 2.0) | units.kg))

            sample = grid.samplePoint([4.0, 4.0, 4.0] | units.m)
            self.assertAlmostRelativeEquals(sample.mass, (4.0 | units.kg))
예제 #23
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test45(self):
     grid = datamodel.new_regular_grid((3, 4, 5, 6), [1.0, 2.0, 3.0, 4.0], axes_names="abcd")
     for _i, _j in [([-1], [-4])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         subgrid = grid[::2, 0, :, :]
         self.assertEquals(subgrid[i, j].a, subgrid.a[i, j])
예제 #24
0
    def test18(self):

        instance = self.new_instance_of_an_optional_code(MpiAmrVac,
                                                         number_of_workers=3)
        instance.parameters.x_boundary_conditions = ("periodic", "periodic")
        instance.parameters.y_boundary_conditions = ("periodic", "periodic")
        instance.parameters.z_boundary_conditions = ("periodic", "periodic")
        instance.parameters.mesh_length = (20.0, 20.0,
                                           20.0) | generic_unit_system.length
        instance.parameters.mesh_length = (20.0, 20.0,
                                           20.0) | generic_unit_system.length
        instance.parameters.mesh_size = (20, 20, 20)
        instance.parameters.maximum_number_of_grid_levels = 1

        for x in instance.itergrids():
            inmem = x.copy()
            inmem.rho = ((inmem.x +
                          ((inmem.y -
                            (0.5 | generic_unit_system.length)) * 20.0) +
                          ((inmem.z -
                            (0.5 | generic_unit_system.length)) * 400.0)) /
                         (1 | generic_unit_system.length)
                         | generic_unit_system.density)
            inmem.rhovx = 0.0 | generic_unit_system.momentum_density
            inmem.energy = 1.0 | generic_unit_system.energy_density
            from_model_to_code = inmem.new_channel_to(x)
            from_model_to_code.copy()
        rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(
            0.5 | generic_unit_system.length, 0.5 | generic_unit_system.length,
            0.5 | generic_unit_system.length)

        self.assertEquals(rho, 0.5 | generic_unit_system.density)

        for value in numpy.arange(0.5, 19.6, 0.1):

            rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(
                value | generic_unit_system.length,
                0.5 | generic_unit_system.length,
                0.5 | generic_unit_system.length)

            self.assertAlmostRelativeEquals(
                rho, value | generic_unit_system.density)

        sample = sample = datamodel.new_regular_grid(
            (4, 4, 76), (2, 2, 19) | generic_unit_system.length)
        sample.x += 9.5 | generic_unit_system.length
        sample.y += 9.5 | generic_unit_system.length
        sample.z += 0.5 | generic_unit_system.length
        x = sample.x.flatten()
        y = sample.y.flatten()
        z = sample.z.flatten()

        rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(
            x, y, z)
        half = 0.5 | generic_unit_system.length

        self.assertAlmostRelativeEquals(
            rho, (x + (20 * (y - half)) + (400 * (z - half))) /
            (1 | generic_unit_system.length) | generic_unit_system.density)
예제 #25
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test20(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid[1:3, :, :].x, grid.x[1:3, :, :])
     self.assertEquals(grid[1:3, 2:3, :].x, grid.x[1:3, 2:3, :])
     self.assertEquals(grid[1:3, 2:3, 0:1].x, grid.x[1:3, 2:3, 0:1])
     self.assertEquals(grid[1:3, :, 0:1].x, grid.x[1:3, :, 0:1])
     self.assertEquals(grid[:, :, 0:1].x, grid.x[:, :, 0:1])
     self.assertEquals(grid[:, 2:3, 0:1].x, grid.x[:, 2:3, 0:1])
예제 #26
0
 def test2(self):
     grid = datamodel.new_regular_grid((5, 5, 5),
                                       [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     samples = grid.samplePoints([[3.5, 3.0, 3.0], [4.5, 3.0, 3.0]]
                                 | units.m)
     self.assertEquals(len(samples), 2)
     self.assertEquals(samples.mass, [3.5, 4.5] | units.kg)
예제 #27
0
 def test45(self):
     grid = datamodel.new_regular_grid((3, 4, 5, 6), [1.0, 2.0, 3.0, 4.0],
                                       axes_names="abcd")
     for _i, _j in [([-1], [-4])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         subgrid = grid[::2, 0, :, :]
         self.assertEquals(subgrid[i, j].a, subgrid.a[i, j])
예제 #28
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test17(self):
     grid = datamodel.new_regular_grid((4, 2), [1.0 | units.m, 1.0 | units.m])
     self.assertEquals(grid.shape, (4, 2))
     self.assertEquals(grid.x.shape, (4, 2))
     self.assertAlmostRelativeEquals(grid[1].x, ([0.375] * 2) | units.m)
     self.assertAlmostRelativeEquals(grid[1][1].y, 0.75 | units.m)
     self.assertEquals(grid[0].x, grid.x[0])
     self.assertEquals(grid[0][1].x, grid.x[0][1])
예제 #29
0
 def test2(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertTrue(
         numpy.all(
             grid.contains([[0.5, 0.5, 0.5], [0.1, 0.1, 0.1]] | units.m)))
     self.assertFalse(
         numpy.all(
             grid.contains([[1.1, 0.5, 0.5], [0.1, 1.1, 0.1]] | units.m)))
예제 #30
0
 def test19(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid[1:3, ..., ...].x, grid.x[1:3, ..., ...])
     self.assertEquals(grid[1:3, 2:3, ...].x, grid.x[1:3, 2:3, ...])
     self.assertEquals(grid[1:3, 2:3, 0:1].x, grid.x[1:3, 2:3, 0:1])
     self.assertEquals(grid[1:3, ..., 0:1].x, grid.x[1:3, ..., 0:1])
     self.assertEquals(grid[..., ..., 0:1].x, grid.x[..., ..., 0:1])
     self.assertEquals(grid[..., 2:3, 0:1].x, grid.x[..., 2:3, 0:1])
예제 #31
0
 def test8(self):
     grid = datamodel.new_regular_grid((5, 4), [1.0, 1.0] | units.m)
     self.assertAlmostRelativeEquals(grid.get_minimum_position(),
                                     ([0.0, 0.0] | units.m))
     self.assertAlmostRelativeEquals(grid.get_maximum_position(),
                                     [1.0, 1.0] | units.m)
     self.assertAlmostRelativeEquals(grid.get_volume(), 1.0 | units.m**2)
     self.assertTrue(grid.contains([0.5, 0.5] | units.m))
예제 #32
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test12(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid[grid.x > 0.4 | units.m].x.shape, (24,))
     self.assertEquals(grid[grid.x > 0.4 | units.m].x, grid.x[grid.x > 0.4 | units.m])
     iarray, jarray, karray = grid.indices()
     self.assertEquals(grid[grid.x > 0.4 | units.m].indices()[0], iarray[grid.x > 0.4 | units.m])
     self.assertEquals(grid[grid.x > 0.4 | units.m].indices()[1], jarray[grid.x > 0.4 | units.m])
     self.assertEquals(grid[grid.x > 0.4 | units.m].indices()[2], karray[grid.x > 0.4 | units.m])
예제 #33
0
 def test41(self):
     grid = datamodel.new_regular_grid((10, 10), [1.0, 2.0] | units.m)
     for _i, _j in [([0, 1], [2, 3])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         self.assertEquals(grid[i, j].x, grid.x[i, j])
         self.assertEquals(grid[i, j][1:].x, grid.x[i, j][1:])
         self.assertEquals(grid[i, j][1::2].x, grid.x[i, j][1::2])
예제 #34
0
 def test40b(self):
     grid = datamodel.new_regular_grid((50, ), [1.0] | units.m)
     for index in [[0], [0, 3, 4], [1, 2, 2], [[2, 3]], [[0, 1], [2, 3]],
                   range(50)]:
         i = numpy.array(index)
         self.assertEquals(grid[i].x, grid.x[i])
         self.assertEquals(grid[i][1:].x, grid.x[i][1:])
         self.assertEquals(grid[i][1::2].x, grid.x[i][1::2])
예제 #35
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test41(self):
     grid = datamodel.new_regular_grid((10, 10), [1.0, 2.0] | units.m)
     for _i, _j in [([0, 1], [2, 3])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         self.assertEquals(grid[i, j].x, grid.x[i, j])
         self.assertEquals(grid[i, j][1:].x, grid.x[i, j][1:])
         self.assertEquals(grid[i, j][1::2].x, grid.x[i, j][1::2])
예제 #36
0
 def test20(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid[1:3, :, :].x, grid.x[1:3, :, :])
     self.assertEquals(grid[1:3, 2:3, :].x, grid.x[1:3, 2:3, :])
     self.assertEquals(grid[1:3, 2:3, 0:1].x, grid.x[1:3, 2:3, 0:1])
     self.assertEquals(grid[1:3, :, 0:1].x, grid.x[1:3, :, 0:1])
     self.assertEquals(grid[:, :, 0:1].x, grid.x[:, :, 0:1])
     self.assertEquals(grid[:, 2:3, 0:1].x, grid.x[:, 2:3, 0:1])
예제 #37
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test19(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid[1:3, ..., ...].x, grid.x[1:3, ..., ...])
     self.assertEquals(grid[1:3, 2:3, ...].x, grid.x[1:3, 2:3, ...])
     self.assertEquals(grid[1:3, 2:3, 0:1].x, grid.x[1:3, 2:3, 0:1])
     self.assertEquals(grid[1:3, ..., 0:1].x, grid.x[1:3, ..., 0:1])
     self.assertEquals(grid[..., ..., 0:1].x, grid.x[..., ..., 0:1])
     self.assertEquals(grid[..., 2:3, 0:1].x, grid.x[..., 2:3, 0:1])
예제 #38
0
 def test18(self):
     
     instance=self.new_instance_of_an_optional_code(MpiAmrVac, number_of_workers=3)
     instance.parameters.x_boundary_conditions = ("periodic","periodic")
     instance.parameters.y_boundary_conditions = ("periodic","periodic")
     instance.parameters.z_boundary_conditions = ("periodic","periodic")
     instance.parameters.mesh_length = (20.0, 20.0, 20.0) | generic_unit_system.length
     instance.parameters.mesh_length = (20.0, 20.0, 20.0) | generic_unit_system.length
     instance.parameters.mesh_size = (20, 20, 20)
     instance.parameters.maximum_number_of_grid_levels = 1
     
     for x in instance.itergrids():
         inmem = x.copy()
         inmem.rho = (
             (
                 inmem.x + 
                 ((inmem.y - (0.5| generic_unit_system.length))* 20.0) +
                 ((inmem.z - (0.5| generic_unit_system.length))* 400.0)
             )
             /(1| generic_unit_system.length) | generic_unit_system.density
         )
         inmem.rhovx = 0.0 | generic_unit_system.momentum_density
         inmem.energy =  1.0 | generic_unit_system.energy_density
         from_model_to_code = inmem.new_channel_to(x)
         from_model_to_code.copy()
     rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(0.5| generic_unit_system.length,0.5| generic_unit_system.length,0.5| generic_unit_system.length)
     
     self.assertEquals(rho , 0.5 | generic_unit_system.density)
     
     for value in numpy.arange(0.5, 19.6, 0.1):
         
         rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(
             value | generic_unit_system.length,
             0.5 | generic_unit_system.length,
             0.5 | generic_unit_system.length
         )
     
         self.assertAlmostRelativeEquals(rho , value | generic_unit_system.density)
     
     sample = sample = datamodel.new_regular_grid(
         (4, 4, 76),
         (2, 2, 19) | generic_unit_system.length
     )
     sample.x += 9.5 | generic_unit_system.length
     sample.y += 9.5 | generic_unit_system.length
     sample.z += 0.5 | generic_unit_system.length
     x = sample.x.flatten()
     y = sample.y.flatten()
     z = sample.z.flatten()
     
     rho, rhovx, rhovy, rhovx, rhoenergy = instance.get_hydro_state_at_point(
         x,
         y,
         z
     )
     half = 0.5 | generic_unit_system.length
     
     self.assertAlmostRelativeEquals(rho , (x + (20 * (y-half)) + (400 * (z-half)))/(1| generic_unit_system.length) | generic_unit_system.density )
예제 #39
0
 def test11(self): 
     instance=self.new_instance_of_an_optional_code(MpiAmrVac)
     instance.parameters.mesh_size = (10,10,10)
     instance.parameters.mesh_length = [1.0, 1.0, 1.0] | generic_unit_system.length
     instance.parameters.maximum_number_of_grid_levels = 1
     instance.parameters.x_boundary_conditions = ("periodic", "periodic")
     instance.parameters.y_boundary_conditions = ("periodic", "periodic")
     instance.parameters.z_boundary_conditions = ("periodic", "periodic")
     instance.parameters.stopping_conditions_timeout = 0.1 | units.s
     
     gamma = 5.0 / 3.0
     
     grid = datamodel.new_regular_grid((10,10,10), [1.0, 1.0, 1.0] | generic_unit_system.length )
     
     density = generic_unit_system.density
     momentum =  generic_unit_system.speed * generic_unit_system.density
     energy =  generic_unit_system.mass / ((generic_unit_system.time**2) * generic_unit_system.length)
     
     
     grid.rho = 0.01 | density
     grid.rhovx = 0.1 | momentum
     grid.rhovy = 0.0 | momentum
     grid.rhovz = 0.0 | momentum
     grid[0:5].rho = 0.015 | density
     
     p = 1.0 | (generic_unit_system.mass / (generic_unit_system.length * generic_unit_system.time**2))
     
     grid.energy =  p / (gamma - 1)
     grid.energy += 0.5 * (grid.rhovx ** 2  + grid.rhovy ** 2 + grid.rhovz ** 2) / grid.rho
     
     grids = list(instance.itergrids())
     self.assertEquals(len(grids), 1)
     igrid = grids[0]
     channel = grid.new_channel_to(igrid)
     channel.copy()
     
     instance.stopping_conditions.timeout_detection.enable()
     instance.evolve_model(1.0 | generic_unit_system.time)
     
     self.assertTrue(instance.stopping_conditions.timeout_detection.is_set())
     rho = instance.itergrids().next().rho[...,0,0]
     print rho
     print instance.model_time
     self.assertAlmostRelativeEquals(rho.mean(), 0.0125 | density)
     self.assertTrue( instance.model_time < 1.0 | generic_unit_system.time)
     
     
     instance.stopping_conditions.timeout_detection.disable()
     print instance.model_time.round(2)
     tnext =  instance.model_time.round(2) + (0.2 | generic_unit_system.time)
     instance.evolve_model(tnext)
     rho = instance.itergrids().next().rho[...,0,0]
     print rho
     self.assertAlmostRelativeEquals( instance.model_time.round(2) ,tnext)
     self.assertAlmostRelativeEquals(rho.mean(), 0.0125 | density)
     self.assertTrue(rho[0] < 0.015 | density)
     
     instance.stop()
예제 #40
0
 def test17(self):
     grid = datamodel.new_regular_grid((4, 2),
                                       [1.0 | units.m, 1.0 | units.m])
     self.assertEquals(grid.shape, (4, 2))
     self.assertEquals(grid.x.shape, (4, 2))
     self.assertAlmostRelativeEquals(grid[1].x, ([0.375] * 2) | units.m)
     self.assertAlmostRelativeEquals(grid[1][1].y, 0.75 | units.m)
     self.assertEquals(grid[0].x, grid.x[0])
     self.assertEquals(grid[0][1].x, grid.x[0][1])
예제 #41
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test3(self):
     grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.index_for_000_cell, [1, 1, 1])
     self.assertEquals(
         sample.surrounding_cell_indices,
         [[1, 1, 1], [2, 1, 1], [1, 2, 1], [1, 1, 2], [2, 1, 2], [1, 2, 2], [2, 2, 1], [2, 2, 2]],
     )
예제 #42
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test42(self):
     grid = datamodel.new_regular_grid((3, 4, 5, 6), [1.0, 2.0, 3.0, 4.0], axes_names="abcd")
     for _i, _j in [([0], [3]), ([0, 1], [2, 3])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         self.assertEquals(grid[i, j].a, grid.a[i, j])
         self.assertEquals(grid[0, 1, i, j].a, grid.a[0, 1, i, j])
         self.assertEquals(grid[i, j, 0, 0].a, grid.a[i, j, 0, 0])
         self.assertEquals(grid[i, 1, 2, j].a, grid.a[i, 1, 2, j])
예제 #43
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test7(self):
     grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
     self.assertTrue(sample.isvalid)
     sample = grid.samplePoint([11.0, 3.0, 3.0] | units.m)
     self.assertFalse(sample.isvalid)
     sample = grid.samplePoint([3.0, -1.0, 3.0] | units.m)
     self.assertFalse(sample.isvalid)
예제 #44
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test18(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid.shape, (5, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].x.shape, (1, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].shape, (1, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].x, grid.x[1:2, ..., ...])
     self.assertEquals(grid[1:3, ..., ...].x.shape, (2, 4, 2))
     self.assertEquals(grid[1:3, ..., ...].shape, (2, 4, 2))
     self.assertEquals(grid[1:3, ..., ...].x, grid.x[1:3, ..., ...])
예제 #45
0
 def test18(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     self.assertEquals(grid.shape, (5, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].x.shape, (1, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].shape, (1, 4, 2))
     self.assertEquals(grid[1:2, ..., ...].x, grid.x[1:2, ..., ...])
     self.assertEquals(grid[1:3, ..., ...].x.shape, (2, 4, 2))
     self.assertEquals(grid[1:3, ..., ...].shape, (2, 4, 2))
     self.assertEquals(grid[1:3, ..., ...].x, grid.x[1:3, ..., ...])
예제 #46
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test9(self):
     grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m, must_return_values_on_cell_center=False)
     self.assertEquals(sample.position, [3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.mass, 3.0 | units.kg)
     sample = grid.samplePoint([3.5, 3.0, 3.0] | units.m, must_return_values_on_cell_center=False)
     self.assertEquals(sample.position, [3.5, 3.0, 3.0] | units.m)
     self.assertEquals(sample.mass, 3.5 | units.kg)
예제 #47
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test1(self):
     grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     samples = grid.samplePoints([[3.0, 3.0, 3.0], [4.0, 3.0, 3.0]] | units.m)
     self.assertEquals(len(samples), 2)
     self.assertEquals(samples.position[0], [3.0, 3.0, 3.0] | units.m)
     self.assertEquals(samples.position[0], samples[0].position)
     self.assertEquals(samples.position[1], samples[1].position)
     self.assertEquals(samples.mass, [3.0, 4.0] | units.kg)
예제 #48
0
    def test1(self):
        grid1 = datamodel.new_cartesian_grid((4, 5), 1.0 | units.m)
        grid2 = datamodel.new_regular_grid((4, 5), [4.0, 5.0] | units.m)
        grid3 = datamodel.new_rectilinear_grid(
            (4, 5), [numpy.arange(5.) | units.m,
                     numpy.arange(6.) | units.m])

        self.assertEqual(grid1.position, grid2.position)
        self.assertEqual(grid2.position, grid3.position)
예제 #49
0
 def test40(self):
     grid1 = datamodel.new_regular_grid((5, 4, 2),
                                        [1.0, 1.0, 1.0] | units.m)
     grid2 = datamodel.new_regular_grid((5, 4, 2),
                                        [1.0, 1.0, 1.0] | units.m)
     grid1.m1 = 1
     grid1.m2 = 2
     channel = grid1.new_channel_to(grid2)
     channel.transform(["m3"], lambda x, y: (x, ), ["m1", "m2"])
     self.assertEquals(grid2.m3, 1)
     channel.transform(["m3"], lambda x, y: (y, ), ["m1", "m2"])
     self.assertEquals(grid2.m3, 2)
     channel.transform(["m3"], lambda x, y: (x + y, ), ["m1", "m2"])
     self.assertEquals(grid2.m3, 3)
     channel.transform(["m3", "m4"], lambda x, y: (x + y, 2 * x - y),
                       ["m1", "m2"])
     self.assertEquals(grid2.m3, 3)
     self.assertEquals(grid2.m4, 0)
예제 #50
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test7(self):
        grid = datamodel.new_regular_grid((5, 5, 5), [10.0, 10.0, 10.0] | units.m)

        self.assertAlmostRelativeEquals(grid[1][2][3].position, [3, 5, 7] | units.m)

        grid[1][2][3].position = [7, 5, 3] | units.m
        self.assertAlmostRelativeEquals(grid[1][2][3].position, [7, 5, 3] | units.m)

        grid[1][2][3].position += [1, 2, 3] | units.m
        self.assertAlmostRelativeEquals(grid[1][2][3].position, [8, 7, 6] | units.m)
예제 #51
0
 def test16(self):
     grid = datamodel.new_regular_grid((5,4,2,4), [1.0 | units.m, 1.0 | units.m, 1.0 | units.m, 1.0 | units.s], ('x', 'y', 'z', 't') )
     self.assertEquals(grid.shape, (5,4,2,4))
     self.assertEquals(grid.x.shape, (5,4,2,4))
     self.assertAlmostRelativeEquals( grid[1][2][1].x, ([0.3] * 4) | units.m)
     self.assertAlmostRelativeEquals( grid[1][2][1].t, [0.125, 0.375, 0.625, 0.875] | units.s)
     self.assertEquals(grid[0].x, grid.x[0])
     self.assertEquals(grid[0][1].x, grid.x[0][1])
     self.assertEquals(grid[1][2][1].x, grid.x[1][2][1])
     self.assertEquals(grid[1][2][1][2].x, grid.x[1][2][1][2])
예제 #52
0
 def test42(self):
     grid = datamodel.new_regular_grid((3, 4, 5, 6), [1.0, 2.0, 3.0, 4.0],
                                       axes_names="abcd")
     for _i, _j in [([0], [3]), ([0, 1], [2, 3])]:
         i = numpy.array(_i)
         j = numpy.array(_j)
         self.assertEquals(grid[i, j].a, grid.a[i, j])
         self.assertEquals(grid[0, 1, i, j].a, grid.a[0, 1, i, j])
         self.assertEquals(grid[i, j, 0, 0].a, grid.a[i, j, 0, 0])
         self.assertEquals(grid[i, 1, 2, j].a, grid.a[i, 1, 2, j])
예제 #53
0
 def test7(self):
     grid = datamodel.new_regular_grid((5, 5, 5),
                                       [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
     self.assertTrue(sample.isvalid)
     sample = grid.samplePoint([11.0, 3.0, 3.0] | units.m)
     self.assertFalse(sample.isvalid)
     sample = grid.samplePoint([3.0, -1.0, 3.0] | units.m)
     self.assertFalse(sample.isvalid)
예제 #54
0
파일: test_grids.py 프로젝트: rieder/amuse
 def test3(self):
     grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
     points = grid.points()
     self.assertEquals(points.shape, (6, 5, 3, 3))
     self.assertAlmostRelativeEquals(points[0][0][0], ([0.0, 0.0, 0.0] | units.m))
     self.assertAlmostRelativeEquals(points[1][0][0], ([0.2, 0.0, 0.0] | units.m))
     self.assertAlmostRelativeEquals(points[1][1][1], [0.2, 0.25, 0.5] | units.m)
     self.assertAlmostRelativeEquals(points[0][-1][-1], ([0.0, 1.0, 1.0] | units.m))
     self.assertAlmostRelativeEquals(points[-1][0][-1], ([1.0, 0.0, 1.0] | units.m))
     self.assertAlmostRelativeEquals(points[-1][-1][0], ([1.0, 1.0, 0.0] | units.m))
     self.assertAlmostRelativeEquals(points[-1][-1][-1], ([1.0, 1.0, 1.0] | units.m))
예제 #55
0
 def test4(self):
     grid = datamodel.new_regular_grid((5, 5, 5),
                                       [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     sample = grid.samplePoint([3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[0].position,
                       [3.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[1].position,
                       [5.0, 3.0, 3.0] | units.m)
     self.assertEquals(sample.surrounding_cells[-1].position,
                       [5.0, 5.0, 5.0] | units.m)
예제 #56
0
 def test1(self):
     grid = datamodel.new_regular_grid((5, 5, 5),
                                       [10.0, 10.0, 10.0] | units.m)
     grid.mass = grid.x.value_in(units.m) | units.kg
     samples = grid.samplePoints([[3.0, 3.0, 3.0], [4.0, 3.0, 3.0]]
                                 | units.m)
     self.assertEquals(len(samples), 2)
     self.assertEquals(samples.position[0], [3.0, 3.0, 3.0] | units.m)
     self.assertEquals(samples.position[0], samples[0].position)
     self.assertEquals(samples.position[1], samples[1].position)
     self.assertEquals(samples.mass, [3.0, 4.0] | units.kg)
예제 #57
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test9(self):
        grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)
        self.assertEquals(grid[0][0][0].x, 0.1 | units.m)
        self.assertEquals(grid[0][0][0].y, 0.125 | units.m)
        self.assertEquals(grid[0][0][0].z, 0.25 | units.m)
        self.assertEquals(grid[..., 0, 0].x, [0.1, 0.3, 0.5, 0.7, 0.9] | units.m)
        self.assertEquals(grid[0, 0, ...].z, [0.25, 0.75] | units.m)

        cellsize = grid.cellsize()
        self.assertAlmostRelativeEquals(cellsize[0], 0.2 | units.m)
        self.assertAlmostRelativeEquals(cellsize[1], 0.25 | units.m)
        self.assertAlmostRelativeEquals(cellsize[2], 0.5 | units.m)
예제 #58
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test26(self):

        grid = datamodel.new_regular_grid((5, 4, 2), [1.0, 1.0, 1.0] | units.m)

        xv, yv, zv = numpy.mgrid[0:5, 0:4, 0:2]
        xv = xv.flatten()
        yv = yv.flatten()
        zv = zv.flatten()
        i = 0
        for cell in grid.iter_cells():
            expected_position = grid[xv[i], yv[i], zv[i]].position
            self.assertEquals(cell.position, expected_position)
            i += 1
예제 #59
0
파일: test_grids.py 프로젝트: rieder/amuse
    def test27(self):
        grid = datamodel.new_regular_grid((3, 3), [1.0, 1.0] | units.m)
        subgrid1 = grid[0:1, 0:2]
        subgrid2 = grid[0:1, 0:2]
        subgrid3 = grid[0:2, 0:3][0:1, 0:2]
        subgrid4 = grid[0:1, 0:3]

        self.assertTrue(subgrid1 == subgrid2)
        self.assertTrue(subgrid1 == subgrid3)
        self.assertTrue(subgrid2 == subgrid3)
        self.assertFalse(subgrid1 == subgrid4)
        self.assertFalse(subgrid2 == subgrid4)
        self.assertFalse(subgrid3 == subgrid4)