def test_multi_poly_lookup(): # A simple quad grid nodes = np.array([ [0.0, 0.0], #0 [0.0, 2.0], #1 [2.0, 0.0], #2 [2.0, 2.0], #3 [4.0, 0.0], #4 [4.0, 2.0], #5 [6.0, 0.0], #6 [6.0, 2.0], #7 [0.0, 4.0], #8 [2.0, 4.0], #9 [4.0, 4.0], #10 [6.0, 4.0] #11 ]) faces = np.array([[0, 8, 9, 5, 2], [9, 11, 7, 5, -1], [4, 7, 6, -1, -1]], dtype=np.intc) tree = CellTree(nodes, faces, num_buckets=2, cells_per_leaf=1) point = np.array([1., 1.]) # in POLY 1 result = tree.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree.locate(point) assert result == 2 point[1] = 3.0 result = tree.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree.locate(point) assert result == -1
def test_multi_poly_lookup(): # A simple quad grid nodes = np.array( [ [0.0, 0.0], # 0 [0.0, 2.0], # 1 [2.0, 0.0], # 2 [2.0, 2.0], # 3 [4.0, 0.0], # 4 [4.0, 2.0], # 5 [6.0, 0.0], # 6 [6.0, 2.0], # 7 [0.0, 4.0], # 8 [2.0, 4.0], # 9 [4.0, 4.0], # 10 [6.0, 4.0], # 11 ] ) faces = np.array([[0, 8, 9, 5, 2], [9, 11, 7, 5, -1], [4, 7, 6, -1, -1]], dtype=np.intc) tree = CellTree(nodes, faces, num_buckets=2, cells_per_leaf=1) point = np.array([1.0, 1.0]) # in POLY 1 result = tree.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree.locate(point) assert result == 2 point[1] = 3.0 result = tree.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree.locate(point) assert result == -1
def test_triangle_lookup(): tree = CellTree(nodes, faces) point = np.array([1., 1.]) # in triangle 1 result = tree.locate(point) assert result == 0 point[0] = 2.0 # tri 2 result = tree.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree.locate(point) assert result == -1
def test_triangle_lookup(): tree = CellTree(nodes, faces) point = np.array([1.0, 1.0]) # in triangle 1 result = tree.locate(point) assert result == 0 point[0] = 2.0 # tri 2 result = tree.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree.locate(point) assert result == -1
def test_build_tree_from_coords(): """ this tests using a structured grid with cell coordinates converting it to a flattened grid with nodes and cells defined as indexes to those nodes as much as anything else, this surves as example code for how to do that. """ x, y = curv_grid(n_x=3, n_y=3, center=(0.0, 0.0), min_radius=9.0, max_radius=18.0, angle=np.pi / 4.0 ) nodes, faces = nodes_from_coords(x, y) # these range from (30., 20.) to (31.1, 21.1) tree = CellTree(nodes, faces) # try to find some points # points outside the domain: result = tree.locate([(0.0, 0.0), (19.0, 5.0), (17.0, -1.0), (9.0, 10.0), ], ) assert np.all(result == -1) # points inside the domain result = tree.locate([(10.0, 1.0), (9.0, 3.0), (8.0, 6.0), (13.0, 1.0), (12.0, 4.0), (11.0, 7.0), (16.0, 1.0), (15.0, 8.0), (13.0, 11.0), ] ) assert np.array_equal(result, [0, 1, 2, 3, 4, 5, 6, 7, 8])
def test_multipoint(): tree = CellTree(nodes21, faces21) points = [ (4.2, 3.0), (7.7, 13.5), (3.4, 7.000000001), (7.0, 5.0), # out of bounds points (8.66, 10.99), (7.3, 0.74), (2.5, 5.5), (9.8, 12.3), ] correct_indexes = (1, 20, 7, -1, -1, -1, -1, -1) ind = tree.locate(points) assert np.array_equal(ind, correct_indexes)
def test_poly_lookup(): # A simple quad grid nodes = np.array([ [0.0, 0.0], #0 [0.0, 2.0], #1 [2.0, 0.0], #2 [2.0, 2.0], #3 [4.0, 0.0], #4 [4.0, 2.0], #5 [6.0, 0.0], #6 [6.0, 2.0], #7 [0.0, 4.0], #8 [2.0, 4.0], #9 [4.0, 4.0], #10 [6.0, 4.0] #11 ]) #quads faces1 = np.array([ [0, 2, 3, 1], [4, 6, 7, 5], ], dtype=np.intc) #Pentas faces2 = np.array([ [0, 8, 9, 5, 2], [9, 11, 6, 2, 5], ], dtype=np.intc) tree1 = CellTree(nodes, faces1, num_buckets=2, cells_per_leaf=1) point = np.array([1., 1.]) # in triangle 1 result = tree1.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree1.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree1.locate(point) assert result == -1 tree2 = CellTree(nodes, faces2, num_buckets=2, cells_per_leaf=1) point = np.array([1., 2.]) # in triangle 1 result = tree2.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree2.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree2.locate(point) assert result == -1
def test_poly_lookup(): # A simple quad grid nodes = np.array( [ [0.0, 0.0], # 0 [0.0, 2.0], # 1 [2.0, 0.0], # 2 [2.0, 2.0], # 3 [4.0, 0.0], # 4 [4.0, 2.0], # 5 [6.0, 0.0], # 6 [6.0, 2.0], # 7 [0.0, 4.0], # 8 [2.0, 4.0], # 9 [4.0, 4.0], # 10 [6.0, 4.0], # 11 ] ) # quads faces1 = np.array([[0, 2, 3, 1], [4, 6, 7, 5]], dtype=np.intc) # Pentas faces2 = np.array([[0, 8, 9, 5, 2], [9, 11, 6, 2, 5]], dtype=np.intc) tree1 = CellTree(nodes, faces1, num_buckets=2, cells_per_leaf=1) point = np.array([1.0, 1.0]) # in triangle 1 result = tree1.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree1.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree1.locate(point) assert result == -1 tree2 = CellTree(nodes, faces2, num_buckets=2, cells_per_leaf=1) point = np.array([1.0, 2.0]) # in triangle 1 result = tree2.locate(point) assert result == 0 point[0] = 5.0 # tri 2 result = tree2.locate(point) assert result == 1 point[0] = -1.0 # out of grid result = tree2.locate(point) assert result == -1