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")
btop = hm.add_boundary_type(4, "btop") g1 = hm.add_unf_rect_grid([0, 0], [1, 1], 10, 10) g2 = hm.add_triangle_grid([0.3, -0.4], [0.5, 0.2], [0.7, -0.4], 10) [g3] = hm.copy_geom(g2) hm.reflect_geom(g3, [0, 0.5], [1, 0.5]) g4 = hm.unite_grids(g1, [(g2, 0.05), (g3, 0.05)]) hm.set_boundary_type(g4, bfun=lambda x0, y0, x1, y1, b: { True: 0, x0 + x1 == 0: 1, x0 + x1 == 2: 2, y0 + y1 == -0.8: 3, y0 + y1 == 2.8: 4 }[True]) hm.export_grid_vtk(g4, "g1.vtk") hm.export_contour_vtk(g4, "c1.vtk") hmdbg.check_ascii_file(15697319238564148717, "g1.vtk", "dev") hmdbg.check_ascii_file(16408920837426241157, "c1.vtk", "dev") hm.export_grid_msh(g4, "g1.msh") hmdbg.check_ascii_file(17685805227099775273, "g1.msh", "dev") print "export 2d to fluent with periodic conditions" hm.export_grid_msh(g4, "g1.msh", [bbot, btop, True]) hmdbg.check_ascii_file(3165188744058895474, "g1.msh", "dev") print "export 2d to fluent with double periodic conditions" hm.export_grid_msh(g4, "g1.msh", [bbot, btop, True, bleft, bright, True]) hmdbg.check_ascii_file(2759680993089544531, "g1.msh", "dev") print "controlled fail on illegal periodic data" try:
left = hm.partition_contour( leftc, "ref_points", [0.2, [0, 0], 0.2, [0.1, 1], 0.05, [0, 0.5]], angle0=180.) right = hm.partition_contour(rightc, "const", 0.12, angle0=180.) top = hm.partition_contour(topc, "const", 0.095, angle0=180.) bot = hm.partition_contour( botc, "ref_points", [0.03, [0, 0], 0.15, [2, 0], 0.15, [1, 0]], angle0=180.) fullc2 = hm.unite_contours([left, bot, right, top]) g2 = hm.add_custom_rect_grid("direct_laplace", left, bot, right, top) hm.export_contour_vtk(fullc1, "left1.vtk") hm.export_grid_vtk(g1, "g1.vtk") hm.export_contour_vtk(fullc2, "left2.vtk") hm.export_grid_vtk(g2, "g2.vtk") pnt = [] addline(pnt, [0, 0], [0.1, 1], 0.1, 0.5) leftc = hm.create_contour(pnt, 1) pnt = [] addline(pnt, [2, 0], [1.93, 1.03], 0.05, 1.5) rightc = hm.create_contour(pnt, 3) pnt = [] addline(pnt, [0, 0], [2, 0], 0.08, 1) botc = hm.create_contour(pnt, 2) pnt = [] addline(pnt, [0.1, 1], [1.93, 1.03], -0.18, 1)
hm.export_grid_vtk(g3, "g3.vtk") check(hm.skewness(g3)['ok']) fular = hm.domain_area(g3) - 0.5 * hm.domain_area(g2) - hm.domain_area(g1) check(abs(fular) < 1e-6) print "two squares: with/without fix_bnd, bc check" g4 = hm.add_unf_rect_grid([10, 10], [15, 15], 5, 5) g5 = hm.add_unf_rect_grid([10, 10], [11, 11], 30, 30) hm.move_geom(g5, -0.05, -0.05) hm.set_boundary_type(g4, 3) hm.set_boundary_type(g5, bfun=lambda x0, y0, x1, y1, b: 1 if max(y0, y1) < 10.8 else 2) hm.export_grid_vtk(g4, "g4.vtk") hm.export_grid_vtk(g5, "g5.vtk") hm.export_contour_vtk(g5, "gc5.vtk") g6 = hm.unite_grids(g5, [(g4, 0.5)], fix_bnd=False) check(hm.info_contour(g6)['btypes'] == {1: 3, 2: 1, 3: 18}) # hm.export_grid_vtk(g4, "g4.vtk") # hm.export_grid_vtk(g5, "g5.vtk") # hm.export_grid_vtk(g6, "g6.vtk") # hm.export_contour_vtk(g4, "c4.vtk") # hm.export_contour_vtk(g5, "c5.vtk") # hm.export_contour_vtk(g6, "c6.vtk") # quit() g7 = hm.unite_grids(g5, [(g4, 0.5)], fix_bnd=True) check(hm.info_contour(g7)['btypes'] == {1: 57, 2: 7, 3: 20})
# to assemble a window we make an superposition of internal frames to outer one # and assigns 'Window' boundary type to the whole resulting grid. window = hm.unite_grids(win_frame1, [(win_frame2, 0.02), (win_frame3, 0.02)]) hm.set_boundary_type(window, bwindow) # finally we move window to its position according to house and # impose it to it. Note that in order to purge area within window spans # option 'empty_holes=True' is used. hm.move_geom(window, 0.5, 0.4) house_final = hm.unite_grids(house_wtube, [(window, 0.05)], empty_holes=True) # now we can check quality of resulting grid by calculating its skewness skew = hm.skewness(house_final) print 'maximum skew value is %f' % skew['max_skew'] if (skew['ok']): print 'resulting grid has no bad cells' else: print '%i cells have large skew coefficient' % len(skew['bad_cells']) # save grid and contour with boundary features to vtk hm.export_grid_vtk(house_final, "house_grid.vtk") hm.export_contour_vtk(house_final, "house_contour.vtk") # ^^^^^^^^^^^^^^^^^^^^^^^^ if (not skew['ok']): raise Exception if (hm.info_contour(house_final)['btypes'] != {0: 122, 1: 25, 2: 77, 3: 160}): print hm.info_contour(house_final)['btypes'], 'vs' print {0: 122, 1: 25, 2: 77, 3: 160} raise Exception
# START OF EXAMPLE # mark b1, b2 as globals so binfo function can find them global b1, b2 # register boundary types b1 = hmscript.add_boundary_type(1, "vertical") b2 = hmscript.add_boundary_type(2, "horizontal") # create rectangular contours cont1 = hmscript.add_rect_contour([0, 0], [1, 1]) # mark contour using `btps` hmscript.set_boundary_type(cont1, btps=[b2, b1, b2, b1]) # same effect using `bfun` cont2 = hmscript.add_rect_contour([0, 0], [1, 1]) def binfo(x0, y0, x1, y1, bold): return b1 if x0 == x1 else b2 hmscript.set_boundary_type(cont2, bfun=binfo) # END OF EXAMPLE print "set_boundary_type example" hmscript.export_contour_vtk(cont1, "_c1.vtk") hmscript.export_contour_vtk(cont2, "_c2.vtk") f1, f2 = open("_c1.vtk", "r"), open("_c2.vtk", "r") if hash(f1.read()) != hash(f2.read()): raise Exception if (hmscript.info_contour(cont1)['btypes'] != {1: 2, 2: 2}): raise Exception
step_bl = 2. bstep = [step_bl, 0, step_main, 0.1, step_main, 0.9, step_bl, 1] bstep1 = [step_bl, 0, step_main, 0.1] bstep_main = [step_bl, 0, step_main, 0.05, step_main, 0.95, step_bl, 1] # boundary types binput_left1 = hm.add_boundary_type(1, "input_left1") binput_left2 = hm.add_boundary_type(2, "input_left2") binput_right1 = hm.add_boundary_type(3, "input_right1") binput_right2 = hm.add_boundary_type(4, "input_right2") boutput_left = hm.add_boundary_type(5, "output_left") boutput_right = hm.add_boundary_type(6, "output_right") # importing cont = hm.import_contour_hmc("../external_files/RRJ2.hmc") hm.export_contour_vtk(cont, "cont.vtk") # =characteristic points # lower bnd c = [None] * 100 c[0] = [-906.994, -42.374] c[1] = [2099.83, -33.8302] c[2] = [1913.45, 1508.89] c[3] = [-729.668, 1501.38] # upper bnd c[5] = [271.595, 1587.21] c[6] = [1124.28, 1589.55] c[7] = [1237.86, 2013.14] c[8] = [156.175, 2009.8] # left appendix line c[9] = [271.027, 1592.65]
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) c2 = hm.create_contour([p2, paft]) c2 = hm.partition_contour(c2, "ref_weights", [hhormin, 0, hblayer, 1], start=p2) [c3] = hm.extract_subcontours(g2, [p2, p1]) c4 = hm.create_contour([pbef, [pbef[0], 100]]) c5 = hm.create_contour([[paft[0], 100], paft])
hm.remove_geom([cont, grid]) angle += diff_ac if angle < op.range_angles[0] else diff print "doubly connected area: all outer" inner_cont = hm.add_rect_contour([0, 0], [1, 1], 1) outer_cont = hm.add_circ_contour([0, 0], 3, 16, 2) full_cont = hm.unite_contours([inner_cont, outer_cont]) op = hm.BoundaryGridOptions(full_cont, [0, 0.01, 0.02, 0.03, 0.04], 'left', 0.01) g5 = hm.build_boundary_grid(op) check_grid(g5, 11440, 20592, 9152, {4: 9152}) check_cont(g5, 4576, 4576, [400, 432, 1872, 1872], {0: 2304, 1: 400, 2: 1872}) print "doubly connected area: all inner" op.direction = 'right' g6 = hm.build_boundary_grid(op) hm.export_contour_vtk(full_cont, "_source6.vtk") hm.export_grid_vtk(g6, "_g6.vtk") hm.export_contour_vtk(g6, "_c6.vtk") check_grid(g6, 11280, 20304, 9024, {4: 9024}) check_cont(g6, 4512, 4512, [400, 368, 1872, 1872], {0: 2240, 1: 400, 2: 1872}) print "doubly connected area: only single contour" op.start_point = op.end_point = [0, 0] g7 = hm.build_boundary_grid(op) check_grid(g7, 1920, 3456, 1536, {4: 1536}) check_cont(g7, 768, 768, [400, 368], {0: 368, 1: 400}) check(len(hm.registered_contours()) == 4) check(len(hm.registered_grids()) == 7)
print "contour partition" i1 = hm.create_contour([[0, 0], [1, 0], [2, 1]]) i2 = hm.add_rect_contour([0, 0], [1, 1], [0, 1, 0, 0]) i3 = hm.add_circ_contour([0, 0], 1, 200) i4 = hm.create_contour([[0, 0], [0.5, 0], [1, 0], [1, 1]]) c1 = hm.partition_contour(i1, "const", 0.18) c2 = hm.partition_contour(i1, "const", 0.18, 180) check(hm.info_contour(c1)['Nedges'] == 14) check(hm.info_contour(c2)['Nedges'] == 13) c1 = hm.partition_contour(i2, "const", 0.18, 100) c2 = hm.partition_contour(i2, "const", 0.18, 100, True) check(hm.info_contour(c1)['Nedges'] == 24) check(hm.info_contour(c2)['Nedges'] == 23) hm.export_contour_vtk(c1, "c1.vtk") hm.export_contour_vtk(c2, "c2.vtk") c1 = hm.partition_contour(i1, "ref_points", [0.18, [0, 0]]) c2 = hm.partition_contour(i1, "ref_points", [0.01, [0, 0], 0.3, [1, 0]]) c3 = hm.partition_contour(i3, "ref_points", [0.01, [-1, -1], 0.3, [0, 1]]) check(hm.info_contour(c1)['Nedges'] == 14) check(hm.info_contour(c2)['Nedges'] == 17) check(hm.info_contour(c3)['Nedges'] == 74) c1 = hm.partition_contour(i4, "ref_points", [1.0, [0, 0], 1.0, [1, 0], 0.01, [1, 1]]) c2 = hm.partition_contour(i4, "ref_points", [1.0, [0, 0], 1.0, [1, 0], 0.01, [1, 1]], angle0=-1)