# 2) copy, replace and rotate to build left, right, bottom tubes. [tube_left, tube_right, tube_bot] = hm.copy_geom([tube_proto] * 3) hm.move_geom([tube_left, tube_right], 0.425, 1.0) hm.move_geom([tube_bot], 0.425, -0.5) hm.rotate_geom([tube_left], -45, [0.5, 0.5]) hm.rotate_geom([tube_right], 45, [0.5, 0.5]) # exclude pentagon from base grid cont5 = hm.create_contour([[0.3, 0.6], [0.35, 0.4], [0.65, 0.4], [0.7, 0.6], [0.5, 0.7], [0.3, 0.6]]) exsqr = hm.exclude_contours(sqr, [cont5], "inner") # ******* see fig2 # make series of grid superpositions with defined buffer sizes imposed = hm.unite_grids(exsqr, [(tube_left, 0.05), (tube_right, 0.05), (tube_bot, 0.1)]) # ******* see fig3 # create a boundary grid prototype around the pentagon. # 1) make partition of pentagon contour with constant step cont5 = hm.partition_contour(cont5, "const", 0.02) # 2) call build_boundary_grid1 procedure with explicitly defined perpendecular segmentation. bnd1 = hm.build_boundary_grid1(cont5, [0, 0.01, 0.02, 0.03], "right") # make final superposition res = hm.unite_grids(imposed, [(bnd1, 0.05)]) # ******* see fig4 # now we can see the result in paraview hm.export_grid_vtk(res, "pentagon.vtk")
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")
hmdbg.check(all(a == b for a, b in zip(zg3, hm.registered_grids3d()))) hmdbg.check(hm.registered_btypes() == [(0, 'default-boundary'), (15, 'boundary15')]) hm.load_project("../external_files/empty.hmp") print "export 2d to fluent" bleft = hm.add_boundary_type(1, "bleft") bright = hm.add_boundary_type(2, "bright") bbot = hm.add_boundary_type(3, "bbot") 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 "extrusion with only const boundary types" 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")
# I. Build body parts grids *************************************************** # build body contour as intersection of two circles circ1 = hm.add_circ_contour3([6, 0], [-6, 0], 0.08, ncirc) circ2 = hm.add_circ_contour3([-6, 0], [6, 0], 0.08, ncirc) bodyc = hm.clip_domain(circ1, circ2, "intersection") # assemble a prototype grid for body by attaching triangles to left and # right side of a rectangle. ntri, nspan = 12, 60 # vertical and horizontal partition of rectangle g3l = hm.add_triangle_grid([0, 0], [-0.5, 0.5], [0, 1], ntri) g3r = hm.add_triangle_grid([5, 0], [5.5, 0.5], [5, 1], ntri) g4 = hm.add_unf_rect_grid([0, 0], [5, 1], nspan, ntri) # Grids in triangle and rectangle areas have same partition at contact line # so we can simply unite them with zero buffer size gb = hm.unite_grids(g4, [(g3l, 0), (g3r, 0)]) # Map grid at hexagon area on body area so that points at the acute angles # of base grid contour be translated into acute angle vertices of body contour. # We use snap="no" since there is no need to preserve initial body contour # precisely. body = hm.map_grid(gb, bodyc, [[-0.5, 0.5], [5.5, 0.5]], [[-6, 0], [6, 0]], snap="no") # build tail area by clipping of three circle areas circ1 = hm.add_circ_contour3([0, 0], [-2, 2], 0.2, ncirc) circ2 = hm.add_circ_contour3([-2.5, -2.3], [0, 0], 0.1, ncirc) circ3 = hm.add_circ_contour3([-1.5, -1.8], [-2, 2], 0.2, ncirc) d1 = hm.clip_domain(circ1, circ2, "intersection") tailc = hm.clip_domain(d1, circ3, "difference") # using triangle as a prototype grid for mapping
b3pts.sort(key=lambda a: a[1]) b3pts_source = [[0., float(i) / nedges] for i in range(nedges + 1)] b3pts.append(p2) b3pts_source.append([1., 0.]) tri = hm.add_triangle_grid([0, 0], [1, 0], [0, 1], nedges) mesh_wake_trans = hm.map_grid( tri, region_wake_trans, b3pts_source, b3pts, snap="shift_vertices") # 5.3 meshing main wake region [b1, b2, b3, b4] = hm.extract_subcontours( region_wake_main, [p1, [Lx_wake_reg, 0.], [Lx_wake_reg, Ly_wake_reg], p2, p1]) [b4] = hm.extract_subcontours(mesh_wake_trans, [p1, p2]) b1 = hm.partition_contour(b1, "ref_weights", [step2, 0, step3, 1], start=p1) mesh_wake_main = hm.add_custom_rect_grid("orthogonal", b4, b1, b2, b3) # 5.4 connect all mesh_around = hm.unite_grids(mesh_wake_main, [(mesh_wake_trans, 0), (mesh_blay, 0)]) hm.reflect_geom([mesh_wake_trans, mesh_blay], [0, 0], [1, 0]) mesh_around = hm.unite_grids(mesh_around, [(mesh_wake_trans, 0), (mesh_blay, 0)]) # 5.5 bottom wake part cmesh_around = hm.grid_bnd_to_contour(mesh_around) p1 = hm.get_point(cmesh_around, vclosest=[hcyl / 2 + Lx2_rib_blay, -Ly]) p2 = [Lx_wake_reg, p1[1]] p3 = [p2[0], 0] p4 = [hcyl / 2 + Lx2_rib_blay, 0] [bl, bt] = hm.extract_subcontours(mesh_around, [p1, p4, p3]) bb = hm.create_contour([p1, p2]) br = hm.create_contour([p2, p3]) mesh_bot_wake = hm.add_custom_rect_grid("orthogonal", bt, bl, bb, br) mesh_around = hm.unite_grids(mesh_around, [(mesh_bot_wake, 0)])
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 "union of rect and ring" g1 = hm.add_unf_rect_grid([-1, -1], [1, 1], 10, 10) g2 = hm.add_unf_ring_grid([0, 0], 0.5, 0.8, 500, 7) hm.move_geom([g2], 0, 1) g3 = hm.unite_grids(g1, [(g2, 0.1)], empty_holes=False) 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")
# Build a background rectangular mesh and cut a house silhouette from it. # Now 'house' grid bears boundary features of 'house_cont' back_grid = hm.add_unf_rect_grid([0, 0], [1, 2], 50, 100) house = hm.exclude_contours(back_grid, house_cont, "outer") # A set of ugly cells near the roof appeared as a result of previous operation. # To get rid of 'em we build a short single layered boundary grid near the # roof section and make a union. 'roof' grid inherits its boundary types # from 'house_cont' which is its source and delivers 'em to 'house_wroof' object. oproof = hm.BoundaryGridOptions(house_cont, start_point=[1, 0.7], end_point=[0, 0.7], partition=[0, 0.01], bnd_step=0.02) roof = hm.build_boundary_grid([oproof]) house_wroof = hm.unite_grids(house, [(roof, 0.03)]) # Build a tube rectangle and set all boundary edges to 'Roof' type gtube = hm.add_unf_rect_grid([0, 0], [0.1, 0.3], 4, 16) hm.set_boundary_type(gtube, btube) hm.move_geom(gtube, 0.7, 0.9) # after combining of 'house_wroof' and 'gtube' the resulting grid # boundary edges will get their features from both parent grids house_wtube = hm.unite_grids(house_wroof, [(gtube, 0.05)]) # first we create an outer window frame by building an external # boundary grid around square contour win_cont = hm.add_rect_contour([-0.15, -0.15], [0.15, 0.15]) op1 = hm.BoundaryGridOptions(win_cont, bnd_step=0.02, direction='right') op1.uniform_partition(0.03, 2)
from hybmeshpack import hmscript as hm cn_bufsize = 0.100 dm_bufsize = 0.050 mr_min = [-3.500e+0, -5.000e+0] mr_max = [3.500e+0, 5.000e+0] mr_step = 0.050 with open("others/botscript1_adata/x1arr.dat") as f: x1arr = map(float, f.read().split()) with open("others/botscript1_adata/x2arr.dat") as f: x2arr = map(float, f.read().split()) cn = hm.add_unf_rect_grid([0, 0], [1, 1], 3, 3, x1arr, x2arr) mr = hm.add_unf_rect_grid(mr_min, mr_max, 13, 13, mr_step, mr_step) hm.export_grid_hmg([cn, mr], "op1.hmg") cn = hm.unite_grids(cn, [(mr, cn_bufsize)], False, False, 0, "4") dpath = "others/botscript1_adata/" files = ["000.msh", "001.msh", "002.msh", "003.msh", "004.msh"] for f in files: print(f) dimple = hm.import_grid_gmsh(dpath + f) hm.export_grid_hmg([cn, dimple], "op" + f[:3] + ".hmg") cn = hm.unite_grids(cn, [(dimple, dm_bufsize)], False, False, 0, "4") hm.export_grid_vtk(cn, "g1.vtk")
keep_pts=[[286.399, 1647.06], [231.428, 1608.5]]) b1 = hm.unite_contours([b1, b2]) bgo = hm.BoundaryGridOptions(b1, bs, "left", 3 * step_bl, "no", start_point=c[10], end_point=c[9]) g41 = hm.build_boundary_grid(bgo) ctri = hm.clip_domain(b1, g41, "difference", False) [c1, c2] = hm.extract_subcontours(ctri, [c[9], c[10], c[9]]) c1 = hm.partition_contour(c1, "const", 4 * step_bl) ctri = hm.unite_contours([c1, c2]) g42 = hm.triangulate_domain(ctri, fill='4') g4 = hm.unite_grids(g41, [(g42, 0)]) # right appendix: g5 g5 = hm.map_grid(g4, c_rappendix, [c[9], c[10], [231.5, 1608.5], [286.399, 1647.06]], [c[11], c[12], [1164, 1611], [1109.88, 1649.44]], "no", "vertex", is_reversed=True) # left input: g6 p1 = hm.get_point(c_bot, vclosest=[-592.302, 1483.16]) p2 = hm.get_point(c_bot, vclosest=[-601.99, 1483.13]) [c1] = hm.extract_subcontours(c_bot, [c[16], c[15]]) [cr, ct, cl] = hm.extract_subcontours(c1, [c[16], p1, p2, c[15]], "vertex")
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) c2 = hm.create_contour([p2, paft]) c2 = hm.partition_contour(c2, "ref_weights", [hhormin, 0, hblayer, 1],
foilgrid_bo.incremental_partition(0.002, 1.5, 7) foilgrid = hm.build_boundary_grid(foilgrid_bo) # === boundary grid around vortex generator vgen = hm.add_circ_contour([0.25, 0.12], 0.015, 32, bcirc) # build boundary grid vgen_bo = hm.BoundaryGridOptions(vgen, direction="right", bnd_step=0.006, bnd_stepping="const") vgen_bo.incremental_partition(0.002, 1.2, 4) vgengrid = hm.build_boundary_grid(vgen_bo) hm.heal_grid(vgengrid) # get rid of hanging boundary nodes # === union res2d = hm.unite_grids(substrate, [(foilgrid, 0.02), (vgengrid, 0.02)], True) # === wake region # mesh resolution in the wake region of vortex generator is not fine enough. # So we apply a patch grid to this region. vgen_wakegrid = hm.add_unf_rect_grid([0.3, 0.09], [0.4, 0.15], 10, 7) res2d = hm.unite_grids(res2d, [(vgen_wakegrid, 0.02)], True) # check if final 2d is fine and stop script if there are bad cells if not hm.skewness(res2d)['ok']: raise Exception("2d grid contains highly skewed cells") # === 3d grid # Since we intend to set periodic conditions on z-faces there is no # need to refine grid towards them. So we use uniform grid in z direction zmin, zmax, nz = -1.0, 1.0, 20
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