def check_grid(grid, nn, ne, nc, ct): info = hm.info_grid(grid) check(info['Nnodes'] == nn) check(info['Nedges'] == ne) check(info['Ncells'] == nc) for k in ct.keys(): check(info['cell_types'][k] == ct[k])
y = 0.1 * math.sin(6 * math.pi * x) cont.append([x, y]) for p in cont[::-1]: cont.append([p[0], p[1] + 1.0]) cont.append(cont[0]) c1 = hm.create_contour(cont) hm.set_boundary_type(c1, 2) print "rectangle to square with sine edges: no, from_contour" a1 = hm.map_grid( g1, c1, [[0, 0], [5, 0], [5, 1], [0, 1]], [[0, 0], [1, 0], [1, 1], [0, 1]], snap="no", btypes="from_contour") checkdict( hm.info_grid(a1), {'cell_types': {4: 100}, 'Nnodes': 121, 'Nedges': 220, 'Ncells': 100}) checkdict( hm.info_contour(a1), {'btypes': {2: 40}, 'Nnodes': 40, 'subcont': [40], 'Nedges': 40}) hm.export_grid_vtk(a1, "g1.vtk") print "rectangle to square with sine edges: no, from_grid" a2 = hm.map_grid( g1, c1, [[0, 0], [5, 0], [5, 1], [0, 1]], [[0, 0], [1, 0], [1, 1], [0, 1]], algo="direct_laplace", snap="no", btypes="from_grid") checkdict( hm.info_grid(a2),
# import os.path from hybmeshpack import hmscript as hm from hybmeshpack.hmscript import _dbg as hmdbg hm.check_compatibility("0.4.6") print "export to natives" # export/import grids 2d to native g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 3, 4) g2 = hm.add_unf_rect_grid([0, 0], [1, 1], 2, 3) g3 = hm.add_unf_rect_grid([0, 0], [1, 1], 5, 6) hm.export_grid_hmg(g1, "g1.hmg") hm.export_grid_hmg(g1, "g2.hmg", "bin") hm.export_grid_hmg(g1, "g3.hmg", "fbin") hm.export_grid_hmg([g1, g2, g3], "g4.hmg") g4 = hm.import_grid_hmg("g2.hmg") hmdbg.check(hm.info_grid(g4)['Ncells'] == 12) g6 = hm.import_grid_hmg("g4.hmg", allgrids=True) hmdbg.check(len(g6) == 3 and hm.info_grid(g6[1])['Ncells'] == 6) for i, z in enumerate(hm.registered_grids()): hmdbg.check(int(z[-1]) == i + 1) hm.remove_all() g7 = hm.import_grid_hmg("g4.hmg", "Grid2D_3") hmdbg.check(g7 == "Grid2D_3" and len(hm.registered_grids()) == 1) hmdbg.check(hm.info_grid(g7)['Ncells'] == 30) # export/import contours 2d to native c1 = hm.add_rect_contour([0, 0], [1, 1], 1) c2 = hm.add_rect_contour([0, 0], [2, 2], 2) hm.export_contour_hmc(c1, "c1.hmc") hm.export_contour_hmc(c2, "c2.hmc", "bin") hm.export_contour_hmc([c1, c2], "c3.hmc", "bin")
from hybmeshpack import hmscript as hm from hybmeshpack.hmscript._dbg import check_ascii_file, checkdict, check hm.check_compatibility("0.4.5") print "add_unf_rect_grid" g1 = hm.add_unf_rect_grid([0.01, -0.2], [1, 1], 15, 10) checkdict(hm.info_grid(g1), {'Ncells': 150}) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(13180744078971206337, "g1.vtk") g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 15, 10, custom_x=0.5) checkdict(hm.info_grid(g1), {'Ncells': 20}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], 15, 10, custom_y=0.2) checkdict(hm.info_grid(g1), {'Ncells': 75}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], 3, 3, custom_x=0.1, custom_y=0.2) checkdict(hm.info_grid(g1), {'Ncells': 50}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], custom_x=[0, 1], custom_y=[0, 1]) checkdict(hm.info_grid(g1), {'Ncells': 1}) g1 = hm.add_unf_rect_grid([1, 1], [2, 2], custom_x=[1, 1.9, 2], custom_y=[-1, -0.2, 2.2]) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(3572940205872809425, "g1.vtk") print "add_unf_circ_grid" g1 = hm.add_unf_circ_grid([1, 1], 1, 13, 3, is_trian=True) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(16381562878152009782, "g1.vtk") g1 = hm.add_unf_circ_grid([0, 0], 1, 5, 5, 0.3, is_trian=False) hm.export_grid_vtk(g1, "g1.vtk") check_ascii_file(419969290668673427, "g1.vtk")
shark = hm.unite_grids(body, [(fin1, 0.1), (fin3, 0.1), (fin4, 0.1)], zero_angle_approx=10) # all other grids have clear intersections and could be united as a chain. # we use empty_holes=True in order to preserve hulls at eye and gills areas. shark = hm.unite_grids(shark, [(gills, 0.1), (tail, 0.1), (eye, 0.1), (jgrid, 0.1), (fin2, 0.15)], empty_holes=True, zero_angle_approx=10) # leave only resulting grid hm.remove_all_but(shark) # boundary grids around gills contain hanging boundary nodes. To get rid of # them we use heal_grid procedure with default parameters hm.heal_grid(shark) # check grid skewness if not hm.skewness(shark)['ok']: print "Grid contains bad cells" # exporting to vtk hm.export_grid_vtk(shark, "shark.vtk") # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if not hm.skewness(shark, 0.75)['ok']: print hm.skewness(shark) raise Exception if not hm.info_grid(shark)['cell_types'].keys() == [3, 4]: raise Exception
g10 = hm.build_boundary_grid(op1) g11 = hm.unite_grids(g9, [(g10, 0.05)]) check(len(hm.skewness(g11)['bad_cells']) <= 4) print "union of detached grids" g12 = hm.add_unf_ring_grid([0, 0], 20, 10, 300, 10) g13 = hm.add_unf_circ_grid([0, 0], 9.5, 50, 5) g14 = hm.unite_grids(g12, [(g13, 5)]) check(len(hm.info_contour(g14)['subcont']) == 3) print "union of grids with common boundary segments" g15 = hm.add_unf_circ_grid([0, 0], 1, 16, 5) g16 = hm.add_unf_rect_grid([-1, -2], [1, -1], 10, 10) g17 = hm.add_unf_rect_grid([-0.7, -3], [0.3, -2], 20, 20) g18 = hm.unite_grids(g15, [(g16, 0.3), (g17, 0.3)], fix_bnd=True) check(hm.skewness(g18)['ok'] and hm.info_grid(g18)['cell_types'][4] == 540) print "large scale difference in non-buffer area" g19 = hm.add_unf_rect_grid([0, 0], [10, 1], 30, 3) g20 = hm.add_unf_rect_grid([3, -1], [6, 0], 3, 20) g21 = hm.unite_grids(g19, [(g20, 0.3)]) check(hm.info_grid(g21)['Ncells'] == 171) hm.remove_all() print "snap grid checks" g1 = hm.add_unf_rect_grid(custom_x=[-0.2, -0.1, 0.0], custom_y=[0, 0.1, 0.2, 0.3]) g2 = hm.add_unf_rect_grid(custom_x=[0.0, 0.2, 0.4], custom_y=[0, 0.12, 0.18, 0.28]) g3 = hm.snap_grid_to_contour(g2, g1, [0, 0.28], [0, 0], [0, 0], [0, 0.3]) g4 = hm.snap_grid_to_contour(g2, g1, [0, 0.28], [0, 0], [0, 0], [0, 0.3],
hm.remove_all() print "spline tests" c1 = hm.create_spline_contour([[0, 0], [1, 0.2], [2.4, 0.5], [3, 1]], [0, 5, 0]) check(hm.info_contour(c1)['btypes'] == {0: 56, 5: 44}) c2 = hm.create_spline_contour([[0, 0], [1, 0.2], [2.4, 0.5], [3, 1], [0, 0]], [0, 5, 3, 1]) check(hm.info_contour(c2)['btypes'] == {0: 16, 1: 50, 3: 12, 5: 22}) print "unstructured fill tests" csqr = hm.add_rect_contour([0, 0], [1, 1], 1) c1 = hm.partition_contour(csqr, 'ref_points', [0.05, [0, 0], 0.3, [1, 1]]) g1 = hm.triangulate_domain(c1) checkdict(hm.info_grid(g1), {'cell_types': {3: 124}}) c1 = hm.partition_contour(csqr, 'const', 0.1) c2 = hm.create_contour([[0.1, 0.2], [0.9, 0.2]]) c2 = hm.partition_contour(c2, 'const', 0.03) c3 = hm.add_circ_contour([0.3, 0.7], 0.15, 16) c4 = hm.add_circ_contour([0.7, 0.7], 0.15, 24) g1 = hm.triangulate_domain(c1, [c2, c3, c4]) checkdict(hm.info_grid(g1), {'cell_types': {3: 1008}}) g1 = hm.triangulate_domain([c1, c3, c4], c2) checkdict(hm.info_grid(g1), {'cell_types': {3: 824}}) c1 = hm.create_spline_contour([[-0.2, 0.35], [0.5, 0.1], [1.2, 0.35]]) c1 = hm.partition_contour(c1, "const", 0.05, crosses=[csqr]) c2 = hm.create_contour([[0.3, 0.5], [0.7, 0.5]])