def test_concvex_cell_containment(self): points = [ (10, 10, 10), (25, 5, 5), (5, 25, 5), (20, 20, 10), (5, 5, 25), (20, 10, 20), (10, 20, 20), (25, 25, 25) ] grid = GridGen.createSingleCellGrid(points) assertPoint = lambda p : self.assertTrue( grid.cell_contains(p[0], p[1], p[2], 0) ) assertNotPoint = lambda p : self.assertFalse( grid.cell_contains(p[0], p[1], p[2], 0) ) # Cell center assertPoint(average(points)); # "Side" center assertPoint(average(points[0:4:])) assertPoint(average(points[4:8:])) assertPoint(average(points[1:8:2])) assertPoint(average(points[0:8:2])) assertPoint(average(points[0:8:4] + points[1:8:4])) assertPoint(average(points[2:8:4] + points[3:8:4])) # Corners for p in points: assertPoint(p) # Edges edges = ([(i, i+1) for i in range(0, 8, 2)] + [(i, i+2) for i in [0, 1, 4, 5]] + [(i, i+4) for i in range(4)] + [(1,2), (2,7), (1,7), (4,7), (2,4), (4,1)]) for a,b in edges: assertPoint(average([points[a], points[b]])) # Epsilon inside from corners middle_point = average(points) for p in points: assertPoint(average(20*[p] + [middle_point])) # Espilon outside middle_point[2] = 0 for p in points[0:4:]: assertNotPoint(average(20*[p] + [middle_point])) middle_point[2] = 30 for p in points[4:8:]: assertNotPoint(average(20*[p] + [middle_point]))
def createWrapperGrid(grid): """ Creates a grid that occupies the same space as the given grid, but that consists of a single cell. """ x, y, z = grid.getNX()-1, grid.getNY()-1, grid.getNZ()-1 corner_pos = [ (0, 0, 0), (x, 0, 0), (0, y, 0), (x, y, 0), (0, 0, z), (x, 0, z), (0, y, z), (x, y, z) ] corners = [ grid.getCellCorner(i, ijk=pos) for i, pos in enumerate(corner_pos) ] return GridGen.createSingleCellGrid(corners)