def test_grid_quadratic_triangle(self): """Test the mesh class functions on a quadratic triangle mesh.""" ref_vertices = quadratic_triangle_vertices ref_cells = quadratic_triangle_cells ref_cell_sets = quadratic_triangle_cell_sets mocmg.initialize() mesh = mocmg.mesh.GridMesh(ref_vertices, ref_cells, ref_cell_sets, name="quad_tri_name") self.assertEqual(mesh.vertices, ref_vertices) self.assertEqual(mesh.cells, ref_cells) self.assertEqual(mesh.cell_sets, ref_cell_sets) # get_cells cell_set = mesh.get_cells("DISK") self.assertTrue( np.array_equal(cell_set, quadratic_triangle_cell_sets["DISK"])) # get_cell_area cell_area_ref = 0.261949 cell_area = mesh.get_cell_area(2) self.assertAlmostEqual(cell_area, cell_area_ref, 6) # get_set_area set_area_ref = 3.1391725 set_area = mesh.get_set_area("DISK") self.assertAlmostEqual(set_area, set_area_ref, 6) # name self.assertEqual(mesh.name, "quad_tri_name")
def test_grid_linear_triangle(self): """Test the mesh class functions on a linear triangle mesh.""" ref_vertices = linear_triangle_vertices ref_cells = linear_triangle_cells ref_cell_sets = linear_triangle_cell_sets mocmg.initialize() mesh = mocmg.mesh.GridMesh(ref_vertices, ref_cells, ref_cell_sets) self.assertEqual(mesh.vertices, ref_vertices) self.assertEqual(mesh.cells, ref_cells) self.assertEqual(mesh.cell_sets, ref_cell_sets) # get_cells cell_set = mesh.get_cells("DISK") self.assertTrue( np.array_equal(cell_set, linear_triangle_cell_sets["DISK"])) # Try w/ name that doesnt exist. with self.assertRaises(SystemExit): cell_set = mesh.get_cells("BAD NAME") # get_cell_area cell_area_ref = 0.210453 cell_area = mesh.get_cell_area(1) self.assertAlmostEqual(cell_area, cell_area_ref, 6) # Try will cell that doesnt exist with self.assertRaises(SystemExit): cell_area = mesh.get_cell_area(-1) # get_set_area set_area_ref = 2.828427 set_area = mesh.get_set_area("DISK") self.assertAlmostEqual(set_area, set_area_ref, 6) # get_vertices_for_cells verts_from_cells = mesh.get_vertices_for_cells([1, 2, 3]) verts_from_cells_ref = [[1, 16, 13], [9, 16, 1], [12, 15, 4]] for i, vset in enumerate(verts_from_cells_ref): for j, v in enumerate(vset): self.assertEqual(v, verts_from_cells[i][j]) # cell that doesnt exist with self.assertRaises(SystemExit): verts_from_cells = mesh.get_vertices_for_cells([1111111]) # get_vertices for cell set verts_from_cell_set_name = mesh.get_vertices("DISK") verts_from_cell_set_name_ref = [ 1, 3, 4, 7, 9, 10, 11, 12, 13, 14, 15, 16 ] for i, vert in enumerate(verts_from_cell_set_name_ref): self.assertEqual(vert, verts_from_cell_set_name[i]) # cell set that doesnt exist with self.assertRaises(SystemExit): verts_from_cell_set_name = mesh.get_vertices("NO_NAME")
def test_quadratic_quadrilateral(self): """Test the mesh class functions on a quadratic quadrilateral mesh.""" ref_vertices = quadratic_quadrilateral_vertices ref_cells = quadratic_quadrilateral_cells ref_cell_sets = quadratic_quadrilateral_cell_sets mocmg.initialize() mesh = mocmg.mesh.Mesh(ref_vertices, ref_cells, ref_cell_sets) self.assertEqual(mesh.vertices, ref_vertices) self.assertEqual(mesh.cells, ref_cells) self.assertEqual(mesh.cell_sets, ref_cell_sets) # get_cells cell_set = mesh.get_cells("DISK") self.assertTrue(np.array_equal(cell_set, quadratic_quadrilateral_cell_sets["DISK"])) # get_cell_area cell_area_ref = 0.7847974 cell_area = mesh.get_cell_area(1) self.assertAlmostEqual(cell_area, cell_area_ref, 6) # get_set_area set_area_ref = 3.1391907 set_area = mesh.get_set_area("DISK") self.assertAlmostEqual(set_area, set_area_ref, 6)
def test_linear_quadrilateral(self): """Test the mesh class functions on a linear quadrilateral mesh.""" ref_vertices = linear_quadrilateral_vertices ref_cells = linear_quadrilateral_cells ref_cell_sets = linear_quadrilateral_cell_sets mocmg.initialize() mesh = mocmg.mesh.Mesh(ref_vertices, ref_cells, ref_cell_sets) self.assertEqual(mesh.vertices, ref_vertices) self.assertEqual(mesh.cells, ref_cells) self.assertEqual(mesh.cell_sets, ref_cell_sets) # get_cells cell_set = mesh.get_cells("DISK") self.assertTrue(np.array_equal(cell_set, linear_quadrilateral_cell_sets["DISK"])) # get_cell_area cell_area_ref = 0.0874078 cell_area = mesh.get_cell_area(1) self.assertAlmostEqual(cell_area, cell_area_ref, 6) # get_set_area set_area_ref = 3.0614675 set_area = mesh.get_set_area("DISK") self.assertAlmostEqual(set_area, set_area_ref, 6)
gmsh.write("three_level_grid.inp") mesh = mocmg.mesh.read_abaqus_file("three_level_grid.inp") # vert_ids = list(mesh.vertices.keys()) # for vid in vert_ids: # print(f"{vid}: np.array({mesh.vertices[vid]}),") # for cell_type in list(mesh.cells.keys()): # print(cell_type,":") # for cell_id in list(mesh.cells[cell_type].keys()): # print(f"{cell_id}: np.array({mesh.cells[cell_type][cell_id]}),") # for set_name in list(mesh.cell_sets.keys()): # print(set_name, mesh.cell_sets[set_name]) for i in range(1, 5): for j in range(1, 5): set_name = f"GRID_L3_{i}_{j}" print("\n" + set_name) grid_cells = mesh.get_cells(set_name) cell_verts = mesh.get_vertices_for_cells(grid_cells) cell_verts_list = np.sort(np.concatenate(cell_verts)) print("vertices") # verts for v in cell_verts_list: c = mesh.vertices[v] print(f"{v}: np.array([{c[0]}, {c[1]}, {c[2]}]),") # cells print("cells") for cell_type in list(mesh.cells.keys()): print(cell_type, ":") for c in grid_cells: if c in list(mesh.cells[cell_type].keys()): print(f"{c}: np.array({mesh.cells[cell_type][c]}),")