def test_refinement_single_cell(self): g = self.OneCellGrid() h, parent = refinement.refine_triangle_grid(g) h.compute_geometry() self.assertTrue(h.num_cells == 4) self.assertTrue(h.num_faces == 9) self.assertTrue(h.num_nodes == 6) self.assertTrue(h.cell_volumes.sum() == 0.5) self.assertTrue(np.allclose(h.cell_volumes, 1 / 8)) known_nodes = np.array([[0, 0.5, 1, 0.5, 0, 0], [0, 0, 0, 0.5, 1, 0.5]]) test_utils.compare_arrays(h.nodes[:2], known_nodes) self.assertTrue(np.all(parent == 0))
def test_refinement_two_cells(self): g = self.TwoCellsGrid() h, parent = refinement.refine_triangle_grid(g) h.compute_geometry() self.assertTrue(h.num_cells == 8) self.assertTrue(h.num_faces == 16) self.assertTrue(h.num_nodes == 9) self.assertTrue(h.cell_volumes.sum() == 1) self.assertTrue(np.allclose(h.cell_volumes, 1 / 8)) known_nodes = np.array([[0, 0.5, 1, 0.5, 0, 0, 1, 1, 0.5], [0, 0, 0, 0.5, 1, 0.5, 0.5, 1, 1]]) test_utils.compare_arrays(h.nodes[:2], known_nodes) self.assertTrue(np.sum(parent == 0) == 4) self.assertTrue(np.sum(parent == 1) == 4) self.assertTrue(np.allclose(np.bincount(parent, h.cell_volumes), 0.5))