コード例 #1
0
 def subdomains(self, n=None):
     d = self.gz / 2
     blocks = [
         SubdomainSpec3D((0, 0, 0), (self.gx, self.gy, d)),
         SubdomainSpec3D((0, 0, d), (self.gx, self.gy, d))
     ]
     return blocks
コード例 #2
0
 def subdomains(self, n=None):
     w = self.gx / 2
     blocks = [
         SubdomainSpec3D((0, 0, 0), (w, self.gy, self.gz)),
         SubdomainSpec3D((w, 0, 0), (w, self.gy, self.gz))
     ]
     return blocks
コード例 #3
0
ファイル: geo.py プロジェクト: zliu72/sailfish
    def subdomains(self):
        if not self.config.geometry_for_decomposition:
            return super(WeightedSubdomainsGeometry3D, self).subdomains()

        geo = util.load_array(self.config.geometry_for_decomposition)

        assert self.gz == geo.shape[0]
        assert self.gy == geo.shape[1]
        assert self.gx == geo.shape[2]

        axes = set([0, 1, 2])
        conn_axis = 'xyz'.index(self.config.conn_axis)
        axes.remove(conn_axis)
        profile = np.sum(np.logical_not(geo), axis=tuple(axes))
        profile = np.cumsum(profile)

        start = [0, 0, 0]
        size = [self.gx, self.gy, self.gz]
        nodes_per_subdomain = profile[-1] // self.config.subdomains

        ret = []
        for i, cum_nodes in enumerate(profile):
            if cum_nodes - profile[start[conn_axis]] >= nodes_per_subdomain:
                size[conn_axis] = i - start[conn_axis] + 1
                ret.append(SubdomainSpec3D(start, size))
                start[conn_axis] = i + 1

        if start[conn_axis] < len(profile) - 1:
            size[conn_axis] = len(profile) - start[conn_axis]
            ret.append(SubdomainSpec3D(start, size))
        return ret
コード例 #4
0
ファイル: geo.py プロジェクト: zmhou/sailfish
    def subdomains(self):
        s = self.config.subdomains

        if self.config.conn_axis == 'x':
            sx = self.gx / s
            rx = self.gx % s
            return [
                SubdomainSpec3D(
                    (i * sx, 0, 0),
                    (sx if i < s - 1 else rx + sx, self.gy, self.gz))
                for i in range(0, s)
            ]
        elif self.config.conn_axis == 'y':
            sy = self.gy / s
            ry = self.gy % s

            return [
                SubdomainSpec3D(
                    (0, i * sy, 0),
                    (self.gx, sy if i < s - 1 else ry + sy, self.gz))
                for i in range(0, s)
            ]
        else:
            sz = self.gz / s
            rz = self.gz % s

            return [
                SubdomainSpec3D(
                    (0, 0, i * sz),
                    (self.gx, self.gy, sz if i < s - 1 else rz + sz))
                for i in range(0, s)
            ]
コード例 #5
0
 def subdomains(self, n=None):
     h = self.gy / 2
     blocks = [
         SubdomainSpec3D((0, 0, 0), (self.gx, h, self.gz)),
         SubdomainSpec3D((0, h, 0), (self.gx, h, self.gz))
     ]
     return blocks
コード例 #6
0
 def subdomains(self, n=None):
     return [
         SubdomainSpec3D((0, 0, 0), (32, 32, 32)),
         SubdomainSpec3D((0, 0, 32), (32, 32, 32)),
         SubdomainSpec3D((0, 32, 0), (32, 32, 32)),
         SubdomainSpec3D((0, 32, 32), (32, 32, 32))
     ]
