def test_3subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = False
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 64), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (8, 64), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((40, 0), (24, 64), envelope_size=1, id_=3)

        proc = LBGeometryProcessor([b1, b2, b3], 2, geo)
        proc._connect_subdomains(config)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b3.id)

        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 63)])
        expected_map = {
            vi(-1, 0): np.array([[0], [63]]),
            vi(-1, 1): np.array([[63]]),
            vi(-1, -1): np.array([[0]])
        }
        _verify_partial_map(self, cpair.src, expected_map)
    def test_2subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 64), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (32, 64), envelope_size=1, id_=2)

        proc = LBGeometryProcessor([b1, b2], 2, geo)
        proc._connect_subdomains(config)

        cpairs = b1.get_connections(SubdomainSpec2D.X_HIGH, b2.id)
        self.assertEqual(len(cpairs), 3)

        cpairs = b1.get_connections(SubdomainSpec2D.X_LOW, b2.id)
        self.assertTrue(
            self._check_partial_map(
                cpairs, [slice(1, 65)], {
                    vi(-1, -1): np.array([[0]]),
                    vi(-1, 0): np.array([[0], [63]]),
                    vi(-1, 1): np.array([[63]])
                }))

        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                                    {vi(-1, -1): np.array([[0]])}))

        self.assertTrue(
            self._check_partial_map(cpairs, [slice(65, 66)],
                                    {vi(-1, 1): np.array([[0]])}))
    def test_2subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 64), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (32, 64), envelope_size=1, id_=2)

        proc = LBGeometryProcessor([b1, b2], 2, geo.gsize)
        proc._connect_subdomains(config)

        cpairs = b1.get_connections(SubdomainSpec2D.X_HIGH, b2.id)
        self.assertEqual(len(cpairs), 3)

        cpairs = b1.get_connections(SubdomainSpec2D.X_LOW, b2.id)
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(1, 65)],
                {vi(-1, -1): np.array([[0]]),
                 vi(-1, 0): np.array([[0], [63]]),
                 vi(-1, 1): np.array([[63]])}))

        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                {vi(-1, -1): np.array([[0]])}))

        self.assertTrue(
            self._check_partial_map(cpairs, [slice(65, 66)],
                {vi(-1, 1): np.array([[0]])}))
