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