コード例 #7
0
    def test_subdomain_connection_edge_non_x(self):
        base = SubdomainSpec3D((10, 10, 10), (10, 10, 10),
                               envelope_size=1,
                               id_=0)
        b1 = SubdomainSpec3D((10, 5, 5), (10, 5, 5), envelope_size=1, id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q19))
        cpair = base.get_connection(SubdomainSpec3D.Y_LOW, b1.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(1, 2)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.dst_low, [0, 4])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi3(0, -1, -1): [(x, 0) for x in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b2 = SubdomainSpec3D((10, 20, 5), (10, 5, 5), envelope_size=1, id_=2)
        self.assertTrue(base.connect(b2, grid=D3Q19))
        cpair = base.get_connection(SubdomainSpec3D.Y_HIGH, b2.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(1, 2)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.dst_low, [0, 4])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi3(0, 1, -1): [(x, 0) for x in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b3 = SubdomainSpec3D((10, 5, 20), (10, 5, 5), envelope_size=1, id_=3)
        self.assertTrue(base.connect(b3, grid=D3Q19))
        cpair = base.get_connection(SubdomainSpec3D.Y_LOW, b3.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(10, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi3(0, -1, 1): [(x, 0) for x in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b4 = SubdomainSpec3D((10, 20, 20), (10, 5, 5), envelope_size=1, id_=4)
        self.assertTrue(base.connect(b4, grid=D3Q19))
        cpair = base.get_connection(SubdomainSpec3D.Y_HIGH, b4.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(10, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi3(0, 1, 1): [(x, 0) for x in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)
コード例 #8
0
ファイル: subdomain.py プロジェクト: zliu72/sailfish
    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])
コード例 #9
0
ファイル: subdomain.py プロジェクト: zliu72/sailfish
    def test_orientation_channel_2subdomains(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec0 = SubdomainSpec3D((0, 0, 0),
                                self.lattice_size,
                                envelope_size=1,
                                id_=0)
        spec0.enable_local_periodicity(1)
        spec1 = SubdomainSpec3D((0, 0, self.lattice_size[2]),
                                self.lattice_size,
                                envelope_size=1,
                                id_=1)
        spec1.enable_local_periodicity(1)

        self.assertTrue(spec0.connect(spec1, grid=D3Q19))

        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()

        sub0 = self._ChannelSubdomain3D(list(reversed(self.lattice_size)),
                                        spec0, D3Q19)
        sub0.allocate()
        sub0.reset()

        sub1 = self._ChannelSubdomain3D(list(reversed(self.lattice_size)),
                                        spec1, D3Q19)
        sub1.allocate()
        sub1.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub0._get_mgrid()

        np.testing.assert_equal(sub0._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub0._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub1._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
コード例 #10
0
    def subdomains(self, n=None):
        subdomains = []
        bps = int(self.config.ldc_subdomains**(1.0 / 3))

        if bps**3 != self.config.ldc_subdomains:
            print('Only configurations with '
                  'a third power of an integer number of subdomains are '
                  'supported.  Falling back to {0} x {0} subdomains.'.format(
                      bps))

        xq = self.gx / bps
        xd = self.gx % bps
        yq = self.gy / bps
        yd = self.gy % bps
        zq = self.gz / bps
        zd = self.gz % bps

        for i in range(0, bps):
            xsize = xq
            if i == bps - 1:
                xsize += xd
            for j in range(0, bps):
                ysize = yq
                if j == bps - 1:
                    ysize += yd
                for k in range(0, bps):
                    zsize = zq
                    if k == bps - 1:
                        zsize += zd
                    subdomains.append(
                        SubdomainSpec3D((i * xq, j * yq, k * zq),
                                        (xsize, ysize, zsize)))
        return subdomains
コード例 #11
0
ファイル: subdomain.py プロジェクト: zherexli/sailfish
    def test_periodic_xz(self):
        self.sim.config.periodic_x = True
        self.sim.config.periodic_z = True

        spec = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec.enable_local_periodicity(0)
        spec.enable_local_periodicity(2)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()

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

        sub = _LinkTaggingSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        hy_tags = reduce(operator.or_, ((1 << i) for i, vec in
                         enumerate(D3Q19.basis[1:]) if vec[1] >= 0))
        np.testing.assert_equal(hy_tags, sub._orientation[hy == 0])

        hy_tags = reduce(operator.or_, ((1 << i) for i, vec in
                         enumerate(D3Q19.basis[1:]) if vec[1] <= 0))
        np.testing.assert_equal(hy_tags, sub._orientation[hy == ny - 1])
コード例 #12
0
    def test_orientation_channel_pbc(self):
        self.sim.config.periodic_z = True
        self.sim.config.periodic_y = True
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=1,
                               id_=0)
        spec.enable_local_periodicity(1)
        spec.enable_local_periodicity(2)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()
        sub = ChannelSubdomain3D(list(reversed(self.lattice_size)), spec,
                                 D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        np.testing.assert_equal(sub._orientation[(hx == 0)],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1)],
                                D3Q19.vec_to_dir([-1, 0, 0]))
コード例 #13
0
    def test_array_setting(self):
        envelope = 1
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=envelope,
                               id_=0)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()
        sub = SubdomainTest3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.reset()

        center_y = 32 / 2
        center_z = 16 / 2
        for y in range(0, 16):
            np.testing.assert_array_almost_equal(
                np.float64(
                    [0.01 * (y - center_y)**2, 0.03 * (y - center_z)**2, 0.0]),
                np.float64(
                    sub._encoder.get_param(
                        (y + envelope, y + envelope, y + envelope), 3)))

        np.testing.assert_equal(sub._type_map[1:6, 1:4, 12:-1], _NTUnused.id)
コード例 #14
0
ファイル: subdomain.py プロジェクト: zherexli/sailfish
    def testBoundaryNodes(self):
        spec = SubdomainSpec3D((0, 0, 0), (5, 8, 3), envelope_size=1, id_=0)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()

        class _LinkTaggingSubdomain3D(Subdomain3D):
            def boundary_conditions(self, hx, hy, hz):
                wall_map = np.array([
                    [[0, 0, 0, 0, 1],
                     [0, 0, 0, 0, 1],
                     [0, 0, 0, 1, 1],
                     [0, 0, 0, 1, 1],  # There was a bug once that caused the
                                       # middle node here to be marked
                                       # PropagationOnly.
                     [0, 0, 1, 1, 1],
                     [0, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1]],
                    [[0, 0, 0, 1, 1],
                     [0, 0, 0, 1, 1],
                     [0, 0, 1, 1, 1],
                     [0, 1, 1, 1, 1],
                     [0, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1]],
                    [[0, 0, 1, 1, 1],
                     [0, 1, 1, 1, 1],
                     [0, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1],
                     [1, 1, 1, 1, 1]]], dtype=np.bool)
                wall_map = np.pad(wall_map, (1, 1), mode='constant',
                                  constant_values=0)
                self.set_node(wall_map, NTFullBBWall)
                self.set_node(np.logical_not(wall_map) & (hz == 0),
                            NTEquilibriumDensity(1.0))

        sub = _LinkTaggingSubdomain3D((3, 8, 5), spec, D3Q19)
        sub.allocate()
        sub.reset(encode=False)

        expected = np.array([
             [ 3,  3,  3,  3,  5],
             [ 3,  3,  3,  3,  5],
             [ 3,  3,  3,  5,  5],
             [ 3,  3,  3,  5, 19],
             [ 3,  3,  5,  5, 19],
             [ 3,  5,  5, 19, 19],
             [ 5,  5, 19, 19, 20],
             [19, 19, 19, 20, 20]])
        expected[expected == 3] = NTEquilibriumDensity.id
        expected[expected == 5] = NTFullBBWall.id
        expected[expected == 19] = _NTPropagationOnly.id
        expected[expected == 20] = _NTUnused.id
        np.testing.assert_equal(expected, sub._type_map[0,:,:])
コード例 #15
0
ファイル: geo.py プロジェクト: zmhou/sailfish
 def subdomains(self):
     """Returns a 1-element list containing a single 3D block
     covering the whole domain."""
     return [
         SubdomainSpec3D(
             (0, 0, 0),
             (self.config.lat_nx, self.config.lat_ny, self.config.lat_nz))
     ]
コード例 #16
0
ファイル: subdomain_runner.py プロジェクト: zliu72/sailfish
    def test_strides_and_size_3d(self):
        block = SubdomainSpec3D(self.location_3d, self.size_3d)
        block.set_actual_size(0)
        runner = self.get_subdomain_runner(block)
        runner._init_shape()

        # Last dimension is rounded up to a multiple of block_size
        real_size = [7, 5, 8]
        self.assertEqual(runner._physical_size, real_size)
        nodes = runner.num_phys_nodes
        self.assertEqual(nodes, reduce(operator.mul, real_size))
コード例 #17
0
    def test_subdomain_connection_z(self):
        base = SubdomainSpec3D((10, 10, 10), (10, 12, 10),
                               envelope_size=1,
                               id_=0)
        face_hi = SubdomainSpec3D.Z_HIGH

        # exact match
        b1 = SubdomainSpec3D((10, 10, 20), (10, 12, 5), envelope_size=1, id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q19))
        cpair = base.get_connection(face_hi, b1.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(1, 13)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(1, 13)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(1, 13)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [slice(1, 9), slice(1, 11)])
        self.assertEqual(cpair.src.dst_full_buf_slice,
                         [slice(1, 9), slice(1, 11)])

        # Order of axes in the connection buffer is: x, y
        # Edges
        l = [(x, 0) for x in range(1, 9)]
        r = [(x, 11) for x in range(1, 9)]
        t = [(9, y) for y in range(1, 11)]
        b = [(0, y) for y in range(1, 11)]

        # Corners
        tl = [(9, 0)]
        tr = [(9, 11)]
        bl = [(0, 0)]
        br = [(0, 11)]

        expected_map = {
            vi3(0, 0, 1): l + r + t + b + tl + tr + br + bl,
            vi3(1, 0, 1): l + r + t + tl + tr,
            vi3(-1, 0, 1): l + r + b + bl + br,
            vi3(0, 1, 1): r + t + b + tr + br,
            vi3(0, -1, 1): l + t + b + tl + bl,
        }
        _verify_partial_map(self, cpair.src, expected_map)
コード例 #18
0
    def subdomains(self):
        c = self.config

        # Recirculation buffer.
        buf = SubdomainSpec3D((0, 0, 0), (c.lat_nx, c.lat_ny, self.buf_nz(c)))
        # Enable PBC along the Z axis.
        buf.enable_local_periodicity(2)
        ret = [buf]

        # Actual simulation domain.
        n = self.config.subdomains
        z = self.buf_nz(c)
        dz = self.main_nz(c) / n
        rz = self.main_nz(c) % n
        for i in range(0, n):
            ret.append(
                SubdomainSpec3D(
                    (0, 0, z),
                    (c.lat_nx, c.lat_ny, dz if i < n - 1 else dz + rz)))
            z += dz
        return ret
コード例 #19
0
ファイル: subdomain.py プロジェクト: zliu72/sailfish
    def test_duct(self):
        self.sim.config.periodic_z = True
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=1,
                               id_=0)
        spec.enable_local_periodicity(2)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()

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

        sub = _DuctSubdomain(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        # Link tags should be the same in every Z-slice.
        for z in range(nz):
            np.testing.assert_equal(sub._orientation[hz == z],
                                    sub._orientation[hz == 0])

        def _get_tags(cond):
            return reduce(
                operator.or_,
                ((1 << i)
                 for i, vec in enumerate(D3Q19.basis[1:]) if cond(vec)))

        expected = np.zeros_like(sub._orientation[0, :, :])
        # Edges.
        expected[1:-1, 0] = _get_tags(lambda v: v[0] >= 0)
        expected[1:-1, -1] = _get_tags(lambda v: v[0] <= 0)
        expected[0, 1:-1] = _get_tags(lambda v: v[1] >= 0)
        expected[-1, 1:-1] = _get_tags(lambda v: v[1] <= 0)

        # Corners.
        expected[0, 0] = _get_tags(lambda v: v[0] >= 0 and v[1] >= 0)
        expected[0, -1] = _get_tags(lambda v: v[0] <= 0 and v[1] >= 0)
        expected[-1, 0] = _get_tags(lambda v: v[0] >= 0 and v[1] <= 0)
        expected[-1, -1] = _get_tags(lambda v: v[0] <= 0 and v[1] <= 0)

        np.testing.assert_equal(expected, sub._orientation[0, :, :])
コード例 #20
0
    def test_subdomain_connection_x(self):
        base = SubdomainSpec3D((10, 10, 10), (10, 12, 10),
                               envelope_size=1,
                               id_=0)
        face_hi = SubdomainSpec3D.X_HIGH

        # exact match
        b1 = SubdomainSpec3D((20, 10, 10), (5, 12, 10), envelope_size=1, id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q19))
        cpair = base.get_connection(face_hi, b1.id)
        self.assertEqual(
            set(cpair.src.dists),
            set([
                vi3(1, 0, 0),
                vi3(1, 1, 0),
                vi3(1, -1, 0),
                vi3(1, 0, 1),
                vi3(1, 0, -1)
            ]))
        self.assertEqual(cpair.src.src_slice, [slice(1, 13), slice(1, 11)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 13), slice(1, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 13), slice(1, 11)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [slice(1, 11), slice(1, 9)])
        self.assertEqual(cpair.src.dst_full_buf_slice,
                         [slice(1, 11), slice(1, 9)])

        # Order of axes in the connection buffer is y, z
        # Edges
        l = [(y, 0) for y in range(1, 11)]
        r = [(y, 9) for y in range(1, 11)]
        t = [(11, z) for z in range(1, 9)]
        b = [(0, z) for z in range(1, 9)]

        # Corners
        tl = [(11, 0)]
        tr = [(11, 9)]
        bl = [(0, 0)]
        br = [(0, 9)]

        expected_map = {
            vi3(1, 0, 0): l + r + t + b + tl + tr + br + bl,
            vi3(1, 1, 0): l + r + t + tl + tr,
            vi3(1, -1, 0): l + r + b + bl + br,
            vi3(1, 0, 1): r + t + b + tr + br,
            vi3(1, 0, -1): l + t + b + tl + bl,
        }
        _verify_partial_map(self, cpair.src, expected_map)

        base = SubdomainSpec3D((10, 10, 10), (10, 10, 10),
                               envelope_size=1,
                               id_=0)

        # full overlap (2nd subdomain is smaller)
        b2 = SubdomainSpec3D((20, 12, 14), (5, 6, 4), envelope_size=1, id_=2)
        self.assertTrue(base.connect(b2, grid=D3Q19))
        cpair = base.get_connection(face_hi, b2.id)
        self.assertEqual(cpair.src.src_slice, [slice(3, 9), slice(5, 9)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(2, 10), slice(4, 10)])
        self.assertEqual(cpair.src.dst_macro_slice, [slice(3, 9), slice(5, 9)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [slice(0, 6), slice(0, 4)])
        self.assertEqual(cpair.src.dst_full_buf_slice,
                         [slice(0, 6), slice(0, 4)])

        # full overlap (2nd subdomain is larger)
        b3 = SubdomainSpec3D((20, 8, 9), (5, 14, 15), envelope_size=1, id_=3)
        self.assertTrue(base.connect(b3, grid=D3Q19))
        cpair = base.get_connection(face_hi, b3.id)
        self.assertEqual(cpair.src.src_slice, [slice(0, 12), slice(0, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(1, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(0, 12), slice(0, 12)])
        self.assertEqual(cpair.src.dst_low, [1, 0])
        self.assertEqual(cpair.src.dst_slice, [slice(3, 11), slice(2, 10)])
        self.assertEqual(cpair.src.dst_full_buf_slice,
                         [slice(2, 10), slice(2, 10)])

        # Edges
        l = [(y, 1) for y in range(2, 10)]
        r = [(y, 10) for y in range(2, 10)]
        t = [(10, z) for z in range(2, 10)]
        b = [(1, z) for z in range(2, 10)]

        le = [(y, 0) for y in range(1, 11)]
        re = [(y, 11) for y in range(1, 11)]
        te = [(11, z) for z in range(1, 11)]
        be = [(0, z) for z in range(1, 11)]

        # Corners
        tl = [(10, 1)]
        tr = [(10, 10)]
        bl = [(1, 1)]
        br = [(1, 10)]

        expected_map = {
            vi3(1, 0, 0): l + r + t + b + tl + tr + br + bl,
            vi3(1, 1, 0): l + r + t + tl + tr + te,
            vi3(1, -1, 0): l + r + b + bl + br + be,
            vi3(1, 0, 1): r + t + b + tr + br + re,
            vi3(1, 0, -1): l + t + b + tl + bl + le,
        }
        _verify_partial_map(self, cpair.src, expected_map)

        # top-left corner match (no connection in D3Q19 topology)
        bf1 = SubdomainSpec3D((20, 20, 5), (5, 5, 5), envelope_size=1)
        self.assertFalse(base.connect(bf1, grid=D3Q19))

        # too far along X axis
        bf2 = SubdomainSpec3D((21, 10, 10), (5, 10, 10), envelope_size=1)
        self.assertFalse(base.connect(bf2, grid=D3Q19))

        # too far along Y axis
        bf3 = SubdomainSpec3D((20, 21, 10), (5, 10, 10), envelope_size=1)
        self.assertFalse(base.connect(bf3, grid=D3Q19))
コード例 #21
0
ファイル: subdomain.py プロジェクト: zherexli/sailfish
    def test_orientation_box(self):
        spec = SubdomainSpec3D((0, 0, 0), self.lattice_size, envelope_size=1, id_=0)
        spec.runner = SubdomainRunner(self.sim, spec, output=None,
                                      backend=self.backend, quit_event=None)
        spec.runner._init_shape()

        class _OrientationSubdomain3D(Subdomain3D):
            def boundary_conditions(self, hx, hy, hz):
                self.set_node((hx == 0) | (hy == 0) | (hz == 0) | (hz == self.gz - 1) |
                              (hx == self.gx - 1) | (hy == self.gy - 1),
                              NTEquilibriumDensity(1.0))

        sub = _OrientationSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.allocate()
        sub.reset()

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        xx = np.logical_not((hx == 0) | (hx == nx - 1))
        yy = np.logical_not((hy == 0) | (hy == ny - 1))
        zz = np.logical_not((hz == 0) | (hz == nz - 1))

        np.testing.assert_equal(sub._orientation[(hx == 0) & yy & zz],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == 0) & xx & zz],
                                D3Q19.vec_to_dir([0, 1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == 0) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, 1]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & yy & zz],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == ny - 1) & xx & zz],
                                D3Q19.vec_to_dir([0, -1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, -1]))

        # No orientation vector for edge nodes.
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == ny - 1)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == ny - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == nz - 1)], 0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == ny - 1)], 0)

        # No orientation vector for corner nodes.
        np.testing.assert_equal(sub._orientation[0, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[0, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, nx - 1], 0)
コード例 #22
0
    def test_orientation(self):
        spec = SubdomainSpec3D((0, 0, 0),
                               self.lattice_size,
                               envelope_size=1,
                               id_=0)
        spec.runner = SubdomainRunner(self.sim,
                                      spec,
                                      output=None,
                                      backend=self.backend,
                                      quit_event=None)
        spec.runner._init_shape()
        sub = TestSubdomain3D(list(reversed(self.lattice_size)), spec, D3Q19)
        sub.reset()
        sub._encoder.detect_orientation(sub._orientation_base)

        nx, ny, nz = self.lattice_size
        hx, hy, hz = sub._get_mgrid()

        xx = np.logical_not((hx == 0) | (hx == nx - 1))
        yy = np.logical_not((hy == 0) | (hy == ny - 1))
        zz = np.logical_not((hz == 0) | (hz == nz - 1))

        np.testing.assert_equal(sub._orientation[(hx == 0) & yy & zz],
                                D3Q19.vec_to_dir([1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == 0) & xx & zz],
                                D3Q19.vec_to_dir([0, 1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == 0) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, 1]))
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & yy & zz],
                                D3Q19.vec_to_dir([-1, 0, 0]))
        np.testing.assert_equal(sub._orientation[(hy == ny - 1) & xx & zz],
                                D3Q19.vec_to_dir([0, -1, 0]))
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & yy & xx],
                                D3Q19.vec_to_dir([0, 0, -1]))

        # No orientation vector for edge nodes.
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == 0)], 0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == 0)], 0)

        np.testing.assert_equal(sub._orientation[(hx == 0) & (hy == ny - 1)],
                                0)
        np.testing.assert_equal(sub._orientation[(hx == 0) & (hz == nz - 1)],
                                0)
        np.testing.assert_equal(sub._orientation[(hz == 0) & (hy == ny - 1)],
                                0)

        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hy == 0)],
                                0)
        np.testing.assert_equal(sub._orientation[(hx == nx - 1) & (hz == 0)],
                                0)
        np.testing.assert_equal(sub._orientation[(hz == nz - 1) & (hy == 0)],
                                0)

        np.testing.assert_equal(
            sub._orientation[(hx == nx - 1) & (hy == ny - 1)], 0)
        np.testing.assert_equal(
            sub._orientation[(hx == nx - 1) & (hz == nz - 1)], 0)
        np.testing.assert_equal(
            sub._orientation[(hz == nz - 1) & (hy == ny - 1)], 0)

        # No orientation vector for corner nodes.
        np.testing.assert_equal(sub._orientation[0, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[0, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[0, ny - 1, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, 0, nx - 1], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, 0], 0)
        np.testing.assert_equal(sub._orientation[nz - 1, ny - 1, nx - 1], 0)
コード例 #23
0
 def subdomains(self, n=None):
     return [
         SubdomainSpec3D((0, 0, 0), (50, 30, 13)),
         SubdomainSpec3D((5, 30, 0), (50, 10, 13))
     ]
コード例 #24
0
    def _corner_helper(self, face):
        base = SubdomainSpec3D((10, 10, 10), (10, 10, 10),
                               envelope_size=1,
                               id_=0)

        if face == SubdomainSpec3D.X_LOW:
            x_low = 5
            x_dir = -1
        else:
            x_low = 20
            x_dir = 1

        b1 = SubdomainSpec3D((x_low, 5, 5), (5, 5, 5), envelope_size=1, id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q15))
        cpair = base.get_connection(face, b1.id)
        self.assertEqual(cpair.src.src_slice, [slice(0, 1), slice(0, 1)])
        self.assertEqual(cpair.src.src_macro_slice, [slice(1, 2), slice(1, 2)])
        self.assertEqual(cpair.src.dst_macro_slice, [slice(0, 1), slice(0, 1)])
        self.assertEqual(cpair.src.dst_low, [4, 4])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi15(x_dir, -1, -1): [(0, 0)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b2 = SubdomainSpec3D((x_low, 20, 5), (5, 5, 5), envelope_size=1, id_=2)
        self.assertTrue(base.connect(b2, grid=D3Q15))
        cpair = base.get_connection(face, b2.id)
        self.assertEqual(cpair.src.src_slice, [slice(11, 12), slice(0, 1)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(10, 11), slice(1, 2)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(11, 12), slice(0, 1)])
        self.assertEqual(cpair.src.dst_low, [0, 4])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi15(x_dir, 1, -1): [(0, 0)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b3 = SubdomainSpec3D((x_low, 20, 20), (5, 5, 5),
                             envelope_size=1,
                             id_=3)
        self.assertTrue(base.connect(b3, grid=D3Q15))
        cpair = base.get_connection(face, b3.id)
        self.assertEqual(cpair.src.src_slice, [slice(11, 12), slice(11, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(10, 11), slice(10, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(11, 12), slice(11, 12)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi15(x_dir, 1, 1): [(0, 0)]}
        _verify_partial_map(self, cpair.src, expected_map)

        b4 = SubdomainSpec3D((x_low, 5, 20), (5, 5, 5), envelope_size=1, id_=4)
        self.assertTrue(base.connect(b4, grid=D3Q15))
        cpair = base.get_connection(face, b4.id)
        self.assertEqual(cpair.src.src_slice, [slice(0, 1), slice(11, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 2), slice(10, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(0, 1), slice(11, 12)])
        self.assertEqual(cpair.src.dst_low, [4, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])
        expected_map = {vi15(x_dir, -1, 1): [(0, 0)]}
        _verify_partial_map(self, cpair.src, expected_map)
コード例 #25
0
 def subdomains(self, n=None):
     return [
         SubdomainSpec3D((0, 0, 0), (20, 15, 30)),
         SubdomainSpec3D((20, 2, 7), (10, 15, 30))
     ]
コード例 #26
0
    def _x_edge_helper(self, face):
        """Tests connections along the edges of one of the faces orthogonal
        to the X axis."""
        base = SubdomainSpec3D((10, 10, 10), (10, 10, 10),
                               envelope_size=1,
                               id_=0)

        if face == SubdomainSpec3D.X_LOW:
            x_low = 5
            x_dir = -1
        else:
            x_low = 20
            x_dir = 1

        # bottom edge match
        b1 = SubdomainSpec3D((x_low, 5, 10), (5, 5, 10),
                             envelope_size=1,
                             id_=1)
        self.assertTrue(base.connect(b1, grid=D3Q19))
        cpair = base.get_connection(face, b1.id)
        self.assertEqual(cpair.src.src_slice, [slice(0, 1), slice(1, 11)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 2), slice(1, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(0, 1), slice(1, 11)])
        self.assertEqual(cpair.src.dst_low, [4, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])

        expected_map = {vi3(x_dir, -1, 0): [(0, z) for z in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        # top edge match
        b2 = SubdomainSpec3D((x_low, 20, 10), (5, 5, 10),
                             envelope_size=1,
                             id_=2)
        self.assertTrue(base.connect(b2, grid=D3Q19))
        cpair = base.get_connection(face, b2.id)
        self.assertEqual(cpair.src.src_slice, [slice(11, 12), slice(1, 11)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(10, 11), slice(1, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(11, 12), slice(1, 11)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])

        expected_map = {vi3(x_dir, 1, 0): [(0, z) for z in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        # right edge match
        b3 = SubdomainSpec3D((x_low, 10, 20), (5, 10, 5),
                             envelope_size=1,
                             id_=3)
        self.assertTrue(base.connect(b3, grid=D3Q19))
        cpair = base.get_connection(face, b3.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(10, 11)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(11, 12)])
        self.assertEqual(cpair.src.dst_low, [0, 0])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])

        expected_map = {vi3(x_dir, 0, 1): [(y, 0) for y in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)

        # left edge match
        b4 = SubdomainSpec3D((x_low, 10, 5), (5, 10, 5),
                             envelope_size=1,
                             id_=4)
        self.assertTrue(base.connect(b4, grid=D3Q19))
        cpair = base.get_connection(face, b4.id)
        self.assertEqual(cpair.src.src_slice, [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.src_macro_slice,
                         [slice(1, 11), slice(1, 2)])
        self.assertEqual(cpair.src.dst_macro_slice,
                         [slice(1, 11), slice(0, 1)])
        self.assertEqual(cpair.src.dst_low, [0, 4])
        self.assertEqual(cpair.src.dst_slice, [])
        self.assertEqual(cpair.src.dst_full_buf_slice, [])

        expected_map = {vi3(x_dir, 0, -1): [(y, 0) for y in range(0, 10)]}
        _verify_partial_map(self, cpair.src, expected_map)
コード例 #27
0
 def subdomains(self, n=None):
     blocks = []
     blocks.append(SubdomainSpec3D((0, 0, 0), (64, 66, 64)))
     blocks.append(SubdomainSpec3D((0, 0, 64), (64, 66, 64)))
     return blocks
コード例 #28
0
 def subdomains(self, n=None):
     return [SubdomainSpec3D((0, 0, 0), (64, 62, 66))]