Exemple #4
0
    def test_periodic_yz_2subdomains(self):
        self.sim.config.periodic_y = True
        self.sim.config.periodic_z = True

        spec0 = SubdomainSpec3D((0, 0, 0),
                                self.lattice_size,
                                envelope_size=1,
                                id_=0)
        spec1 = SubdomainSpec3D((0, 0, self.lattice_size[2]),
                                self.lattice_size,
                                envelope_size=1,
                                id_=1)

        nx, ny, nz = self.lattice_size
        spec0, spec1 = LBGeometryProcessor(
            [spec0, spec1], 3, (nx, ny, 2 * nz)).transform(self.sim.config)

        spec0.runner = SubdomainRunner(self.sim,
                                       spec0,
                                       output=None,
                                       backend=self.backend,
                                       quit_event=None)
        spec0.runner._init_shape()
        spec1.runner = SubdomainRunner(self.sim,
                                       spec1,
                                       output=None,
                                       backend=self.backend,
                                       quit_event=None)
        spec1.runner._init_shape()

        class _LinkTaggingSubdomain3D(Subdomain3D):
            def boundary_conditions(self, hx, hy, hz):
                self.set_node((hx == 0) | (hx == self.gx - 1), NTHalfBBWall)

        sub0 = _LinkTaggingSubdomain3D(list(reversed(self.lattice_size)),
                                       spec0, D3Q19)
        sub0.allocate()
        sub0.reset()
        sub1 = _LinkTaggingSubdomain3D(list(reversed(self.lattice_size)),
                                       spec1, D3Q19)
        sub1.allocate()
        sub1.reset()

        hx, hy, hz = sub1._get_mgrid()
        hx_tags = reduce(
            operator.or_,
            ((1 << i) for i, vec in enumerate(D3Q19.basis[1:]) if vec[0] >= 0))
        np.testing.assert_equal(hx_tags, sub0._orientation[hx == 0])
        np.testing.assert_equal(hx_tags, sub1._orientation[hx == 0])

        hx_tags = reduce(
            operator.or_,
            ((1 << i) for i, vec in enumerate(D3Q19.basis[1:]) if vec[0] <= 0))
        np.testing.assert_equal(hx_tags, sub0._orientation[hx == nx - 1])
        np.testing.assert_equal(hx_tags, sub1._orientation[hx == nx - 1])
    def test_5subdomains(self):
        config = LBConfig()
        config.lat_nx = 50
        config.lat_ny = 75
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (25, 25), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((25, 0), (25, 25), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((0, 25), (50, 25), envelope_size=1, id_=3)
        b4 = SubdomainSpec2D((0, 50), (25, 25), envelope_size=1, id_=4)
        b5 = SubdomainSpec2D((25, 50), (25, 25), envelope_size=1, id_=5)

        proc = LBGeometryProcessor([b1, b2, b3, b4, b5], 2, geo)
        proc._connect_subdomains(config)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b5.id)
        expected_map = {vi(-1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.X_HIGH, b5.id)
        expected_map = {vi(1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.Y_LOW, b4.id)
        expected_map = {
            vi(0, -1): np.array([[0], [24]]),
            vi(1, -1): np.array([[24]]),
            vi(-1, -1): np.array([[0]])
        }
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b2.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.X_HIGH, b2.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.Y_HIGH, b3.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b3.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi(-1, 1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)
    def test_5subdomains(self):
        config = LBConfig()
        config.lat_nx = 50
        config.lat_ny = 75
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (25, 25), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((25, 0), (25, 25), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((0, 25), (50, 25), envelope_size=1, id_=3)
        b4 = SubdomainSpec2D((0, 50), (25, 25), envelope_size=1, id_=4)
        b5 = SubdomainSpec2D((25, 50), (25, 25), envelope_size=1, id_=5)

        proc = LBGeometryProcessor([b1, b2, b3, b4, b5], 2, geo.gsize)
        proc._connect_subdomains(config)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b5.id)
        expected_map = {vi(-1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.X_HIGH, b5.id)
        expected_map = {vi(1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.Y_LOW, b4.id)
        expected_map = {vi(0, -1): np.array([[0], [24]]),
                        vi(1, -1): np.array([[24]]),
                        vi(-1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b2.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.X_HIGH, b2.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.Y_HIGH, b3.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 24)])

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b3.id)
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi(-1, 1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)
Exemple #7
0
    def test_periodic_yz_2subdomains(self):
        self.sim.config.periodic_y = True
        self.sim.config.periodic_z = True

        spec0 = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec1 = SubdomainSpec3D((0, 0, self.lattice_size[2]), self.lattice_size, envelope_size=1, id_=1)

        nx, ny, nz = self.lattice_size
        spec0, spec1 = LBGeometryProcessor([spec0, spec1], 3, (nx, ny, 2 * nz)).transform(self.sim.config)

        spec0.runner = SubdomainRunner(self.sim, spec0, output=None,
                                       backend=self.backend, quit_event=None)
        spec0.runner._init_shape()
        spec1.runner = SubdomainRunner(self.sim, spec1, output=None,
                                       backend=self.backend, quit_event=None)
        spec1.runner._init_shape()

        class _LinkTaggingSubdomain3D(Subdomain3D):
            def boundary_conditions(self, hx, hy, hz):
                self.set_node((hx == 0) | (hx == self.gx - 1), NTHalfBBWall)

        sub0 = _LinkTaggingSubdomain3D(list(reversed(self.lattice_size)), spec0, D3Q19)
        sub0.allocate()
        sub0.reset()
        sub1 = _LinkTaggingSubdomain3D(list(reversed(self.lattice_size)), spec1, D3Q19)
        sub1.allocate()
        sub1.reset()

        hx, hy, hz = sub1._get_mgrid()
        hx_tags = reduce(operator.or_, ((1 << i) for i, vec in
                         enumerate(D3Q19.basis[1:]) if vec[0] >= 0))
        np.testing.assert_equal(hx_tags, sub0._orientation[hx == 0])
        np.testing.assert_equal(hx_tags, sub1._orientation[hx == 0])

        hx_tags = reduce(operator.or_, ((1 << i) for i, vec in
                         enumerate(D3Q19.basis[1:]) if vec[0] <= 0))
        np.testing.assert_equal(hx_tags, sub0._orientation[hx == nx - 1])
        np.testing.assert_equal(hx_tags, sub1._orientation[hx == nx - 1])
    def test_3subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = False
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 64), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (8, 64), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((40, 0), (24, 64), envelope_size=1, id_=3)

        proc = LBGeometryProcessor([b1, b2, b3], 2, geo.gsize)
        proc._connect_subdomains(config)

        cpair = b1.get_connection(SubdomainSpec2D.X_LOW, b3.id)

        self.assertEqual(cpair.src.dst_full_buf_slice, [slice(1, 63)])
        expected_map = {
            vi(-1, 0): np.array([[0], [63]]),
            vi(-1, 1): np.array([[63]]),
            vi(-1, -1): np.array([[0]])}
        _verify_partial_map(self, cpair.src, expected_map)
    def test_4subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 32), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (32, 32), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((0, 32), (32, 32), envelope_size=1, id_=3)
        b4 = SubdomainSpec2D((32, 32), (32, 32), envelope_size=1, id_=4)

        proc = LBGeometryProcessor([b1, b2, b3, b4], 2, geo)
        proc._connect_subdomains(config)

        ## b1 - b4

        cpairs = b1.get_connections(SubdomainSpec2D.X_LOW, b4.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                                    {vi(-1, -1): np.array([[0]])}))
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(33, 34)],
                                    {vi(-1, 1): np.array([[0]])}))

        cpairs = b1.get_connections(SubdomainSpec2D.X_HIGH, b4.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                                    {vi(1, -1): np.array([[0]])}))
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(33, 34)],
                                    {vi(1, 1): np.array([[0]])}))

        cpairs = b1.get_connections(SubdomainSpec2D.Y_LOW, b4.id)
        self.assertEqual(len(cpairs), 0)

        cpairs = b1.get_connections(SubdomainSpec2D.Y_HIGH, b4.id)
        self.assertEqual(len(cpairs), 0)

        ### b2 - b3

        cpairs = b2.get_connections(SubdomainSpec2D.X_LOW, b3.id)

        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                                    {vi(-1, -1): np.array([[0]])}))
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(33, 34)],
                                    {vi(-1, 1): np.array([[0]])}))

        cpairs = b2.get_connections(SubdomainSpec2D.X_HIGH, b3.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(0, 1)],
                                    {vi(1, -1): np.array([[0]])}))
        self.assertTrue(
            self._check_partial_map(cpairs, [slice(33, 34)],
                                    {vi(1, 1): np.array([[0]])}))

        cpairs = b2.get_connections(SubdomainSpec2D.Y_LOW, b3.id)
        self.assertEqual(len(cpairs), 0)

        cpairs = b2.get_connections(SubdomainSpec2D.Y_HIGH, b3.id)
        self.assertEqual(len(cpairs), 0)
    def test_4subdomains(self):
        config = LBConfig()
        config.lat_nx = 64
        config.lat_ny = 64
        config.periodic_x = True
        config.periodic_y = True
        config.grid = 'D2Q9'

        geo = LBGeometry2D(config)
        b1 = SubdomainSpec2D((0, 0), (32, 32), envelope_size=1, id_=1)
        b2 = SubdomainSpec2D((32, 0), (32, 32), envelope_size=1, id_=2)
        b3 = SubdomainSpec2D((0, 32), (32, 32), envelope_size=1, id_=3)
        b4 = SubdomainSpec2D((32, 32), (32, 32), envelope_size=1, id_=4)

        proc = LBGeometryProcessor([b1, b2, b3, b4], 2, geo.gsize)
        proc._connect_subdomains(config)

        ## b1 - b4

        cpairs = b1.get_connections(SubdomainSpec2D.X_LOW, b4.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(0, 1)],
                    {vi(-1, -1): np.array([[0]])}))
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(33, 34)],
                    {vi(-1, 1): np.array([[0]])}))

        cpairs = b1.get_connections(SubdomainSpec2D.X_HIGH, b4.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(0, 1)],
                    {vi(1, -1): np.array([[0]])}))
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(33, 34)],
                    {vi(1, 1): np.array([[0]])}))

        cpairs = b1.get_connections(SubdomainSpec2D.Y_LOW, b4.id)
        self.assertEqual(len(cpairs), 0)

        cpairs = b1.get_connections(SubdomainSpec2D.Y_HIGH, b4.id)
        self.assertEqual(len(cpairs), 0)

        ### b2 - b3

        cpairs = b2.get_connections(SubdomainSpec2D.X_LOW, b3.id)

        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(0, 1)],
                    {vi(-1, -1): np.array([[0]])}))
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(33, 34)],
                    {vi(-1, 1): np.array([[0]])}))

        cpairs = b2.get_connections(SubdomainSpec2D.X_HIGH, b3.id)
        self.assertEqual(len(cpairs), 2)
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(0, 1)],
                    {vi(1, -1): np.array([[0]])}))
        self.assertTrue(
                self._check_partial_map(cpairs, [slice(33, 34)],
                    {vi(1, 1): np.array([[0]])}))

        cpairs = b2.get_connections(SubdomainSpec2D.Y_LOW, b3.id)
        self.assertEqual(len(cpairs), 0)

        cpairs = b2.get_connections(SubdomainSpec2D.Y_HIGH, b3.id)
        self.assertEqual(len(cpairs), 0)