import hybmeshpack.hmscript as hm outercont = hm.create_contour([[0, 0], [0.2, -0.6], [1, -1.3], [2, -1.3], [2.5, -0.3], [2.6, 0.4], [1.5, 1], [0.4, 0.4], [0, 0]]) faultline = hm.create_contour([[0, 1], [1.5, -0.5]]) w1 = [0.64, -0.11] w2 = [1.54, 0.4] gw1 = hm.add_unf_circ_grid(w1, 0.05, 16, 5, 1.2, False) gw2 = hm.add_unf_circ_grid(w2, 0.05, 16, 5, 1.2, False) faultline = hm.partition_contour(faultline, "const", 0.01, crosses=[outercont]) outercont = hm.matched_partition(outercont, 0.05, 0.5, [faultline]) hm.export_contour_vtk([outercont, faultline], "outer.vtk") g = hm.pebi_fill(outercont, [faultline]) g = hm.unite_grids(g, [(gw1, 0.01), (gw2, 0.01)], buffer_fill='4') hm.export_grid_vtk([g], "grid.vtk")
'Nnodes': 1196, 'Nedges': 2382, 'Ncells': 1186 }) hmdbg.check(len(hm.registered_btypes()) == 6) hm.export_grid_msh(g1, "g1.msh") hmdbg.check_ascii_file(10239002963502473, "g1.msh") hm.remove_all() print "export 3d to fluent" tribnd = hm.add_boundary_type(1, "triangle") circbnd = hm.add_boundary_type(2, "circle") botbnd = hm.add_boundary_type(3, "bottomz") topbnd = hm.add_boundary_type(4, "topz") g1 = hm.add_triangle_grid([0, 0], [1, 0], [0.5, 0.5], 10) g2 = hm.add_unf_circ_grid([0.5, 1], 1.0, 30, 10, 1, False) hm.set_boundary_type(g1, tribnd) hm.set_boundary_type(g2, circbnd) g3 = hm.unite_grids(g2, [(g1, 0.05)]) g4 = hm.extrude_grid(g3, [0, 0.05, 0.2, 0.5, 0.65, 0.7], botbnd, topbnd) hm.export3d_grid_vtk(g4, None, "c1.vtk") hmdbg.check_ascii_file(7889578680359330313, "c1.vtk", 'dev') hm.export3d_grid_msh(g4, "g1.msh") hmdbg.check_ascii_file(450400077272399620, "g1.msh", 'dev') print "export 3d to fluent with periodic condition" hm.export3d_grid_msh(g4, "g1.msh", [botbnd, topbnd, [0, 0, 0.0], [0, 0, 0.7]]) hmdbg.check_ascii_file(12326414976139824718, "g1.msh", 'dev') hm.remove_all() print "export contour to tecplot"
z = [] for i in range(0, 101): z.append(float(i) / 100) s1 = hm.extrude_grid(g1, z, 1, 2, 3) hm.export3d_grid_vtk(s1, None, "s2.vtk") hmdbg.check_ascii_file(17599784844569501681, "s2.vtk") hm.remove_geom(s1) print "full revolution, no contact" g1 = hm.add_unf_rect_grid([2, 2], [5, 3], 4, 6) g2 = hm.add_unf_ring_grid([5, 3], 0.1, 0.6, 10, 3) hm.set_boundary_type(g1, 1) hm.set_boundary_type(g2, 2) g3 = hm.unite_grids(g1, [(g2, 0.2)], True) g4 = hm.revolve_grid(g3, [0, 0], [0.4, 1], 20) hm.export3d_grid_msh(g4, "g1.msh") hmdbg.check_ascii_file(11816494025308685888, "g1.msh", "dev") print "incomplete revolution, with contact, no tri" g1 = hm.add_unf_circ_grid([4, 4], 15, 32, 15, is_trian=False) hm.set_boundary_type(g1, 1) s = 3.5 c1 = hm.add_rect_contour([s, -20], [40, 20], 2) g1 = hm.exclude_contours(g1, c1, "outer") g3 = hm.revolve_grid(g1, [s, 0], [s, 1], phi=[0, 10, 20, 30, 40, 50, 60], merge_central=True) hm.export3d_grid_tecplot(g3, "g1.dat") hmdbg.check_ascii_file(9784631763273424912, "g1.dat") hm.export3d_grid_vtk(g3, "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") g1 = hm.add_unf_circ_grid([0, 0], 1, 6, 6, custom_rads=0.5) checkdict(hm.info_grid(g1), {'Ncells': 12}) g1 = hm.add_unf_circ_grid([0, 0], 1, 6, 6, custom_rads=[0.5, 0.9, 1.5]) checkdict(hm.info_grid(g1), {'Ncells': 18}) g1 = hm.add_unf_circ_grid([0, 0], 2, 6, 6, custom_arcs=[0.1]) checkdict(hm.info_grid(g1), {'Ncells': 756}) g1 = hm.add_unf_circ_grid([0, 0], 2, 6, 6, custom_arcs=[0.1, 0.2, 0.4, 0.7, 1]) hm.export_grid_vtk(g1, "g1.vtk")
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]) def check_zero(a): check(abs(a) < 1e-8) print "exclude intersecting domain" g1 = hm.add_unf_circ_grid([0, 0], 1, 20, 10, 1.2, False) hm.set_boundary_type(g1, 1) c1 = hm.add_rect_contour([0, 0], [1, 1], [2, 3, 4, 5]) g2 = hm.exclude_contours(g1, c1, "outer") g3 = hm.exclude_contours(g1, c1, "inner") check_grid(g1, 200, 380, 181, {20: 1, 4: 180}) check_grid(g2, 61, 106, 46, {7: 1, 4: 45}) check_grid(g3, 161, 296, 136, {17: 1, 4: 135}) check_cont(g2, 25, 25, [25], {1: 5, 5: 10, 2: 10}) check_cont(g3, 35, 35, [35], {1: 15, 5: 10, 2: 10}) check_zero(hm.domain_area(g2) + hm.domain_area(g3) - hm.domain_area(g1)) print "exclude internal domain" g4 = hm.add_unf_rect_grid([0, 0], [0.3, 0.3], 2, 2) hm.set_boundary_type(g4, 6)
print "union of with a boundary grid" plist = cosine_boundary(20) c1 = hm.create_contour(plist, [1] * (len(plist) - 3) + [2, 2]) hm.rotate_geom(c1, 17) g8 = hm.add_unf_rect_grid([-0.1, -0.1], [1.3, 1.3], 20, 20) g9 = hm.exclude_contours(g8, c1, "outer") op1 = hm.BoundaryGridOptions(c1, bnd_stepping="keep_all", bnd_step=0.05) op1.uniform_partition(0.1, 5) 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)
# main area parameters hmain = 5. arc = hm.partition_segment(0, alpha, hblayer/rad, hhormin/rad) +\ hm.partition_segment(alpha, pi-alpha, hhormin/rad, hhormin/rad, [pi/2., hcave/rad])[1:]+\ hm.partition_segment(pi-alpha, pi, hhormin/rad, hblayer/rad)[1:]+\ hm.partition_segment(pi, 2.*pi, hblayer/rad, hblayer/rad, [1.5*pi, hcave/rad])[1:] rads = [0, rad - layheight] for b in list(reversed(blay))[1:]: rads.append(rad - b) g = hm.add_unf_circ_grid(pc, custom_arcs=arc, custom_rads=rads, is_trian=False) gfiller = hm.add_circ_rect_grid(pc, rad - 1.3 * layheight, internal_step) g = hm.unite_grids(g, [(gfiller, buf)]) chord = hm.add_circ_contour2(p2, [pc[0], p1[1] + shiftlay], p1, 512) mapping_area = hm.clip_domain(chord, g, "intersection") hm.export_contour_vtk(mapping_area, "c1.vtk") g2 = hm.map_grid(g, mapping_area, [p1, p2], [p1, p2], algo="direct_laplace") pbef, paft = [p1[0] - layheight, 0], [p2[0] + layheight, 0] c1 = hm.create_contour([pbef, p1]) c1 = hm.partition_contour(c1, "ref_weights", [hblayer, 1, hhormin, 0], start=p1)
from hybmeshpack import hmscript # START OF EXAMPLE # lower level grid g1 = hmscript.add_unf_rect_grid([0, 0], [10, 10], 10, 10) # first imposition grid g2 = hmscript.add_unf_rect_grid([0, 0], [3, 3], 7, 7) # second imposition grid g3 = hmscript.add_unf_circ_grid([5, 5], 1.5, 10, 4) # impose grids impgrid = hmscript.unite_grids(g1, [(g2, 2.0), (g3, 1.0)]) # END OF EXAMPLE print "unite_grids example" hmscript.export_grid_vtk(impgrid, "_g2.vtk") if (abs(hmscript.domain_area(impgrid) - 100) > 1e-8): raise Exception if (not hmscript.skewness(impgrid)['ok']): raise Exception